Basic Test

We can get started by testing the GPS right at the command line.

Before you start, you'll want to make sure the GPS modules has a 'fix' - that means it has received enough data from satellites to determinet he location.

You can quickly determine fix status by looking at the Red LED on the GPS Hat:

  • Blinking on and off once every other second - NO FIX
  • Blinking once per 10 seconds or so - HAS FIX

You may need to put the Pi near a window or attach an external antenna. Once it has a fix, continue!

Serial test

Lets stat by just reading the 'raw' data from the GPS on the command line. Run:

stty -F /dev/serial0 raw 9600 cs8 clocal -cstopb

To set /dev/ttyAMA0 (the built in terminal console) to raw data (raw) 9600 baud (9600) 8-bits (cs8) no modem control (-clocal) and 1 stop bit (cstopb)

It's pretty picky so please use those settings and not noodle with them too much unless you're sure!

Now run

cat /dev/serial0

To read raw data directly from the GPS HAT

You should see something like this!

This is the raw GPS "NMEA sentence" output from the GPS module. There are a few different kinds of NMEA sentences, the most common ones people use are the $GPRMC (Global Positioning Recommended Minimum Coordinates or something like that) and the $GPGGA sentences. These two provide the time, date, latitude, longitude, altitude, estimated land speed, and fix type. Fix type indicates whether the GPS has locked onto the satellite data and received enough data to determine the location (2D fix) or location+altitude (3D fix).

For more details about NMEA sentences and what data they contain, check out this site

If your data looks like this, with a lot of commas, with no data in between them. That's because this module is does not have a 'fix'. DONT FORGET To get a fix, we need to put the module or antenna outside or have it able to see the sky!

GPS modules will always send data EVEN IF THEY DO NOT HAVE A FIX! In order to get 'valid' (not-blank) data you must have the GPS module directly outside, with the square ceramic antenna pointing up with a clear sky view. In ideal conditions, the module can get a fix in under 45 seconds. however depending on your location, satellite configuration, solar flares, tall buildings nearby, RF noise, etc it may take up to half an hour (or more) to get a fix! This does not mean your GPS module is broken, the GPS module will always work as fast as it can to get a fix.

OK lets look at a good NMEA sentence with 'fix'

Something that starts with $GPRMC like:

$GPRMC,194509.000,A,4042.6142,N,07400.4168,W,2.03,221.11,160412,,,A*77 

This line is called the RMC (Recommended Minimum) sentence and has pretty much all of the most useful data. Each chunk of data is separated by a comma.

The first part 194509.000 is the current time GMT (Greenwich Mean Time). The first two numbers 19 indicate the hour (1900h, otherwise known as 7pm) the next two are the minute, the next two are the seconds and finally the milliseconds. So the time when this screenshot was taken is 7:45 pm and 9 seconds. The GPS does not know what time zone you are in, or about "daylight savings" so you will have to do the calculation to turn GMT into your timezone

The second part is the 'status code', if it is a V that means the data is Void (invalid). If it is an A that means its Active (the GPS could get a lock/fix)

The next 4 pieces of data are the geolocation data. According to the GPS, my location is 4042.6142,N (Latitude 40 degrees, 42.6142 decimal minutes North) & 07400.4168,W. (Longitude 74 degrees, 0.4168 decimal minutes West) To look at this location in Google maps, type +40° 42.6142', -74° 00.4168' into the google maps search box . Unfortunately gmaps requires you to use +/- instead of NSWE notation. N and E are positive, S and W are negative.

People often get confused because the GPS is working but is "5 miles off" - this is because they are not parsing the lat/long data correctly. Despite appearances, the geolocation data is NOT in decimal degrees. It is in degrees and minutes in the following format: Latitude: DDMM.MMMM (The first two characters are the degrees.) Longitude: DDDMM.MMMM (The first three characters are the degrees.)

The next data is the ground speed in knots. We're going 2.03 knots

After that is the tracking angle, this is meant to approximate what 'compass' direction we're heading at based on our past travel

The one after that is 160412 which is the current date (this sentence was first 'grabbed' on 16th of April, 2012).

Finally there is the *XX data which is used as a data transfer checksum

Once you get a fix using your GPS module, verify your location with google maps (or some other mapping software). Remember that GPS is often only accurate to 5-10 meters and worse if you're indoors or surrounded by tall buildings.

Last updated on 2017-08-20 at 10.52.03 PM Published on 2014-12-26 at 05.22.11 PM