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).
Revision 0:214ec6f2cde1, committed 2016-07-28
- Comitter:
- davidnicholai
- Date:
- Thu Jul 28 20:59:39 2016 +0000
- Commit message:
- Working perfectly, no errors. ;
Changed in this revision
diff -r 000000000000 -r 214ec6f2cde1 DHT22.lib --- /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
diff -r 000000000000 -r 214ec6f2cde1 main.cpp --- /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
diff -r 000000000000 -r 214ec6f2cde1 mbed.bld --- /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