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