GPS Scripts

Python code for GPS Modules, NMEA and Google Earth

Copyright: Copyright 2007 Dean Hall. All rights reserved.
Author: Dean Hall
Revision: 01
Date: 2007/12/11

Aside

The KML track as seen in Google Earth

I found a great open-source GPS reading converter, gpsbabel, that talks to nearly any GPS module and can format that data in a number of ways. In the photo to the right, I have converted an automobile trip from raw NMEA sentences to a Google Earth KML file. At each measured point, the KML track has a marker that contains the Lat, Lon, Heading, Speed and Time.

Prerequisites

gps.py

gps.py reads input from the computer's serial port (or USB posing as a serial port) at 4800 8-N-1 and echos the data to stdout.

usage: gps [-EHpcghlstv]

-E          Use the EverMore GPS module
-H          Use the Holux GPS module
-p port     Use the module connected to the given port.
-c          Filter in $GPRMC sentence type.
-g          Filter in $GPGGA sentence type.
-h          Prints this help message
-l          Filter in $GPGLL sentence type
-s          Filter in $GPGSA sentence type.
-t          Filter in $GPVTG sentence type.
-v          Filter in $GPGSV sentence type.
--EverMore  Use the EverMore GPS module
--Holux     Use the Holux GPS module
--port=port Use the module connected to the given port.
--rmc       Filter in $GPRMC sentence type.
--gga       Filter in $GPGGA sentence type.
--gll       Filter in $GPGLL sentence type
--gsa       Filter in $GPGSA sentence type.
--vtg       Filter in $GPVTG sentence type.
--gsv       Filter in $GPGSV sentence type.

It has two built-in devices that it tries automatically. If you do not have one of those devices, you will have to supply the path to your device using the -p port option. If you like, you can add your device/port to the DEVICES dict in the source code and it will be used automatically thereafter.

If you do not specify any filter, all NMEA sentences will be echoed.

I typically pipe output from this script straight to a text file:

$ ./gps.py --port=/dev/cu.usbserial > test.nmea

nmeagram.py

You must download this module for the other scripts (below) to work.

nmeagram.py parses NMEA sentences and is used by the other scripts.

nmeatokml.py

KML file plotted onto satellite image using Google Earth

nmeatokml.py takes an NMEA text file as input and creates a Google Earth compatible output file.

Typical usage:

$ ./nmeatokml.py < test.nmea > test.kml

Then open the kml file in Google Earth.

nmeatoenglish.py

nmeatoenglish.py takes an NMEA text file as input and writes an english translation of each sentence (only the important fields are printed).

Typical usage:

$ export PYTHONUNBUFFERED=t
$ ./gps.py | ./nmeatoenglish.py