Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

Serial Port setup in Raspberry Pi OS Bookworm

Configuring the serial port on the Raspberry Pi


The Raspberry Pi contains a UART serial port on the GPIO header on pins 8, TXD (GPIO 14) and 10, RXD (GPIO 15).  The UART port can connect directly to a wide range of devices using 3.3V UART pins or a serial interface to convert the UART voltages to an industry standard such as RS232 or RS485.  When connecting a device to the UART serial port, always ensure your device operates at the correct voltage, 3.3V.  Connecting a 5V device to the UART port can damage the Raspberry Pi GPIO header.

Illustration of the UART pins on a Raspberry Pi GPIO header

Using the UART serial port

The UART port can be enabled using the raspi-config utility.

Step 1 - Install Raspberry Pi OS onto an SD card and boot the Raspberry Pi.

Login via terminal or desktop and shell.

Configure the system with the following:

sudo raspi-config

Step 2 - Select “3 Interface Options”

raspi-config screen 1

Step 3 - Select “I6 Serial Port”

raspi-config screen 2

Step 4 - A screen will ask if you want a login shell accessible over serial.  Select Yes to control the Raspberry Pi through a serial port terminal.  Select No if you use the serial port to control other devices.

raspi-config screen 3

Step 5 - When asked if you would like the serial port hardware to be enabled, select Yes.

raspi-config screen 4

Step 6 - A confirmation screen should appear, showing the serial port has been enabled.

raspi-config screen 5

Step 7 - On the main raspi-config screen, select finish and reboot your Raspberry Pi.  The UART serial port should now be enabled.

Disabling the Serial Login Shell (alternative method)

You can use the following steps to disable the serial login shell without using raspi-config.

Step 1:  To disable the serial login shell, edit the /boot/cmdline.txt file.

sudo nano /boot/cmdline.txt

Step 2:  Find the following text and remove it:

console=serial0,115200

Step 3:  Exit the editor, save your changes, and then:

sudo reboot

With the serial login shell disabled, you can now access the UART serial port at /dev/ttyS0.

Notes for the Raspberry Pi 3 Model B, B+, 4 and Raspberry Pi Zero W:

The Raspberry Pi 3 Model B, B+, 4 and Raspberry Pi Zero W contain two UART controllers which can be used for serial communication, the mini UART and PL011 UART.  By default, the mini UART is mapped to the TXD (GPIO 14) and RXD (GPIO 15) on the 40-pin GPIO header and the PL011 UART is used for the Bluetooth/Wireless module, but either module can be mapped to the GPIO port.

The mini UART port can be accessed using the /dev/ttyS0 device in Linux.  One issue with the mini UART controller is that its baud rate is linked to the VPU core frequency, so as the VPU frequency changes depending on processor load, so does the baud rate of the UART controller.  This will cause problems as serial devices expect a constant baud rate during communication.

To fix this issue, the VPU core frequency must be fixed, which can either limit the speed of the Raspberry Pi or increase power consumption and heat generated, depending on the speed at which the core frequency is set.

The mini UART controller has a smaller FIFO buffer than the PL011 UART controller.  This can cause problems at higher baud rates, making losing characters more likely.

The PL011 UART controller is not linked to the VPU core frequency.  This means that the baud rate stays the same regardless of VPU speed.  The PL011 UART controller also includes other features not present in the mini UART controller, such as framing error detection, break detection, receive timeout interrupts and parity bit support.

The main disadvantage of using the PL011 UART controller is that it disables the Bluetooth/Wireless module, so you cannot use the Bluetooth features of the Raspberry Pi 3 and Zero W.
We recommend using the PL011 UART controller when a reliable data connection, power consumption, and processor speed are priorities.

If you need to use the Bluetooth module on the Raspberry Pi, use the mini UART controller. 

Using the PL011 UART port

For Raspberry Pi OS and Raspbian Linux, there is a device tree file called disable-bt, which makes the Raspberry Pi disable the Bluetooth module and map pl011 UART on pins 14 and 15.

Step 1 - Login via terminal or desktop and shell

Step 2:  Device Tree settings as below:

Add the device tree to /boot/config.txt to disable the Bluetooth module.

sudo nano /boot/config.txt

Add at the end of the file

dtoverlay=disable-bt

Exit the editor.

Step 3:  You must also disable the hciuart service, which initialises the Bluetooth modem:

sudo systemctl disable hciuart

Step 4:  Reboot your Raspberry Pi to enable the changes:

sudo reboot

You can check if the serial port works by following our Serial Port Loopback Test tutorial steps.

For programming the serial port on a Raspberry Pi, we recommend the pySerial Python library.


Was this article helpful? Yes No

Please tell us how we can improve this article:

Submit
Created 19/03/2016 | Last Updated: 29/10/2023