mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Configurable pullup delay time, default 55 usec
This commit is contained in:
parent
1e752b12ee
commit
7cec0cb06d
9
DHT.cpp
9
DHT.cpp
@ -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
|
||||||
@ -179,8 +182,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(40); // 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.
|
||||||
|
3
DHT.h
3
DHT.h
@ -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);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=DHT sensor library
|
name=DHT sensor library
|
||||||
version=1.3.2
|
version=1.3.3
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user