Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By hiddenbit
#42260 Hey guys, I tried your code, which looks like this, merged with my content:

Code: Select all#include "DHT.h"

#define DHTPIN 2     

#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321


DHT dht(DHTPIN, DHTTYPE);

void getSensorData();

void setup() {
  Serial.begin(9600);
  pinMode(DHTPIN, INPUT_PULLUP);
  dht.begin();
}

void loop() {
  Serial.println("Woke up!");
  // Wait a few seconds between measurements.
 
  delay(5000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
 
  // try the an other methode ..
  getSensorData();

  Serial.println("Sleep now!");
  //delay(20 * 1000); // Send data every 20 seconds
  ESP.deepSleep(0.1 * 60000000); // Send to sleep for 35 minutes
 
}

void getSensorData() {
    int retry_limit = 50;       // Limit read attempts.

    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();
    while ((isnan(temperature) || isnan(humidity))
           || (temperature == 0 && humidity == 0)) {
        if (--retry_limit < 1) {
            temperature = -1;
            humidity = -1;
            Serial.println(F("No DHT sensor detected."));
            return;
        }
#ifdef DEBUG
        RFlash();
        Serial.print(F("!"));
#endif
        delay(5000);
        temperature = dht.readTemperature();
        humidity = dht.readHumidity();
    }
#ifdef DEBUG
    Serial.println("");
    RFlash();
#endif
}


And that's the result :(

Code: Select all0�~�4�!�{�OAa�Woke up!
Humidity: 47.20 %   Temperature: 21.10 *C Sleep now!
0�~?�4�!�{�OA,�Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!
Woke up!
Failed to read from DHT sensor!



I am unable to read data from the dht22, even if I loop through the sensor reading.
User avatar
By hiddenbit
#42261 I just realized the following fact. If I unplug the dht22 from the breadboard while the esp8266 is running and plug it back to the board, I am able to read sensor data once again. On the next wake up state --> no more sensor data. crazy!
User avatar
By schufti
#42291 most likely due to some "misunderstanding" between the powerdown or wakeup "sequence" of the esp and the dht.
possibly the dht sees an initiated communication and gets confused. Consult the datasheet for a reset method of the dht; but I'd prefer sensors with i2c.