int main() { /* --------- MQ303A EXAMPLE -------- */ mq303a_context dev = mq303a_init(0, 15); printf("init done for mq303a\n"); int value; mq303a_heater_enable(dev, true); upm_delay(12); while(1){ mq303a_get_value(dev, &value); printf("returned value: %d\n", value); upm_delay(1); } return 0; }
int main(int argc, char **argv) { signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a BME280 instance using default i2c bus and // address. We use the BMP280 driver to do all of our work, since // the BMP280 and the BME280 are identical except for the fact // that the BME280 includes a humidity sensor. bmp280_context sensor = bmp280_init(BME280_DEFAULT_I2C_BUS, BME280_DEFAULT_ADDR, -1); if (!sensor) { printf("bmp280_init() failed\n"); return 1; } // For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS: // bmp280_init(BME280_DEFAULT_SPI_BUS, // -1, 10) while (shouldRun) { // update our values from the sensor if (bmp280_update(sensor)) { printf("bmp280_update() failed\n"); bmp280_close(sensor); return 1; } printf("Compensation Temperature: %f C\n", bmp280_get_temperature(sensor)); printf("Pressure: %f Pa\n", bmp280_get_pressure(sensor)); printf("Computed Altitude: %f m\n", bmp280_get_altitude(sensor)); printf("Relative Humidity: %f %%\n\n", bmp280_get_humidity(sensor)); upm_delay(1); } //! [Interesting] printf("Exiting...\n"); bmp280_close(sensor); return 0; }
int main(int argc, char **argv) { signal(SIGINT, sig_handler); //! [Interesting] printf("Initializing...\n"); // Instantiate an DS18B20 instance using the uart 0 ds18b20_context sensor = ds18b20_init(0); if (!sensor) { printf("ds18b20_init() failed.\n"); return(1); } printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor)); // update and print available values every second while (shouldRun) { // update our values for all sensors ds18b20_update(sensor, -1); int i; for (i=0; i<ds18b20_devices_found(sensor); i++) { printf("Device %02d: Temperature: %f C\n", i, ds18b20_get_temperature(sensor, i)); } printf("\n"); upm_delay(2); } printf("Exiting...\n"); ds18b20_close(sensor); //! [Interesting] return 0; }
upm_result_t bno055_reset_system(const bno055_context dev) { assert(dev != NULL); if (bno055_set_page(dev, 0, false)) return UPM_ERROR_OPERATION_FAILED; uint8_t reg = 0; if (bno055_read_reg(dev, BNO055_REG_SYS_TRIGGER, ®)) return UPM_ERROR_OPERATION_FAILED; reg |= BNO055_SYS_TRIGGER_RST_SYS; if (bno055_write_reg(dev, BNO055_REG_SYS_TRIGGER, reg)) return UPM_ERROR_OPERATION_FAILED; upm_delay(1); return UPM_SUCCESS; }
upm_result_t es9257_set_angle(es9257_context dev, int32_t angle){ if(ES9257_MAX_ANGLE < angle || angle < 0){ printf("The angle specified is either above the max angle or below 0"); return UPM_ERROR_UNSPECIFIED; } printf("setting angle to: %d\n", angle); mraa_pwm_enable(dev->pwm, 1); mraa_pwm_period_us(dev->pwm, ES9257_PERIOD); int32_t val = 0; es9257_calc_pulse_travelling(dev, &val, angle); mraa_pwm_pulsewidth_us(dev->pwm, val); upm_delay(1); mraa_pwm_enable(dev->pwm, 0); return UPM_SUCCESS; }
int main() { signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a HKA5 sensor on uart 0. We don't use the set or // reset pins, so we pass -1 for them. hka5_context sensor = hka5_init(0, -1, -1); if (!sensor) { printf("hka5_init() failed.\n"); return 1; } // update once every 2 seconds and output data while (shouldRun) { if (hka5_update(sensor) != UPM_SUCCESS) { printf("hka5_update() failed, exiting.\n"); shouldRun = false; } printf("PM 1 : %d ug/m3\n", hka5_get_pm1(sensor)); printf("PM 2.5: %d ug/m3\n", hka5_get_pm2_5(sensor)); printf("PM 10 : %d ug/m3\n", hka5_get_pm10(sensor)); printf("\n"); upm_delay(2); } //! [Interesting] printf("Exiting\n"); hka5_close(sensor); return 0; }
int main() { mpr121_context dev = mpr121_init(MPR121_I2C_BUS, MPR121_DEFAULT_I2C_ADDR); if(mpr121_config_an3944(dev) != UPM_SUCCESS){ printf("unable to configure device\n"); } uint32_t states; while(1){ if(mpr121_read_buttons(dev, &states, 0) != UPM_SUCCESS){ printf("Error while reading button values\n"); } printf("retrieved button states: %d\n", states); upm_delay(1); } mpr121_close(dev); printf("all done!!\n"); return 0; }
int main() { signal(SIGINT, sig_handler); //! [Interesting] // Instantiate a SHT1X sensor using D2 as the clock, and D3 as the // data pin. sht1x_context sensor = sht1x_init(2, 3); if (!sensor) { printf("sht1x_init() failed.\n"); return 1; } // Every 2 seconds, update and print values while (shouldRun) { if (sht1x_update(sensor)) { printf("sht1x_update() failed, exiting.\n"); break; } printf("Temperature: %f C\n", sht1x_get_temperature(sensor)); printf("Humidity: %f RH\n", sht1x_get_humidity(sensor)); printf("\n"); upm_delay(2); } //! [Interesting] printf("Exiting\n"); sht1x_close(sensor); return 0; }