LoginSignup
0
2

More than 3 years have passed since last update.

Raspberry Pi で uart 通信のテスト

Last updated at Posted at 2020-09-29

2台の Raspberry Pi をつないで uart 通信のテストをします。

結線は次の3箇所です。

GND --- GND (6 --- 6)
TxD --- RxD (8 --- 10)
RxD --- TxD (10 --- 8)
raspberry_sep30.png

送信のプログラム

serialTest.py
#! /usr/bin/python3
#
import serial
#
ser = serial.Serial('/dev/ttyS0', '115200', timeout=0.1)
#
ser.write(str.encode('Hello, World!\r\n'))
print(repr(ser.readline()))
ser.close()

受信側で、cu を起動

sudo cu -s 115200 -l /dev/ttyS0

送信側で serialTest.py を起動

sudo ./serialTest.py

受信側の結果

$ sudo cu -s 115200 -l /dev/ttyS0
Connected.
Hello, World!

cu を停止させるには

~.

/dev/ttyS0 のグループも root にする必要があります。

sudo chgrp root /dev/ttyS0

次のページを参考にしました。
Raspberry PiでUARTの有効化+シリアル通信

0
2
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
2