Raspberry Pi GPS Time Server with Bullseye

I’m into accurate time. Ever since I stumbled across the SatSignal.eu site I have been running a Raspberry Pi on my network as a Stratum 1 time server. For those not familiar with the stratum, the only level higher is Stratum 0 and that is reserved for the absolute standard of time sources like the National Institute of Technology clock and GPS Satellites.

2016 Raspberry Pi Clock showing leap second addition at the end of 2016

I had been having some entropy on my current set of 6 GPS clocks from various issues, so I decided to rebuild my clock from the base install of the new Raspbian Bullseye distribution. Since I didn’t see a single definitive source, I put this listing together and I’m glad to share it with the community because it has been good to me with previous builds. My sources include SatSignal.eu, tomasgreno.cz, and adafruit.com. Much of what I did is just compiling and changing the order of some steps slightly to minimize reboots. Those others may work better for you, but this version worked for me.

Let’s talk hardware. I have done this project with a Raspberry Pi 1 through a Pi 4 as well as the Pi Zero and Zero W. I prefer the form factor of the full sized Pi to go along with the GPS hardware, but as long as you can make the GPIO connections from the GPS to the Pi all should work.

For a GPS module I use the Adafruit Ultimate GPS with the following pin connections. If you want to use something different, consult the breakout manufacturer and use pinout.xyz to set the proper connections. For my connections I typically use:

GPS Breakout PinRaspberry Pi Pin
VIN (Voltage in)Pin 4 – 5V Power
GND (Ground)Pin 6 – Ground
RX (Receive, to get data from the Pi TX)Pin 8 – GPIO 14 – UART TX
TX (Transmit, to send data to the Pi RX)Pin 10 – GPIO 16 – UART RX
PPS (Pulse Per Second)Pin 12 – GPIO 18

It’s not a typo, make sure TX goes to RX on the other board and vice versa.

Now on to software. Start with a clean version of Raspbian Bullseye on an MicroSD. I downloaded mine from the official RaspberryPi .com website. I used the “Raspberry Pi OS with Desktop” version and used an 8 GB MicroSD card as the media. I’m skipping the items related to base configuration of the host name and other start-up items, there are other sources for that. All the commands you see will be via the command prompt.

The instructions from here forward assume you have a working Raspberry Pi, connected to the internet with the GPS attached.

  • Start by adding two additional lines to the /boot/config.txt file. This starts the process to disable Bluetooth on the Pi and sets the Pulse Per Second GPIO Pin if your GPS supports it.
    • Note in this document, the command following $ gets entered at the command prompt, other commands are entered inside the file, at the bottom on a new line is usually good. Once commands are entered, use Ctrl-X, Y and Enter to save and exit the file and return to the command prompt. And yes, I use NANO as my text editor. You should use what you want. I’m not a text editor drill sergeant.
$ sudo nano /boot/config.txt

#Changes for GPS Clock
dtoverlay=pi3-miniuart-bt
dtoverlay=pps-gpio,gpiopin=18 (Customize to appropriate pin)
  • Disable Bluetooth in system control
$ sudo systemctl disable hciuart
  • Add a reference to /etc/modules to software for PPS management we will install shortly.
$ sudo nano /etc/modules

pps-gpio
  • Run a complete set of updates to the Pi Software
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo rpi-update
$ sudo reboot

Once the computer has rebooted, it’s time to begin installing the key software.

  • Install PPS tools and a set of system libraries
$ sudo apt-get install pps-tools
$ sudo apt-get install libcap-dev
$ sudo reboot
  • Now let’s test to see if the PPS software was installed by checking some OS boot logs
$ lsmod | grep pps 

You should get two responses back that look something like this. Don’t worry if the numbers are different.

$ dmesg | grep pps

Make sure you have a line that says “new PPS source…”

  • Once you see both of those, we can check and see if the GPS is sending data. Your GPS must have a “fix” which means it’s getting data from at least three satellites in order for this to work.
$ sudo ppstest /dev/pps0

Success looks like this:

Don’t worry about the specific numbers, just look for incrementing sequence numbers. The data will continue to populate every second until you hit CTRL-C to stop it.

  • Moving on, we have installed the GPS module and gotten data from part of it, but have not installed the main GPS software set yet. This should do it:
$ sudo apt-get install gpsd gpsd-clients gpsd-tools 

Once those are complete we can take a look at the data coming from the GPS by peeking at the port.

$ sudo cat /dev/ttyAMA0

You should get a continuing output with lines like this. I look for lines that start with $GPRMC (Specific location obscured by X’s)

pi@Telstar5A:~ $ sudo cat /dev/ttyAMA0
$GPGGA,220752.000,33XX.XXXX6,N,084XX.XXXX,W,1,07,1.13,278.6,M,-30.9,M,,*5E
$GPGSA,A,3,04,03,26,31,22,27,16,,,,,,1.46,1.13,0.92*0A
$GPRMC,220752.000,A,33XX.XXXX,N,084XX.XXXX,W,0.27,216.85,171121,,,A*7C
$GPZDA,220752.000,17,11,2021,,*51

Again, CTRL-C to stop it. If you get a stream of data and it’s gibberish your GPS may be sending at a different rate. A good place to start if you see that is this SatSignal.eu page which looks at other GPS modules and other methods.

  • Now, let’s temporarily send that data to some GPS software for interpretation.
$ sudo gpsd /dev/ttyAMA0 -n -F /var/run/gpsd.sock

Then we’ll open the GPSMON software to look. (There’s also a tool called CGPS. Use either, this is a personal preference thing)

$ gpsmon
Location obscured for privacy.

The screenshot above will tell you your exact position, the number of satellites your GPS sees, and the status of your PPS data all in one screen. Did I mention you CTRL-C to get out of a screen like this? Because you do.

  • Configure the GPS software to auto-start when you boot your machine. I have seen a couple of different processes, but this one works consistently for me.
$ sudo nano /etc/default/gpsd

Unlike the other file edits where you add a line, this is what the whole file should look like when you are done. You may just want to cut and paste this whole section, or type it in, whatever works for you, I won’t judge.

#Updated for GPS Pi Clock

START_DAEMON="true"

# Devices gpsd should collect to at boot time.

GPSD_SOCKET="/var/run/gpsd.sock"

# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyAMA0"

# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"
GPSD_SOCKET="/var/run/gpsd.sock"

# Automatically hot add/remove USB GPS devices via gpsdctl
USBAUTO="false"
  • Almost done with the GPS section. Four more commands to go.
$ sudo systemctl stop gpsd.socket
$ sudo systemctl disable gpsd.socket
$ sudo ln -s /lib/systemd/system/gpsd.service /etc/systemd/system/multi-user.target.wants/
$ sudo reboot

That third $ command (between “disable” and “reboot” goes on a single line, this blog text tool wraps it. It should look like this:

  • If you want to reconfirm everything is working again after reboot, run GPSMON like above and look at the pretty data fly by. Now let’s connect the GPS to the clock. I’m choosing to use NTP as my time server software for this project. You might want to play with Chrony as well.
$ sudo apt-get install ntp

Once that is done, you want to stop the timesyncd service that is installed by default with Bullseye and replace it with NTP.

$ sudo systemctl stop systemd-timesyncd
$ sudo systemctl disable systemd-timesyncd
$ sudo service ntp stop
$ sudo service ntp startntp q -

Let’s test. “Out of the box” the NTP software checks with servers on the internet to get the time. It will look something like this:

$ ntpq -p -c rl
The * on the left indicates the chosen server, this one is at Georgia Tech.

Great news! Clock is syncing, but if you look at the bottom you’ll see after “leap=00” it says “stratum=2” which is nice, but we want to use the GPS to make it a Stratum 1 clock.

  • It’s time to cross the streams and point the NTP software to look at the GPS and PPS signals for time. That means editing the NTP configuration file.
$ sudo nano /etc/ntp.conf

There are a lot of other settings in the file, so I won’t give the whole file this time but here’s what I recommend. Scroll down until you get to this section:

Use the # sign as the beginning of a line to comment out several of those “debian.pool” lines. You do want to keep an internet server on the list as a backup and for diversity, but you won’t need all of them. Save that for the folks that don’t have satellite time at home. Just below the “pool” entries, add each of the 6 lines on a new line:

# Kernel-mode PPS reference-clock for the precise seconds
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0 refid PPS

# Coarse time reference-clock - nearest second
server 127.127.28.0 minpoll 4 maxpoll 4 iburst prefer
fudge 127.127.28.0 time1 +0.105 flag1 1 refid GPS

If you want to use different servers on the internet, there are plenty to supplement. The manual page about ntp.conf can tell you more about other things you can do with this file.

When your changes are made it should look like this.

Do that cool CTRL-X thing and get out of there before you break anything (kidding).

Time to get the NTP client to read the new configuration file.

$ sudo service ntp restart

It sometimes helps to reboot too. Your call.
Now let’s check and see what time source we are using:

$ ntpq -p -c rl

Success! Why? Three things you want to see on this screen:
1 – The SHM / .GPS. line has a * next to it, indicating it’s the primary time source. In the “st” column you can see a 0 which indicates it’s connected to a “Stratum 0” source.
2 – The PPS / .PPS. line has an o next to it, indicating it is a “PPS peer” and it’s getting very specific pulse data from the GPS signal. It’s also a “Stratum 0” source.
3 – The “stratum” field for your NTP server now is “stratum=1” which is pretty much the best you can get as a home user.

It may take a little bit for the PPS to settle in as the primary time source, so don’t worry if it doesn’t do it in the first 5 minutes.


So, that’s the project. Why do you need this? Well, I do it for fun, but there are several applications that require very accurate time. For instance in Ham Radio the cycles for a program like FT8 depend on an accurate clock to switch between receive and send modes. Is this the thing I’m going to replace a Rubidium time standard with? No, but for about $100 bucks it’s a nice thing to have an a good early project for someone learning about Raspberry Pi. You can set Windows, Mac or Linux clients to point to your home server for time instead of time.windows.com or other sources.

One final note, this is accurate for me as of the time in that last screen shot. Something is bound to change eventually, so expect these instructions to drift over time as things change. Figuring that out is one of the fun things for me.

If you do this project and want to share success, you can tweet me @N4BFR or find me in other place on the internet.

Solving Family Problems with Technology – The Pi/Flip Dot Alert System

Maybe this is a solution in search of a problem, but there are use cases. On occasion I will be down stairs in my Tech Center rocking out on some Ham Radio DX or writing some code for a Raspberry Pi and oblivious to the world. Those are usually the times when my wife Tammy is trying to get ahold of me, but is worried about interrupting me.

Introducing the Jim Alert system. It starts with the button on this Raspberry Pi Zero.

Tammy pushes the button which writes a file to a server which trips the LED on the Pi. This allows her to know the alert has been triggered.

Once every minute (for now) my flip dot clock will check for that file. If it finds it, it will trigger a custom message on the clock and an alert sound. (Literally, ALERT in Morse Code). Here’s what it looks like…

Once the alert displays, the LED on the Pi Zero goes off and it clears from the Flip Dot in about 30 seconds, at the top of the next minute.

A possible future enhancement might be to add multiple Pi’s and show the room the alert came from.

For more on my Flip Dot project, read here:

Building a Flip Dot Clock powered by a Raspberry Pi

Flip Dot clock as part of my clock wall.

It’s a nice confluence of my fandoms, I love old technology, I love clocks and I love Raspberry Pi’s, so when I found a Luminator 7×90 Flip Dot display on eBay in early January, I bought it. This is the fairly-detailed, well illustrated story of how I brought a 90’s sign together with a low cost but powerful computer.

Continue reading “Building a Flip Dot Clock powered by a Raspberry Pi”

My Raspberry Pi version of the Big Ben Clock

Last winter, early post retirement, I was tinkering around with one of my many clocks one day and added the chimes of Big Ben to it. Whenever I would visit my grandparents growing up, I would hear their clock that struck the Windsor Chimes and I always thought that would be a fun project.

This was fairly straightforward, I grabbed some sound files from the UK Parliament website and one other source for the 45 minute chime, and did a little editing. Work done implemented via CRON in a couple of hours, fast forward on to other things.

A few months later and I am on the phone with my mother and she hears the chimes in the background. She starts reminiscing about the sounds and her parents clock and I agree to make something for her.

This video documents the major elements of the build but here’s the parts list:

– Raspberry Pi Model 3 B with Raspberry Pi Touch Screen – I have had good luck with Canakit and Adafruit if you are looking for sources.
Basic USB Powered Speakers
Micro USB Power Cable with switch
16 GB SanDisk Class 10 Micro SD Card
– 1/4 inch Birch Veneer Plywood
– Gloss White Spray Paint

The Software Build

I had all the sound files to go on from my build into my exciting digital clock, so no additional work done there. One tricky bit was to get the hourly chime to trigger at about 59:40 after the hour so the big ben bell would start striking the hour right at the top of the minute. Since CRON works on minutes, I solved that by making a 59 second file. So the file starts at 59 after but plays a silent section for the first 40 seconds before the chime.

How the hourly Big Ben bell plays: CRON is programmed at xx:59 to trigger a shell script that first plays the chimes, this is the file mentioned above. It then triggers the Big Ben bell sound, and loops the appropriate number of times for each hour. Here’s an example of the code for 9 o’clock. There are 12 files, 1 for each hour.

#!/bin/bash
#export XDG_RUNTIME_DIR="/run/user/1000"
mplayer -really-quiet "/home/pi/chime/h59.mp3" -volume 100
mplayer -really-quiet "/home/pi/chime/bong.mp3" -loop 9 -volume 100

A couple of new skills for me were achieved on this project. The first was working with JavaScript clock elements for an analog clock. This came together by adding the face of the Great Clock as a background image, editing the photo for size and removing the hands from the face. I then found some similar looking clock hands and did a JavaScript analog clock overlay via HTML. Adjusting the pivot points for the hands took some time, they would drift around the clock face until set just right.

The other element to this was hardening it so it was hands off for mom. With her being 1,000 miles away, I couldn’t do a local install so it had to be right. I had her send me her WiFi info so I could pre-program it on the card. I chose USB powered speakers with an on-cord volume control so she could just lift the touch screen off the case to adjust. Also added a “kill switch” to the back for easy shut down. Finally I included a backup USB card in the case incase the current one is corrupted and I keep an image on my NAS as well if needed.

I did not put a RTC in the Pi. Partially because some of the GPIO ports I wanted we used by the Touch Screen and partly because I had the clock programmed to get NTP time via WiFi so there would be no updating needed.

The Hardware Build

I started with the standard elements I knew the Raspberry Pi 3B+. I chose the B+ because I didn’t need the horsepower of a Pi 4 for a basic display and I had one I had recently swapped out for a Pi 4 on another project. I used the 16 GB Class 10 MicroSD cards in all my Pi projects. They rarely corrupt for me when powered correctly, they offer enough space to power most projects I do, and the are small enough to back up on my NAS without completely killing storage.

I’ve used the Pi Touch Screen in a couple of other projects and it’s very easy to set up and control the display natively. In most cases I also use a commercial Pi Touch Screen stand however in this case I wanted to hide the electronics and let the clock be the focal point.

I tried to build a simple box that would hold the Pi, Screen and Speakers and I accomplished it, but I might do it differently in the future. I assembled the 4 structural elements first, the 2 sides, back and the bottom. Small birch strips held the front out from the back of the box to provide a little extra room.

On the first attempt, I made the face frame from a single piece of plywood cut in 2, so I could notch out the hole to mount the touch screen. I wasn’t really happy with the fit or the structural integrity of that, so I started with another single piece, made a small slat through which I could cut a hole for the screen with my band saw and then used putty to seal the small gap, which worked much better.

Several other holes in the box to allow for air flow, speaker audio to escape and power. I was going to put some grommets on the rough wooden holes I cut in the back but I had to give that up for time so I could get it to Mom by Christmas.

Great news is that it arrived on time and worked perfectly. We plugged it in about 10 minutes to one and by 12:59 it had synced up with the NTP server for a real time update and was playing it’s chimes.

Before it comes up

I intentionally have not packaged this all up as a GitHub project or some other repository. I don’t own the rights to all the photos or sound files. Hopefully your build will use all the open source stuff!

Other questions on my build? Contact me on Social Media…

– Facebook: facebook.com/N4BFRVision
– Twitter: @N4BFRVision
– Reddit: u/N4BFR

I was not paid in any way for this build or post. Some of the links in this post lead to shopping sites, however I make no commission. If this post helped or inspired you, consider dropping something in my tip jar.

The Russian Submarine Clock

During the Blue Ridge Parkway road trip last year I found this mechanical clock with a Russian Submarine design right down to the CCCP in the lower right corner. When I picked it up, it was working OK but seemed to run down quickly until it stopped. I took it in to Bowers Watch and Clock Repair in Atlanta and they ended up restoring it to full functionality for about half of what the original estimate was.

Great, but the fascinating part of the story was talking to the senior Mr. Bowers (it’s a father and son business) who told me that, “no Russian captain would have that poor quality clock on their ship.” He went on to tell me these were made for the tourist trade. Fair enough.

Mr. Bowers went on to tell me about the Ansonia Clock Company, which was started not far from where I grew up in Connecticut, though about 100 years earlier than when I lived there. Eventually Ansonia was sold to Amtorg Trading which moved the machine shop to Russia. According to Mr. Bowers, “one lathe operator said they took everything from the floorboards on up. When they started the steam boiler in Moscow it still had American water in the tank. The lathe had the same piece in it and the trash in the trash can was the same.” Quite a statement! (Note, I typed that quote from memory so there may be a little paraphrasing in it.)

So, is it real or repro? Probably 70’s repro would be my guess judging by some other blog posts. If you want one new, here’s one https://www.russian-watches.info/shop/vostok-watches/russian-vostok-ship-marine-8-days-clock-5-chm-submarine/ for about $300. Note on the dial between the 5 and 6 digit mine cays B CCCP, while the one I linked says POCCHH. I think this clock is likely an early clock that was actually on a ship. Something to watch for in future shopping trips.

Solution for displaying Pocket Watches & Stop Watches

As a watch fan, I have collected a few stop watches and pocket watches but I have struggled on how to display them. Looking at the brass frame I built for the Nixie Clock (See it in the 24 Hours of Clock Videos) I thought I could use the same material to crate a watch holder. It only takes 3 parts and 4 tools:

  • A piece of wood for the base (and a saw to cut it to size)
  • 3/32″ brass (and some wire cutters to trim)
  • Solder (and a Soldering Iron)
  • A drill to create the mounting holes

24 Hours of Clocks Video Project

I admit it. I have a thing for clocks. So I took some of my favorite clocks and put together a video montage to showcase these interesting time pieces. What kind of clocks:

  • A Sony Flip Clock tells the time from 2-4 AM. This clock radio was on so many bedside tables back in the day. It evokes the movie Groundhog Day when Phil wakes up to Sonny & Cher every morning.
  • James Remind-O-Timer. A took for the later day 50’s and 60’s hotel desk clerk. Need a 5:50 AM wake-up call? No problem, just flip the lever to 5:50 and the buzzer will remind you.
  • Heathkit GC1005. When I worked in radio in the 80’s, these were a staple of every studio.
  • Raspberry Pi GPS clock. When you need super accurate time wherever you go. It’s my home made favorite and I use it when I want to do time sensitive digital modes on the road.
  • Chelsea Military Clock. One of my all time favorites. A beautiful 7 day mechanical movement (that needs a little fine tuning) that looks in place in any bridge, hanger or ward room.

Coca-Cola Pizza Shop Clock Repair

I was at a yard sale on Saturday and had the opportunity to grab this 1986 LED clock that looks like it would be perfectly in place in a Pizza Shop that you would watch while waiting to pick up a pie for the family. Primarily the restoration was about reattaching the Coke sign and some minor clean up. Now to decide where this one will live.

LCDClock – My First Github Project

I’ve used Github quite a bit to source either partial or complete code for many of my Raspberry Pi projects. Github is a code sharing platform that makes it easy to get and keep software updated on devices like Raspberry Pi’s.

When I first created my Pi-clocks I made one with an LCD display that showed local and UTC time. You can see it in this leap second video from 2015.

Five years later that clock has been long out of commission as I do upgrades and other clock projects, but I missed having the LCD clock. So as I worked on the Chrony project I decided to rebuild one as an LCD clock. This has taken me deep into the world of Python and I am sure when someone looks at it there will be comments like “it’s clunky” or “why didn’t you do it this way.” All valid I am sure, but I made it work and even built in some error handling so I feel pretty good for a start.

Starting with the basic Chrony build, the LCD screen gets added from Adafruit. In the last 5 years they have evolved to a version of python called “Circuit Python” to drive many of their devices, so I went with this as the base code to drive the display.

sudo pip3 install adafruit-circuitpython-charlcd

As part of the new design, instead of using this to be a UTC clock (i have plenty of those), I wanted the clock to display variables. The first one I chose was to display the Stratum of the clock. This assures me if I see “Stratum: 1” that I am getting the time from the satellite data. I get that by running a CRON job to output that data to a text file, then I read that from the text file with the Python program. The CRON line that runs every 2 minutes is:

/2 * * * * chronyc tracking > /home/pi/lcdclock/tracking.txt

The second variable is the current IP address of the clock. Always helpful if you want to do some quick editing. That’s a standard python variable, so no additional libraries were needed.

The third variable is the current GPS position. To grab that data I use the gps3 python client to pick up the location of the clock. While this generally won’t change, I might take this on the road in the future to a ham fest or Field Day. There are a bunch of variables I could have pulled, but Lat/Long is just what I needed.

sudo pip3 install gps3

The last variable is a vanity card. I created a file called “msg4.txt” that can be used to display any message in the last 14 second window. Maybe in the future I might make it a YouTube follower counter.

You can grab the code from GitHub here:

https://github.com/n4bfr/lcdclock.git

Here’s how it all comes together:

I’m eager for feedback! Here’s where you can give me notes:
– The N4BFR Vision YouTube Channel
– My Facebook Page: https://www.facebook.com/N4BFRVision
– My Twitter: https://twitter.com/N4BFR_Vision

Follow Friday – YouTube Edition – April 24

Time to share what I am watching, hope it inspires you to watch something new.

Simone Giertz
The queen of shitty robots is awesome. In her most recent video she makes a “proud parent” machine and uses a bunch of dirty words. Which is awesome in so many ways.



Fran Lab
Fran has a very similar taste in projects to me. I found a Heathkit GC1005 clock to refurbish at the Orlando Hamcation, back before we had to social distance. Come to find out Fran had recently refurbished one which really helped me. Mine is still in progress but check out Fran’s here.



Mythbusters Jr.
I didn’t really jump into this because I was put off by the non-Adam version that they tried to reboot through a reality show. Lots of fun builds here. I was really hyped to find a Breaking Bad episode.


Whose Line Is It Anyway Cocktail Hour
Every Monday the cast from Whose Line gets together to preview the show and basically talk s#!t. It’s fun to watch with your feet up. Here’s the video from Monday 4/20.


I have a YouTube Channel too
I talk about clocks, ham radio and other nerdy stuff. I just added a video of the Chronometer Raspberry Pi clock I built this week. As they say, please Like, Comment and Subscribe!