2013-08-28 07:57:45 -04:00
|
|
|
//
|
|
|
|
// FILE: dht.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2014-10-15 02:00:59 -04:00
|
|
|
// VERSION: 0.1.17
|
2013-08-28 07:57:45 -04:00
|
|
|
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
|
|
|
// URL: http://arduino.cc/playground/Main/DHTLib
|
|
|
|
//
|
|
|
|
// HISTORY:
|
|
|
|
// see dht.cpp file
|
2014-02-08 07:53:52 -05:00
|
|
|
//
|
2013-08-28 07:57:45 -04:00
|
|
|
|
|
|
|
#ifndef dht_h
|
|
|
|
#define dht_h
|
|
|
|
|
|
|
|
#if ARDUINO < 100
|
|
|
|
#include <WProgram.h>
|
2014-10-15 02:00:59 -04:00
|
|
|
#include <pins_arduino.h> // fix for broken pre 1.0 version - TODO TEST
|
2013-08-28 07:57:45 -04:00
|
|
|
#else
|
|
|
|
#include <Arduino.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-15 02:00:59 -04:00
|
|
|
#define DHT_LIB_VERSION "0.1.17"
|
2014-06-01 03:48:06 -04:00
|
|
|
|
2014-10-15 02:00:59 -04:00
|
|
|
#define DHTLIB_OK 0
|
|
|
|
#define DHTLIB_ERROR_CHECKSUM -1
|
|
|
|
#define DHTLIB_ERROR_TIMEOUT -2
|
|
|
|
#define DHTLIB_ERROR_CONNECT -3
|
|
|
|
#define DHTLIB_ERROR_ACK_L -4
|
|
|
|
#define DHTLIB_ERROR_ACK_H -5
|
2014-06-01 03:48:06 -04:00
|
|
|
|
2014-10-15 02:00:59 -04:00
|
|
|
#define DHTLIB_DHT11_WAKEUP 18
|
|
|
|
#define DHTLIB_DHT_WAKEUP 1
|
2013-08-28 07:57:45 -04:00
|
|
|
|
2014-10-05 04:52:52 -04:00
|
|
|
// max timeout is 100 usec.
|
|
|
|
// For a 16 Mhz proc 100 usec is 1600 clock cycles
|
|
|
|
// loops using DHTLIB_TIMEOUT use at least 4 clock cycli
|
2014-06-01 07:58:36 -04:00
|
|
|
// so 100 us takes max 400 loops
|
|
|
|
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
2014-10-15 01:48:27 -04:00
|
|
|
#define DHTLIB_TIMEOUT 400 // (F_CPU/40000)
|
2013-08-28 07:57:45 -04:00
|
|
|
|
|
|
|
class dht
|
|
|
|
{
|
|
|
|
public:
|
2014-06-26 14:48:20 -04:00
|
|
|
// return values:
|
|
|
|
// DHTLIB_OK
|
|
|
|
// DHTLIB_ERROR_CHECKSUM
|
|
|
|
// DHTLIB_ERROR_TIMEOUT
|
2014-10-15 02:00:59 -04:00
|
|
|
// DHTLIB_ERROR_CONNECT
|
|
|
|
// DHTLIB_ERROR_ACK_L
|
|
|
|
// DHTLIB_ERROR_ACK_H
|
2014-02-08 07:53:52 -05:00
|
|
|
int read11(uint8_t pin);
|
2014-06-26 14:48:20 -04:00
|
|
|
int read(uint8_t pin);
|
|
|
|
|
|
|
|
inline int read21(uint8_t pin) { return read(pin); };
|
|
|
|
inline int read22(uint8_t pin) { return read(pin); };
|
|
|
|
inline int read33(uint8_t pin) { return read(pin); };
|
|
|
|
inline int read44(uint8_t pin) { return read(pin); };
|
2014-02-08 07:53:52 -05:00
|
|
|
|
|
|
|
double humidity;
|
|
|
|
double temperature;
|
2013-08-28 07:57:45 -04:00
|
|
|
|
|
|
|
private:
|
2014-02-08 07:53:52 -05:00
|
|
|
uint8_t bits[5]; // buffer to receive data
|
2014-06-26 14:48:20 -04:00
|
|
|
int _readSensor(uint8_t pin, uint8_t wakeupDelay);
|
2013-08-28 07:57:45 -04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
// END OF FILE
|
|
|
|
//
|