=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:
Tue Jun 21 03:44:05 2011 +0000
Revision:
0:547e68daeb1b
Child:
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 0:547e68daeb1b 27
hwkit 0:547e68daeb1b 28 /**
hwkit 0:547e68daeb1b 29 * Currently supports DHT22 (SparkFun Electronics)
hwkit 0:547e68daeb1b 30 * Humidity and Temperature Sensor
hwkit 0:547e68daeb1b 31 *
hwkit 0:547e68daeb1b 32 * Features:
hwkit 0:547e68daeb1b 33 * > 3.3-6V Input
hwkit 0:547e68daeb1b 34 * > 1-1.5mA measuring current
hwkit 0:547e68daeb1b 35 * > 40-50uA standby current
hwkit 0:547e68daeb1b 36 * > Humidity from 0-100% RH
hwkit 0:547e68daeb1b 37 * > -40 - 80 degrees C temperature range
hwkit 0:547e68daeb1b 38 * > +-2% RH accuracy
hwkit 0:547e68daeb1b 39 * > +-0.5 degrees C
hwkit 0:547e68daeb1b 40 *
hwkit 0:547e68daeb1b 41 * Usages
hwkit 0:547e68daeb1b 42 * #include "DHT22.h"
hwkit 0:547e68daeb1b 43 *
hwkit 0:547e68daeb1b 44 * DTH22 dth22(PinName sda, PinName scl, int addr); // pin
hwkit 0:547e68daeb1b 45 *
hwkit 0:547e68daeb1b 46 * int main() {
hwkit 0:547e68daeb1b 47 * err=dth22.readData();
hwkit 0:547e68daeb1b 48 *
hwkit 0:547e68daeb1b 49 *
hwkit 0:547e68daeb1b 50 */
hwkit 0:547e68daeb1b 51
hwkit 0:547e68daeb1b 52 #define DHT22_ERROR_VALUE -99.5
hwkit 0:547e68daeb1b 53
hwkit 0:547e68daeb1b 54 typedef enum {
hwkit 0:547e68daeb1b 55 DHT_ERROR_NONE = 0,
hwkit 0:547e68daeb1b 56 DHT_BUS_HUNG,
hwkit 0:547e68daeb1b 57 DHT_ERROR_NOT_PRESENT,
hwkit 0:547e68daeb1b 58 DHT_ERROR_ACK_TOO_LONG,
hwkit 0:547e68daeb1b 59 DHT_ERROR_SYNC_TIMEOUT,
hwkit 0:547e68daeb1b 60 DHT_ERROR_DATA_TIMEOUT,
hwkit 0:547e68daeb1b 61 DHT_ERROR_CHECKSUM,
hwkit 0:547e68daeb1b 62 DHT_ERROR_TOOQUICK
hwkit 0:547e68daeb1b 63 } DHT22_ERROR;
hwkit 0:547e68daeb1b 64
hwkit 0:547e68daeb1b 65 class DHT22 {
hwkit 0:547e68daeb1b 66 private:
hwkit 0:547e68daeb1b 67 uint8_t _bitmask;
hwkit 0:547e68daeb1b 68 volatile uint8_t *_baseReg;
hwkit 0:547e68daeb1b 69 time_t _lastReadTime;
hwkit 0:547e68daeb1b 70 PinName _vcc, _data;
hwkit 0:547e68daeb1b 71 int m_addr;
hwkit 0:547e68daeb1b 72 float _lastHumidity;
hwkit 0:547e68daeb1b 73 float _lastTemperature;
hwkit 0:547e68daeb1b 74
hwkit 0:547e68daeb1b 75 public:
hwkit 0:547e68daeb1b 76 DHT22(PinName Data);
hwkit 0:547e68daeb1b 77 ~DHT22();
hwkit 0:547e68daeb1b 78 DHT22_ERROR readData(void);
hwkit 0:547e68daeb1b 79 float getHumidity();
hwkit 0:547e68daeb1b 80 float getTemperatureC();
hwkit 0:547e68daeb1b 81 void clockReset();
hwkit 0:547e68daeb1b 82 };
hwkit 0:547e68daeb1b 83
hwkit 0:547e68daeb1b 84 #endif /*_DHT22_H_*/