0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電子工作メモ - シリアル通信(UART)

Last updated at Posted at 2024-03-21

シリアル通信(UART)

  • TX: 送信
  • RX: 受信
  • baudrate: 通信速度。両側で合わせる。

USBに統合されているシリアル

import time

print("Raspberry Pi Pico initialization completed !")

while True:
    print("Running time : ", time.time()%60,"s")
    time.sleep(1)
print(str("\nRaspberry Pi Pico initialization completed!\n")
      + str("Please input some characters,\n")
      + str("select \"Newline\" below and click send button. \n"))
while True:
    print("inputString: ",input())

UART

  • UART0, UART1 の2つ使える
type GPIO Pin
UART0 TX GPIO0 1
UART0 RX GPIO1 2
UART1 TX GPIO8 11
UART1 RX GPIO9 12
  • TX と RX をつなぐ
    • UART0 TX(GPIO0) <=> UART1 RX(GPIO9)

    • UART0 RX(GPIO1) <=> UART1 TX(GPIO8)

      from machine import UART, Pin
      import time
      
      myUsart0 = UART(0, baudrate=9600, bits=8, tx=Pin(0), rx=Pin(1), timeout=10)
      myUsart1 = UART(1, baudrate=9600, bits=8, tx=Pin(8), rx=Pin(9), timeout=10)
      
      while True:
          rxData = bytes()
          input_cnt = str(input("myUsart1: "))
          myUsart1.write(input_cnt)
          time.sleep(0.1)
          while myUsart0.any() > 0:
              rxData += myUsart0.read(1)
          print("myUsart0: " , rxData.decode('utf-8'))
      
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?