Hello World program for HYT temp & humidity sensor
Hello Word program for HYT temp & humidity sensor library. MCU perform polling and then sends data to PC via serial interface once a second.
Connection
Remember to use pull-up resisrors to communicate with sensor by I2C
Revision 0:cd8ba9e5f346, committed 2016-09-14
- Comitter:
- Ksenia
- Date:
- Wed Sep 14 15:54:13 2016 +0000
- Commit message:
- Initial commit
Changed in this revision
diff -r 000000000000 -r cd8ba9e5f346 HYT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HYT.lib Wed Sep 14 15:54:13 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/Ksenia/code/HYT/#cb02bfe8cf44
diff -r 000000000000 -r cd8ba9e5f346 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 14 15:54:13 2016 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "HYT.h" + +Serial pc(USBTX, USBRX); +Ticker timeKeeping; +// for SLSTK3400A board +HYT SENSOR (PD6, PD7); // sda, scl +// for WIZwiki-W7500P board +//HYT SENSOR (D14, D15); // sda, scl +// for ATSAMD21-XPRO board +//HYT SENSOR (PA08, PA09); // sda, scl + + +// HYT sensor polling cycle +void dataUpdate(void) +{ + SENSOR.MRCommand(); + wait_ms(100); + SENSOR.DFCommand(); +} + +void secondsCallback(void) { + pc.printf("Humidity level: %.1f\r\n%", SENSOR.humidity); + pc.printf("Temperature level: %.1f\r\n%", SENSOR.temperature); + pc.printf("-------------------------------\r\n%", SENSOR.temperature); +} + +int main() +{ + timeKeeping.attach(&secondsCallback, 1.0f); + while(1) { + dataUpdate(); + } +} \ No newline at end of file
diff -r 000000000000 -r cd8ba9e5f346 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 14 15:54:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file