get humidity data and send to LoRa gateway
Dependencies: mbed X_NUCLEO_IKS01A2
main.cpp
- Committer:
- reversi
- Date:
- 2020-04-22
- Revision:
- 0:5b9fdd76a7d6
- Child:
- 1:73299b677405
File content as of revision 0:5b9fdd76a7d6:
#include "mbed.h" #include "XNucleoIKS01A2.h" int main() { Serial pc(PA_2, PA_3, 115200); XNucleoIKS01A2* board = XNucleoIKS01A2::instance(D14, D15, D4, D5); HTS221Sensor *ht_sensor = board->ht_sensor; pc.printf("Initialization..\r\n"); uint8_t id; int error_code = ht_sensor->read_id(&id); if (error_code != 0) { pc.printf("Error %d reading sensor ID\r\n", error_code); return 1; } pc.printf("Connected to sensor with ID 0x%x\r\n", id); if (ht_sensor->enable() != 0) { pc.printf("Error enabling the ht sensor\r\n"); return 2; } if (ht_sensor->set_odr(1.0f) != 0) { pc.printf("Error setting ODR\r\n"); return 3; } while(1) { float humidity = 0, temperature = 0; if (ht_sensor->get_humidity(&humidity) != 0) pc.printf("Error reading humidity\r\n"); else pc.printf("Humidity [%%]\t\t%f\r\n", humidity); if (ht_sensor->get_temperature(&temperature) != 0) pc.printf("Error reading temperature\r\n"); else pc.printf("Temperature ['C]\t%f\r\n", temperature); pc.printf("\r\n"); wait(1); } }