I am trying to use 4 dht22 sensors with an esp32 and I keep experiencing these crashes. The program will run fine for 15-40mins and then the microcontroller will reset itself. It seems to have something to do with reading the sensor data but im a noob and i'm struggling to figure it out. Does anyone have any ideas?
I am programming an ESP32_Devkitc_v4 WROOM-32D using the arduino framework in platformio.
Here is the register dump with stack trace
20:16:23.918 > Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
20:16:23.925 >
20:16:23.925 > Core 1 register dump:
20:16:23.927 > PC : 0x400e785f PS : 0x00060935 A0 : 0x800e54c5 A1 : 0x3ffb2040
20:16:23.935 > A2 : 0x0000001a A3 : 0x00000000 A4 : 0x00000027 A5 : 0x00060123
20:16:23.943 > A6 : 0x00060120 A7 : 0x00000001 A8 : 0x3ff44000 A9 : 0x0000001f
20:16:23.950 > A10 : 0x3ff5f07c A11 : 0x04000000 A12 : 0x0000001a A13 : 0x00060f23
20:16:23.958 > A14 : 0x00060f20 A15 : 0x00000001 SAR : 0x0000001a EXCCAUSE: 0x00000006
20:16:23.966 > EXCVADDR: 0x00000000 LBEG : 0x400849d1 LEND : 0x400849d9 LCOUNT : 0x00000027
20:16:23.974 >
20:16:23.974 >
20:16:23.974 > Backtrace: 0x400e785c:0x3ffb2040 0x400e54c2:0x3ffb2070 0x400e2843:0x3ffb2090 0x400e293e:0x3ffb20b0 0x400e2a1f:0x3ffb2210 0x400d3316:0x3ffb2240 0x400d6fd2:0x3ffb2270 0x400e6d71:0x3ffb2290
20:16:24.099 >
20:16:24.099 > #0 0x400e785c:0x3ffb2040 in gpio_ll_get_level at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/hal/esp32/include/hal/gpio_ll.h:473
20:16:24.099 > (inlined by) gpio_get_level at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/driver/gpio.c:233
20:16:24.099 > #1 0x400e54c2:0x3ffb2070 in __digitalRead at C:/Users/3dPrintStation/.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-gpio.c:150
20:16:24.099 > #2 0x400e2843:0x3ffb2090 in DHT::expectPulse(bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:382
20:16:24.099 > #3 0x400e293e:0x3ffb20b0 in DHT::read(bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:306
20:16:24.099 > #4 0x400e2a1f:0x3ffb2210 in DHT::readTemperature(bool, bool) at .pio/libdeps/esp32dev/DHT sensor library/DHT.cpp:88
20:16:24.099 > #5 0x400d3316:0x3ffb2240 in readSensorData() at src/DHT_SENSORS.cpp:29
20:16:24.099 > #6 0x400d6fd2:0x3ffb2270 in loop() at src/main.cpp:48
20:16:24.099 > #7 0x400e6d71:0x3ffb2290 in loopTask(void*) at C:/Users/3dPrintStation/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50
This is the function that reads the temp and humidity data. It is only called in the main loop. Originally I had it inside another function and I was using a shorter interval for readings but i've been moving things around seeing if I could get something to work.
float temperature[NUM_SLOTS];
float humidity[NUM_SLOTS];
void readSensorData()
{
unsigned long currentMillis = millis();
const int Interval = 5000;
static unsigned long previousMillis;
if (currentMillis - previousMillis >= Interval)
{
previousMillis = currentMillis;
for (uint8_t i = 0; i < NUM_SLOTS; i++)
{
temperature[i] = dht[i].readTemperature();
humidity[i] = dht[i].readHumidity();
}
}
}
I spent all afternoon looking into this yesterday and I can't figure out what I've done wrong. Any guidance would be much appreciated
@jaywhy Hey there,
Can you please post the whole sketch you´re using? When you see the error core paniced, there´s something wrong with the coding or wiring but mostly coding or an indefintive loop.
Maybe I can test the code with 2 dht22´s.
Never used this sensor, but Google tells me that the min sample time of these sensors is two seconds (0.5Hz). It seems you're reading the sensors multiple (NUM_SLOTS) times after each other, without that 2-second break.
Leo..
I appreciate the offer. My code is at least 1000 lines long and is broken up amongst multiple tabs. I leave for work soon but I can reformat it and post tonight.
According to the stack trace, it seems to be something to do with reading the sensors and that only happens once in the sketch.
Yesterday I commented out the readSensorData function and it ran for a few hours without crashing so i went back to trying to troubleshoot it. I have commented it out again and i'm going to let it run for the rest of the day to see what happens.
I've searched for anywhere that it could be getting stuck in a loop but every other part of the sketch works fine, even with readSensorData included. All buttons work, the rotary encoder works, all of the buttons on the webpage work, etc. and the temp and humidity readings update consistently both on the webpage and on the lcd screens up until it crashes. I cant find any condition where something becomes unresponsive.
I do have everything hooked up to a single power supply though. Do you think that it could be a power supply issue? It is only a cheap one that comes in the beginner kits and it is powering quite a bit of stuff
edit: in this photo the temp and humidity readings are zero because i have commented out readSensorData. They normally work fine.
Wouldn't it be that each individual sensor needs a 2sec interval?
NUM_SLOTS = 4 because there are 4 sensors in the array.
The code should:
only after the 5 second interval has passed
read temp from sensor0
read hum from sensor0
read temp from sensor1
read hum from sensor1
read temp from sensor2
read hum from sensor2
read temp from sensor3
read hum from sensor3
Then there is another 5 second interval before the sensors should be read again. i have used the serial monitor to confirm that they are only being read every 5 seconds
edit: I just realised it could be because i am reading the temp and humidity immediately after each other. I haven't tried reading them separately with a 2 second interval in between each!
I didnt. I tried 10k resistors when i first got them and they would all read NAN.
I just tried some 5.1k and they are returning actual values. Will leave running for a while and see what happens. If i have no luck then i will start reformatting my code to post
Check your library and wiring. I had a similar problem with an esp8266 and it turned out the library I was using was waiting for data that never came. The data wire was loose so no data, which eventually caused a wdt timeout.
Thank you everyone for the help and suggestions.
I ended up spending more time on this, rewiring things, swapping out components, running a modified version of the DHT example code, etc. and didn't get anywhere. Sometimes it would run fine for 1.5hrs, I would think I had made progress, then it would ultimately crash. I did find that I was getting failed readings but not from one sensor consistently.
// Check if any reads failed and exit early (to try again).
if (isnan(humidity[i]) || isnan(temperature[i])) {
Serial.print("Failed to read from DHT sensor");
Serial.println(i);
return;
Last night I decided to to try some DS18b20s for the temperature readings and it has run over night with no crashes. I am just going to leave the DHTs for now and look for another solution for the humidity readings so that I can keep working. If I ever figure out what was wrong I'll make another post.