This post shows how to setup serial communication between two Raspberry Pi boards.
Here is the list of contents of this post.
- Two Raspberry Pi boards : Any Raspberry Pi should work. In this post, I use Raspberry Pi 3 B+ and Raspberry Pi Zero W running Raspbian Stretch.
- 3 jumper wires (female-female) : to connect GPIO pins between Raspberry Pis.
Steps
1. Wiring
Connect jumper wires between two Raspberry Pi boards. Check this useful site for pinout (GND, Tx, and Rx).
Note: Rx pin on one Raspberry Pi should be connected to Tx pin on the other Raspberry Pi.
Note: Step 2 to Step 4 need to be done on both Raspberry Pis.
2. Enabling UART
2-1. Open “/boot/config.txt”.
sudo nano /boot/config.txt
2-2. Add the lines below at the end of the file.
# Enable UART enable_uart=1
3. Disabling console service
3-1. Disable serial-getty service.
sudo systemctl disable serial-getty@ttyS0.service
sudo nano /boot/cmdline.txt
3-3. Remove “console=serial0,115200”, then save the file.
sudo reboot
4. Setting up terminal emulator
To send and receive data, I’ll use minicom, a text-based terminal emulator.
4-1. Install minicom.
sudo apt-get install minicom -y
4-2. Type below to launch minicom and connect to UART.
minicom -b 115200 -o -D /dev/ttyS0
4-3. Press Ctrl-A then E to enable local echo. You should see “Local echo ON” message at the bottom of the screen.
4-4. Press Ctrl-A then A to enable linefeed. You should see “Add linefeed ON” message at the bottom of the screen.
5. Verify
5-1. Type something in minicom on one Raspberry Pi. You should be able to see the text on the other Raspberry Pi.
5-2. Type something back on the other Raspberry Pi.
Note: You can exit minicom by pressing Ctrl-A, and X, then select “Yes”.
Would it be possible for a PI to communicate with more than one other pi? Like 8?
Hi John,
Yes, but not with UART. UART only supports Point-to-Point communication. You can use SPI or I2C to communicate with multiple PIs. Or, you can use Wi-Fi/Ethernet.
What about using RS485/uart modbus to connect more than one pi?
Hi max,
good tutorial!
How can I access the terminal on the target raspi? I have the console service option turned on on the target raspi and turned off on the other raspi, but I cannot get it to work. Would I use minicom/screen for this, too?