← index #8160Issue #9634
Related · high · value 0.395
QUERY · ISSUE

uart.any freezing when second data has sended

openby ertugrulcakiciopened 2022-01-11updated 2026-03-16
port-rp2needs-info

main.py in rasberry pi pico

from machine import UART
from time import sleep


uart = UART(0,9600)

def read():
    global uart
    data = uart.read()

while True:
    if uart.any():
        read()
        sleep(0.3)

When i open the serial port with the same settings as rasberry pi pico's serial port, its works nicely. But then, I open Arduino Uno editor then serial port screen, I'm able to send the first data but when I send the second data, it's just freezing forever.
I tried with different rasberry pi pico but the result is the same.

CANDIDATE · ISSUE

Raspberry Pico W MicroPython execution freezes a few seconds after disconnecting screen from UART

closedby robert-hhopened 2022-10-15updated 2022-11-09
port-rp2

Discussed in https://github.com/orgs/micropython/discussions/9633

<div type='discussions-op-text'>

<sup>Originally posted by cirosantilli October 15, 2022</sup>
I got my program running fine as explained at: https://stackoverflow.com/questions/66183596/how-can-you-make-a-micropython-program-on-a-raspberry-pi-pico-autorun/74078142#74078142

I'm installing a main.py that does:

import machine
import time

led = machine.Pin('LED', machine.Pin.OUT)
# For Rpi Pico (non-W) it was like this instead apparently.
# led = Pin(25, Pin.OUT)

i = 0
while (True):
    led.toggle()
    print(i)
    time.sleep(.5)
    i += 1

When I power the device on by plugging the USB to my laptop, it seems to run fine, with the LED blinking.

Then, if I connect from my laptop to the UART with:

screen /dev/ttyACM0 115200

I can see the numbers coming out on my host terminal correctly, and the LED still blinks, all as expected.

However, when I disconnect from screen with Ctrl-A K, after a few seconds, the LED stops blinking! It takes something around 15 seconds for it to stop, but it does so every time I tested.

If I reconnect the UART again with:

screen /dev/ttyACM0 115200

it starts blinking again.

Also also noticed that after I reconnect the UART and execution resumes, the count has increased much less than the actual time passed, so one possibility is that the Pico is going into some slow low power mode?

Micropython firmware: rp2-pico-w-20221014-unstable-v1.19.1-544-g89b320737.uf2, Ubuntu 22.04 host.

Also asked at:

  • https://stackoverflow.com/questions/74081960/raspberry-pico-w-micropython-execution-freezes-a-few-seconds-after-disconnecting</div>

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied