Skip to content

Commit 7cec0cb

Browse files
Configurable pullup delay time, default 55 usec
1 parent 1e752b1 commit 7cec0cb

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

DHT.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
2222
// based on the speed of the processor.
2323
}
2424

25-
void DHT::begin(void) {
25+
// Optionally pass pull-up time (in microseconds) before DHT reading starts.
26+
// Default is 55 (see function declaration in DHT.h).
27+
void DHT::begin(uint8_t usec) {
2628
// set up the pins!
2729
pinMode(_pin, INPUT_PULLUP);
2830
// Using this value makes sure that millis() - lastreadtime will be
2931
// >= MIN_INTERVAL right away. Note that this assignment wraps around,
3032
// but so will the subtraction.
3133
_lastreadtime = millis() - MIN_INTERVAL;
3234
DEBUG_PRINT("DHT max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC);
35+
pullTime = usec;
3336
}
3437

3538
//boolean S == Scale. True == Fahrenheit; False == Celcius
@@ -179,8 +182,10 @@ bool DHT::read(bool force) {
179182
// End the start signal by setting data line high for 40 microseconds.
180183
pinMode(_pin, INPUT_PULLUP);
181184

185+
// Delay a moment to let sensor pull data line low.
186+
delayMicroseconds(pullTime);
187+
182188
// Now start reading the data line to get the value from the DHT sensor.
183-
delayMicroseconds(40); // Delay a bit to let sensor pull data line low.
184189

185190
// Turn off interrupts temporarily because the next sections
186191
// are timing critical and we don't want any interruptions.

DHT.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ written by Adafruit Industries
3939
class DHT {
4040
public:
4141
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
42-
void begin(void);
42+
void begin(uint8_t usec=55);
4343
float readTemperature(bool S=false, bool force=false);
4444
float convertCtoF(float);
4545
float convertFtoC(float);
@@ -58,6 +58,7 @@ class DHT {
5858
#endif
5959
uint32_t _lastreadtime, _maxcycles;
6060
bool _lastresult;
61+
uint8_t pullTime; // Time (in usec) to pull up data line before reading
6162

6263
uint32_t expectPulse(bool level);
6364

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DHT sensor library
2-
version=1.3.2
2+
version=1.3.3
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors

0 commit comments

Comments
 (0)