Read GNSS/GPS Data with Sixfab Shield/HAT

In this tutorial, we will learn how to get GPS data using Sixfab HATs with Quectel modules.

GPS(Global Positioning System) also known as NavStar indicates the position of an individual on the Earth. The satellite orbiting around the Earth sends precise details of their positions at a regular interval of time. Once the information is received by a GPS receiver, a GPS receiver can pinpoint the location. There are also navigation systems that support their specific regions like GLONASS provided in Russia.

In this article, we’ll explain how to use Python to obtain the positioning data from the LTE module and use it in your own projects.

Hardware Setup

It is important to properly setup your hardware before you get started.

Warning: This tutorial does not apply to Telit modules.

Getting the Software

They send strings that contain GPS data and other status messages. These strings are called NMEA sentences. You can access those commands by directly reading the serial port.

To use the GPS data in Python, you can directly read the strings that the module sends to the Raspberry Pi’s serial port. However, you’ll have to do all the parsing and error handling yourself.
The Python script below shows how to access GPS data by connecting directly to the serial interface.
It filters on $GPRMC NMEA sentences and then splits the well know attributes into different variables.

Install pyserial using pip3:

pip3 install pyserial

Download the GPS.py by the following command.

wget https://raw.githubusercontent.com/sixfab/Sixfab_RPi_3G-4G-LTE_Base_HAT/master/script/GPS.py

Change permission.

sudo chmod +x GPS.py

You can then run it with the following command:

python3 GPS.py
[email protected]:~ $ python3 GPS.py Connecting Port.. Receiving GPS data $GPGSV,3,1,11,02,35,049,15,12,45,105,25,18,13,201,25,24,04,168,30*76 $GPGSV,3,2,11,25,80,015,22,29,59,278,21,05,16,108,,06,,,*47 $GPGSV,3,3,11,31,31,305,,32,00,251,,49,,,34*72 $GPGGA,182142.00,3757.324422,N,02916.602155,E,1,04,1.5,162.1,M,39.0,M,,*60 $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182142.00,A,3757.324422,N,02916.602155,E,0.0,0.0,120121,4.0,E,A*32 -----Parsing GPRMC----- Latitude: 37.95540703333333N Longitute: 121.276702583333332E time : 18:21:42, latitude : 37 deg 57.324422 min(N), longitude : 029 deg 16.602155 min(E), speed : 0.0,True Course : 0.0, Date : 12/01/21, Magnetic Variation : 4.0(A),Checksum : 32 $GPGSA,A,2,02,12,24,29,,,,,,,,,1.8,1.5,0.9*3B $GPGSV,3,1,11,02,35,049,15,12,45,105,24,18,13,201,26,24,04,168,29*7C $GPGSV,3,2,11,25,80,015,23,29,59,278,21,05,16,108,,06,,,*46 $GPGSV,3,3,11,31,31,305,,32,00,251,,49,,,34*72 $GPGGA,182143.00,3757.324079,N,02916.602576,E,1,04,1.5,163.5,M,39.0,M,,*6B $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182143.00,A,3757.324079,N,02916.602576,E,0.0,0.0,120121,4.0,E,A*3C -----Parsing GPRMC----- Latitude: 37.955401316666666N Longitute: 121.2767096E time : 18:21:43, latitude : 37 deg 57.324079 min(N), longitude : 029 deg 16.602576 min(E), speed : 0.0,True Course : 0.0, Date : 12/01/21, Magnetic Variation : 4.0(A),Checksum : 3C $GPGSA,A,2,02,12,24,29,,,,,,,,,1.8,1.5,0.9*3B $GPGSV,3,1,11,02,35,049,15,12,45,105,24,18,13,201,25,24,04,168,29*7F $GPGSV,3,2,11,25,80,015,22,29,59,278,19,05,16,108,,06,,,*4C $GPGSV,3,3,11,31,31,305,,32,00,251,,49,,,34*72 $GPGGA,182144.00,3757.323621,N,02916.603135,E,1,04,1.5,165.4,M,39.0,M,,*65 $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182144.00,A,3757.323621,N,02916.603135,E,0.0,0.0,120121,4.0,E,A*35 -----Parsing GPRMC----- Latitude: 37.955393683333334N Longitute: 121.276718916666667E time : 18:21:44, latitude : 37 deg 57.323621 min(N), longitude : 029 deg 16.603135 min(E), speed : 0.0,True Course : 0.0, Date : 12/01/21, Magnetic Variation : 4.0(A),Checksum : 35

Troubleshooting

  • Make sure the USB is connected.
  • Check whether there is any interference in your test environment and see if a quality GPS signal is received.
  • Place the GPS antenna in a location that has a clear line of sight to the sky in all directions.
  • If sufficient GPS signal still can't be acquired, test your modem in a different location.
  • Place the GPS antenna as high as physically possible.
  • Please check the module firmware version with ATI command, we need to confirm whether the module you used can support GPS or not.
  • It is better to check the satellite signal quality via NEMA sentence.
  • Please inquire the GPS/GNSS on/off state. If it's off, you need to turn on GPS/GNSS.
  • Check the module's configuration with the AT commands below:

AT Commands

AT+QGPS? # Should return 1

AT+QGPS=1 # If previous command returns 0

AT+QGPSLOC? # Obtain Positioning Information. Wait few seconds before sending this command.

AT+QGPSCFG="outport" # GNSS output port configuration, should return usbnmea

+CME ERROR: 516

If you are getting +CME ERROR: 516, this means the location is not fixed yet. Either continue to wait for a few minutes, or move the GPS antenna near a window or outside.

More Details

  1. LTE Standard GNSS Application Note

  2. EC25&EC21 GNSS AT Commands Manual

  3. BG96 GNSS AT Commands Manual

  4. GPS - NMEA sentence information