8 Commits
1.3.1 ... 1.3.4

Author SHA1 Message Date
Phillip Burgess
f566d58f47 Move ESP8266 yield() out of InterruptLock 2019-02-18 10:20:28 -08:00
Phillip Burgess
9bf12551d8 ESP8266: yield() immediately before & after interrupt disablage 2019-02-14 09:27:28 -08:00
Phillip Burgess
7cec0cb06d Configurable pullup delay time, default 55 usec 2019-02-14 09:24:17 -08:00
Paint Your Dragon
1e752b12ee Merge pull request #125 from sijskes/master
fixed incorrect values on DHT11 below 0 degrees celcius
2019-02-14 09:03:16 -08:00
Simon IJskes
8b9624479e removed '*' copy error. 2019-02-11 12:33:06 +01:00
Simon IJskes
57fe95c1be split off the DHT11 conversion, corrected the algorithm for temperatures below 0 degrees celsius. 2019-02-08 22:18:10 +01:00
Phillip Burgess
d6488c1fbe Change initial HIGH delay, fix comments in examples 2019-01-28 17:05:54 -08:00
Phillip Burgess
d26e8ec729 Clarified the Unified Sensor Lib requirement in examples & README 2019-01-14 16:35:30 -08:00
6 changed files with 47 additions and 22 deletions

22
DHT.cpp
View File

@@ -22,7 +22,9 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
// based on the speed of the processor. // based on the speed of the processor.
} }
void DHT::begin(void) { // Optionally pass pull-up time (in microseconds) before DHT reading starts.
// Default is 55 (see function declaration in DHT.h).
void DHT::begin(uint8_t usec) {
// set up the pins! // set up the pins!
pinMode(_pin, INPUT_PULLUP); pinMode(_pin, INPUT_PULLUP);
// Using this value makes sure that millis() - lastreadtime will be // Using this value makes sure that millis() - lastreadtime will be
@@ -30,6 +32,7 @@ void DHT::begin(void) {
// but so will the subtraction. // but so will the subtraction.
_lastreadtime = millis() - MIN_INTERVAL; _lastreadtime = millis() - MIN_INTERVAL;
DEBUG_PRINT("DHT max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC); DEBUG_PRINT("DHT max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC);
pullTime = usec;
} }
//boolean S == Scale. True == Fahrenheit; False == Celcius //boolean S == Scale. True == Fahrenheit; False == Celcius
@@ -39,6 +42,15 @@ float DHT::readTemperature(bool S, bool force) {
if (read(force)) { if (read(force)) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
f = data[2];
if (data[3] & 0x80) {
f = -1 - f ;
}
f += (data[3] & 0x0f) * 0.1;
if(S) {
f = convertCtoF(f);
}
break;
case DHT12: case DHT12:
f = data[2]; f = data[2];
f += (data[3] & 0x0f) * 0.1; f += (data[3] & 0x0f) * 0.1;
@@ -143,6 +155,10 @@ bool DHT::read(bool force) {
// Reset 40 bits of received data to zero. // Reset 40 bits of received data to zero.
data[0] = data[1] = data[2] = data[3] = data[4] = 0; data[0] = data[1] = data[2] = data[3] = data[4] = 0;
#if defined(ESP8266)
yield(); // Handle WiFi / reset software watchdog
#endif
// Send start signal. See DHT datasheet for full signal diagram: // Send start signal. See DHT datasheet for full signal diagram:
// http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf // http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf
@@ -170,8 +186,10 @@ bool DHT::read(bool force) {
// End the start signal by setting data line high for 40 microseconds. // End the start signal by setting data line high for 40 microseconds.
pinMode(_pin, INPUT_PULLUP); pinMode(_pin, INPUT_PULLUP);
// Delay a moment to let sensor pull data line low.
delayMicroseconds(pullTime);
// Now start reading the data line to get the value from the DHT sensor. // Now start reading the data line to get the value from the DHT sensor.
delayMicroseconds(60); // Delay a bit to let sensor pull data line low.
// Turn off interrupts temporarily because the next sections // Turn off interrupts temporarily because the next sections
// are timing critical and we don't want any interruptions. // are timing critical and we don't want any interruptions.

4
DHT.h
View File

@@ -39,7 +39,7 @@ written by Adafruit Industries
class DHT { class DHT {
public: public:
DHT(uint8_t pin, uint8_t type, uint8_t count=6); DHT(uint8_t pin, uint8_t type, uint8_t count=6);
void begin(void); void begin(uint8_t usec=55);
float readTemperature(bool S=false, bool force=false); float readTemperature(bool S=false, bool force=false);
float convertCtoF(float); float convertCtoF(float);
float convertFtoC(float); float convertFtoC(float);
@@ -58,6 +58,7 @@ class DHT {
#endif #endif
uint32_t _lastreadtime, _maxcycles; uint32_t _lastreadtime, _maxcycles;
bool _lastresult; bool _lastresult;
uint8_t pullTime; // Time (in usec) to pull up data line before reading
uint32_t expectPulse(bool level); uint32_t expectPulse(bool level);
@@ -75,7 +76,6 @@ class InterruptLock {
interrupts(); interrupts();
#endif #endif
} }
}; };
#endif #endif

View File

@@ -1,15 +1,14 @@
This is an Arduino library for the DHT series of low cost temperature/humidity sensors. # Adafruit DHT Humidity & Temperature Sensor Library
An Arduino library for the DHT series of low cost temperature/humidity sensors.
Tutorial: https://learn.adafruit.com/dht Tutorial: https://learn.adafruit.com/dht
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. **You must have the following Arduino libraries installed to use this class:**
# Adafruit DHT Humidity & Temperature Unified Sensor Library
This library also includes an optional class for the
[DHT humidity and temperature sensor](https://learn.adafruit.com/dht/overview)
which is designed to work with the [Adafruit unified sensor library](https://learn.adafruit.com/using-the-adafruit-unified-sensor-driver/introduction).
You must have the following Arduino libraries installed to use this class:
- [Adafruit Unified Sensor Library](https://github.com/adafruit/Adafruit_Sensor) - [Adafruit Unified Sensor Library](https://github.com/adafruit/Adafruit_Sensor)
Examples include both a "standalone" DHT example, and one that works along with the Adafruit Unified Sensor Library. Unified sensor library is required even if using the standalone version.
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

View File

@@ -3,15 +3,17 @@
// Written by Tony DiCola for Adafruit Industries // Written by Tony DiCola for Adafruit Industries
// Released under an MIT license. // Released under an MIT license.
// Depends on the following Arduino libraries: // REQUIRES the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
#include <DHT.h> #include <DHT.h>
#include <DHT_U.h> #include <DHT_U.h>
#define DHTPIN 2 // Pin connected to the DHT sensor. #define DHTPIN 2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment the type of sensor in use: // Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT11 // DHT 11

View File

@@ -1,9 +1,15 @@
// Example testing sketch for various DHT humidity/temperature sensors // Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain // Written by ladyada, public domain
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include "DHT.h" #include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to #define DHTPIN 2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment whatever type you're using! // Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT11 // DHT 11

View File

@@ -1,5 +1,5 @@
name=DHT sensor library name=DHT sensor library
version=1.3.1 version=1.3.4
author=Adafruit author=Adafruit
maintainer=Adafruit <info@adafruit.com> maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors