DTH22, RHT03 and DTH11 sensors can be read with this code!

This DHT22 sensor reading class works with the mbed LPC1768. The code is time dependent but has been tested with mbed LPC1768 currently. I may add timing defines for other platforms if needed but i currently only use the mbed LPC1768 platform. Please feel free to import the code and modify it for other platforms if needed. BITREADTIME define and STARTTRANSBITSIZE define would be the main items to change for any other platform to operate properly. BITREADTIME is the us time value used in a basic look for a wait value to get next reading. This may work simply on other platforms at other system speeds but it may not. A more general solution maybe to add another calculation that generates these defines based on some platform speed value. At this writing the code performs very well with little to no read failures(in fact i have not seen a read failure yet in testing). The issues that i have seen with other classes and this sensor is the fact that the sensor always produces the correct Temperature and Humidity output values on the io pin but the class reading these values miss many reading causing errors. This class avoids this because it reads the output from the DTH22 sensor completely and then processes the values from a run length bit measurement perspective that i feel is far more accurate. Anyways the results speak for them self.

I have now added a member function for reading the DTH11 sensor as it is read the same way as the DTH22 sensor. The only difference is the final use of the retrieved bytes from the sensor for calculating the temperature and humidity. Note the DTH11 sensor has less range and less accuracy but it also can be found for less money!

Revision:
3:57c9abcd9646
Parent:
2:4d307eacba27
Child:
4:85dd45e5ab32
--- a/DTH22.h	Tue Dec 03 09:09:07 2013 +0000
+++ b/DTH22.h	Tue Dec 03 09:14:49 2013 +0000
@@ -38,14 +38,14 @@
  * @code
  * // show how the DTH22_RHT03 class works
  * #include "mbed.h"
- * #include "DTH22_RHT03.h"
+ * #include "DTH22.h"
  * int main()
  * {
  *
  *  int temp ;
  *  int humidity;
  *  int error ;
- *  DTH22_RHT03 myhumtemp(p24);
+ *  DTH22 myhumtemp(p24);
  *  while(1) {
  *      error = myhumtemp.getTH(&temp,&humidity);
  *      printf("Temp is %ld\r\n",temp);
@@ -91,15 +91,14 @@
     * @param returns 0 for no errors.  Any other number is some type of communication error and data might not be valid!
     */
     int getTH(int *temp,int *humidity);    // get both temperature and pressure fully compensated values! Note this only returns when measurements are complete
-    int testing(bool *bits,signed short int *data,int *temp,int *humidity);
-    
+
 protected:
     DigitalInOut DTH22pin;
     bool rawdata[MAXRAWDATA];
     unsigned short int timingData[100];
-    //int temperature, humidity, checksum;
     bool rawdatabits[DATABITS];
-    
+
+    int testing(bool *bits,signed short int *data,int *temp,int *humidity);
     void getraw();
     void getrawbits();
     int transistionCount(int index);