Browse Source

Support for Itead's SI7021 sensor with DHT interface

fastled
Xose Pérez 7 years ago
parent
commit
55ffb506ac
1 changed files with 6 additions and 10 deletions
  1. +6
    -10
      code/espurna/dht.ino

+ 6
- 10
code/espurna/dht.ino View File

@ -58,22 +58,15 @@ int readDHT(unsigned char gpio, unsigned char type) {
delay(250); delay(250);
} }
pinMode(gpio, OUTPUT); pinMode(gpio, OUTPUT);
digitalWrite(gpio, LOW);
delay(20);
noInterrupts(); noInterrupts();
digitalWrite(gpio, LOW);
delayMicroseconds(500);
digitalWrite(gpio, HIGH); digitalWrite(gpio, HIGH);
delayMicroseconds(40); delayMicroseconds(40);
pinMode(gpio, INPUT_PULLUP); 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 // 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 // Starts new data transmission with >50us low signal
low = _getSignalLevel(gpio, 56, LOW); low = _getSignalLevel(gpio, 56, LOW);
@ -83,6 +76,9 @@ int readDHT(unsigned char gpio, unsigned char type) {
high = _getSignalLevel(gpio, 75, HIGH); high = _getSignalLevel(gpio, 75, HIGH);
if (high==0) return DHT_TIMEOUT_ERROR; if (high==0) return DHT_TIMEOUT_ERROR;
// Skip the first bit
if (k==0) continue;
// add the current read to the output data // add the current read to the output data
// since all dhtData array where set to 0 at the start, // since all dhtData array where set to 0 at the start,
// only look for "1" (>28us us) // only look for "1" (>28us us)


Loading…
Cancel
Save