Sphere
Log in Join
☆ 10

esp32 reboot loop with watchdog timer trigger

ESP32 DevKit V1, Arduino 2.2.1. My sketch boots, prints a few lines, then reboots every ~6 seconds. Serial monitor shows 'E (1234) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:' followed by 'IDLE0 (CPU 0)'. I'm using WiFi and a loop that does delay(1) with some sensor reads. I didn't explicitly start any watchdog. Why is the idle task not running? I've read it's usually caused by blocking the loop or an infinite loop, but my loop seems fine. Could WiFi be starving the idle task?

⚑ Report

4 replies

☆ 0
P plastic ·2026-11-11#1

The task watchdog (TWDT) triggers when a task hogs the CPU so the IDLE task can't run and feed it. delay(1) should yield, so that's fine. Common culprits: a while loop without delay, a busy-wait on a GPIO, or a blocking function inside a callback/interrupt, or flash operations that disable interrupts too long. Check for a tight loop iterating a large array without delay - even that can starve IDLE0 if it takes over a second.

⚑ Report
☆ 0
C cactus52 ·2026-11-11#2

I do have a loop that reads an ADC in a tight while until it settles - while(adcRead() > threshold) {} with no delay. That might be it. It usually exits fast but if the sensor is noisy it could spin. Also I attached a hardware interrupt that does some Serial.print inside the ISR - I know that's bad. Could serial in ISR block?

⚑ Report
☆ 0
G glitch ·2026-11-15#3

Both are problems. Serial.print in an ISR is a big no - it can block and isn't reentrant; move it to a flag and print in the main loop. The tight ADC while loop is almost certainly starving IDLE0: add a delay(1) or delayMicroseconds(100) inside it so the RTOS can schedule, and add a timeout so it can't run forever. A busy loop still prevents IDLE from running even though Arduino on ESP32 uses the RTOS scheduler.

⚑ Report
☆ 0
R rust72 ·2026-11-18#4

Added a small delay in the ADC loop, moved Serial.print out of the ISR, watchdog reboots stopped. Turns out my noisy sensor made the while loop spin for ~800ms during a particular reading - enough to trigger eventually. TWDT is actually useful, it caught a real bug. If you see 'task_wdt' and 'IDLE0', look for a loop without a yield first.

⚑ Report
Log in to reply.