DHT22_Fail

Dependencies:   mbed

Committer:
binoit
Date:
Tue Sep 18 09:16:00 2018 +0000
Revision:
0:b8130f9ba1c3
Test_DHT22_fail

Who changed what in which revision?

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