DHT22
An interrupt-driven library for the DHT22 temperature and humidity sensor
|
An interrupt-driven library for the DHT22 sensor. More...
#include <DHT22.h>
Public Types | |
enum | Result { None, Ok, ChecksumMismatch, WakeUpError, DataError } |
Possible result values. More... | |
enum | Status { WakingUp, Reading, Done, Invalid } |
The status of the library state machine. More... | |
Public Member Functions | |
DHT22 (int pin) | |
Construct a DHT22 library instance. More... | |
void | onFallingEdge () |
Signals the library that the data pin has gone low. More... | |
bool | startRead () |
Wakes up the sensor and starts waiting for data. More... | |
Result | blockingRead () |
Starts reading, if necessary, and waits for result. More... | |
int16_t | getTemp () |
The last temperature reading. More... | |
uint16_t | getHumidity () |
The last humidity reading. More... | |
Status | state () |
The sensor status. More... | |
Result | lastResult () |
The result of the last reading. More... | |
An interrupt-driven library for the DHT22 sensor.
This class provides an interrupt-driven interface to the DHT22 sensor. The user must attach an ISR to the falling edge of the DHT22 data pin and invoke onFallingEdge() in the ISR.
Reading can be started with startRead(), which returns immediately, or blockingRead(), which waits for the reading to complete.
If state() returns Done, the data has been read and can be accessed with getTemp() and getHumidity(). Be aware of the measuring units!! If state() returns Invalid, lastResult() can give some information on the cause.
Usage example:
enum DHT22::Result |
enum DHT22::Status |
DHT22::DHT22 | ( | int | pin | ) |
Construct a DHT22 library instance.
pin | The data pin of the sensor |
DHT22::Result DHT22::blockingRead | ( | ) |
Starts reading, if necessary, and waits for result.
uint16_t DHT22::getHumidity | ( | ) |
The last humidity reading.
int16_t DHT22::getTemp | ( | ) |
The last temperature reading.
DHT22::Result DHT22::lastResult | ( | ) |
The result of the last reading.
void DHT22::onFallingEdge | ( | ) |
Signals the library that the data pin has gone low.
bool DHT22::startRead | ( | ) |
Wakes up the sensor and starts waiting for data.
DHT22::Status DHT22::state | ( | ) |
The sensor status.