Add a CircuitPython Watchdog So Your Build Reboots Itself
Your line-following robot ran clean for six laps, then froze on the seventh and sat there blinking while the judges walked to the next table. Nobody was close enough to hit reset. The fix is a weekend-sized one: about ten lines of CircuitPython that let the chip reboot itself when your code stops responding.
What Adafruit just published
Adafruit shipped a new Learn Guide for the CircuitPython watchdog module, the binding that exposes the hardware watchdog already sitting inside most modern microcontrollers. The concept is old and stubbornly reliable. You tell the silicon "if I go quiet for longer than N seconds, assume I have hung and restart me." Your main loop then has to check in on schedule. The guide calls this feeding the dog, and letting the timeout elapse without feeding means the dog bites and the board resets into a clean state.
This matters most where nobody can reach the hardware: a weather node bolted to a rooftop, a competition robot mid-run, a data logger left in a stockroom over semestral break.
The code, and the parts you already own
Cost of this build: zero pesos. If you have an RP2040 Pico, an ESP32-S3 Feather, or a SAMD51 Metro on the breadboard already, the module is baked into the firmware. No library to copy into lib/, no extra pin, no soldering.
import microcontroller
from watchdog import WatchDogModew = microcontroller.watchdog
w.timeout = 2.5
w.mode = WatchDogMode.RESET
while True:
read_sensors()
w.feed()
Two knobs, and both matter. timeout is a float in seconds, and the ceiling is set by the chip rather than by CircuitPython. The RP2040 tops out near 8.3 seconds, so a 2.5 second budget leaves comfortable headroom. mode is either RESET, which hard-resets the board, or RAISE, which throws a WatchDogTimeout exception inside your code so you can flush a log or park a servo before going down. Not every port implements RAISE, so read the support table in the guide before you design around it.
The gotcha that catches everyone: any blocking call longer than your timeout will trigger a boot loop. A slow I2C sensor read, a Wi-Fi reconnect, or a long SD card write can each blow past 2.5 seconds. Feed the dog inside those routines, or raise the timeout to match your worst-case path.
Spend Sunday testing it properly
Adding the watchdog takes ten minutes. Proving it works takes the rest of the afternoon, and that is the part worth doing. Set the mode to RESET, then deliberately break something: yank the SDA line off your I2C sensor mid-run, or drop a while True: pass into a branch you can trigger. If the board comes back on its own within your timeout window, the safety net is real. Full guide and the per-chip support table are at Adafruit's announcement, with the API reference in the CircuitPython docs.
Originally published on blog.circuit.rocks.
#maker #electronics #diy #engineering #tech #circuitpython #watchdogtimer #circuitrocks


