UART Loopback example script (phyduino.py) Sends a numbered message out of UART0 and reads it back, twice a second.
- Wiring
- Connect a jumper wire from D1 (TX) to D0 (RX) first; without it, nothing comes back.
- Output
sent 'hello 0', received 'hello 0'
import time
import phyduino as mcu
serial = mcu.uart(0, 115200)
count = 0
while True:
message = "hello %d" % count
serial.write(message)
time.sleep(0.05)
received = serial.read()
print("sent %r, received %r" % (message, received.decode() if received else None))
count += 1
time.sleep(0.5)