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
For Telit Modules
Open a new serial port to set up the module GPS/GNSS configuration.
sudo minicom -b 115200 -D /dev/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
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.
Check that after history buffer cleaning no GPS information is available
For enabling unsolicited messages of GNSS data in NMEA format, refer to [1]. In this example, all sentence is enabled:
Start the GNSS receiver in standalone mode:
Open a new port through the ttyUSB1 port to watch the NMEA stream.
sudo minicom -b 115200 -D /dev/ttyUSB1
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.