GPS NMA Decoders

Routines for decoding the raw NMEA output from GPS receivers.

NMEA GPS - Generic GPS Decoder

NMEA provides a library of routines to read the output from a GPS receiver and translate the output into a series of messages for the application. A number of decoders are provided for the application developer:


The library is compatible with NMEA GPS such as the following:

Three connections are required as a minimum:

GPS Connection Netduino Connection
Power 3.3V or 5V
GND Ground
Tx Rx on one of the COM ports.

A 5V power connection is acceptable as the digital pins on the Netduino are 5V tolerant.


The following application creates a new NMEA GPS object and attaches the object to COM1. A location (GLL) decoder is then attached to the GPS and messages are processed by the ggaDecoder_OnPositionReceived method:

using Microsoft.SPOT;
using Netduino.Foundation.Sensors.GPS;
using System;
using System.Threading;

namespace NMEAExample
    public class Program
        public static void Main()
            NMEA gps = new NMEA("COM1", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            GGADecoder ggaDecoder = new GGADecoder();
            ggaDecoder.OnPositionReceived += ggaDecoder_OnPositionReceived;

        static string DecodeDMPostion(DegreeMinutePosition dmp)
            string position = dmp.Degrees.ToString("f2") + "d " + dmp.Minutes.ToString("f2") + "m ";
            switch (dmp.Direction)
                case DirectionIndicator.East:
                    position += "E";
                case DirectionIndicator.West:
                    position += "W";
                case DirectionIndicator.North:
                    position += "N";
                case DirectionIndicator.South:
                    position += "S";
                case DirectionIndicator.Unknown:
                    position += "Unknown";
            return (position);

        static void ggaDecoder_OnPositionReceived(object sender, GPSLocation location)
            Debug.Print("Location information received.");
            Debug.Print("Time of reading: " + location.ReadingTime);
            Debug.Print("Latitude: " +  DecodeDMPostion(location.Latitude));
            Debug.Print("Longitude: " + DecodeDMPostion(location.Longitude));
            Debug.Print("Altitude: " + location.Altitude);
            Debug.Print("Number of satellites: " + location.NumberOfSatellites);
            Debug.Print("Fix quality: " + location.FixQuality);
            Debug.Print("HDOP: " + location.HorizontalDilutionOfPrecision.ToString("f2"));

Decoding follows the same pattern for all of the decoders:

  • Create a new decoder
  • Provide a message handler for the decoder.
  • Associate the decoder with the NMEA object


Much of the work of decoding the NMEA messages is handled by the decoders. The NMEA object provides a mechanism for receiving lines of text from the COM port on the Netduino, decoding the messages and sending the data to the application.


public NMEA(string port, int baudRate, Parity parity, int dataBits, StopBits stopBits)

Create a new NMEA object and attach the object to the specified COM port with the specified communication parameters.

Note that this does not start to process the text from the GPS unit, a call to Open is required following construction of the NMEA class.


void Open()

Open the connection to the GPS unit.

void Close()

Close the connection to the GPS unit.

void AddDecoder(NMEADecoder decoder)

Add a new decoder to the list of registered decoders.