mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 13:22:19 +01:00
dht: Fix sensor reading from DHT22 (#926)
* dht: Fix sensor reading from DHT22 (#239) Looking at the datasheet for DHT22, it claims to need a delay of 18ms, not 800us. Change to use the same delay as DHT11. Tested working with NodeMCUv3 and DHT22 sensor with board with built-in resistor. * dht: Add model DHT22_TYPE2 with 2ms delay instead of 0.8ms The model DHT22_TYPE2 is exactly the same as DHT22, but uses a different delay. * dht: Fix bogus negative temperature reading on DHT22_TYPE2 The workaround for negative numbers associated with DHT22s can be skipped on these sensors.
This commit is contained in:
@@ -92,6 +92,8 @@ bool HOT ICACHE_RAM_ATTR DHT::read_sensor_(float *temperature, float *humidity,
|
||||
delayMicroseconds(500);
|
||||
this->pin_->digital_write(true);
|
||||
delayMicroseconds(40);
|
||||
} else if (this->model_ == DHT_MODEL_DHT22_TYPE2) {
|
||||
delayMicroseconds(2000);
|
||||
} else {
|
||||
delayMicroseconds(800);
|
||||
}
|
||||
@@ -208,7 +210,7 @@ bool HOT ICACHE_RAM_ATTR DHT::read_sensor_(float *temperature, float *humidity,
|
||||
uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
|
||||
uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
|
||||
|
||||
if ((raw_temperature & 0x8000) != 0)
|
||||
if (this->model_ != DHT_MODEL_DHT22_TYPE2 && (raw_temperature & 0x8000) != 0)
|
||||
raw_temperature = ~(raw_temperature & 0x7FFF);
|
||||
|
||||
if (raw_temperature == 1 && raw_humidity == 10) {
|
||||
|
Reference in New Issue
Block a user