Description
CircuitPython version and board name
Adafruit CircuitPython 9.2.8 on 2025-05-28; Raspberry Pi Pico W with rp2040
Code/REPL
#!/usr/bin/env python3
import os
import time
import busio
import wifi
import microcontroller
from microcontroller import watchdog
from watchdog import WatchDogMode
import socketpool
import board
import alarm
# this gives you time to copy something else to code.py if CIRCUITPY won't mount
def microcontroller_reset():
ttt = 7
print(f'resetting microcontroller in {ttt:f} seconds')
for idx in range(ttt):
print(f'feed_sleep iter = {idx:d} / {ttt:f} ......')
time.sleep(1)
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> feed watchdog timer")
watchdog.feed()
microcontroller.reset()
class FileClient:
"""stub"""
def __init__(self):
print('FileClient.__init__')
self.i2c = busio.I2C(board.GP27, board.GP26)
try:
wifi_ssid = os.getenv('CIRCUITPY_WIFI_SSID')
wifi_password = os.getenv('CIRCUITPY_WIFI_PASSWORD')
wifi.radio.connect(wifi_ssid, wifi_password)
print('-------------------------- WIFI PASSED --------------------------')
except Exception as exc:
print(f'wifi.radio.connection {exc=}')
raise exc
try:
self.socket_pool = socketpool.SocketPool(wifi.radio)
print('----------------------- SOCKETPOOL PASSED ----------------------')
except Exception as exc:
print(f'socketpool {exc=}')
raise exc
print('FileClient.__init__ PASS')
def run(self):
"""stub"""
print('run')
for idx in range(4):
print(f'---------------- awake and feeding {idx:3d} ----------------')
watchdog.feed()
time.sleep(5.0)
print('---------------- reset 4 ----------------')
microcontroller.reset()
def example_main():
"""stub"""
try:
print('example_main')
loop_sleep_time = 12
print(f'alarm.wake_alarm = {alarm.wake_alarm}')
if not alarm.wake_alarm:
print('wake up from reset;')
print('start deep_sleep() before WatchDogTimerLocal.init();')
ds_alarm = alarm.time.TimeAlarm(monotonic_time = time.monotonic() + loop_sleep_time)
alarm.exit_and_deep_sleep_until_alarms(ds_alarm)
print('wake up from alarm after deep sleep')
weatherc = None
print('!!!!!!!!!!!!!!!!!!!!!!! starting WatchDogTimerLocal !!!!!!!!!!!')
watchdog.timeout = 8
watchdog.mode = WatchDogMode.RESET
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> feed watchdog timer")
watchdog.feed()
weatherc = FileClient()
weatherc.run()
print('---------------- reset 1 ----------------')
microcontroller_reset()
except Exception as exc:
print(f"main exception {exc=}")
if weatherc:
weatherc.close()
print('---------------- reset 2 ----------------')
microcontroller_reset()
if __name__ == '__main__':
example_main()
# eee eof
Behavior
Pretending to deep sleep until alarm, CTRL-C or file write.
Woken up by alarm.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
log.setLevel() level = 10
log.setLevel() level = 10
example_main
alarm.wake_alarm = <TimeAlarm>
wake up from alarm after deep sleep
!!!!!!!!!!!!!!!!!!!!!!! starting WatchDogTimerLocal !!!!!!!!!!!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> feed watchdog timer
FileClient.__init__
-------------------------- WIFI PASSED --------------------------
----------------------- SOCKETPOOL PASSED ----------------------
FileClient.__init__ PASS
run
---------------- awake and feeding 0 ----------------
---------------- awake and feeding 1 ----------------
---------------- awake and feeding 2 ----------------
---------------- awake and feeding 3 ----------------
---------------- reset 4 ----------------
[22:25:36.332] Disconnected
[22:25:37.333] Warning: Could not open /dev/ttypicoi (No such file or directory)
[22:25:37.333] Waiting for tty device..
[22:25:47.345] Connected to /dev/ttypicoi
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Press any key to enter the REPL. Use CTRL-D to reload.
Pretending to deep sleep until alarm, CTRL-C or file write.
Woken up by alarm.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
log.setLevel() level = 10
log.setLevel() level = 10
example_main
alarm.wake_alarm = <TimeAlarm>
wake up from alarm after deep sleep
!!!!!!!!!!!!!!!!!!!!!!! starting WatchDogTimerLocal !!!!!!!!!!!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> feed watchdog timer
FileClient.__init__
-------------------------- WIFI PASSED --------------------------
----------------------- SOCKETPOOL PASSED ----------------------
FileClient.__init__ PASS
run
---------------- awake and feeding 0 ----------------
---------------- awake and feeding 1 ----------------
---------------- awake and feeding 2 ----------------
---------------- awake and feeding 3 ----------------
---------------- reset 4 ----------------
[22:26:18.091] Disconnected
[22:26:19.092] Warning: Could not open /dev/ttypicoi (No such file or directory)
[22:26:19.093] Waiting for tty device..
[22:26:31.108] Connected to /dev/ttypicoi
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Press any key to enter the REPL. Use CTRL-D to reload.
Pretending to deep sleep until alarm, CTRL-C or file write.
Woken up by alarm.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
log.setLevel() level = 10
log.setLevel() level = 10
example_main
alarm.wake_alarm = <TimeAlarm>
wake up from alarm after deep sleep
!!!!!!!!!!!!!!!!!!!!!!! starting WatchDogTimerLocal !!!!!!!!!!!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> feed watchdog timer
FileClient.__init__
-------------------------- WIFI PASSED --------------------------
----------------------- SOCKETPOOL PASSED ----------------------
FileClient.__init__ PASS
run
---------------- awake and feeding 0 ----------------
---------------- awake and feeding 1 ----------------
---------------- awake and feeding 2 ----------------
---------------- awake and feeding 3 ----------------
---------------- reset 4 ----------------
[22:27:02.031] Disconnected
[22:27:03.032] Warning: Could not open /dev/ttypicoi (No such file or directory)
[22:27:03.032] Waiting for tty device..
[22:27:30.065] Connected to /dev/ttypicoi
Auto-reload is off.
Running in safe mode! Not running saved code.
You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.
Description
After a couple (or a great many) iterations, following a deep sleep the usb tty output of the pico boots to the circuit python (I think this is the) repl prompt >>> and does not resume running. This time above it actually booted into safe mode which is worse than usual. Also the first time you run this program it almost always boots to the >>> prompt and does not resume running; after resetting it with Control-C Control-D the second and following times it keeps running for a long time and eventually gets stuck booting to the repl >>> instead of resuming.
Desired behavior is to alternate; (1) sleep (2) run (1) sleep (2) run etc.
Additional information
note this is a synopsis of a larger program that has a lot of tty print statement debugging output.
I attach the tty with the udev rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="239a",ATTRS{idProduct}=="8120",ATTRS{serial}=="E66141040383362E",OWNER="garberw",GROUP="garberw",MODE="0600",SYMLINK+="ttypicoi"
in /etc/udev/rules.d/whatever.rules
and there is also an entry for the CIRCUITPY mount in udev and fstab;
I use the linux program screen applied to the linux program tio (terminal) to access and log the tty;
maybe it is just not triggering the udev rule fast enough to reconnect the tty; the beginning output of the program before sleeping is chopped off