2015-07-04 12:53:13 -04:00
|
|
|
//
|
|
|
|
// FILE: dht.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2018-04-03 13:10:49 -04:00
|
|
|
// VERSION: 0.2.4
|
2015-07-04 12:53:13 -04:00
|
|
|
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
2017-07-27 09:34:44 -04:00
|
|
|
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable
|
2015-07-04 12:53:13 -04:00
|
|
|
//
|
|
|
|
// HISTORY:
|
|
|
|
// see dht.cpp file
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef dht_h
|
|
|
|
#define dht_h
|
|
|
|
|
|
|
|
#if ARDUINO < 100
|
|
|
|
#include <WProgram.h>
|
|
|
|
#else
|
|
|
|
#include <Arduino.h>
|
|
|
|
#endif
|
|
|
|
|
2018-02-21 09:06:00 -05:00
|
|
|
#define DHT_LIB_VERSION "0.2.3 - dhtstable"
|
2015-07-04 12:53:13 -04:00
|
|
|
|
2018-02-21 09:06:00 -05:00
|
|
|
const int DHTLIB_OK = 0;
|
|
|
|
const int DHTLIB_ERROR_CHECKSUM = -1;
|
|
|
|
const int DHTLIB_ERROR_TIMEOUT = -2;
|
|
|
|
const int DHTLIB_INVALID_VALUE = -999;
|
2015-07-04 12:53:13 -04:00
|
|
|
|
2018-02-21 09:06:00 -05:00
|
|
|
const int DHTLIB_DHT11_WAKEUP = 18;
|
|
|
|
const int DHTLIB_DHT_WAKEUP = 1;
|
2015-07-04 12:53:13 -04:00
|
|
|
|
|
|
|
// max timeout is 100usec.
|
|
|
|
// For a 16Mhz proc that is max 1600 clock cycles
|
|
|
|
// loops using TIMEOUT use at least 4 clock cycli
|
|
|
|
// so 100 us takes max 400 loops
|
|
|
|
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
2018-02-21 09:06:00 -05:00
|
|
|
const int DHTLIB_TIMEOUT = (F_CPU/40000);
|
2015-07-04 12:53:13 -04:00
|
|
|
|
|
|
|
class dht
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// return values:
|
|
|
|
// DHTLIB_OK
|
|
|
|
// DHTLIB_ERROR_CHECKSUM
|
|
|
|
// DHTLIB_ERROR_TIMEOUT
|
2017-12-12 14:29:52 -05:00
|
|
|
int read11(uint8_t pin); // DHT11 & DHT12
|
|
|
|
int read(uint8_t pin); // DHT22
|
2015-07-04 12:53:13 -04:00
|
|
|
|
2018-04-03 13:10:49 -04:00
|
|
|
inline int read12(uint8_t pin) { return read11(pin); }; // ok
|
|
|
|
inline int read21(uint8_t pin) { return read(pin); }; // ok
|
|
|
|
inline int read22(uint8_t pin) { return read(pin); }; // ok
|
|
|
|
inline int read33(uint8_t pin) { return read(pin); }; // ok
|
|
|
|
inline int read44(uint8_t pin) { return read(pin); }; // ok
|
2017-12-12 14:29:52 -05:00
|
|
|
inline int read2301(uint8_t pin) { return read(pin); }; // ok
|
|
|
|
inline int read2302(uint8_t pin) { return read(pin); }; // ok
|
|
|
|
inline int read2320(uint8_t pin) { return read(pin); }; //.ok
|
|
|
|
inline int read2322(uint8_t pin) { return read(pin); }; // ok
|
2015-07-04 12:53:13 -04:00
|
|
|
|
2017-07-27 09:34:44 -04:00
|
|
|
float humidity;
|
|
|
|
float temperature;
|
2015-07-04 12:53:13 -04:00
|
|
|
|
2018-04-03 13:10:49 -04:00
|
|
|
bool getDisableIRQ() { return _disableIRQ; };
|
|
|
|
void setDisableIRQ(bool b ) { _disableIRQ = b; };
|
|
|
|
|
2015-07-04 12:53:13 -04:00
|
|
|
private:
|
|
|
|
uint8_t bits[5]; // buffer to receive data
|
2018-04-03 13:10:49 -04:00
|
|
|
int _readSensor(uint8_t pin, uint8_t wakeupDelay);
|
|
|
|
bool _disableIRQ = false;
|
2015-07-04 12:53:13 -04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
// END OF FILE
|
|
|
|
//
|