Read GNSS/GPS Data with Sixfab Base HAT

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

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.

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.

For Quectel Modules

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
pi@raspberrypi:~ $ 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

For Telit Modules

Open a new serial port to set up the module GPS/GNSS configuration.

sudo minicom -b 115200 -D /dev/ttyUSB2
Welcome to minicom 2.7.1 OPTIONS: I18n Compiled on Aug 13 2017, 15:25:34. Port /dev/ttyUSB2 Press CTRL-A Z for help on special keys _ CTRL-A Z for help | 115200 8N1 | NOR | Minicom 2.7.1 | VT102 | Offline | ttyUSB2

Switch off/on the module and restore the default GNSS parameters in order to start from a known GNSS setting.

AT$GPSRST command resets the GNSS parameters to "Factory Default" configuration

AT$GPSRST OK

Delete the GPS information stored in NVM. It is the history buffer interfacing the GPS
receiver to the module. This action is not mandatory; it should be performed only if you need
to clean the buffer.

AT$GPSNVRAM=15,0 OK

Check that after history buffer cleaning no GPS information is available

AT$GPSACP $GPSACP: OK

For enabling unsolicited messages of GNSS data in NMEA format, refer to [1]. In this example, all sentence is enabled:

AT$GPSNMUN=2,1,1,1,1,1,1 OK

Start the GNSS receiver in standalone mode:

AT$GPSP=1 OK

Open a new port through the ttyUSB1 port to watch the NMEA stream.

sudo minicom -b 115200 -D /dev/ttyUSB1
Welcome to minicom 2.7.1 OPTIONS: I18n Compiled on Aug 13 2017, 15:25:34. Port /dev/ttyUSB1, 10:22:40 Press CTRL-A Z for help on special keys $GPGSV,2,1,05,06,,,36,13,10,175,18,15,24,208,26,39,,,37,1*6A $GPGSV,2,2,05,41,,,34,1*63 $GPGGA,182144.00,3757.595246,N,01115.606721,E,1,02,1.1,139.2,M,39.0,M,,*69 $GPGLL,3757.595246,N,01115.606721,E,182144.00,A,A*6D $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182144.00,A,3757.595246,N,01115.606721,E,0.0,0.0,240321,4.0,E,A,V*49 $GPGSA,A,3,06,15,,,,,,,,,,,1.5,1.1,0.9,1*20 $GPGSV,2,1,05,06,,,36,13,10,175,18,15,24,208,26,39,,,37,1*6A $GPGSV,2,2,05,41,,,34,1*63 $GPGGA,182145.00,3757.595210,N,01115.606739,E,1,02,1.1,139.2,M,39.0,M,,*62 $GPGLL,3757.595210,N,01115.606739,E,182145.00,A,A*66 $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182145.00,A,3757.595210,N,01115.606839,E,0.0,0.0,240321,4.0,E,A,V*42 $GPGSA,A,3,06,15,,,,,,,,,,,1.5,1.1,0.9,1*20 $GPGSV,2,1,05,06,,,36,13,10,175,18,15,24,208,25,39,,,37,1*69 $GPGSV,2,2,05,41,,,34,1*63 $GPGGA,182143.00,3757.595177,N,01115.606762,E,1,02,1.1,139.2,M,39.0,M,,*6F $GPGLL,3757.595177,N,01115.606760,E,182143.00,A,A*6B $GPVTG,0.0,T,356.0,M,0.0,N,0.0,K,A*23 $GPRMC,182143.00,A,3757.595177,N,01115.606760,E,0.0,0.0,240321,4.0,E,A,V*4F $GPGSA,A,3,06,15,,,,,,,,,,,1.5,1.1,0.9,1*20 $GPGSV,2,1,05,06,,,36,15,24,208,25,13,10,175,,39,,,37,1*60 $GPGSV,2,2,05,41,,,34,1*63 ... ... ... CTRL-A Z for help | 115200 8N1 | NOR | Minicom 2.7.1 | VT102 | Offline | ttyUSB2
Note: If you want to use active GNSS/GPS antenna with Cellular IoT Shield, you will need to solder the SJx jumper as in the picture here. For Cellular IoT HAT, solder as in the picture here.

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:
For Quectel Modules AT Commands
AT+QGPS? # Should return 1
AT+QGPS=1 # If previous command returns 0
AT+QGPSLOC? # Obtain Positioning Information.
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. Telit LE910Cx/ME910C1/ML865C1/NE910C1 A-GPS Application Note

  4. BG96 GNSS AT Commands Manual

  5. GPS - NMEA sentence information

Related Documents

[1] ME910C1/NE910C1/ML865C1 AT Commands Reference Guide