from machine import Pin, UART
uart = UART(2,baudrate=115200)
while True:
if uart.any():
msg = uart.read(128)
try:
str_msg = msg.decode('utf-8')
if str_msg == 'get_msg':
print('我收到了')
uart.write('我收到了')
else:
uart.write("你好!".encode("utf-8"))
uart.write("你好!")
print("指令错误!")
except Exception as e:
print("串口连接参数异常!波特率:115200,数据位:8,停止位:1,校验位:无")
print("Error:", e)