← index #8160Issue #16801
Off-topic · high · value 0.726
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 Pi Pico - No UART after lightsleep when not connected to USB

openby juehvopened 2025-02-24updated 2025-03-03
bugport-rp2

Port, board and/or hardware

Raspberry Pi Pico (1)

MicroPython version

MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico with RP2040

Reproduction

Run this code in main.py

from machine import UART, Pin, lightsleep
from utime import sleep_ms


UART_BAUD_RATE=9600
UART_BITS=8
UART_PARITY=None
UART_STOP=1
UART_INSTANCE=0
TX_PIN = 16
RX_PIN=17


uart = UART(UART_INSTANCE, baudrate=UART_BAUD_RATE, tx=Pin(TX_PIN), rx=Pin(RX_PIN), bits=UART_BITS, parity=UART_PARITY, stop=UART_STOP)

sleep_ms(5000) # give windows a chance to identify device before everything is messed up

while True:
    print ("run loop")
    uart.write("second uart")
    uart.flush()
    lightsleep(1000) 
    sleep_ms(10) # wait for everything to wake up  

Expected behaviour

Expected to putout this on second uart0 (not USB Uart, but second UART device). This is also the case when constantly connected to PC (Windows 10 in my case, but doesn't matter).

second uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uartsecond uart

Observed behaviour

This is observed when connected to a power bank via USB instead of PC (same behaviour with other powering methods)

second uartsgV▒sc▒▒sc▒▒sg▒▒sg▒▒wg▒▒sg▒▒sg▒▒sg▒▒sg▒▒sg▒▒sg▒▒sg▒▒sg▒▒wg▒▒sg▒▒wg▒▒sc▒▒

Additional Information

No, I've provided everything above.

PS: My personal theory is that uart is not put to sleep when connected to PC and therefore works fine, but is put to slepp when no PC connection is present and does not wake properly ...

Code of Conduct

Yes, I agree

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