print doesn't come back after light sleep on rpi pico #14401
-
print seems problematic on the rpi pico (upython v 1.22.2)
The led flashes 3 times which means the loop runs as expected but I get only one of the 4 prints I expected. Is there a work around for this behaviour? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 33 replies
-
Try adding: |
Beta Was this translation helpful? Give feedback.
-
This blocking of print is caused by lightsleep(). lightsleep turns of the USB clock and slows down other clocks. It seems that USB needs input from the PC to get working again. The same would happen if you use sys.stdout.write() instead of print(). Using sleep_ms() instead of lightsleep() works. |
Beta Was this translation helpful? Give feedback.
-
I've submitted a pull request that keeps the USB peripheral clocks enabled during lightsleep on rp2, if a USB host is connected and active: #15111 |
Beta Was this translation helpful? Give feedback.
-
Ahem, has this been tested? #!micropython
from machine import lightsleep, Pin
led = Pin(25, Pin.OUT)
for i in range(10):
led.toggle()
lightsleep(100)
for i in range(6):
print(f'cycle {i}')
led.toggle()
lightsleep(500) Hangs. Sometimes during the first run, sometimes during the second. EDIT: |
Beta Was this translation helpful? Give feedback.
This PR was merged in a84c7a0 (not part of the v1.23.0 release, will be in the next release).