GPS Parser

Post your NXJ projects, project ideas, etc here!

Moderators: imaqine, 99jonathan, roger

User avatar
Advanced Member
Posts: 361
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes

GPS Parser

Postby esmetaman » Sun Sep 16, 2007 2:49 pm


a "future" pseudocde for new GPS Parse for NXJ could be:

Code: Select all

import lejos.nxt.*;
import lejos.nxt.comm.*;

public class GPSParserTest {

    * @param args
   public static void main(String[] args) {
      String GPSDeviceName = "BTDevice";
      String GPSPinCode = "12345";
      BTUtilities BTUObj = new BTUtilities();

      LCD.drawString("Try to connect...", 0, 5);
      BTRemoteDevice btrd = Bluetooth.getKnownDevice(GPSDeviceName);
      BTConnection btc = Bluetooth.connect(btrd);
      LCD.drawString("Connected", 0, 5);

      String LAT;
      String LONG;
      }catch(IOException e){

      LAT = GPSParser.getLat();
      LONG = GPSParser.getLong();



Juan Antonio Breña Moral

User avatar
Advanced Member
Posts: 361
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes

NMEA 0183

Postby esmetaman » Tue Sep 18, 2007 9:28 pm

Version 6.3 April 25, 2000

Additions, corrections, and comments should be emailed to the author,
Peter Bennett

1. What is NMEA?
1.1 What is an NMEA Standard
1.2 NMEA Address

2. Electrical Interface

3. NMEA-0180 and NMEA-0182
3.1 Simple Format
3.2 Complex Format

4. NMEA-0183

4.1 General Sentence Format
4.2 Sentences sent by specific equipment
4.3 Sample Sentences Dissected
4.3.1 Standard Sentences
4.3.2 Garmin Proprietary Sentences

5. RS-232 connections

6. Troubleshooting

7. About the author
7.1 Acknowledgements

1. What is NMEA?

The National Marine Electronics Association is dedicated to the
education and advancement of the marine electronics industry and
the market which it serves.

It is a non-profit association composed of manufacturers,
distributors, dealers, educational institutions, and others
interested in peripheral marine electronics occupations
(quoted from a promo in "NMEA News")

1.1 What is an NMEA standard?

For the purposes of this article, an NMEA standard defines an
electrical interface and data protocol for communications
between marine instrumentation. (They may also have standards
for other things.)

1.2 NMEA Address

P.O. Box 3435
New Bern NC, 28564-3435
Phone: 919-638-2626
Fax: 919-638-4885
web page:

2. Electrical Interface

These standards allow a single "talker", and several "listeners"
on one circuit. The recommended interconnect wiring is a
shielded twisted pair, with the shield grounded only at the
talker. The standards do not specify the use of any particular

The NMEA-0180 and 0182 standards say that the talker output may
be RS-232, or from a TTL buffer, capable of delivering 10 mA at
4 V. A sample circuit shows an open collector TTL buffer with a
680 ohm resistor to +12 V, and a diode to prevent the output
voltage from rising above +5.7 V.

NMEA-0183 accepts this, but recommends that the talker output
comply with EIA-422. This is a differential system, having two
signal lines, A and B. The voltages on the "A" line correspond
to those on the older TTL single wire, while the "B" voltages
are reversed (while "A" is at +5, "B" is at ground, and vice

In either case, the recommended receive circuit uses an
opto-isolator with suitable protection circuitry. The input
should be isolated from the receiver's ground.

In practice, the single wire, or the EIA-422 "A" wire may be
directly connected to a computer's RS-232 input.

3. NMEA-0180 and NMEA 0182

NMEA-0180 and 0182 are very limited, and just deal with
communcations from a Loran-C (or other navigation receiver,
although the standards specifically mention Loran), and an

From the information I have, it appears that 0180 and 0182 are
identical. I suspect that equipment claiming to use NMEA-0180
will use the "simple" format described below, while those using
NMEA-0182 will use the "complex" format. (but this is really
just a guess... corrections??)

3.1 "Simple" data format

The simple format consists of a single data byte transmitted at
intervals of 0.8 to 5 seconds, at 1200 baud with odd parity.
Bits 5 - 0 give the cross-track error in units of 0.1 uS or 0.01
nautical mile. The error is given in offset binary, with a
count of 1 representing full scale right error, 32 (hex 20) for
on course, and 63 (hex 3f) full scale left error. Bit 6 is a 1
if the data is valid, and bit 7 is 0 to indicate the simple
data format.

3.2 "Complex" data format

The complex format consists of a data block of 37 bytes of
(mostly) readable ASCII text giving cross-track error, bearing
to waypoint, present Lat/Long, and a binary status byte. The
data block shall be sent at intervals of 2 to 8 sec. All bytes
in the complex format have bit 7 = 1 to distinguish them from
the simple format. It is permissible for a sending device to
send both simple and complex data, and even to send a "simple"
data byte in the middle of a "complex" data block.

Byte Data
1 $
2 M | device
3 P | address

4 K = kilometres | cross track
N = nautical miles | error
U = microseconds | units

5 - 8 0 - 9 or . cross track error value
9 L or R cross track error position

10 T or M True or Magnetic bearing
11 - 13 0 - 9 bearing to next waypoint

14 - 23 12D34'56"N or present latitude
24 - 34 123D45'56"W or present longitude

35 non-ASCII status byte
bit 0 = 1 for manual cycle lock
1 = 1 low SNR
2 = 1 cycle jump
3 = 1 blink
4 = 1 arrival alarm
5 = 1 discontinuity of TDs
6 = 1 always
36 "NUL" character (hex 80)(reserved status byte)
37 "ETX" character (hex 83)
Any unavailable data is filled with "NUL" bytes.

4. NMEA-0183

4.1 General Sentence Format

Under the NMEA-0183 standard, all characters used are printable
ASCII text (plus carriage return and line feed). NMEA-0183 data
is sent at 4800 baud.

The data is transmitted in the form of "sentences". Each
sentence starts with a "$", a two letter "talker ID", a three
letter "sentence ID", followed by a number of data fields
separated by commas, and terminated by an optional checksum, and
a carriage return/line feed. A sentence may contain up to 82
characters including the "$" and CR/LF.

If data for a field is not available, the field is simply
omitted, but the commas that would delimit it are still sent,
with no space between them.

Since some fields are variable width, or may be omitted as
above, the receiver should locate desired data fields by
counting commas, rather than by character position within the

The optional checksum field consists of a "*" and two hex digits
representing the exclusive OR of all characters between, but not
including, the "$" and "*". A checksum is required on some

The standard allows individual manufacturers to define
proprietary sentence formats. These sentences start with "$P",
then a 3 letter manufacturer ID, followed by whatever data the
manufacturer wishes, following the general format of the
standard sentences.

Some common talker IDs are:
GP Global Positioning System receiver
LC Loran-C receiver
OM Omega Navigation receiver
II Integrated Instrumentation
(eg. AutoHelm Seatalk system)

4.2 Sentences sent by specific equipment

This section lists the sentence types used by various equipment.
The format and data included in each sentence type is given in
section 4.3.

Eagle AccuNav
Standard: RMB, RMC, GLL, APB
Proprietary: PSLIB
It also pretends it's a Loran, sending LCGLL, as well as GPGLL

Garmin 12XL, NMEA-0183 V 1.5
Standard: RMB, RMC, WPL
Proprietary: PGRMM (map datum), PGRMZ (altitude), PSLIB (DGPS ctrl)

Garmin 12XL, NMEA-0183 V 2.0
Proprietary: PGRME (estimated error) PGRMM, PSLIB

Garmin GPS-38, NMEA-0183 V. 1.5 mode
Proprietary: PGRMM (map datum), PGRMZ (altitude), PSLIB (dgps ctrl)

Garmin GPS-38, NMEA-0183 V. 2.0 mode
Proprietary: PGRME (estimated error), PGRMM, PGRMZ, PSLIB

Garmin GPS-45 (and probably GPS-40 and GPS-90)
Proprietary: PGRME, PGRMM, PGRMZ

Garmin GPS-65 (and probably GPS-75)
Standard: BWC, GLL, RMB, RMC, R00, WPL, XTE, VTG
Proprietary: PGRMM, PGRMZ, PSLIB

Lowrance Global Map 100
Standard: GLL, RMC, RMB, APB, GGA, GSV
Proprietary: PSLIB

Magellan Trailblazer
Trimble Ensign XL
Standard: APA, BWC, BWR, GGA, GLL, RMB

Trimble Flightmate Pro and Scoutmaster

Autohelm Seatalk
Autohelm Seatalk is a proprietary bus for communications
between various intruments. Some of the instruments can act
as NMEA-0183 talkers or listeners. Data received from an
external NMEA-0183 device will, if Seatalk understands the
sentence, be re-transmitted, but not necessarily in the same
sentence type.

The specific sentences sent will depend on the data
available on the Seatalk bus (i.e. sentences containing wind
speed and direction will only be sent if the system includes
a wind instrument) Note that NMEA data can only be sent to,
or received from, a SeaTalk system using AutoHelm's
NMEA<->SeaTalk interface box, or those instruments that provide
an NMEA-0183 interface. SeaTalk itself is not compatible
with NMEA, and cannot be read with a normal PC serial port.

Seatalk output:

Seatalk input:

4.3 Sample Sentences Dissected
4.3.1 Standard Sentences

A talker typically sends a group of sentences at intervals
determined by the unit's update rate, but generally not more
often than once per second.

Characters following the "*" are a checksum. Checksums are
optional for most sentences, according to the standard.

APB - Autopilot format B
A Loran-C blink/SNR warning
A Loran-C cycle warning
0.10 cross-track error distance
R steer Right to correct (or L for Left)
N cross-track error units - nautical miles
V arrival alarm - circle
V arrival alarm - perpendicular
011,M magnetic bearing, origin to destination
DEST destination waypoint ID
011,M magnetic bearing, present position to destination
011,M magnetic heading to steer
(bearings could be given in True as 033,T)
(note: some pilots, Roberston in particular, misinterpret "bearing
from origin to destination" as "bearing from present position to
destination". This apparently results in poor performance if the
boat is sufficiently off-course that the two bearings are

BOD - Bearing - origin to destination waypoint
045.,T bearing 045 True from "START" to "DEST"
023.,M breaing 023 Magnetic from "START" to "DEST"
DEST destination waypoint ID
START origin waypoint ID

BWC - Bearing and distance to waypoint - great circle
225444 UTC time of fix 22:54:44
4917.24,N Latitude of waypoint
12309.57,W Longitude of waypoint
051.9,T Bearing to waypoint, degrees true
031.6,M Bearing to waypoint, degrees magnetic
001.3,N Distance to waypoint, Nautical miles
004 Waypoint ID

BWR - Bearing and distance to waypoint - rhumb line
(format same as BWC)

DBT - Depth below transducer
0017.6,f 17.6 feet
0005.4,M 5.4 Metres

GGA - Global Positioning System Fix Data
GGA,123519,4807.038,N,01131.324,E,1,08,0.9,545.4,M,46.9,M, , *42
123519 Fix taken at 12:35:19 UTC
4807.038,N Latitude 48 deg 07.038' N
01131.324,E Longitude 11 deg 31.324' E
1 Fix quality: 0 = invalid
1 = GPS fix
2 = DGPS fix
08 Number of satellites being tracked
0.9 Horizontal dilution of position
545.4,M Altitude, Metres, above mean sea level
46.9,M Height of geoid (mean sea level) above WGS84
(empty field) time in seconds since last DGPS update
(empty field) DGPS station ID number

GLL - Geographic position, Latitude and Longitude
4916.46,N Latitude 49 deg. 16.45 min. North
12311.12,W Longitude 123 deg. 11.12 min. West
225444 Fix taken at 22:54:44 UTC
A Data valid
(Garmin 65 does not include time and status)

GSA - GPS DOP and active satellites
A Auto selection of 2D or 3D fix (M = manual)
3 3D fix
04,05... PRNs of satellites used for fix (space for 12)
2.5 PDOP (dilution of precision)
1.3 Horizontal dilution of precision (HDOP)
2.1 Vertical dilution of precision (VDOP)
DOP is an indication of the effect of satellite geometry on
the accuracy of the fix.

GSV - Satellites in view
2 Number of sentences for full data
1 sentence 1 of 2
08 Number of satellites in view
01 Satellite PRN number
40 Elevation, degrees
083 Azimuth, degrees
46 Signal strength - higher is better
<repeat for up to 4 satellites per sentence>
There my be up to three GSV sentences in a data packet

HDM - Heading, Magnetic
HDM Heading, Magnetic
235.,M Heading 235 deg. Magnetic
(HDG, which includes deviation and variation, is recommended

HSC - Command heading to steer
258.,T 258 deg. True
236.,M 136 deg. Magnetic

MTW - Water temperature, Celcius
11.,C 11 deg. C

R00 - List of waypoint IDs in currently active route
(This sentence is produced by a Garmin 65, but is not listed
in Version 2.0 of the standard. The standard lists RTE for
this purpose.)

RMB - Recommended minimum navigation information (sent by nav.
receiver when a destination waypoint is active)
A Data status A = OK, V = warning
0.66,L Cross-track error (nautical miles, 9.9 max.),
steer Left to correct (or R = right)
003 Origin waypoint ID
004 Destination waypoint ID
4917.24,N Destination waypoint latitude 49 deg. 17.24 min. N
12309.57,W Destination waypoint longitude 123 deg. 09.57 min. W
001.3 Range to destination, nautical miles
052.5 True bearing to destination
000.5 Velocity towards destination, knots
V Arrival alarm A = arrived, V = not arrived
*0B mandatory checksum

RMC - Recommended minimum specific GPS/Transit data
225446 Time of fix 22:54:46 UTC
A Navigation receiver warning A = OK, V = warning
4916.45,N Latitude 49 deg. 16.45 min North
12311.12,W Longitude 123 deg. 11.12 min West
000.5 Speed over ground, Knots
054.7 Course Made Good, True
191194 Date of fix 19 November 1994
020.3,E Magnetic variation 20.3 deg East
*68 mandatory checksum

RTE - Waypoints in active route
2 two sentences for full data
1 this is sentence 1 of 2
c c = complete list of waypoints in this route
w = first listed waypoint is start of current leg
0 Route identifier
W3IWI... Waypoint identifiers

VHW - Water speed and heading
259.,T Heading 259 deg. True
237.,M Heading 237 deg. Magnetic
05.00,N Speed 5 knots through the water
09.26,K Speed 9.26 KPH

VWR - Relative wind direction and speed
148.,L Wind from 148 deg Left of bow
02.4,N Speed 2.4 Knots
01.2,M 1.2 Metres/Sec
04.4,K Speed 4.4 Kilometers/Hr

VTG - Track made good and ground speed
054.7,T True track made good
034.4,M Magnetic track made good
005.5,N Ground speed, knots
010.2,K Ground speed, Kilometers per hour

WCV - Waypoint Closure Velocity
WDC - Distance to Waypoint
WDR - Waypoint Distance, Rhumb Line

WPL - waypoint location
4917.16,N Latitude of waypoint
12310.64,W Longitude of waypoint
003 Waypoint ID
When a route is active, this sentence is sent once for each
waypoint in the route, in sequence. When all waypoints have
been reported, GPR00 is sent in the next data set. In any
group of sentences, only one WPL sentence, or an R00
sentence, will be sent.

XTE - Cross track error, measured
A General warning flag V = warning
(Loran-C Blink or SNR warning)
A Not used for GPS (Loran-C cycle lock flag)
0.67 cross track error distance
L Steer left to correct error (or R for right)
N Distance units - Nautical miles

XTR - Cross-Track Error - Dead Reckoning
0.67 cross track error distance
L Steer left to correct error (or R for right)
N Distance units - Nautical miles

4.3.2 Proprietary Sentences

The following are Garmin proprietary sentences. "P" denotes
proprietary, "GRM" is Garmin's manufacturer code, and "M" or "Z"
indicates the specific sentence type.

15.0,M Estimated horizontal position error in metres (HPE)
45.0,M Estimated vertical error (VPE) in metres
25.0,M Overall spherical equivalent position error

93,f Altitude in feet
3 Position fix dimensions 2 = user altitude
3 = GPS altitude
This sentence shows in feet, regardless of units shown on the display.

$PGRMM,NAD27 Canada*2F
Currently active horizontal datum

Proprietary sentences to control a Starlink differential beacon
receiver. (I assume Garmin's DBR is made by Starlink)
These two sentences are normally sent together in each group
of sentences from the GPS.
The three fields are: Frequency, bit Rate, Request Type. The
value in the third field may be:
J = status request
K = configuration request
blank = tuning message

When the GPS receiver is set to change the DBR frequency or
baud rate, the "J" sentence is replaced (just once) by (for
example): $PSLIB,320.0,200*59 to set the DBR to 320 KHz, 200

5. RS-232 connections

Although this is not really related to NMEA, many people want to
connect a GPS to a computer, so need to know about the RS-232
serial ports on a computer.

The RS-232 standard defines two classes of devices that may
communicate using RS-232 serial data - Data Terminal Equipment
(DTE), and Data Communication Equipment (DCE). Computers and
terminals are considered DTE, while modems are DCE. The
standard defines pinouts for DTE and DCE such that a "straight
through" cable (pin 2 to pin 2, 3 to 3, etc) can be used between
a DTE and DCE. To connect two DTEs together, you need a "null
modem" cable, that swaps pins between the two ends (eg. pin 2 to
3, 3 to 2). Unfortunately, there is sometimes disagreement
whether a certain device is DTE or DCE, hence my standard RS-232
if it doesn't work, swap pins 2 and 3!

The standard RS-232 connector is a 25 conductor DB-25, although
many PCs (and some other equipment) now use a 9 pin DE-9 (often
incorrectly called DB-9)

Serial Port Connections
Computer (DTE) Modem
DB-25 DE-9 Signal Direction DB-25
2 3 Tx Data -> 2
3 2 Rx Data <- 3
4 7 Request to send -> 4
5 8 Clear to send <- 5
6 6 Data Set Ready <- 6
7 5 signal ground 7
8 1 Data CarrierDetect <- 8
20 4 Data Terminal Ready -> 20
22 9 Ring Indicator <- 22

For NMEA-0183 interfacing, we are only concerned with Rx Data,
signal ground (and possibly Tx Data, if we want the computer to
talk to the GPS)

NMEA-0183 data is sent at 4800 baud.

6. Troubleshooting

First check that the talker (usually GPS or Loran) can send
NMEA-0183, and determine what sentences it sends. Also, verify
that the listener understands NMEA-0183, and that it understands
the sentences the talker is sending. In some cases the same
information may be sent in two or more different sentences. If
the talker and listener don't both use the same sentences, there
will be no communication. It may be possible to change the
sentences sent by the talker, to match those understood by the

Next, check that the talker is indeed set to send NMEA-0183
data. Some talkers may have provision to send NMEA-0180 or
0182, or some proprietary format.

A computer, using any convenient terminal program (Telix,
Procomm, Windows Terminal, etc.) set to 4800 baud, can be used
to monitor the NMEA data, and confirm what sentences are sent,
and that the data is in the correct format.
Verify that the wiring is correct - that the talker data output
is connected to the listener data input, and that a signal
ground line is connected between the two pieces of equipment.

If you have multiple listeners connected to a single talker, you
may be overloading the talker port. Try connecting only one
listener at a time.

On any NMEA-0183 circuit, there can _only_ be one talker. If
you must have more than one talker, and one of the talker
devices can also act as a listener, you may be able to connect
things "in series", so a talker-only output is connected to a
listener/talker input, and the listener/talker output is
connected to other listeners. However, some listener/talker
devices may reformat the data, or only pass data they
understand. (The Autohelm Seatalk system does this, and claims
the data as it's own, starting all output sentences with "$II".)

Particularly with older equipment, the equipment may claim to
comply with NMEA-0183, but in fact have an error in the data
format. (My Kings 8001 Loran-C claims to send an APB sentence,
but gets some of the fields in the wrong order, so my autopilot
can't understand it.) This sort of problem can be verified by
capturing the NMEA-0183 data on a computer, and comparing the
data formats with those given above.

7. About the author

This FAQ was written by:
Peter Bennett

I have an Web site containing this file, a GPS FAQ, and other
NMEA information files and PC programs for capturing and
displaying NMEA data, and related things:
This site is mirrored in Germany at: ... index.html

7.1 Acknowlegments

I would like to thank the following for their contributions
or corrections to this document:
Tom Clark,
Bob Shearer,
David Steckler,
Karl Olmstead,
Dave Wells, KD6TO,
Mike Morrow,
Juan Antonio Breña Moral

User avatar
Advanced Member
Posts: 361
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes

$GPGGA Global Positioning System Fix Data

Postby esmetaman » Wed Sep 19, 2007 7:52 pm


Global Positioning System Fix Data

Name Example Data Description
Sentence Identifier $GPGGA Global Positioning System Fix Data
Time 170834 17:08:34 Z
Latitude 4124.8963, N 41d 24.8963' N or 41d 24' 54" N
Longitude 08151.6838, W 81d 51.6838' W or 81d 51' 41" W
Fix Quality:
- 0 = Invalid
- 1 = GPS fix
- 2 = DGPS fix 1 Data is from a GPS fix
Number of Satellites 05 5 Satellites are in view
Horizontal Dilution of Precision (HDOP) 1.5 Relative accuracy of horizontal position
Altitude 280.2, M 280.2 meters above mean sea level
Height of geoid above WGS84 ellipsoid -34.0, M -34.0 meters
Time since last DGPS update blank No last update
DGPS reference station id blank No station id
Checksum *75 Used by program to check for transmission errors

Courtesy of Brian McClure, N8PQI.

Global Positioning System Fix Data. Time, position and fix related data for a GPS receiver.

eg2. $--GGA,,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx = UTC of position
llll.ll = latitude of position
a = N or S
yyyyy.yy = Longitude of position
a = E or W
x = GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix)
xx = number of satellites in use
x.x = horizontal dilution of precision
x.x = Antenna altitude above mean-sea-level
M = units of antenna altitude, meters
x.x = Geoidal separation
M = units of geoidal separation, meters
x.x = Age of Differential GPS data (seconds)
xxxx = Differential reference station ID

eg3. $GPGGA,,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
1 = UTC of Position
2 = Latitude
3 = N or S
4 = Longitude
5 = E or W
6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
7 = Number of satellites in use [not those in view]
8 = Horizontal dilution of position
9 = Antenna altitude above/below mean sea level (geoid)
10 = Meters (Antenna height unit)
11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and
mean sea level. -=geoid is below WGS-84 ellipsoid)
12 = Meters (Units of geoidal separation)
13 = Age in seconds since last update from diff. reference station
14 = Diff. reference station ID#
15 = Checksum
Juan Antonio Breña Moral

New User
Posts: 7
Joined: Thu Mar 06, 2008 3:20 pm

Is the Bluetooth GPS support already out for leJOS?

Postby gps4nxt » Thu Mar 06, 2008 3:52 pm

Hi Guys,

I would like to know if the GPS support (NMEA parser fucntionliaty etc..) is out in leJOS. Please direct me to the correct place.

Thanks a lot.

User avatar
Site Admin
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Postby bbagnall » Thu Mar 06, 2008 9:10 pm

You already asked this in another thread. Anyway, in case someone stumbles on this message using search, the answer is it will be released in the next version of leJOS NXJ, or you can play with the current alpha-code if you know what you are doing: ... les/BTGPS/

User avatar
Advanced Member
Posts: 361
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes

Postby esmetaman » Sat Mar 08, 2008 7:55 pm

Thanks Brian, you are the master.

Juan Antonio Breña Moral

Return to “NXJ Projects”

Who is online

Users browsing this forum: No registered users and 0 guests