The NMEA sentences carry the position, the time and the satellites in view; the module sends them on a USB serial port while the AT commands go to another.
Requirements
Assemble the Base HAT first, as in Get started with Base HAT, with the USB cable connected.
Hardware
- Base HAT with a module that has GNSSGNSS depends on the module variant: check it in the module’s datasheet, or with
ATIfor the firmware version. - GNSS antennaOn the GNSS connector of the module, with a clear view of the sky. A SIM card is not needed.
Software
- Serial terminalTo send AT commands: see Send AT commands to cellular module.
- Python 3 and pySerialFor the Quectel script:
sudo apt install python3-serial.
Turn GNSS on and read NMEA data
-
Open AT port
Open
/dev/ttyUSB2at 115200 baud, as in Send AT commands to cellular module. -
Check NMEA output port
AT+QGPSCFG="outport"The answer
+QGPSCFG: "outport","usbnmea"means the NMEA sentences go to the USB NMEA port,/dev/ttyUSB1. With another value, set it:AT+QGPSCFG="outport","usbnmea" -
Turn GNSS on
AT+QGPS=1The answer is
OK, or+CME ERROR: 504when GNSS is already on.AT+QGPS?answers+QGPS: 1while it is on. -
Watch NMEA sentences
In a second terminal, open the NMEA port:
sudo minicom -b 115200 -D /dev/ttyUSB1The module sends a group of sentences every second.
$GPRMCcarries the time, the position and the speed:$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 $GPGSA,A,2,02,12,24,29,,,,,,,,,1.8,1.5,0.9*3B -
Read position with AT command
AT+QGPSLOC=2The answer
+QGPSLOC:gives the UTC time, the latitude and the longitude in decimal degrees, then the horizontal precision, altitude, fix type, course, speed, date and number of satellites.+CME ERROR: 516means there is no fix yet. -
Turn GNSS off
AT+QGPSEND
-
Open AT port
Open
/dev/ttyUSB2at 115200 baud, as in Send AT commands to cellular module. -
Restore default GNSS settings
AT$GPSRSTThe module answers
OK; the GNSS parameters are back to the factory defaults. -
Clear stored GNSS data
Only when you want to start without the history of the receiver, which is kept in the module’s memory:
AT$GPSNVRAM=15,0AT$GPSACPthen answers$GPSACP:with no position. -
Turn NMEA output on
This enables every NMEA sentence type; the parameters are in the AT commands reference guide:
AT$GPSNMUN=2,1,1,1,1,1,1 -
Start receiver in standalone mode
AT$GPSP=1 -
Watch NMEA sentences
In a second terminal, open the NMEA port:
sudo minicom -b 115200 -D /dev/ttyUSB1$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 -
Turn receiver off
AT$GPSP=0
Read position with Python
For Quectel modules. The script turns GNSS on, reads the NMEA port, checks each RMC sentence against its checksum and prints the position in decimal degrees (negative for south and west).
-
Save script
Save the script as
gps.py:#!/usr/bin/env python3 """Read the position from the NMEA output of a Quectel module on the Sixfab Base HAT.""" import serial AT_PORT = "/dev/ttyUSB2" # AT command port of the module NMEA_PORT = "/dev/ttyUSB1" # NMEA port of the module def send_at(command): """Send one AT command and return the module's answer.""" with serial.Serial(AT_PORT, 115200, timeout=1) as port: port.write((command + "\r").encode()) return port.read(256).decode(errors="replace") def checksum_ok(sentence): """Compare the hex digits after '*' with the XOR of the characters between '$' and '*'.""" if not sentence.startswith("$") or "*" not in sentence: return False body, _, given = sentence[1:].partition("*") calc = 0 for char in body: calc ^= ord(char) return given[:2].upper() == f"{calc:02X}" def to_degrees(value, hemisphere): """Convert ddmm.mmmm or dddmm.mmmm to signed decimal degrees.""" if not value: return None dot = value.index(".") degrees = int(value[:dot - 2]) + float(value[dot - 2:]) / 60 return -degrees if hemisphere in ("S", "W") else degrees def parse_rmc(sentence): """Return the date, time, position and speed of an RMC sentence, or None without a fix.""" fields = sentence.split("*")[0].split(",") if len(fields) < 10 or fields[2] != "A": return None return { "date": fields[9], "time": fields[1][:6], "latitude": to_degrees(fields[3], fields[4]), "longitude": to_degrees(fields[5], fields[6]), "speed": float(fields[7] or 0), } def main(): # OK, or +CME ERROR: 504 when GNSS is already on print(send_at("AT+QGPS=1").strip()) with serial.Serial(NMEA_PORT, 115200, timeout=1) as nmea: while True: line = nmea.readline().decode("ascii", errors="replace").strip() # RMC from any constellation: $GPRMC, $GNRMC ... if line[3:6] != "RMC" or not checksum_ok(line): continue fix = parse_rmc(line) if fix is None: print("No fix yet") else: print(f"{fix['date']} {fix['time']} UTC " f"lat {fix['latitude']:.6f} lon {fix['longitude']:.6f} " f"speed {fix['speed']} kn") if __name__ == "__main__": main()Change
AT_PORTandNMEA_PORTif the ports of the module are numbered differently (find the ports). -
Run script
Run it, and stop it with Ctrl+C:
python3 gps.pyWith the stream of the example above, it prints one line per second:
OK 120121 182142 UTC lat 37.955407 lon 29.276703 speed 0.0 kn 120121 182143 UTC lat 37.955401 lon 29.276710 speed 0.0 kn 120121 182144 UTC lat 37.955394 lon 29.276719 speed 0.0 kn
Verify
-
Check fix
In the NMEA stream, read the third field of the
$GPRMCsentence:Ameans a valid fix,Vno fix yet.Result: the third field of$GPRMCisA, and the sentence carries the latitude and the longitude.
Details
Active antenna on legacy boards
On the legacy Cellular IoT Application Shield and Cellular IoT HAT, an active GNSS antenna needs a solder jumper; a passive antenna needs it open. Application Shield:

Cellular IoT HAT, the solder jumper beside the GNSS connector:

Troubleshooting
Check the USB cable, that GNSS is on (AT+QGPS?, AT$GPSP?) and, on Quectel, the output port (AT+QGPSCFG="outport").
No fix yet. Wait a few minutes; the first fix takes longer.
Move the antenna near a window or outdoors, as high as possible, with a clear view of the sky in all directions and away from interference. Try another location. The $GPGSV sentences show the satellites in view and their signal levels.
Check that the module variant and firmware support GNSS (ATI).
Next steps
- Connect cellular module to internet in ECM mode Connect the module to the internet to send the position on.
- Base HAT hardware reference Pinout, layout, LEDs and specifications of the HAT.
See also
- Quectel LTE Standard GNSS Application Note GNSS commands, output ports and error codes of the EC25 and EG25-G.
- Quectel EC25 and EC21 GNSS AT Commands Manual The GNSS AT commands in detail.
- Quectel BG96 GNSS AT Commands Manual The GNSS AT commands of the BG96.
- Telit A-GPS Application Note GNSS on the LE910Cx, ME910C1, ML865C1 and NE910C1.
- NMEA sentences The fields of each NMEA sentence type.