UART Communication with Raspberry Pi - RolandoMagico/ESP32NodeMCU GitHub Wiki
This page describes how the Raspberry Pi can be configured for UART communication. As the UART interface is used for a serial linux console by default, some adaptions are required to use the UART interface in other applicatiions.
Environment
The settings has been tested in the following environment:
- Raspberry Pi 4
- Rasperry Pi OS of December 2nd 2020 (2020-12-02-raspios-buster-armhf-full.zip)
Write Image
Download the image, unpack it and flash it to your SD card as described here: https://www.raspberrypi.org/software/
Configure UART usage
Before starting the Raspberry Pi the first time, modify the following files:
- Add the follwoing line at the end of /boot/config.txt
enable_uart=1
- Change /boot/cmdline.txt, remove the following text
console=serial0,115200
Optional: Enable SSH access by default
If you want to access the Raspberry Pi via SSH by default, create an empty file /boot/SSH.txt
Install Screen
After booting the Raspberry Pi, install screen:
sudo apt-get install screen
Test UART communication in loopback mode
The pins GPIO 14 (TX) and GPIO 15 (RX) are used for UART communication. For loopback testing, connect both pins to each other.
For testing, we use screen as a terminal:
screen /dev/serial0 115200
Now you should be able to enter text. If the text is shown in the screen window, the loopback test works.
For exiting screen, press Ctrl + A
, than \
.