Handle ESP32 interrupts and detect stalled work
Capture button edges promptly and use a task watchdog to notice missing progress.
Opening the Python editor…
Requirements and learning goals
Before you start
- Complete Run your first ESP32 app on an ESP32-C6-DevKitC-1
- Button between GPIO 10 and GND
You will be able to
- Move interrupt work into a FreeRTOS task
- Observe a task watchdog timeout
React without blocking
An pauses normal execution when hardware needs attention. It can catch a brief button edge that a slow polling loop misses. Keep its handler short so other interrupts and tasks can run.
FreeRTOS schedules tasks on the ESP32. Our handler notifies a task; the task prints the event. A checks that the task keeps completing work. That helps distinguish a quiet sensor from frozen during a demo.
Use app diagnostics for the Linux side of a sensor system, and the firmware console for ESP32 resets; they observe different failure boundaries.
Capture button edges
With power disconnected, connect a button between 10 and GND. Reuse the first app's project. Save the complete example as main/main.c and the component configuration as main/CMakeLists.txt. Keep the other files and wendy_core dependency.
wendy runThe interrupt uses vTaskNotifyGiveFromISR() to record an edge. The task waits at most 100 ms, handles any notifications, then reports progress:
uint32_t edges = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100));
if (edges) {
printf("Falling edges: %" PRIu32 "\n", edges);
}
ESP_ERROR_CHECK(esp_task_wdt_reset());A notification count preserves multiple edges between task wakeups. Printing and waiting happen outside the interrupt.
Expected result
Press the button and expect edge counts in the logs. Several edges per press are normal mechanical bounce; this example counts electrical edges, not debounced presses.
Temporarily comment out the esp_task_wdt_reset() call and redeploy. After the configured timeout, expect a watchdog report naming the stalled task. Whether it reboots depends on the firmware's panic setting. Restore the call and redeploy after the test.
Troubleshooting
No edges? Check GPIO 10, ground, and the button's paired legs. No timeout? Check that task watchdog support is enabled and that no debugger has disabled it.
The example keeps an existing watchdog configuration; it initializes a three-second timeout only if none exists. Feed the watchdog after useful work, never from an unrelated timer.
Reference: ESP32-C6 watchdogs.
Before you move on
Can you do each of these?
- Move interrupt work into a FreeRTOS task
- Observe a task watchdog timeout
0 of 2 checkpoints solved. Try checkpoint 1
All lessons in this topic
- 1. Install Wendy Lite on your ESP32
- 2. Update an ESP32 app over Wi-Fi
- 3. Find your ESP32 on Wendy Net
- 4. Use ESP32 sensors from Linux and ROS 2
- 5. Run your first ESP32 app
- 6. Read a button, sample voltage, and drive PWM
- 7. Connect ESP32 sensors with I²C, SPI, and UART
- 8. Handle ESP32 interrupts and detect stalled work
- 9. Build an ESP32 alarm that tolerates noisy readings