Skip to content
Browse files

Version 0.4

  • Loading branch information...
1 parent 027d2de commit a655c6299b019cf53173139dad824466486591c8 @nethoncho committed
Showing with 60 additions and 16 deletions.
  1. +14 −4 DHT22.cpp
  2. +4 −0 README
  3. +33 −12 examples/Serial/Serial.pde
  4. +9 −0 keywords.txt
View
18 DHT22.cpp
@@ -20,6 +20,10 @@
Humidity and Temperature Sensor DHT22 info found at
http://www.sparkfun.com/products/10167
+Version 0.4: 24-Jan-2011 by Ben Adams
+Added return code constants to keywords.txt
+Returns DHT_ERROR_CHECKSUM on check sum mismatch
+
Version 0.3: 17-Jan-2011 by Ben Adams
This version reads data
Needs check sum code added at the end of readData
@@ -76,7 +80,7 @@ DHT22_ERROR_t DHT22::readData()
uint8_t bitTimes[DHT22_DATA_BIT_COUNT];
int currentHumidity;
int currentTemperature;
- uint8_t checkSum;
+ uint8_t checkSum, csPart1, csPart2, csPart3, csPart4;
unsigned long currentTime;
int i;
@@ -209,9 +213,15 @@ DHT22_ERROR_t DHT22::readData()
_lastTemperature = float(currentTemperature) / 10.0;
}
- // TODO: Test the checksum and return DHT_ERROR_CHECKSUM if bad
-
- return DHT_ERROR_NONE;
+ csPart1 = currentHumidity >> 8;
+ csPart2 = currentHumidity & 0xFF;
+ csPart3 = currentTemperature >> 8;
+ csPart4 = currentTemperature & 0xFF;
+ if(checkSum == ((csPart1 + csPart2 + csPart3 + csPart4) & 0xFF))
+ {
+ return DHT_ERROR_NONE;
+ }
+ return DHT_ERROR_CHECKSUM;
}
float DHT22::getHumidity()
View
4 README
@@ -4,6 +4,10 @@
Humidity and Temperature Sensor DHT22 info found at
http://www.sparkfun.com/products/10167
+Version 0.4: 24-Jan-2011 by Ben Adams
+Added return code constants to keywords.txt
+Returns DHT_ERROR_CHECKSUM on check sum mismatch
+
Version 0.3: 17-Jan-2011 by Ben Adams
This version reads data
Needs check sum code added at the end of readData
View
45 examples/Serial/Serial.pde
@@ -21,18 +21,39 @@ void loop(void)
delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
- if(errorCode == DHT_ERROR_NONE)
+ switch(errorCode)
{
- Serial.print("Got Data ");
- Serial.print(myDHT22.getTemperatureC());
- Serial.print("C ");
- Serial.print(myDHT22.getHumidity());
- Serial.println("%");
- }
- else
- {
- Serial.print("Error Code ");
- Serial.print(errorCode);
- Serial.println(" readData Failed");
+ case DHT_ERROR_NONE:
+ Serial.print("Got Data ");
+ Serial.print(myDHT22.getTemperatureC());
+ Serial.print("C ");
+ Serial.print(myDHT22.getHumidity());
+ Serial.println("%");
+ break;
+ case DHT_ERROR_CHECKSUM:
+ Serial.print("check sum error ");
+ Serial.print(myDHT22.getTemperatureC());
+ Serial.print("C ");
+ Serial.print(myDHT22.getHumidity());
+ Serial.println("%");
+ break;
+ case DHT_BUS_HUNG:
+ Serial.println("BUS Hung ");
+ break;
+ case DHT_ERROR_NOT_PRESENT:
+ Serial.println("Not Present ");
+ break;
+ case DHT_ERROR_ACK_TOO_LONG:
+ Serial.println("ACK time out ");
+ break;
+ case DHT_ERROR_SYNC_TIMEOUT:
+ Serial.println("Sync Timeout ");
+ break;
+ case DHT_ERROR_DATA_TIMEOUT:
+ Serial.println("Data Timeout ");
+ break;
+ case DHT_ERROR_TOOQUICK:
+ Serial.println("Polled to quick ");
+ break;
}
}
View
9 keywords.txt
@@ -25,3 +25,12 @@ clockReset KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
+
+DHT_ERROR_NONE LITERAL1
+DHT_BUS_HUNG LITERAL1
+DHT_ERROR_NOT_PRESENT LITERAL1
+DHT_ERROR_ACK_TOO_LONG LITERAL1
+DHT_ERROR_SYNC_TIMEOUT LITERAL1
+DHT_ERROR_DATA_TIMEOUT LITERAL1
+DHT_ERROR_CHECKSUM LITERAL1
+DHT_ERROR_TOOQUICK LITERAL1

0 comments on commit a655c62

Please sign in to comment.
Something went wrong with that request. Please try again.