A simple working example showing the usage of Stefan Nielsen's DHT22 library. I found this library to be much more stable than the more often used DHT.h library. My thanks also to mohamedgamal for his initial draft of this code (which is more than servicable in and of itself).

Dependencies:   DHT22 mbed

Files at this revision

API Documentation at this revision

Comitter:
davidnicholai
Date:
Thu Jul 28 20:59:39 2016 +0000
Commit message:
Working perfectly, no errors. ;

Changed in this revision

DHT22.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT22.lib	Thu Jul 28 20:59:39 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Julepalme/code/DHT22/#7fd3ff04ae95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 28 20:59:39 2016 +0000
@@ -0,0 +1,19 @@
+
+#include "mbed.h"
+#include "DHT22.h"
+DHT22 dht22(PB_7);
+int main() {
+    double hum;
+    double temp;
+    
+    printf("\r\nSetting up...\r\n");
+    
+    while (1) {
+        dht22.sample() ;
+        hum=dht22.getHumidity()/10.0;
+        temp=dht22.getTemperature()/10.0;
+        printf("temperature: %3.1f, humidity: %3.1f\n\r",temp,hum);
+        wait(2);
+    }
+}
+            
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 28 20:59:39 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f9eeca106725
\ No newline at end of file