=DHT22 Temperature and Humidity Sensor= The DHT-22 is a low cost humidity and temperature sensor with a single wire digital interface. The sensor is calibrated and doesn\\\'t require extra components so you can get right to measuring relative humidity and temperature. [[http://dlnmh9ip6v2uc.cloudfront.net/images/products/10167-01_i_ma.jpg]] Features: * 3.3-6V Input * 1-1.5mA measuring current * 40-50 uA standby current * Humidity from 0-100% RH * -40 - 80 degrees C temperature range * +-2% RH accuracy * +-0.5 degrees C ***(same as RHT03 www.humiditycn.com)*** Available as http://www.sparkfun.com/products/10167 | DHT22(pin) | Function | mbed | | 1 - VDD | VDD-power supply (3.3-6V) | (Vout) 5V | | 2 - DATA | Single pin signal | p15 | | 3 - NULL | | | | 4 - GND | Connect to ground | GND | == Library == <<library /users/hwkit/libraries/DHT22/latest/docs/DHT22_8h_source.html>> <<library users=\"\" hwkit=\"\" libraries=\"\" dht22=\"\" latest=\"\" docs=\"\" dht22_8cpp_source.html=\"\">></library>
Diff: DHT22.cpp
- Revision:
- 1:5b20ff4fd227
- Parent:
- 0:547e68daeb1b
- Child:
- 2:340957cc8fef
--- a/DHT22.cpp Tue Jun 21 03:44:05 2011 +0000 +++ b/DHT22.cpp Mon Jul 04 07:35:03 2011 +0000 @@ -36,13 +36,16 @@ #include "DHT22.h" + // This should be 40, but the sensor is adding an extra bit at the start #define DHT22_DATA_BIT_COUNT 41 +Serial pc(USBTX, USBRX); // Tx, Rx Using USB Virtual Serial Port + // Read Data From /etc/ttyACM* (linux port) + DHT22::DHT22(PinName Data) { _data = Data; // Set Data Pin - DigitalInOut VCC(_vcc); - _lastReadTime = time(NULL)-2; + _lastReadTime = time(NULL); _lastHumidity = 0; _lastTemperature = DHT22_ERROR_VALUE; } @@ -52,23 +55,23 @@ DHT22_ERROR DHT22::readData() { int i, retryCount; - int currentTemperature; - int currentHumidity; - unsigned int checkSum, csPart1, csPart2, csPart3, csPart4; + int currentTemperature=0; + int currentHumidity=0; + unsigned int checkSum = 0, csPart1, csPart2, csPart3, csPart4; unsigned int bitTimes[DHT22_DATA_BIT_COUNT]; - time_t currentTime; + time_t currentTime = time(NULL); DigitalInOut DATA(_data); - currentHumidity = 0; - currentTemperature = 0; - checkSum = 0; - currentTime = time(NULL); + for (i = 0; i < DHT22_DATA_BIT_COUNT; i++) { bitTimes[i] = 0; } + if (currentTime - _lastReadTime < 2) { - // Caller needs to wait 2 seconds between each call to read Data + // Caller needs to wait 2 seconds between each call to read Data + pc.printf("Current Time: %s\n",currentTime); + pc.printf("Last Read Time: %s\n", _lastReadTime); return DHT_ERROR_TOOQUICK; } _lastReadTime = currentTime;