Setting Up UART Serial Communication between Raspberry Pis


This post shows how to setup serial communication between two Raspberry Pi boards.

Here is the list of contents of this post.

Contents

 

Prerequisites

 

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
3-2. Open “/boot/cmdline.txt”.
sudo nano /boot/cmdline.txt

3-3. Remove “console=serial0,115200”, then save the file.

3-4. Reboot.
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”.

 

 

Sponsor Link

4 Comments

  1. Would it be possible for a PI to communicate with more than one other pi? Like 8?

    1. 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.

  2. 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?

Comments are closed.