int main(void) { hdc1000_t dev; uint16_t rawtemp, rawhum; int temp, hum; puts("HDC1000 Temperature and Humidity Sensor driver test application\n"); printf("Initializing HDC1000 sensor at I2C_%i... ", TEST_HDC1000_I2C); if (hdc1000_init(&dev, TEST_HDC1000_I2C, TEST_HDC1000_ADDR) == 0) { puts("[OK]\n"); } else { puts("[Failed]"); return -1; } while (1) { if (hdc1000_startmeasure(&dev)) { puts("Start measure failed."); return -1; } vtimer_usleep(HDC1000_CONVERSION_TIME); hdc1000_read(&dev, &rawtemp, &rawhum); printf("Raw data T: %5i RH: %5i\n", rawtemp, rawhum); hdc1000_convert(rawtemp, rawhum, &temp, &hum); printf("Data T: %d RH: %d\n", temp, hum); vtimer_usleep(SLEEP); } return 0; }
static void send_update(size_t pos, char *buf) { uint32_t pressure; uint16_t rawtemp, rawhum; int temp, hum, temp_abs, hum_abs, pressure_abs; uint8_t status; tcs37727_data_t light_data; hdc1000_read(&th_dev, &rawtemp, &rawhum); hdc1000_convert(rawtemp, rawhum, &temp, &hum); temp_abs = temp / 100; hum_abs = hum / 100; temp -= temp_abs * 100; hum -= hum_abs * 100; mpl3115a2_read_pressure(&p_dev, &pressure, &status); pressure_abs = pressure / 100000; pressure -= pressure_abs * 100000; //mpl3115a2_read_temp(&p_dev, &temp); tcs37727_read(&light_dev, &light_data); pos += sprintf(&buf[pos], "{\"n\":\"s:temp\", \"u\":\"°C\", \"v\":\"%2i.%03i\"},", temp_abs, temp); pos += sprintf(&buf[pos], "{\"n\":\"s:hum\", \"u\":\"%%RH\", \"v\":\"%2i.%03i\"},", hum_abs, hum); pos += sprintf(&buf[pos], "{\"n\":\"s:pres\", \"u\":\"bar\", \"v\":\"%2i.%03i\"},", pressure_abs, (unsigned int) pressure); pos += sprintf(&buf[pos], "{\"n\":\"s:rgb\", \"u\":\"RGB\", \"v\":\"[%"PRIu32", %"PRIu32", %"PRIu32"]\"}]", light_data.red, light_data.green, light_data.blue); hdc1000_startmeasure(&th_dev); send_coap_post((uint8_t *)buf, pos); }
int main(void) { hdc1000_t dev; int16_t temp, hum; size_t len; char tstr[8]; char hstr[8]; puts("HDC1000 Temperature and Humidity Sensor driver test application\n"); printf("Initializing HDC1000 sensor at I2C_DEV(%i)... ", (int)hdc1000_params[0].i2c); if (hdc1000_init(&dev, &hdc1000_params[0]) == HDC1000_OK) { puts("[OK]\n"); } else { puts("[Failed]"); return 1; } while (1) { hdc1000_read(&dev, &temp, &hum); len = fmt_s16_dfp(tstr, temp, 2); tstr[len] = '\0'; len = fmt_s16_dfp(hstr, hum, 2); hstr[len] = '\0'; printf("Reading: T: %s °C RH: %s %%\n", tstr, hstr); xtimer_usleep(SLEEP); } return 0; }
/** * @brief Measures the temperature and humitity with a HDC1000. * * @param[out] temp the measured temperature in degree celsius * 100 * @param[out] hum the measured humitity in % * 100 */ void hdc1000_measure(int *temp, int *hum) { uint16_t rawtemp; uint16_t rawhum; if (hdc1000_startmeasure(&hdcDev)) { puts("[sensors] ERROR: HDC1000 starting measure failed"); return; } // wait for the measurment to finish xtimer_usleep(HDC1000_CONVERSION_TIME); //26000us hdc1000_read(&hdcDev, &rawtemp, &rawhum); hdc1000_convert(rawtemp, rawhum, temp, hum); printf("[sensors] INFO: HDC1000 Data T: %d RH: %d\n", *temp, *hum); }