![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
DHT testprogram
Fork of DHT_TestProgram by
DHT/DHT.h@0:9ef709bfeb08, 2012-07-10 (annotated)
- Committer:
- Wimpie
- Date:
- Tue Jul 10 13:11:23 2012 +0000
- Revision:
- 0:9ef709bfeb08
- Child:
- 1:731de3b11b74
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wimpie | 0:9ef709bfeb08 | 1 | /* |
Wimpie | 0:9ef709bfeb08 | 2 | * DHT Library for Digital-output Humidity and Temperature sensors |
Wimpie | 0:9ef709bfeb08 | 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) |
Wimpie | 0:9ef709bfeb08 | 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 | */ |
Wimpie | 0:9ef709bfeb08 | 32 | |
Wimpie | 0:9ef709bfeb08 | 33 | #ifndef MBED_DHT_H |
Wimpie | 0:9ef709bfeb08 | 34 | #define MBED_DHT_H |
Wimpie | 0:9ef709bfeb08 | 35 | |
Wimpie | 0:9ef709bfeb08 | 36 | #include "mbed.h" |
Wimpie | 0:9ef709bfeb08 | 37 | |
Wimpie | 0:9ef709bfeb08 | 38 | enum eType{ |
Wimpie | 0:9ef709bfeb08 | 39 | DHT11 = 11, |
Wimpie | 0:9ef709bfeb08 | 40 | SEN11301P = 11, |
Wimpie | 0:9ef709bfeb08 | 41 | RHT01 = 11, |
Wimpie | 0:9ef709bfeb08 | 42 | DHT22 = 22, |
Wimpie | 0:9ef709bfeb08 | 43 | AM2302 = 22, |
Wimpie | 0:9ef709bfeb08 | 44 | SEN51035P = 22, |
Wimpie | 0:9ef709bfeb08 | 45 | RHT02 = 22, |
Wimpie | 0:9ef709bfeb08 | 46 | RHT03 = 22 |
Wimpie | 0:9ef709bfeb08 | 47 | } ; |
Wimpie | 0:9ef709bfeb08 | 48 | |
Wimpie | 0:9ef709bfeb08 | 49 | enum eError { |
Wimpie | 0:9ef709bfeb08 | 50 | ERROR_NONE = 0, |
Wimpie | 0:9ef709bfeb08 | 51 | BUS_BUSY =1, |
Wimpie | 0:9ef709bfeb08 | 52 | ERROR_NOT_PRESENT =2 , |
Wimpie | 0:9ef709bfeb08 | 53 | ERROR_ACK_TOO_LONG =3 , |
Wimpie | 0:9ef709bfeb08 | 54 | ERROR_SYNC_TIMEOUT = 4, |
Wimpie | 0:9ef709bfeb08 | 55 | ERROR_DATA_TIMEOUT =5 , |
Wimpie | 0:9ef709bfeb08 | 56 | ERROR_CHECKSUM = 6, |
Wimpie | 0:9ef709bfeb08 | 57 | ERROR_NO_PATIENCE =7 |
Wimpie | 0:9ef709bfeb08 | 58 | } ; |
Wimpie | 0:9ef709bfeb08 | 59 | |
Wimpie | 0:9ef709bfeb08 | 60 | typedef enum { |
Wimpie | 0:9ef709bfeb08 | 61 | CELCIUS =0 , |
Wimpie | 0:9ef709bfeb08 | 62 | FARENHEIT =1, |
Wimpie | 0:9ef709bfeb08 | 63 | KELVIN=2 |
Wimpie | 0:9ef709bfeb08 | 64 | } eScale; |
Wimpie | 0:9ef709bfeb08 | 65 | |
Wimpie | 0:9ef709bfeb08 | 66 | |
Wimpie | 0:9ef709bfeb08 | 67 | class DHT { |
Wimpie | 0:9ef709bfeb08 | 68 | |
Wimpie | 0:9ef709bfeb08 | 69 | public: |
Wimpie | 0:9ef709bfeb08 | 70 | |
Wimpie | 0:9ef709bfeb08 | 71 | DHT(PinName pin,int DHTtype); |
Wimpie | 0:9ef709bfeb08 | 72 | ~DHT(); |
Wimpie | 0:9ef709bfeb08 | 73 | int readData(void); |
Wimpie | 0:9ef709bfeb08 | 74 | float ReadHumidity(void); |
Wimpie | 0:9ef709bfeb08 | 75 | float ReadTemperature(eScale Scale); |
Wimpie | 0:9ef709bfeb08 | 76 | float CalcdewPoint(float celsius, float humidity); |
Wimpie | 0:9ef709bfeb08 | 77 | float CalcdewPointFast(float celsius, float humidity); |
Wimpie | 0:9ef709bfeb08 | 78 | |
Wimpie | 0:9ef709bfeb08 | 79 | private: |
Wimpie | 0:9ef709bfeb08 | 80 | time_t _lastReadTime; |
Wimpie | 0:9ef709bfeb08 | 81 | float _lastTemperature; |
Wimpie | 0:9ef709bfeb08 | 82 | float _lastHumidity; |
Wimpie | 0:9ef709bfeb08 | 83 | PinName _pin; |
Wimpie | 0:9ef709bfeb08 | 84 | bool _firsttime; |
Wimpie | 0:9ef709bfeb08 | 85 | int _DHTtype; |
Wimpie | 0:9ef709bfeb08 | 86 | int DHT_data[6]; |
Wimpie | 0:9ef709bfeb08 | 87 | float CalcTemperature(); |
Wimpie | 0:9ef709bfeb08 | 88 | float CalcHumidity(); |
Wimpie | 0:9ef709bfeb08 | 89 | float ConvertCelciustoFarenheit(float); |
Wimpie | 0:9ef709bfeb08 | 90 | float ConvertCelciustoKelvin(float); |
Wimpie | 0:9ef709bfeb08 | 91 | |
Wimpie | 0:9ef709bfeb08 | 92 | }; |
Wimpie | 0:9ef709bfeb08 | 93 | |
Wimpie | 0:9ef709bfeb08 | 94 | #endif |