From 94992f0597ed21d0c02ed38ebb5b9b5f25c3c40e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:20:00 +0200 Subject: [PATCH] Revert changes DHT11 timing --- CHANGELOG.md | 1 - RELEASENOTES.md | 1 - tasmota/xsns_06_dht.ino | 28 ++++++++++++---------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7956c25bb..9cc2fe944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ All notable changes to this project will be documented in this file. - Speed up initial GUI console refresh - Simplified configuration for ir-full and removal of tasmota-ircustom - Add Esp32 Partition Manager as a Berry component -- Update timing DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321), SI7021 (#12488) ### Fixed - ESP32 Webcam add boundary marker before sending mjpeg image (#12376) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index daab68a0f..8f90d9786 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -105,7 +105,6 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Force ESP32 defines USE_UFILESYS, GUI_TRASH_FILE and #define GUI_EDIT_FILE - Speed up initial GUI console refresh - Simplified configuration for ir-full and removal of tasmota-ircustom [#12428](https://github.com/arendst/Tasmota/issues/12428) -- Update timing DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321), SI7021 [#12488](https://github.com/arendst/Tasmota/issues/12488) ### Fixed - DDS238-2 wrong reactive power value [#12283](https://github.com/arendst/Tasmota/issues/12283) diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 46a250526..ffd6c4b44 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -25,9 +25,9 @@ * Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) * * Changelog - * 20210627 - https://github.com/arendst/Tasmota/pull/12488 * 20210524 - https://github.com/arendst/Tasmota/issues/12180 * 20200621 - https://github.com/arendst/Tasmota/pull/7468#issuecomment-647067015 + * 20200313 - https://github.com/arendst/Tasmota/issues/7717#issuecomment-585833243 \*********************************************************************************************/ #define XSNS_06 6 @@ -50,20 +50,17 @@ struct DHTSTRUCT { float h = NAN; } Dht[DHT_MAX_SENSORS]; -// 20210627: Changed from bool to uint32_t returning the time to wait until state changes -uint32_t DhtWaitState(uint32_t sensor, uint32_t level) { - uint32_t startms = micros(); - uint32_t timeout = startms + 100; - +bool DhtWaitState(uint32_t sensor, uint32_t level) { + unsigned long timeout = micros() + 100; while (digitalRead(Dht[sensor].pin) != level) { if (TimeReachedUsec(timeout)) { AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " %s " D_PULSE), (level) ? D_START_SIGNAL_HIGH : D_START_SIGNAL_LOW); - return 0; // 20210627: Return 0 (==false for compatibility) if timeout reached + return false; } delayMicroseconds(1); } - return micros() - startms; + return true; } bool DhtRead(uint32_t sensor) { @@ -82,8 +79,7 @@ bool DhtRead(uint32_t sensor) { break; case GPIO_DHT22: // DHT21, DHT22, AM2301, AM2302, AM2321 // delay(2); // minimum 1ms -// delayMicroseconds(2000); // 20200621: See https://github.com/arendst/Tasmota/pull/7468#issuecomment-647067015 - delayMicroseconds(1100); // 20210627: Changed to Arduino DHT library value + delayMicroseconds(2000); // 20200621: See https://github.com/arendst/Tasmota/pull/7468#issuecomment-647067015 break; case GPIO_SI7021: // iTead SI7021 delayMicroseconds(500); @@ -108,14 +104,14 @@ bool DhtRead(uint32_t sensor) { uint32_t i = 0; noInterrupts(); - if (DhtWaitState(sensor, 0)) { // Only wait for one state change to 0 + if (DhtWaitState(sensor, 0) && DhtWaitState(sensor, 1) && DhtWaitState(sensor, 0)) { for (i = 0; i < 40; i++) { if (!DhtWaitState(sensor, 1)) { break; } - uint32_t wt = DhtWaitState(sensor, 0); // Determine time to change state - if (0 == wt) { break; } - if (wt > 50) { - dht_data[i / 8] |= (1 << (7 - i % 8)); // If longer than 50 usec then 1, else 0 + delayMicroseconds(32); // Was 30 + if (digitalRead(Dht[sensor].pin)) { + dht_data[i / 8] |= (1 << (7 - i % 8)); } + if (!DhtWaitState(sensor, 0)) { break; } } } interrupts(); @@ -134,7 +130,7 @@ bool DhtRead(uint32_t sensor) { switch (Dht[sensor].type) { case GPIO_DHT11: // DHT11 humidity = dht_data[0]; - // DHT11 (Adafruit): + // 20200313: DHT11 (Adafruit): temperature = dht_data[2]; if (dht_data[3] & 0x80) { temperature = -1 - temperature;