About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Knowledge Base

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

Knowledge Base

Raspberry Pi 3, 4 and Zero W Serial Port Usage

Configure the serial port on Raspberry Pi 3, 3+, 4 and Raspberry Pi Zero W
Created: 19/03/2016 | Last Updated: 27/06/2019

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.

UART GPIO Pins

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 what speed the core frequency is set at.

The mini UART controller has a smaller FIFO buffer than the PL011 UART controller.  This can cause problems at higher baud rates as it makes 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 will be unable to use the Bluetooth features of the Raspberry Pi 3 and Zero W.
We recommend using the PL011 UART controller in any situation where a reliable data connection is needed, or power consumption and processor speed are a priority.

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

Using the Mini UART port

Since the November 2018 release of Raspbian Stretch the mini UART port can be enabled using the raspi-config utility.

Step 1 - Install Raspbian Stretch or later onto a SD card and boot the Pi when connected to a network

Login via terminal or desktop and shell

Configure the system with:

sudo raspi-config

Step 2 - Select “5 Interfacing Options”

raspi-config screen 1

Step 3 - Select “P6 Serial”

raspi-config screen 2

Step 4 - A screen will ask you if you would like a login shell to be accessible over serial.  If you want to control the Raspberry Pi through a serial port terminal, select Yes.  If you are using the serial port to control other serial devices, select No.

raspi-config screen 3

Step 5 - If you selected No another screen will ask you if you would like the serial port hardware to be enabled.  Select Yes.

raspi-config screen 4

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

Using the PL011 UART port

For Raspbian Linux releases after 18th March 2016 there is a device tree file called pi3-miniuart-bt which makes the Raspberry Pi disable the Bluetooth module and map pl011 UART on pins 14 and 15 as before.

Step 1 - Login via terminal or desktop and shell

Step 2:  Device Tree settings as below:

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

sudo nano /boot/config.txt

Add at the end of the file

dtoverlay=pi3-miniuart-bt

Step 3:  Exit the editor saving your changes and then:

sudo reboot

Disabling the Serial Console

The serial console on Raspberry Pi Stretch is enabled by default.  To use the UART port with serial devices you will need to disable the console.

Step 1:  To disable the serial console, you need to 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 saving your changes and then:

sudo reboot

With the serial console disabled you can now access the UART serial port at /dev/ttyAMA0.
 

Was this article helpful? Yes / No

Releated Products

Order a Serial Pi Plus

Serial Pi Plus

£8.99 Inc VAT: £10.79

Order a Serial Pi Zero

Serial Pi Zero

£8.49 Inc VAT: £10.19

Order a RS485 Pi RS485 Pi

RS485 Pi

£10.99 Inc VAT: £13.19

Related Articles