RaspberryPico串口通讯

在这里插入图片描述

from machine import UART,Pin
import time
import _thread

# 设置波特率和串口号
uart0 = UART(0, baudrate=9600,tx=Pin(0),rx=Pin(1))
LED=machine.Pin(25,machine.Pin.OUT)

#线程1定时发送其他数据
def write():
    i=0
    while True:
        i=i+1
        msg="w=%d"%(i)
        print(msg)
        uart0.write(msg)
        LED.toggle()
        time.sleep(1)  
        
_thread.start_new_thread(write,())

while True:
    if uart0.any() == 0:
        continue
    r = uart0.readline()
    print(r)
    uart0.write(r)

猜你喜欢

转载自blog.csdn.net/u014492512/article/details/125522159