DHT testprogram

Dependencies:   mbed

Fork of DHT_TestProgram by Wim De Roeve

Committer:
zainzafar
Date:
Tue Dec 29 10:55:05 2015 +0000
Revision:
1:731de3b11b74
Parent:
0:9ef709bfeb08
by Zain Zafar;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zainzafar 1:731de3b11b74 1 /*
zainzafar 1:731de3b11b74 2 * DHT Library for Digital-output Humidity and Temperature sensors
zainzafar 1:731de3b11b74 3 *
Wimpie 0:9ef709bfeb08 4 * Works with DHT11, DHT21, DHT22
Wimpie 0:9ef709bfeb08 5 * SEN11301P, Grove - Temperature&Humidity Sensor (Seeed Studio)
Wimpie 0:9ef709bfeb08 6 * SEN51035P, Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
zainzafar 1:731de3b11b74 7 * AM2302 , temperature-humidity sensor
Wimpie 0:9ef709bfeb08 8 * RHT01,RHT02, RHT03 , Humidity and Temperature Sensor (Sparkfun)
Wimpie 0:9ef709bfeb08 9 *
Wimpie 0:9ef709bfeb08 10 * Copyright (C) Wim De Roeve
Wimpie 0:9ef709bfeb08 11 * based on DHT22 sensor library by HO WING KIT
Wimpie 0:9ef709bfeb08 12 * Arduino DHT11 library
Wimpie 0:9ef709bfeb08 13 *
Wimpie 0:9ef709bfeb08 14 * Permission is hereby granted, free of charge, to any person obtaining a copy
Wimpie 0:9ef709bfeb08 15 * of this software and associated documnetation files (the "Software"), to deal
Wimpie 0:9ef709bfeb08 16 * in the Software without restriction, including without limitation the rights
Wimpie 0:9ef709bfeb08 17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Wimpie 0:9ef709bfeb08 18 * copies of the Software, and to permit persons to whom the Software is
Wimpie 0:9ef709bfeb08 19 * furished to do so, subject to the following conditions:
Wimpie 0:9ef709bfeb08 20 *
Wimpie 0:9ef709bfeb08 21 * The above copyright notice and this permission notice shall be included in
Wimpie 0:9ef709bfeb08 22 * all copies or substantial portions of the Software.
Wimpie 0:9ef709bfeb08 23 *
Wimpie 0:9ef709bfeb08 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wimpie 0:9ef709bfeb08 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wimpie 0:9ef709bfeb08 26 * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wimpie 0:9ef709bfeb08 27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wimpie 0:9ef709bfeb08 28 * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wimpie 0:9ef709bfeb08 29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wimpie 0:9ef709bfeb08 30 * THE SOFTWARE.
Wimpie 0:9ef709bfeb08 31 */
zainzafar 1:731de3b11b74 32
Wimpie 0:9ef709bfeb08 33 #ifndef MBED_DHT_H
Wimpie 0:9ef709bfeb08 34 #define MBED_DHT_H
zainzafar 1:731de3b11b74 35
Wimpie 0:9ef709bfeb08 36 #include "mbed.h"
zainzafar 1:731de3b11b74 37
zainzafar 1:731de3b11b74 38 typedef enum eType eType;
zainzafar 1:731de3b11b74 39 enum eType {
zainzafar 1:731de3b11b74 40 DHT11 = 11,
zainzafar 1:731de3b11b74 41 SEN11301P = 11,
zainzafar 1:731de3b11b74 42 RHT01 = 11,
zainzafar 1:731de3b11b74 43 DHT22 = 22,
zainzafar 1:731de3b11b74 44 AM2302 = 22,
zainzafar 1:731de3b11b74 45 SEN51035P = 22,
zainzafar 1:731de3b11b74 46 RHT02 = 22,
zainzafar 1:731de3b11b74 47 RHT03 = 22
zainzafar 1:731de3b11b74 48 };
zainzafar 1:731de3b11b74 49
zainzafar 1:731de3b11b74 50 typedef enum eError eError;
Wimpie 0:9ef709bfeb08 51 enum eError {
Wimpie 0:9ef709bfeb08 52 ERROR_NONE = 0,
zainzafar 1:731de3b11b74 53 BUS_BUSY,
zainzafar 1:731de3b11b74 54 ERROR_NOT_PRESENT,
zainzafar 1:731de3b11b74 55 ERROR_ACK_TOO_LONG,
zainzafar 1:731de3b11b74 56 ERROR_SYNC_TIMEOUT,
zainzafar 1:731de3b11b74 57 ERROR_DATA_TIMEOUT,
zainzafar 1:731de3b11b74 58 ERROR_CHECKSUM,
zainzafar 1:731de3b11b74 59 ERROR_NO_PATIENCE
zainzafar 1:731de3b11b74 60 };
zainzafar 1:731de3b11b74 61
zainzafar 1:731de3b11b74 62 typedef enum eScale eScale;
zainzafar 1:731de3b11b74 63 enum eScale {
zainzafar 1:731de3b11b74 64 CELCIUS = 0,
zainzafar 1:731de3b11b74 65 FARENHEIT,
zainzafar 1:731de3b11b74 66 KELVIN
zainzafar 1:731de3b11b74 67 };
zainzafar 1:731de3b11b74 68
zainzafar 1:731de3b11b74 69
zainzafar 1:731de3b11b74 70 class DHT
zainzafar 1:731de3b11b74 71 {
zainzafar 1:731de3b11b74 72
Wimpie 0:9ef709bfeb08 73 public:
zainzafar 1:731de3b11b74 74
zainzafar 1:731de3b11b74 75 DHT(PinName pin, eType DHTtype);
Wimpie 0:9ef709bfeb08 76 ~DHT();
zainzafar 1:731de3b11b74 77 eError readData(void);
Wimpie 0:9ef709bfeb08 78 float ReadHumidity(void);
zainzafar 1:731de3b11b74 79 float ReadTemperature(eScale const Scale);
zainzafar 1:731de3b11b74 80 float CalcdewPoint(float const celsius, float const humidity);
zainzafar 1:731de3b11b74 81 float CalcdewPointFast(float const celsius, float const humidity);
zainzafar 1:731de3b11b74 82
Wimpie 0:9ef709bfeb08 83 private:
Wimpie 0:9ef709bfeb08 84 time_t _lastReadTime;
Wimpie 0:9ef709bfeb08 85 float _lastTemperature;
Wimpie 0:9ef709bfeb08 86 float _lastHumidity;
Wimpie 0:9ef709bfeb08 87 PinName _pin;
Wimpie 0:9ef709bfeb08 88 bool _firsttime;
zainzafar 1:731de3b11b74 89 eType _DHTtype;
zainzafar 1:731de3b11b74 90 uint8_t DHT_data[5];
Wimpie 0:9ef709bfeb08 91 float CalcTemperature();
Wimpie 0:9ef709bfeb08 92 float CalcHumidity();
zainzafar 1:731de3b11b74 93 float ConvertCelciustoFarenheit(float const);
zainzafar 1:731de3b11b74 94 float ConvertCelciustoKelvin(float const);
zainzafar 1:731de3b11b74 95 eError stall(DigitalInOut &io, int const level, int const max_time);
zainzafar 1:731de3b11b74 96
Wimpie 0:9ef709bfeb08 97 };
zainzafar 1:731de3b11b74 98
zainzafar 1:731de3b11b74 99 #endif