From fee6beb1d8549389470198671d489f8158e0d6c3 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 27 Dec 2015 10:43:41 -0500 Subject: [PATCH 1/5] Modified the class constructor to remove count. --- DHT.cpp | 22 ++++++++++++++++++++-- DHT.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index 86ad91c..d3f0b46 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -8,7 +8,26 @@ written by Adafruit Industries #define MIN_INTERVAL 2000 +/* + * Old constructor left in for backwards compatability. + */ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { + DHT::_init(pin, type); + // Note that count is now ignored as the DHT reading algorithm adjusts itself + // based on the speed of the processor. +} + +/* + * New constructor. + */ +DHT::DHT(uint8_t pin, uint8_t type) { + DHT::_init(pin, type); +} + +/* + * Common class initialization code. + */ +void DHT::_init(uint8_t pin, uint8_t type) { _pin = pin; _type = type; #ifdef __AVR @@ -17,10 +36,9 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { #endif _maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for // reading pulses from DHT sensor. - // Note that count is now ignored as the DHT reading algorithm adjusts itself - // basd on the speed of the processor. } + void DHT::begin(void) { // set up the pins! pinMode(_pin, INPUT_PULLUP); diff --git a/DHT.h b/DHT.h index d81f6db..d20a268 100644 --- a/DHT.h +++ b/DHT.h @@ -38,6 +38,7 @@ written by Adafruit Industries class DHT { public: DHT(uint8_t pin, uint8_t type, uint8_t count=6); + DHT(uint8_t pin, uint8_t type); void begin(void); float readTemperature(bool S=false, bool force=false); float convertCtoF(float); @@ -59,6 +60,7 @@ class DHT { uint32_t expectPulse(bool level); + void _init(uint8_t pin, uint8_t type); }; class InterruptLock { From a9b139e5554c4006b695aba90ea3a92010b2d883 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 27 Dec 2015 11:09:06 -0500 Subject: [PATCH 2/5] Moved backwards compatibility to header file. --- DHT.cpp | 20 +++++--------------- DHT.h | 6 +++++- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index d3f0b46..5c7dcbb 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -8,26 +8,16 @@ written by Adafruit Industries #define MIN_INTERVAL 2000 -/* - * Old constructor left in for backwards compatability. - */ -DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { - DHT::_init(pin, type); - // Note that count is now ignored as the DHT reading algorithm adjusts itself - // based on the speed of the processor. -} +// Old constructor. +//DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) { /* * New constructor. + * + * Note that count is now ignored as the DHT reading algorithm adjusts itself + * based on the speed of the processor. */ DHT::DHT(uint8_t pin, uint8_t type) { - DHT::_init(pin, type); -} - -/* - * Common class initialization code. - */ -void DHT::_init(uint8_t pin, uint8_t type) { _pin = pin; _type = type; #ifdef __AVR diff --git a/DHT.h b/DHT.h index d20a268..b1ed5e0 100644 --- a/DHT.h +++ b/DHT.h @@ -37,7 +37,11 @@ written by Adafruit Industries class DHT { public: - DHT(uint8_t pin, uint8_t type, uint8_t count=6); + // Note that count is now ignored as the DHT reading algorithm adjusts itself + // based on the speed of the processor. + DHT(uint8_t pin, uint8_t type, uint8_t count) { + DHT(pin, type); + }; DHT(uint8_t pin, uint8_t type); void begin(void); float readTemperature(bool S=false, bool force=false); From 5973a39fc9073ab105f26eda1b3f55a50bbf7a9e Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 9 Jan 2016 08:01:00 -0500 Subject: [PATCH 3/5] Added convenience methods for Fahrenheit and Celcius. --- DHT.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DHT.h b/DHT.h index b1ed5e0..bb2ae10 100644 --- a/DHT.h +++ b/DHT.h @@ -44,9 +44,21 @@ class DHT { }; DHT(uint8_t pin, uint8_t type); void begin(void); + float readFahrenheit(bool force=false) { + return readTemperature(true, force); + }; + float readCelcius(bool force=false) { + return readTemperature(false, force); + }; float readTemperature(bool S=false, bool force=false); float convertCtoF(float); float convertFtoC(float); + float computeHeatIndexFahrenheit(float temperature, float percentHumidity) { + return computeHeatIndex(temperature, percentHumidity, true); + }; + float computeHeatIndexCelcius(float temperature, float percentHumidity) { + return computeHeatIndex(temperature, percentHumidity, false); + }; float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); float readHumidity(bool force=false); boolean read(bool force=false); From 0e7c652c1bb3aca8ef753be96b1e826494f56217 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 9 Jan 2016 08:08:06 -0500 Subject: [PATCH 4/5] Added standard C and vi .gitignore entries --- .gitignore | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b92380a --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Vi files +*~ + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app From 1b2234d4c6e4182d2d379607d79e927ad7297438 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 13 Feb 2016 16:22:43 -0500 Subject: [PATCH 5/5] Accepted Issue#48 which uses pull up resistor instead of raising line high in software. --- DHT.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index 5c7dcbb..2093cb6 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -160,8 +160,12 @@ boolean DHT::read(bool force) { InterruptLock lock; // End the start signal by setting data line high for 40 microseconds. - digitalWrite(_pin, HIGH); - delayMicroseconds(40); + //digitalWrite(_pin, HIGH); + //delayMicroseconds(40); + // WEB: This is an error. DHT tries to pull the line low as soon as it came back to high. + // therefore the low-high transition after the start signal "low" needs to be realised by + // the pullup resistor only, uC pin must already be in INPUT mode. + // ref: https://github.com/adafruit/DHT-sensor-library/issues/48 // Now start reading the data line to get the value from the DHT sensor. pinMode(_pin, INPUT_PULLUP);