UIFlow Guide
不断地在 uart1 和 uart2 之间交换数据,实现双向通信。
from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x292929)
label0 = M5TextBox(15, 106, "Slave Baud", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(12, 130, "115200", lcd.FONT_DejaVu40, 0x02c7fc, rotate=0)
label2 = M5TextBox(15, 20, "TX", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(139, 20, "RX", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(12, 40, "G17", lcd.FONT_DejaVu40, 0x00ff38, rotate=0)
label5 = M5TextBox(136, 40, "G16", lcd.FONT_DejaVu40, 0x00ff38, rotate=0)
label9 = M5TextBox(173, 106, "/", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0)
label10 = M5TextBox(199, 125, "PC default baud", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label11 = M5TextBox(224, 149, "115200", lcd.FONT_Default, 0xFFFFFF, rotate=0)
uart1 = machine.UART(1, tx=1, rx=3)
uart1.init(115200, bits=8, parity=None, stop=1)
uart2 = machine.UART(2, tx=17, rx=16)
uart2.init(115200, bits=8, parity=None, stop=1)
while True:
if uart1.any():
uart2.write(bytes(uart1.read()))
if uart2.any():
uart1.write(bytes(uart2.read()))
wait_ms(2)
uart1 = machine.UART(1, tx=14, rx=13)
uart1.init(9600, bits=8, parity=None, stop=1)
uart1.write(''+"\r\n")
uart1.write('')
uart1.write(bytes([0, 0, 0]))
str(uart1.read())
label0.set_text(str(uart1.read(10)))
str(uart1.readline())
str(uart1.any())