=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.h
- Revision:
- 0:547e68daeb1b
- Child:
- 1:5b20ff4fd227
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT22.h Tue Jun 21 03:44:05 2011 +0000 @@ -0,0 +1,84 @@ +/* mbed DHT22 Library + * Copyright (c) 2011, sford, http://mbed.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documnetation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MBED_DHT22_H +#define MBED_DHT22_H + +#include "mbed.h" + +/** + * Currently supports DHT22 (SparkFun Electronics) + * Humidity and Temperature Sensor + * + * Features: + * > 3.3-6V Input + * > 1-1.5mA measuring current + * > 40-50uA standby current + * > Humidity from 0-100% RH + * > -40 - 80 degrees C temperature range + * > +-2% RH accuracy + * > +-0.5 degrees C + * + * Usages + * #include "DHT22.h" + * + * DTH22 dth22(PinName sda, PinName scl, int addr); // pin + * + * int main() { + * err=dth22.readData(); + * + * + */ + +#define DHT22_ERROR_VALUE -99.5 + +typedef enum { + DHT_ERROR_NONE = 0, + DHT_BUS_HUNG, + DHT_ERROR_NOT_PRESENT, + DHT_ERROR_ACK_TOO_LONG, + DHT_ERROR_SYNC_TIMEOUT, + DHT_ERROR_DATA_TIMEOUT, + DHT_ERROR_CHECKSUM, + DHT_ERROR_TOOQUICK +} DHT22_ERROR; + +class DHT22 { +private: + uint8_t _bitmask; + volatile uint8_t *_baseReg; + time_t _lastReadTime; + PinName _vcc, _data; + int m_addr; + float _lastHumidity; + float _lastTemperature; + +public: + DHT22(PinName Data); + ~DHT22(); + DHT22_ERROR readData(void); + float getHumidity(); + float getTemperatureC(); + void clockReset(); +}; + +#endif /*_DHT22_H_*/