A library for the use of DHT11, a temperature and humidity sensor

Dependents:   HTTP_SERVER2 lightweight-weather-station

Revision:
8:160047ca45bf
Parent:
7:50f5c8efd967
Child:
9:056d1e9b428c
--- a/DHT11.cpp	Wed Sep 10 17:48:35 2014 +0000
+++ b/DHT11.cpp	Wed Sep 10 18:00:31 2014 +0000
@@ -36,13 +36,13 @@
         return BUS_BUSY;
     }
 
-    // Sending start signal
+    // Sending start signal, low signal for 20 ms
     io.output();
     t.reset();
     t.start();
     do {
         io = 0;
-    } while (t.read_ms() < 18);
+    } while (t.read_ms() < 20);
     io = 1;
     io.input();
 
@@ -72,7 +72,6 @@
     do {} while (io == 1);
 
     // Starting the pulse width sensing
-
     io_irq.enable_irq();
 
     do {
@@ -89,8 +88,6 @@
              + ((data & 0x0000ff0000) >> 16)
              + ((data & 0x000000ff00) >> 8);
     if (chksum != (data & 0x00000000ff)) {
-        io.input();
-        io = 1;
         return CHKSUM_ERR;
     } else {
         t.reset();
@@ -148,10 +145,10 @@
     // Disabling the interruptions
     io_irq.disable_irq();
 
-    // Reading the length of
+    // Reading the positive pulse width
     t_pulse_us = t.read_us();
 
-    // Detecting 0 if the pulse width ranges from 26 us to 28 us
+    // Detecting 0 if the pulse width ranges from 20 us to 30 us
     if (20 <= t_pulse_us && t_pulse_us <= 30) {
         // Shifting the data buffer and not adding 1 (because this bit is zero)
         data = data << 1;
@@ -160,7 +157,7 @@
         cnt++;
     }
 
-    // Detecting 1 if the pulse width ranges from 68 us to 72 us
+    // Detecting 1 if the pulse width ranges from 60 us to 80 us
     else if (60 <= t_pulse_us && t_pulse_us <= 80) {
         // Shifting the data buffer and adding 1 (because this bit is one)
         data = data << 1;