Temp and Humidity sensor device driver.

Dependents:   temp_hum IAC_send Smart_Home_sensors

Fork of DHT by Components

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Sat May 28 11:11:34 2016 +0000
Parent:
2:df22ddf10d75
Commit message:
Remove warnings about implicit conversion from float to double and unify DHT11 and DHT22 init command sequence

Changed in this revision

DHT.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r df22ddf10d75 -r 6937e130feca DHT.cpp
--- a/DHT.cpp	Fri Aug 15 20:55:43 2014 +0000
+++ b/DHT.cpp	Sat May 28 11:11:34 2016 +0000
@@ -77,13 +77,12 @@
     // start the transfer
     DHT_io.output();
     DHT_io = 0;
-    // only 500uS for DHT22 but 18ms for DHT11
-    (_DHTtype == 11) ? wait_ms(18) : wait(1);
+    wait_ms(18);
     DHT_io = 1;
     wait_us(30);
     DHT_io.input();
     // wait till the sensor grabs the bus
-    if (ERROR_NONE != stall(DHT_io, 1, 40)) {
+    if (ERROR_NONE != stall(DHT_io, 1, 100)) {
         return ERROR_NOT_PRESENT;
     }
     // sensor should signal low 80us and then hi 80us
@@ -166,22 +165,22 @@
 
 float DHT::ConvertCelciustoKelvin(float const celsius)
 {
-    return celsius + 273.15;
+    return celsius + 273.15f;
 }
 
 // dewPoint function NOAA
 // reference: http://wahiduddin.net/calc/density_algorithms.htm
 float DHT::CalcdewPoint(float const celsius, float const humidity)
 {
-    float A0= 373.15/(273.15 + celsius);
+    float A0= 373.15f/(273.15f + celsius);
     float SUM = -7.90298 * (A0-1);
-    SUM += 5.02808 * log10(A0);
-    SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
+    SUM += 5.02808f * log10(A0);
+    SUM += -1.3816e-7 * (pow(10, (11.344f*(1-1/A0)))-1) ;
     SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
     SUM += log10(1013.246);
     float VP = pow(10, SUM-3) * humidity;
-    float T = log(VP/0.61078);   // temp var
-    return (241.88 * T) / (17.558-T);
+    float T = log(VP/0.61078f);   // temp var
+    return (241.88f * T) / (17.558f-T);
 }
 
 // delta max = 0.6544 wrt dewPoint()