|The primary reason that I had originally
purchased my first Raspberry
Pi 2 Model B SBC
(Single Board Computer) was to operate my Flight Tracking Station.|
With the prices of GPS modules dropping to extremely affordable levels (about $4 CDN), I decided to swap out the U-Blox NEO-6M GPS module for one that had a 5th pin -- a PPS (Pulse-Per-Second) contact that I could use to implement a high-accuracy NTP (Network Time Protocol) stratum 1 time server! In other words, using the primary (stratum 0) time clock sources available on GPS satellites to make my own secondary (stratum 1) shareable computer time source.
My primary source of information on how to do this came from these excellent sources:
Setting up a Stratum 1 NTP server on a Raspberry Pi
The Raspberry Pi as a Stratum-1 NTP Server
GPSD Time Service HOWTO
A Guide To GPS Network Time Synchronization
The wiring for the GPS module that I used is as follows:
Power (VCC/3V3) and Ground (GND) pins are basic. The Receive-Data (RXD) and Transmit-Data (TXD) are used to receive and transmit the serial-based GPS data stream (notice that reversal when connecting the pins i.e. the GPS 'transmit' pin is connected to the Raspberry Pi 'receive' pin, and vice versa). The magic comes from the Pulse-Per-Second (PPS) GPS pin being connected to the Raspberry Pi Pulse-Code-Modulation (PCM) pin (also acting as Pulse-Width-Modulation (PWM0)).
When a good GPS satellites lock has been achieved, my GPS will transmit useful time (as well as position) data (at 9600 baud) using various NMEA sentence structures. The one that the NTP utility uses to extract time are the following:
$GPRMC,POS_UTC,POS_STAT,LAT,LAT_REF,LON,LON_REF,SPD,HDG,DATE,MAG_VAR,MAG_REF*CC<cr><lf> $GPGLL,LAT,LAT_REF,LONG,LONG_REF,POS_UTC,POS_STAT*CC<cr><lf> $GPGGA,POS_UTC,LAT,LAT_REF,LONG,LONG_REF,FIX_MODE,SAT_USED,HDOP,ALT,ALT_UNIT,GEO,G_UNIT,D_AGE,D_REF*CC<cr><lf>Here are some samples of those sentences from my GPS (with position information obscured):
$GPRMC,195038.00,A,xx11.02333,N,xxx07.52859,W,0.052,,140817,,,A*61Here is a sample NTP time statistics from my time server soon after it was running:
pi@raspberrypi ~ $ ntpq -p
remote refid st t when poll reach delay offset jitterIn this sample, the GPS source is providing a time accuracy of 0.003 microseconds (3 millionths of a second) to my computer network! This time source is good enough to join (if I chose to do so) the list of other NTP time sources used by millions of computers around the world: How do I join pool.ntp.org?
UPDATE: Unfortunately, after upgrading my Raspberry Pi linux version to Raspbian/Debian 9 'Stretch', my GPS/PPS functionality stopped working (still haven't figured it out yet), so I swapped to using my backup server: an Orange Pi PC Plus (info here, purchased here):
The instructions for setting up a GPS/PPS time server on an Orange Pi are a bit more complicated that with the Raspberry Pi, but this page helped a lot:
ORANGE PI PLUS H3 with GPS/PPS – — The Black Magic Boxes
If everything is working OK, and a PPS lock has been established (sometimes tricky inside my home), this text will show the NTP statistics results: