watchdog – Watchdog Timer

The watchdog module provides support for a Watchdog Timer. This timer will reset the device if it hasn’t been fed after a specified amount of time. This is useful to ensure the board has not crashed or locked up. Note that on some platforms the watchdog timer cannot be disabled once it has been enabled.

The WatchDogTimer is used to restart the system when the application crashes and ends up into a non recoverable state. Once started it cannot be stopped or reconfigured in any way. After enabling, the application must “feed” the watchdog periodically to prevent it from expiring and resetting the system.

Example usage:

from microcontroller import watchdog as w
from watchdog import WatchDogMode
w.timeout=2.5 # Set a timeout of 2.5 seconds
w.mode = WatchDogMode.RAISE
w.feed()

Available on these boards
  • ARAMCON Badge 2019
  • ARAMCON2 Badge
  • ATMegaZero ESP32-S2
  • Adafruit CLUE nRF52840 Express
  • Adafruit Circuit Playground Bluefruit
  • Adafruit Feather Bluefruit Sense
  • Adafruit Feather RP2040
  • Adafruit Feather nRF52840 Express
  • Adafruit FunHouse
  • Adafruit ItsyBitsy RP2040
  • Adafruit ItsyBitsy nRF52840 Express
  • Adafruit LED Glasses Driver nRF52840
  • Adafruit Macropad RP2040
  • Adafruit MagTag
  • Adafruit Metro ESP32S2
  • Adafruit Metro nRF52840 Express
  • Adafruit QT Py RP2040
  • Adafruit QT2040 Trinkey
  • Arduino Nano 33 BLE
  • Arduino Nano RP2040 Connect
  • Artisense Reference Design RD00
  • AtelierDuMaker nRF52840 Breakout
  • BLE-SS dev board Multi Sensor
  • BastBLE
  • BastWiFi
  • BlueMicro840
  • Challenger RP2040 WiFi
  • CrumpS2
  • Cytron Maker Pi RP2040
  • ESP 12k NodeMCU
  • Electronut Labs Blip
  • Electronut Labs Papyr
  • EncoderPad RP2040
  • Feather ESP32S2 without PSRAM
  • FeatherS2
  • FeatherS2 Neo
  • FeatherS2 PreRelease
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Gravitech Cucumber M
  • Gravitech Cucumber MS
  • Gravitech Cucumber R
  • Gravitech Cucumber RS
  • HMI-DevKit-1.1
  • HiiBot BlueFi
  • IkigaiSense Vita nRF52840
  • Kaluga 1
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • MDBT50Q-DB-40
  • MDBT50Q-RX Dongle
  • MORPHEANS MorphESP-240
  • MakerDiary nRF52840 MDK
  • MakerDiary nRF52840 MDK USB Dongle
  • Makerdiary M60 Keyboard
  • Makerdiary Pitaya Go
  • Makerdiary nRF52840 M.2 Developer Kit
  • Oak Dev Tech PixelWing ESP32S2
  • Open Hardware Summit 2020 Badge
  • PCA10056 nRF52840-DK
  • PCA10059 nRF52840 Dongle
  • PCA10100 nRF52833 Dongle
  • Particle Argon
  • Particle Boron
  • Particle Xenon
  • Pimoroni Interstate 75
  • Pimoroni Keybow 2040
  • Pimoroni PGA2040
  • Pimoroni Pico LiPo (16MB)
  • Pimoroni Pico LiPo (4MB)
  • Pimoroni PicoSystem
  • Pimoroni Plasma 2040
  • Pimoroni Tiny 2040
  • Raspberry Pi Pico
  • S2Mini
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Simmel
  • SparkFun MicroMod RP2040 Processor
  • SparkFun MicroMod nRF52840 Processor
  • SparkFun Pro Micro RP2040
  • SparkFun Pro nRF52840 Mini
  • SparkFun Thing Plus - RP2040
  • TG-Watch
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • Teknikio Bluebird
  • TinkeringTech ScoutMakes Azul
  • TinyS2
  • WarmBit BluePixel nRF52840
  • micro:bit v2
  • microS2
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom
  • nice!nano

class watchdog.WatchDogMode

run state of the watchdog timer

Enum-like class to define the run mode of the watchdog timer.

RAISE :WatchDogMode

Raise an exception when the WatchDogTimer expires.

RESET :WatchDogMode

Reset the system if the WatchDogTimer expires.

class watchdog.WatchDogTimer

Timer that is used to detect code lock ups and automatically reset the microcontroller when one is detected.

A lock up is detected when the watchdog hasn’t been fed after a given duration. So, make sure to call feed within the timeout.

Not currently dynamically supported. Access the sole instance through microcontroller.watchdog.

timeout :float

The maximum number of seconds that can elapse between calls to feed()

mode :WatchDogMode

The current operating mode of the WatchDogTimer watchdog.WatchDogMode.

Setting a WatchDogMode activates the WatchDog:

import microcontroller
import watchdog

w = microcontroller.watchdog
w.timeout = 5
w.mode = watchdog.WatchDogMode.RAISE

Once set, the WatchDogTimer will perform the specified action if the timer expires.

feed(self)None

Feed the watchdog timer. This must be called regularly, otherwise the timer will expire.

deinit(self)None

Stop the watchdog timer. This may raise an error if the watchdog timer cannot be disabled on this platform.