Here is a first upgrade for my ADSB receiver box – GPS precision time. The MLAT position calculation for aircrafts depends on a precise time. While there is already a time synchronization between MLAT receivers in a specific area it is also possible to add a precise time source to improve the calculation result. A GPS receiver is such source when equipped with a PPS (pulse per second) output. The PPS is a signal with a width of less than one second and a sharply rising or abruptly falling edge that accurately repeats once per second with low jitter. The GPS time and PPS signal are then used to sync the internal ntp time service and keep a low offset and jitter.
My choice for GPS receiver was the Adafruit GPS v3 breakout board as it was a spare in my boxes. Beside the small size and high channel GPS receiver it has a PPS output and operates at 3.3V-5V input, but 3.3V TTL logic output, perfect for the Raspberry Pi. The additional backup battery come in handy in case of a power cut.
GPS board connection to Raspberry Pi 2/3
|Adafruit GPS v3 pin||Raspberry Pi I/O header pin|
|VIN||Pin 2 = 5V|
|GND||Pin 14 = GND|
|TX||Pin 10 = GPIO 15|
|RX||Pin 8 = GPIO 14|
|PPS||Pin 12 = GPIO 18|
Enable PPS input and set UART baudrate
To enable the PPS input and setting the correct baudrate for the GPS the Raspberry Pi config file
/boot/config.txt must be changed. Add at the end:
# GPS PPS input
init_uart_baud = 9600
Disable serial console on UART0
The GPS is connected to the UART0 serial interface (ttyAMA0) that is usually occupied by the Raspberry Pi serial console. That needs to be disbaled. So we edit
/boot/cmdline.txt and change
Also the getty instance on ttyAMA0 needs to be disabled:
$ sudo systemctl disable serial-getty@ttyAMA0.service
Install GPS service
This service is required to access the GPS and it provides a shared memory the for the ntp service with its own time informations.
$ sudo apt-get install gpsd gpsd-clients python-gps
To successfully run the GPS service, its configuration needs to be changed to access the UART0. So edit
/etc/default/gpsd as follows.
# Default settings for the gpsd init script and the hotplug wrapper.
# Start the gpsd daemon automatically at boot time
# Use USB hotplugging to add new USB devices automatically to the daemon
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
# Other options you want to pass to gpsd
Now we reboot and check that PPS and GPS are working.
$ dmesg | grep pps
[ 5.957377] pps_core: LinuxPPS API ver. 1 registered [ 5.957515] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <firstname.lastname@example.org> [ 5.973778] pps pps0: new PPS source pps.-1 [ 5.973907] pps pps0: Registered IRQ 184 as PPS source
Installing pps-tools will provide some additional informations. This is a mandatory step in order to get ntp service with PPS working. Compiling ntp has a dependency for timepps.h that comes with pps-tools.
$ sudo apt-get install pps-tools
$ sudo ppstest /dev/pps0
trying PPS source "/dev/pps0" found PPS source "/dev/pps0" ok, found 1 source(s), now start fetching data... source 0 - assert 1482268186.000006148, sequence: 4647 - clear 0.000000000, sequence: 0> source 0 - assert 1482268187.000003768, sequence: 4648 - clear 0.000000000, sequence: 0 source 0 - assert 1482268188.000003324, sequence: 4649 - clear 0.000000000, sequence: 0
Checking that GPS service is running:
$ sudo service gpsd status
gpsd.service - GPS (Global Positioning System) Daemon Loaded: loaded (/lib/systemd/system/gpsd.service; static) Active: active (running) since Tue 2016-12-20 19:45:08 UTC; 1h 26min ago Main PID: 745 (gpsd) CGroup: /system.slice/gpsd.service └─745 /usr/sbin/gpsd -N -n /dev/ttyAMA0
Dec 20 19:45:08 raspberrypi systemd: Started GPS (Global Positioning System) Daemon.
$ cgps -s should output something like:
x Time: 2016-12-20T21:14:35.000Z xxPRN: Elev: Azim: SNR: Used: x x Latitude: xx.xxxxxx N xx 12 78 291 24 Y x x Longitude: xx.xxxxxx E xx 24 67 133 00 Y x x Altitude: xxx.x m xx 25 36 261 29 Y x x Speed: 1.1 kph xx 32 33 303 15 Y x x Heading: 71.1 deg (true) xx 19 32 050 17 Y x x Climb: 0.0 m/min xx 6 21 087 00 N x x Status: 3D FIX (5 secs) xx 17 18 042 00 N x x Longitude Err: +/- 16 m xx 2 15 122 00 N x x Latitude Err: +/- 27 m xx 14 14 322 21 N x x Altitude Err: +/- 19 m xx 15 10 182 19 N x x Course Err: n/a xx 29 04 203 00 N x x Speed Err: +/- 199 kph xx 10 01 268 00 N x x Time offset: 0.506 xx 136 00 000 00 N x x Grid Square: xxxxxx xx x