Pi Pico watchdog

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BrianEnce
 
Posts: 7
Joined: Fri Feb 21, 2020 8:55 pm

Pi Pico watchdog

Post by BrianEnce »

I'm trying to implement the watchdog timer on a Pico. Using the code below I was expecting to see the Pico re-start every 5 seconds, that is: see the count go up to 5 then start over. What happens is: after five seconds it resets and appears as though I have just plugged it in and the Circuitpy directory is displayed. Seconds later it again resets, displaying the directory again, etc. It never resumes the program and I have to "nuke" it to regain control.

Code: Select all

import time
import microcontroller
import watchdog

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


count = 0

while 1:
    count += 1
    print(count)
    time.sleep(1)
    
I'm using MuEditor-win64-1.2.0 and adafruit-circuitpython-rasbperry-pi-pico-en-US-8.0.5.uf2
What am I missing?

User avatar
BrianEnce
 
Posts: 7
Joined: Fri Feb 21, 2020 8:55 pm

Re: Pi Pico watchdog

Post by BrianEnce »

The problem with that code was relying on getting access to Mu to see the output.
This works:

Code: Select all

# watchdog test
import time
import board
import digitalio

import microcontroller
import watchdog

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

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

led.value = True
time.sleep(1) # this helps to visually verify that the program did restart

# do something to visualize operation without using MU:
while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)
The only problem now is how stop the watchdog so that I can modify/add to the program.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”