pinMode(DHTPIN, OUTPUT);
digitalWrite(DHTPIN, LOW);
ESP.deepSleep(0.1 * 60000000); // Send to sleep for 35 minutes
Moderator: igrr
My ESP board comes out of deep sleep, but then I can't read DHT22 values any longer.
If I remove the DHT22 from the breadboard and plug it back in, it reads a value.
What is the solution?
I have:
- NodeMCU v3 Lolin
- DHT22 sensor
- D0 is connected to RST
- DHT22 is connected to D4
Parts of code:
#define DHTTYPE DHT22
uint8_t DHTPIN = D4;
void setup() {
// this code will only run once
Serial.begin(115200);
Serial.println(F("Setting up DHT..."));
pinMode(DHTPIN, INPUT);
dht.begin();
// set up wifi
delay(100); // doesn't work if we go straight to WiFi setup...
Serial.println(F("Setting up Wifi"));
WiFi.begin(ssid, password);
connect_wifi();
...
}
void connect_wifi() {
...
}
void loop() {
int i;
if (WiFi.status() != WL_CONNECTED) {
Serial.println(F("Wifi: disconnected -> reconnecting"));
connect_wifi();
}
client.loop();
for (i=0; i<20; i++) {
temperatureC = dht.readTemperature();
Serial.print(F("Temperature: ")); Serial.println(temperatureC);
publish_mqtt(mqtt_temp_topic, temperatureC);
humidity = dht.readHumidity();
Serial.print(F("Humidity: ")); Serial.println(humidity);
publish_mqtt(mqtt_humidity_topic, humidity);
delay((i+1)*1000);
if (isnan(temperatureC)) {
client.publish(mqtt_debug_topic, "impossible de relever la temperature via DHT22");
} else {
break;
}
}
// disconnect & sleep
client.disconnect();
WiFi.disconnect();
delay(100);
Serial.println(F("Entering deep sleep for 60 seconds"));
ESP.deepSleep(60 * 1000000, WAKE_RF_DEFAULT);
delay(1000);
Serial.println(F("Init DHT")); // tried this
dht.begin();
}
Thanks