timeserver logo
JPG rpi 2 model
                ublox neo-6m gps

PNG rpi 2 model b pinout

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:

Raspberry Pi
  RXD (GPIO15)

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:
Here are some samples of those sentences from my GPS (with position information obscured):
Here 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  jitter
 LOCAL(0)        .LOCL.          10 l  45h   64    0    0.000    0.000   0.000
oGPS_NMEA(0)     .GPS.            0 l    8   16  377    0.000    0.003   0.002
*   2 u   37   64  377   51.341    1.001 166.392
+kirdu.smartacti  2 u    3   64   77   42.552   10.272  99.637
+host1.hosttechn  2 u   20   64  377   38.465   10.301 161.560      2 u   65   64  376   34.556    0.719  52.451
In 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

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:

Embedded Text Document

UPDATE: After upgrading my Raspberry Pi linux version to Raspbian/Debian 9 'Stretch', my GPS/PPS functionality stopped working -- which I have now finally fixed by doing the following -- since I found out that the '/dev/ttyAMA0' device was being used by the 'login' process, which was interferring with 'ntp' from getting at it as well:
  • Type: "sudo raspi-config"
  • Pick: "5 Interfacing Options  Configure connections to peripheral"
  • Pick: "P6 Serial Enable/Disable shell and kernel messages on the serial connection"
  • Answer 'No' for: "Would you like a login shell to be accessible over serial?"
  • Answer 'Yes' for: "Would you like the serial port hardware to be enabled?"
  • Type: "sudo reboot"

I also did the following, but was not sure whether it was necessary or helped:

systemctl stop serial-getty@ttyAMA0.service
systemctl disable serial-getty@ttyAMA0.service
systemctl mask serial-getty@ttyAMA0.service
I also activated the same feature on my backup server: an Orange Pi PC Plus (info here, purchased here):

PNG orange pi pc plus
PNG orange pi pinout
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:

Embedded Text Document