シリアル通信

2021/10/23

MicroPython1.17(RP2)

送信

import utime
from machine import UART, Pin

uart1 = UART(1, 115200, tx=Pin(4), rx=Pin(5))

while True:
    uart1.write(b'Hello World')
    utime.sleep(1)


受信

import utime
from machine import UART, Pin

uart1 = UART(1, 115200, tx=Pin(4), rx=Pin(5))

while True:
    rxData = bytes()
    while uart1.any() > 0:
        rxData += uart1.read(1)
    if len(rxData) > 0:
        print(rxData.decode('utf-8'))
    utime.sleep(1)


RaspberryPi ZeroとPicoのシリアル通信
https://tiblab.net/blog/2021/08/raspberrypi-zero-pico-serial/