HO WING KIT / DHT22
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DHT22.h Source File

DHT22.h

00001 /* mbed DHT22 Library
00002  * Copyright (c) 2011, sford, http://mbed.org
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documnetation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to  whom the Software is
00009  * furished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 #ifndef MBED_DHT22_H
00024 #define MBED_DHT22_H
00025 
00026 #include "mbed.h"
00027 #include "NokiaLCD.h"
00028 
00029 /**
00030  * Currently supports DHT22 (SparkFun Electronics)
00031  * Humidity and Temperature Sensor
00032  *
00033  * Features:
00034  *  >   3.3-6V Input
00035  *  >   1-1.5mA measuring current
00036  *  >   40-50uA standby current
00037  *  >   Humidity from 0-100% RH
00038  *  >   -40 - 80 degrees C  temperature range
00039  *  >   +-2% RH accuracy
00040  *  >   +-0.5 degrees C
00041  *
00042  * Usages
00043  * #include "DHT22.h"
00044  *
00045  * DTH22 dth22(PinName sda, PinName scl, int addr);  // pin
00046  *
00047  * int main() {
00048  *     err=dth22.readData();
00049  *     if (err==0) {
00050           printf("Temperature is %f.2 C\n",dht22.getTemperature());
00051           printf("Humidity is %f.2 \%\n",dht22.getHumidity());
00052        }
00053  *
00054  *
00055  */
00056 
00057 #define DHT22_ERROR_VALUE -99.5
00058 
00059 typedef enum {
00060     DHT_ERROR_NONE = 0,
00061     DHT_BUS_HUNG,
00062     DHT_ERROR_NOT_PRESENT,
00063     DHT_ERROR_ACK_TOO_LONG,
00064     DHT_ERROR_SYNC_TIMEOUT,
00065     DHT_ERROR_DATA_TIMEOUT,
00066     DHT_ERROR_CHECKSUM,
00067     DHT_ERROR_TOOQUICK
00068 } DHT22_ERROR;
00069 
00070 class DHT22 {
00071 private:
00072     time_t  _lastReadTime;
00073     PinName _data;
00074     float   _lastHumidity;
00075     float   _lastTemperature;
00076 public:
00077     DHT22(PinName Data);
00078     ~DHT22();
00079     DHT22_ERROR readData(void);
00080     float getHumidity();
00081     float getTemperatureC();
00082     void clockReset();
00083 };
00084 
00085 #endif /*_DHT22_H_*/