GPS: NMEA 101
web gps nmea
An introduction to receiving and interpreting NMEA GPS messages, including one possible “gotcha”.
Link
National Marine Electronics Association (NMEA) Global Positioning Service (GPS) data is determined by a GPS device simultaneously triangulating signals from multiple satellites and is delivered as line based text messages (sentences). Each sentence is a CSV list of location properties of the decoding device along with status information about the satellites in view. The sentences are provided for end use over a serial interface, whether RS232 or Bluetooth.
It is a simple matter to programmatically split the serial text stream line-by-line into NMEA sentences and then get each sentence’s properties with some CSV processing. There are a number of sources/technologies of GPS satellites. A sample sentence is:
$GPGGA,181908.00,3404.7041778,N,07044.3966270,W,4,13,1.00,495.144,M,29.200,M,0.10,0000*40
- The first CSV entity in the line starts with a ‘$’ indicates the source of the message and the type of message:
- $GPGGA in this case:
- All NMEA messages start with the $ character, and each data field is separated by a comma.
- GP represents that it is a GPS position (GL would denote GLONASS).
- GGA means Global Positioning System Fixed Data.
- 181908.00 is the time stamp: UTC time in hours, minutes and seconds.
- 3404.7041778 is the latitude in the DDMM.MMMMM format. Decimal places are variable.
- N denotes north latitude.
- 07044.3966270 is the longitude in the DDDMM.MMMMM format. Decimal places are variable.
- W denotes west longitude.
- There are other entities in that message such as altitude.
Some GPS Sources
The first 2 letters refer to the satellite type (Talker) as follows:
Signature | Source |
---|---|
GP | GPS |
GL | GLONASS |
BD or GB | BeiDou |
GA | Galileo |
The Main GPS Sentences
Sentence | Description |
---|---|
$Talker ID+GGA | Global Positioning System Fixed Data |
$Talker ID+GLL | Geographic Position– Latitude and Longitude |
$Talker ID+GSA | GNSS DOP and active satellites |
$Talker ID+GSV | GNSS satellites in view |
$Talker ID+RMC | Recommended minimum specific GPS data |
$Talker ID+VTG | Course over ground and ground speed |
So the example above GPGGA is GPS - Global Positioning System Fixed Data
Gotcha moment
Recently I have been developing GPS processing and mapping for an Arduino device. Not reading the fine print the mapped data points were offset by over 100km north of where they should be. The mistake I made was, with the latitude and longitude, to treat the values as decimal numbers and to simply just shift the “decimal point” 2 spaces to the left! As Homer Simpson would say, “D’oh!”.
I have in past the developed GPS code but have used libraries for that purpose. The current context is Arduino so I was looking for a quick and simple implementation, such as the shift left method above, although there are Arduino libraries for that purpose such as TinyGPS and TinyGPS++.
The altitude 3404.7041778
is NOT an angle of 34.047041778
but need to be interpreted in terms of the pattern DDMM.MMMMM
:
- DD is the degrees = 34
- MMMMM is the minutes and is 04.7041778
- Other digits to the right ARE decimal fractions of the minutes, not seconds._
- A minute is 1/60th of a degree
- So to convert to decimal fraction of a degree divide by 60.
Latitude = DD + (The rest)/60
= 34.0 + 04.7041778/60
= 34.07840296333
This is significantly different in the second decimal place to the erroneous shift left calculation of:
34.047041778
!
So the algorithm, rather than shift left by 2, now is:
- Split the string into 2 at the decimal point.
- Convert the first string into to a double and is the whole part of the the degrees.
- Divide the second string (converted to a double), by 60.0 and add the degrees as the fractional part.
History
I must acknowledge some quick clarification I got on this when I posted a query on the u-blox public forum. I used a u-blox Neo-7M module. The comment there was that the patterns used, as above, for Latitude and Longitude is that we are looking back in time, in a shipping context, to the days of 7 segment displays and it was simple matter to just to shift the digits into a set of 7 segment digits to view the angle as degrees and minutes. They could then clearly see global position as latitude and longitude in degrees and minutes.
u-blox links
Most hobbyist applications developed for GPS focus only on the download of GPS data, the Tx part of a GPS device. It can be hard to find any configuration information, using the Rx side. u-blox has a Windows app for configuring NEO6/7 devices, u-center.
The u-blox u center app
- u-center download Note u-center not u-center 2
- u-center doc
- A lead into this is here
- I did finally find some info on configuring the NEO device starting here.
Topic | Subtopic | |
Next: > | Aged Care Independent Living | MPU6050 Fall Detection App |
< Prev: | RPI-Pico-Arduino-AzSDK | Bluetooth and GPS Update |
This Category Links | ||
Category: | Web Sites Index: | Web Sites |
Next: > | Jekyll | New post and Clone PS scripts |
< Prev: | Jekyll | Rendering on a Mobile Part 2 |