mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Revert changes DHT11 timing
This commit is contained in:
parent
464ab2cb6b
commit
94992f0597
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user