---
title: "Read GNSS data with Base HAT"
description: "Turn on the GNSS receiver of a Quectel or Telit module on the Base HAT, read its NMEA sentences over USB and print the position with a Python script."
url: "https://docs.sixfab.com/guides/read-gnss-gps-data-base-hat/"
last_updated: "2026-10-12"
---

# Read GNSS data with Base HAT

Turn on the GNSS receiver of a Quectel or Telit module on the Base HAT, read its NMEA sentences over USB and print the position with a Python script.

**Works with:** [Base HAT](https://docs.sixfab.com/cellular/base-hat/)

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](https://docs.sixfab.com/cellular/base-hat/quickstart/), with the USB cable connected.

**Required**

**Hardware**

- **Base HAT with a module that has GNSS**: GNSS depends on the module variant: check it in the module’s datasheet, or with `ATI` for the firmware version.
- **GNSS antenna**: On the GNSS connector of the module, with a clear view of the sky. A SIM card is not needed.

**Software**

- **Serial terminal**: To send AT commands: see [Send AT commands to cellular module](https://docs.sixfab.com/guides/send-at-commands-cellular-module/).
- **Python 3 and pySerial**: For the Quectel script: `sudo apt install python3-serial`.

## Turn GNSS on and read NMEA data

**Quectel**

1. **Open AT port**

   Open `/dev/ttyUSB2` at 115200 baud, as in [Send AT commands to cellular module](https://docs.sixfab.com/guides/send-at-commands-cellular-module/).

2. **Check NMEA output port**

   ```text
   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:

   ```text
   AT+QGPSCFG="outport","usbnmea"
   ```

3. **Turn GNSS on**

   ```text
   AT+QGPS=1
   ```

   The answer is `OK`, or `+CME ERROR: 504` when GNSS is already on. `AT+QGPS?` answers `+QGPS: 1` while it is on.

4. **Watch NMEA sentences**

   In a second terminal, open the NMEA port:

   ```bash
   sudo minicom -b 115200 -D /dev/ttyUSB1
   ```

   The module sends a group of sentences every second. `$GPRMC` carries the time, the position and the speed:

   ```text
   $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
   ```

5. **Read position with AT command**

   ```text
   AT+QGPSLOC=2
   ```

   The 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: 516` means there is no fix yet.

6. **Turn GNSS off**

   ```text
   AT+QGPSEND
   ```

**Telit**

1. **Open AT port**

   Open `/dev/ttyUSB2` at 115200 baud, as in [Send AT commands to cellular module](https://docs.sixfab.com/guides/send-at-commands-cellular-module/).

2. **Restore default GNSS settings**

   ```text
   AT$GPSRST
   ```

   The module answers `OK`; the GNSS parameters are back to the factory defaults.

3. **Clear stored GNSS data**

   Only when you want to start without the history of the receiver, which is kept in the module’s memory:

   ```text
   AT$GPSNVRAM=15,0
   ```

   `AT$GPSACP` then answers `$GPSACP:` with no position.

4. **Turn NMEA output on**

   This enables every NMEA sentence type; the parameters are in the [AT commands reference guide](https://sixfab.com/wp-content/uploads/2021/02/Telit_ME910C1_NE910C1_ML865C1_AT_Commands_Reference_Guide_r14.pdf):

   ```text
   AT$GPSNMUN=2,1,1,1,1,1,1
   ```

5. **Start receiver in standalone mode**

   ```text
   AT$GPSP=1
   ```

6. **Watch NMEA sentences**

   In a second terminal, open the NMEA port:

   ```bash
   sudo minicom -b 115200 -D /dev/ttyUSB1
   ```

   ```text
   $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
   ```

7. **Turn receiver off**

   ```text
   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).

1. **Save script**

   Save the script as `gps.py`:

   ```python
   #!/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_PORT` and `NMEA_PORT` if the ports of the module are numbered differently ([find the ports](https://docs.sixfab.com/guides/send-at-commands-cellular-module/#port)).

2. **Run script**

   Run it, and stop it with Ctrl+C:

   ```bash
   python3 gps.py
   ```

   With the stream of the example above, it prints one line per second:

   ```text
   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

1. **Check fix**

   In the NMEA stream, read the third field of the `$GPRMC` sentence: `A` means a valid fix, `V` no fix yet.

   **Result:** the third field of `$GPRMC` is `A`, 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 Application Shield GNSS solder jumper, open for a passive antenna and soldered for an active antenna](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/Solder-Jumper-for-Active-Antenna.jpg)

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

![Cellular IoT HAT with the GNSS solder jumper beside the GNSS connector marked in red](https://docs.sixfab.com/wp-content/uploads/sixfab-docs/raspberry-pi-cellular-iot-hat-active-and-passive-antenna.png)

## Troubleshooting

### No NMEA sentences appear

Check the USB cable, that GNSS is on (`AT+QGPS?`, `AT$GPSP?`) and, on Quectel, the output port (`AT+QGPSCFG="outport"`).

### The module answers +CME ERROR: 516, or the RMC sentence shows V

No fix yet. Wait a few minutes; the first fix takes longer.

### There is no fix after several minutes

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.

### GNSS commands return errors

Check that the module variant and firmware support GNSS (`ATI`).

## Next steps

- [Connect cellular module to internet in ECM mode](https://docs.sixfab.com/guides/connect-cellular-module-internet-ecm-mode/): Connect the module to the internet to send the position on.
- [Base HAT hardware reference](https://docs.sixfab.com/cellular/base-hat/hardware-reference/): Pinout, layout, LEDs and specifications of the HAT.

## See also

- [Quectel LTE Standard GNSS Application Note](https://sixfab.com/wp-content/uploads/2021/01/Quectel_LTE_Standard_GNSS_Application_Note_V1.2.pdf): GNSS commands, output ports and error codes of the EC25 and EG25-G.
- [Quectel EC25 and EC21 GNSS AT Commands Manual](https://sixfab.com/wp-content/uploads/2018/09/Quectel_EC25EC21_GNSS_AT_Commands_Manual_V1.1.pdf): The GNSS AT commands in detail.
- [Quectel BG96 GNSS AT Commands Manual](https://sixfab.com/wp-content/uploads/2018/09/Quectel_BG96_GNSS_AT_Commands_Manual_V1.1.pdf): The GNSS AT commands of the BG96.
- [Telit A-GPS Application Note](https://sixfab.com/wp-content/uploads/2021/02/Telit_LE910Cx_ME910C1_ML865C1_NE910C1_A-GPS_Application_Note_r2.pdf): GNSS on the LE910Cx, ME910C1, ML865C1 and NE910C1.
- [NMEA sentences](http://aprs.gids.nl/nmea/): The fields of each NMEA sentence type.
