Connect two Raspberry Pis and test uart communication.
There are three connections as follows.
GND --- GND (6 --- 6) TxD --- RxD (8 --- 10) RxD --- TxD (10 --- 8)
Sending program
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()
Start cu on the receiving side
sudo cu -s 115200 -l /dev/ttyS0
Launch serialTest.py on the sender
sudo ./serialTest.py
Results on the receiving side
$ sudo cu -s 115200 -l /dev/ttyS0
Connected.
Hello, World!
To stop cu
~.
The group in / dev / ttyS0 must also be root.
sudo chgrp root /dev/ttyS0
I referred to the next page. Enable UART on Raspberry Pi + serial communication
Recommended Posts