=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>> &lt;<library users=\"\" hwkit=\"\" libraries=\"\" dht22=\"\" latest=\"\" docs=\"\" dht22_8cpp_source.html=\"\">&gt;</library>

Committer:
hwkit
Date:
Sat Jul 09 02:18:38 2011 +0000
Revision:
2:340957cc8fef
Parent:
1:5b20ff4fd227
0.1 -> Beta test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hwkit 0:547e68daeb1b 1 /* mbed DHT22 Library
hwkit 0:547e68daeb1b 2 * Copyright (c) 2011, sford, http://mbed.org
hwkit 0:547e68daeb1b 3 *
hwkit 0:547e68daeb1b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
hwkit 0:547e68daeb1b 5 * of this software and associated documnetation files (the "Software"), to deal
hwkit 0:547e68daeb1b 6 * in the Software without restriction, including without limitation the rights
hwkit 0:547e68daeb1b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hwkit 0:547e68daeb1b 8 * copies of the Software, and to permit persons to whom the Software is
hwkit 0:547e68daeb1b 9 * furished to do so, subject to the following conditions:
hwkit 0:547e68daeb1b 10 *
hwkit 0:547e68daeb1b 11 * The above copyright notice and this permission notice shall be included in
hwkit 0:547e68daeb1b 12 * all copies or substantial portions of the Software.
hwkit 0:547e68daeb1b 13 *
hwkit 0:547e68daeb1b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hwkit 0:547e68daeb1b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hwkit 0:547e68daeb1b 16 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hwkit 0:547e68daeb1b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hwkit 0:547e68daeb1b 18 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hwkit 0:547e68daeb1b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hwkit 0:547e68daeb1b 20 * THE SOFTWARE.
hwkit 0:547e68daeb1b 21 */
hwkit 0:547e68daeb1b 22
hwkit 0:547e68daeb1b 23 #ifndef MBED_DHT22_H
hwkit 0:547e68daeb1b 24 #define MBED_DHT22_H
hwkit 0:547e68daeb1b 25
hwkit 0:547e68daeb1b 26 #include "mbed.h"
hwkit 1:5b20ff4fd227 27 #include "NokiaLCD.h"
hwkit 0:547e68daeb1b 28
hwkit 0:547e68daeb1b 29 /**
hwkit 0:547e68daeb1b 30 * Currently supports DHT22 (SparkFun Electronics)
hwkit 0:547e68daeb1b 31 * Humidity and Temperature Sensor
hwkit 0:547e68daeb1b 32 *
hwkit 0:547e68daeb1b 33 * Features:
hwkit 0:547e68daeb1b 34 * > 3.3-6V Input
hwkit 0:547e68daeb1b 35 * > 1-1.5mA measuring current
hwkit 0:547e68daeb1b 36 * > 40-50uA standby current
hwkit 0:547e68daeb1b 37 * > Humidity from 0-100% RH
hwkit 0:547e68daeb1b 38 * > -40 - 80 degrees C temperature range
hwkit 0:547e68daeb1b 39 * > +-2% RH accuracy
hwkit 0:547e68daeb1b 40 * > +-0.5 degrees C
hwkit 0:547e68daeb1b 41 *
hwkit 0:547e68daeb1b 42 * Usages
hwkit 0:547e68daeb1b 43 * #include "DHT22.h"
hwkit 0:547e68daeb1b 44 *
hwkit 0:547e68daeb1b 45 * DTH22 dth22(PinName sda, PinName scl, int addr); // pin
hwkit 0:547e68daeb1b 46 *
hwkit 0:547e68daeb1b 47 * int main() {
hwkit 0:547e68daeb1b 48 * err=dth22.readData();
hwkit 1:5b20ff4fd227 49 * if (err==0) {
hwkit 1:5b20ff4fd227 50 printf("Temperature is %f.2 C\n",dht22.getTemperature());
hwkit 1:5b20ff4fd227 51 printf("Humidity is %f.2 \%\n",dht22.getHumidity());
hwkit 1:5b20ff4fd227 52 }
hwkit 0:547e68daeb1b 53 *
hwkit 0:547e68daeb1b 54 *
hwkit 0:547e68daeb1b 55 */
hwkit 0:547e68daeb1b 56
hwkit 0:547e68daeb1b 57 #define DHT22_ERROR_VALUE -99.5
hwkit 0:547e68daeb1b 58
hwkit 0:547e68daeb1b 59 typedef enum {
hwkit 0:547e68daeb1b 60 DHT_ERROR_NONE = 0,
hwkit 0:547e68daeb1b 61 DHT_BUS_HUNG,
hwkit 0:547e68daeb1b 62 DHT_ERROR_NOT_PRESENT,
hwkit 0:547e68daeb1b 63 DHT_ERROR_ACK_TOO_LONG,
hwkit 0:547e68daeb1b 64 DHT_ERROR_SYNC_TIMEOUT,
hwkit 0:547e68daeb1b 65 DHT_ERROR_DATA_TIMEOUT,
hwkit 0:547e68daeb1b 66 DHT_ERROR_CHECKSUM,
hwkit 0:547e68daeb1b 67 DHT_ERROR_TOOQUICK
hwkit 0:547e68daeb1b 68 } DHT22_ERROR;
hwkit 0:547e68daeb1b 69
hwkit 0:547e68daeb1b 70 class DHT22 {
hwkit 0:547e68daeb1b 71 private:
hwkit 0:547e68daeb1b 72 time_t _lastReadTime;
hwkit 1:5b20ff4fd227 73 PinName _data;
hwkit 0:547e68daeb1b 74 float _lastHumidity;
hwkit 0:547e68daeb1b 75 float _lastTemperature;
hwkit 0:547e68daeb1b 76 public:
hwkit 0:547e68daeb1b 77 DHT22(PinName Data);
hwkit 0:547e68daeb1b 78 ~DHT22();
hwkit 0:547e68daeb1b 79 DHT22_ERROR readData(void);
hwkit 0:547e68daeb1b 80 float getHumidity();
hwkit 0:547e68daeb1b 81 float getTemperatureC();
hwkit 0:547e68daeb1b 82 void clockReset();
hwkit 0:547e68daeb1b 83 };
hwkit 0:547e68daeb1b 84
hwkit 0:547e68daeb1b 85 #endif /*_DHT22_H_*/