Raspberry Pi serial configuration for GPS receivers

This page explains how to set up a Raspberry Pi 3B or Zero W so that the default serial configuration is changed to allow a GPS receiver to use the more reliable hardware serial port.
The Raspberry Pi 3B and Zero W each have two serial ports. One is a hardware serial port that by default is connected to the Bluetooth module. The other is a software based mini UART used for Linux console output by default. The baud rate of the mini UART is not stable as it does not have its own clock. Instead its baudrate is based on the system GPU clock speed. The mini UART also has smaller FIFOs, no flow control and is prone to losing characters at higher baud rates. For these reasons it is better to use the hardware serial port for connection to a GPS receiver.
From the command line enter the command sudo raspi-config to start the Raspberry Pi software configuration tool as shown below. Select option 5 Interfacing options.

Then select option P6 Serial as shown below.

Then select No to the login shell.

Then select Yes to the serial port being enabled.

At the end of this process the serial login shell is disabled and the serial interface is enabled.

Follow the instructions to reboot so the changes you have made to the serial configuration come into effect. When you have rebooted use the command ls -l /dev/ser* to show the serial device settings. As serial1 is the Bluetooth module and ttyS0 is the mini UART we want to swap these around so that the external serial connector serial0 uses the hardware UART ttyAMA0.

Enter sudo leafpad /boot/config.txt from the command line to edit the config.txt file. Go to the bottom of the file and after the enable_uart=1 line, as shown below, add the following lines:
dtoverlay=pi3-miniuart-bt
core_freq=250
The pi3-miniuart-bt is a device tree overlay which switches the Raspberry Pi Bluetooth module to use the mini UART, ttyS0. The hardware UART ttyAMA0 is then available to the external serial port on the GPIO header. Save and Close the file. Then reboot with command sudo reboot. After the system has restarted use the command ls -l /dev/ser* once again to show the revised serial device settings.

The default baud rate of the serial port is 9600. If the baud rate of the GPS receiver is 9600, like the L80, then you can proceed to test the serial port. Otherwise when the baud rate of the receiver is different , the Gmm transmits at 38400 for example, you need to reset the baud rate of the serial port. To do this use the folowing command stty -F /dev/ttyAMA0 38400 as shown below. Where 38400 should be replaced with your desired baud rate.
Then enter the command sudo cat /dev/ttyAMA0. This will display the incoming NMEA serial data from the attached GPS receiver. The data may initially appear garbled as the serial buffer FIFO is cleared of old data first. To terminate the input type CTRL+C to quit.

 

Home

Back

© The BlackBoxCameraTM Company Limited 2019