GPS NMEA parser

For project with GPS, I've ported free NMEA parser for mbed.

2010/3/15 Update: Modify trace_h and error_h function to avoid disordered output.

Library Ported

I've ported NMEA Library. Key features of NMEA Library are:

  • Support GPGGA, GPGSA, GPGSV, GPRMC, GPVTG
  • Gather GPS data in C structures which you can obtain almost all GPS data
  • Execute parser in each N bytes of data reception (not message line by line, but can call parser when message buffer reachs full)

This library may require more RAM than TinyGPS, but can parse almost all NMEA message parameters. For details about NMEA Library, please refer to document attached to the download file (you need to generate html documents by doxygen).

Library can work without modification. I just added cast for a few lines contain malloc() to avoid compiler error.

Sample Project

The following is sample project using NMEA Library.

GPS_nmeaLib

GPS receiver used is Sparkfun GPS Micro-Mini. I changed clock speed to 48MHz and disabled Ethernet MAC to reduce noise from mbed. I think this could improve sensitivity of GPS module a bit...  To change clock speed and power control, mbed Clock Control and mbed Power Control are used.

With line 15 of gps.h (#define SERIAL_OUTPUT) uncommented, which is default, this program send output message to USB serial port as follows:

Trace: $GPGSA,A,2,29,18,22,,,,,,,,,,5.0,4.8,1.0*39
Trace: $GPGSV,3,1,11,22,45,225,32,18,24,186,34,29,16,148,32,30,82,102,*73
Trace: $GPGSV,3,2,11,14,59,327,,05,53,049,,01,47,321,31,12,47,048,*75
9140, Lat: 35.xxxxxx, Lon: 139.xxxxxx, Sig:1, Fix:2, Inuse:3
  sat_id:22, sig:32, Inuse:1
  sat_id:18, sig:34, Inuse:1
  sat_id:29, sig:32, Inuse:1
  sat_id:01, sig:31, Inuse:0

You can obtain not only latitude and longitude, but also fix type, number of satellites in-use, satellite-id, signal level, etc.

With line 15 of gps.h comment out, this program display parse result on LCD with serial interface as follows:

mged GPS

LCD used for this project is soled in Japan only, so it is just for your information.


1 comment

25 Feb 2013 . Edited: 25 Feb 2013

As an alternative, here is a highly optimized NMEA parser originally written for microcontrollers:
https://code.google.com/p/avr-nmea-gps-library/

The GPS NMEA data is handled in nmea.cpp and nmea.h, easy to customize / add to your project as the classes seems to encapsulate everything you need.

The interesting thing here is that this code was written for microcontrollers, with very little memory and processing power, making this code a very fast alternative if performance is also required. The parsing is done in one go, meaning that as the chars are received the NMEA code is interpreted on the fly, without using any additional / redundant buffers.

You need to log in to post a comment