from machine import UART, Pin
import time
time.sleep(0.5)
print("Starting UART loopback test")
uart = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9))
# Clear any old bytes
while uart.any():
uart.read()
message = "Hello Wokwi"
# Send the string
uart.write(message)
# Give the bytes time to loop back
time.sleep(0.2)
# Read back whatever arrived
received = b""
while uart.any():
chunk = uart.read()
if chunk:
received += chunk
if received:
print("Received:", received.decode())
else:
print("No data received")