From c7c5bdf661e98bb61688d1a4b2f4162a11ea146e Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sun, 29 Sep 2013 12:35:28 +0200 Subject: [PATCH] + finalized support for DHT21 + made TIMEOUT depends on clock ==> F_CPU --- libraries/DHTlib/dht.cpp | 26 ++----------------- .../{dht_test1.pde => dht_test1.ino} | 5 ++-- 2 files changed, 5 insertions(+), 26 deletions(-) rename libraries/DHTlib/examples/dht_test1/{dht_test1.pde => dht_test1.ino} (96%) diff --git a/libraries/DHTlib/dht.cpp b/libraries/DHTlib/dht.cpp index 5237f3d0..c4d31267 100644 --- a/libraries/DHTlib/dht.cpp +++ b/libraries/DHTlib/dht.cpp @@ -22,7 +22,7 @@ #include "dht.h" -#define TIMEOUT 10000 +#define TIMEOUT (F_CPU/1600) // unsigned int in code, for higher CPU speeds this might exceed MAXINT. ///////////////////////////////////////////////////// // @@ -62,29 +62,7 @@ int dht::read11(uint8_t pin) // DHTLIB_ERROR_TIMEOUT int dht::read21(uint8_t pin) { - // READ VALUES - int rv = read(pin); - if (rv != DHTLIB_OK) - { - humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? - temperature = DHTLIB_INVALID_VALUE; // invalid value - return rv; // propagate error value - } - - // CONVERT AND STORE - humidity = bits[0] + bits[1] * 0.00390625; // == 1/256.0 - temperature = (bits[2] & 0x7F) + bits[3] * 0.00390625; - - if (bits[2] & 0x80) // negative temperature - { - temperature = -temperature; - } - - // TEST CHECKSUM - uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3]; - if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; - - return DHTLIB_OK; + return read22(pin); // dataformat identical to DHT22 } // return values: diff --git a/libraries/DHTlib/examples/dht_test1/dht_test1.pde b/libraries/DHTlib/examples/dht_test1/dht_test1.ino similarity index 96% rename from libraries/DHTlib/examples/dht_test1/dht_test1.pde rename to libraries/DHTlib/examples/dht_test1/dht_test1.ino index 9e23834a..a60460e1 100644 --- a/libraries/DHTlib/examples/dht_test1/dht_test1.pde +++ b/libraries/DHTlib/examples/dht_test1/dht_test1.ino @@ -13,7 +13,8 @@ dht DHT; #define DHT11_PIN 4 -#define DHT22_PIN 5 +#define DHT21_PIN 5 +#define DHT22_PIN 6 void setup() { @@ -55,7 +56,7 @@ void loop() // READ DATA Serial.print("DHT21, \t"); - int chk = DHT.read21(DHT21_PIN); + chk = DHT.read21(DHT21_PIN); switch (chk) { case DHTLIB_OK: