From 55ffb506ac611e0cc242a2d99dc303b2b155bcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 3 Dec 2017 11:14:19 +0100 Subject: [PATCH] Support for Itead's SI7021 sensor with DHT interface --- code/espurna/dht.ino | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/code/espurna/dht.ino b/code/espurna/dht.ino index be31ce41..c4ad71df 100644 --- a/code/espurna/dht.ino +++ b/code/espurna/dht.ino @@ -58,22 +58,15 @@ int readDHT(unsigned char gpio, unsigned char type) { delay(250); } pinMode(gpio, OUTPUT); - digitalWrite(gpio, LOW); - delay(20); noInterrupts(); + digitalWrite(gpio, LOW); + delayMicroseconds(500); digitalWrite(gpio, HIGH); delayMicroseconds(40); pinMode(gpio, INPUT_PULLUP); - delayMicroseconds(10); - - // DHT will keep the line low for 80 us and then high for 80us - low = _getSignalLevel(gpio, 85, LOW); - if (low==0) return DHT_TIMEOUT_ERROR; - high = _getSignalLevel(gpio, 85, HIGH); - if (high==0) return DHT_TIMEOUT_ERROR; // No errors, read the 40 data bits - for( int k = 0; k < 40; k++ ) { + for( int k = 0; k < 41; k++ ) { // Starts new data transmission with >50us low signal low = _getSignalLevel(gpio, 56, LOW); @@ -83,6 +76,9 @@ int readDHT(unsigned char gpio, unsigned char type) { high = _getSignalLevel(gpio, 75, HIGH); if (high==0) return DHT_TIMEOUT_ERROR; + // Skip the first bit + if (k==0) continue; + // add the current read to the output data // since all dhtData array where set to 0 at the start, // only look for "1" (>28us us)