Temperature and humidity example for NXP rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011 .

Dependencies:   AMS_ENS210_temp_humid_sensor

Files at this revision

API Documentation at this revision

Comitter:
batman52
Date:
Tue Dec 03 18:50:24 2019 +0000
Parent:
79:0431b9fd3dc0
Commit message:
first example of temperature and humidity senor for NXP Rapid iot Prototyping kit

Changed in this revision

AMS_ENS210_temp_humid_sensor.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AMS_ENS210_temp_humid_sensor.lib	Tue Dec 03 18:50:24 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/batman52/code/AMS_ENS210_temp_humid_sensor/#e121ac861a82
--- a/main.cpp	Sat Nov 23 18:03:20 2019 +0000
+++ b/main.cpp	Tue Dec 03 18:50:24 2019 +0000
@@ -1,32 +1,41 @@
 #include "mbed.h"
+#include "AMS_ENS210.h"
 
-DigitalOut rgb_red(LED_RED, 1);       //     LED1 = LED_RED,  1 --> OFF, 0 --> ON
-DigitalOut rgb_blue(LED_BLUE, 1);     //     LED3 = LED_BLUE, 1 --> OFF, 0 --> ON
-DigitalOut rgb_green(PTE7,1);         //                      1 --> OFF, 0 --> ON
+#define WAIT() wait(0.2)
 
-void rgb_sel(int8_t idx) {
+AMS_ENS210 temphumid(I2C_SDA, I2C_SCL);
 
-switch(idx) {
-                case 0:
-                    rgb_red = 0; rgb_blue=1; rgb_green = 1;
-                    break;
-                case 1:
-                    rgb_red = 1; rgb_blue=0; rgb_green = 1;
-                    break;
-                case 2:
-                    rgb_red = 1; rgb_blue=1; rgb_green = 0;
-                    break;
-            }
-    
+void read_temperature(void)
+{
+    temphumid.init();
+    WAIT();
+    temphumid.start(true);
+    WAIT();
+    while(!temphumid.temp_has_data());
+      // printf("Wait for temperature read!\n\r");
+    temphumid.stop(true);
+    WAIT();
+    printf("Temp: %d [C]\r\n", ((temphumid.temp_read() >> 6)-273) );
+}
+
+void read_humidity(void)
+{
+    temphumid.init();
+    WAIT();
+    temphumid.start(false,true);
+    WAIT();
+    while(!temphumid.humid_has_data());      
+    temphumid.stop(false,true);
+    WAIT();
+    printf("Humidity: %d [%]\r\n", ( temphumid.humid_read() >> 9) );
 }
 
 // main() runs in its own thread in the OS
 int main() {
-    int idx;
     while (true) {
-        for(idx=0;idx<3;idx++) {
-            rgb_sel(idx);
-            wait(0.5);
-        }        
+        read_temperature();
+        WAIT();          
+        read_humidity();
+        WAIT();        
     }
 }
\ No newline at end of file