10 June 2021

GPS and Raspberry Pi Stratum 1 Server

This is certainly not a difficult project, but I am going to assume you can put a hat on a raspberry pi, get the OS installed and do some basic command line work. (hint: Don't forget that blank file named ssh in the root of the boot drive so you can remote in)


Time is essential to any communication method, but particularly so to low-power digital communications in ham radio.  Modes like FT8 or JS8 utilize a single RF frequency and utilize the Audio bandwidth to handle multiple stations.  To accomplish this, everyone has to be transmitting and decoding in fairly exacting time segments.  In my attempt to be more effective in a grid-down scenario I started building local NTP servers that would provide a time standard, separate from the internet, for my radio shack, etc.  I started with a simple USB GPS receiver on a Raspberry PI over wifi, and now this project is to build a hardwired server with a serial GPS receiver that has PPS (pulse per second) timing.

Version 1


Julian: OH8STN Video on the original GPS PI
Mike Richards: The Original, as far as I am concerned, walkthrough of the GPS PI
Rob Robinette: Troubleshooting resource for this setup

Parts List

Raspberry Pi 4
Micro SD Card
Uputronics GPS/RTC Expansion Board
Uputronics Active GPS Antenna
ThePiHut Pi GPS HAT Case for Raspberry Pi 4
(Optional) 12 volt to USB charger
(Optional) PoE splitter
Some form of power supply for Raspberry Pi 


To be clear Version 1 of this project, as detailed by Mike and Julian in the resources is MORE than adequate for most people.  Below is an estimated error comparison between just using the NMEA stream and then using the PPS versus standard internet NTP sources.

As a reminder, a second is bigger than a millisecond (ms) which is bigger than a microsecond (┬Ás) which is bigger than a nanosecond (ns).

I have no hesitancy recommending the Version 1 GPS Pi and you can follow the first two resources and it will be excellent.

If you want to play with the PPS part, read on.

The HAT I used is a little different in the way it works.  The baud rate for the GPS unit is faster than standard, and it uses the kernel PPS instead of SHM 1 on the serial unit.  That being said, it is easy to set up and I think it is the best one available.

I am using Raspberry Pi OS released 2021-05-07

Once you get the raspberry pi up and running and are logged in:
sudo raspi-config
Select Interfacing Options and Enable I2C

Next, we will install the tools to read the Real-Time Clock and the PPS signal from the expansion card
sudo apt -y install python-smbus i2c-tools pps-tools
And make sure you see 42 and 52 show up in the command below
sudo i2cdetect -y 1
Next add real time clock, pps, and activate the onboard serial port by adding these three lines to config.txt
sudo nano /boot/config.txt
(ctrl-x and y to exit nano on all of these.  You can try VI but on pi it doesn't always work right on my terminals)

Next, we want to make sure the onboard console is not interfering with our gps serial connection
sudo nano /boot/cmdline.txt
Delete this part of the first line: console=serial0,115200 (if present)

Next, execute the following commands to get rid of the fake hardware clock on the pi
sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
sudo systemctl disable fake-hwclock
sudo nano /lib/udev/hwclock-set
and comment out the following 4 lines
#if [ -e /run/systemd/system ] ; then
# exit 0
# /sbin/hwclock --rtc=$dev --systz --badyear
To set the baud rate we mentioned before add the following line to rc.local   BEFORE the exit command
sudo nano /etc/rc.local
stty -F /dev/ttyS0 115200
Add PPS to modules
sudo nano /etc/modules
and reboot
sudo reboot
After reboot, you can test the PPS part with the following command:
sudo ppstest /dev/pps0

You can optionally use minicom to test the GPS over serial or you can do a cat command.  Either way, you can see what serial ports are being used for either.  In my case it was /dev/ttyS0
ls -lh  /dev/serial[0,1]
Option 1
sudo apt-get install minicom
minicom -b 115200 -o -D /dev/ttyS0
Option 2
sudo cat /dev/ttyS0
Once you are comfortable that things are working, we can install chrony and gpsd.  Goes between the GPS device and Chrony.  Chrony is our NTP server.
sudo apt -y install gpsd gpsd-clients python-gps chrony python-gi-cairo
We will configure GPSD to read NMEA and PPS signals.
sudo nano /etc/default/gpsd
 DEVICES="/dev/ttyS0 /dev/pps0"
Next at the bottom of the Chrony config file, modify the makestep and add the lines to add NMEA and PPS.  The last line could be allow all, but this lets you limit to only respond to NTP requests from your network.
sudo nano /etc/chrony/chrony.conf
makestep .1 5
refclock PPS /dev/pps0 refid PPS prefer
refclock SHM 0 refid NMEA

and reboot
sudo reboot
At this point, you should be able to point your clients to the IP address of your NTP server and you are off to the races!


The following 4 commands will tell you a lot about your system and what to troubleshoot.
gpsmon -n

This will tell you what is coming off of your GPS receiver
chronyc sources -v
This will tell you what is being used by chrony and how it relates to the other available time references.
sudo timedatectl

This will show you all the time standards used by the hardware pi.
sudo chronyc makestep
This will force your hardware to sync up to the time reference immediately, otherwise, it does it in steps.
After you are sure it is working, mount it somewhere handy.  I have it in the shack right now, but I do have a power over ethernet (PoE) injector and splitter so I can put it anywhere in the house and keep the cables down.  I also recommend setting up RaspAP on it so that it can host its own hotspot if your network goes down and you still want to use it as your time reference.

No comments:

Post a Comment