Raspberry Pi 5 notes
Home Page Up Setup on Windows Using NTP Windows LAN tips Events Cable modem notes Monitoring with MRTG GPS 18 + FreeBSD GPS 18 + Windows GPS 18x firmware GPS 18x waveforms NTP 4.2.4 vs. 4.2.5 NTP 4.2.7p241 Rapco 1804M notes Raspberry Pi Raspberry Pi 5 notes RPi - ntpheat RPi - quick-start RPi - notes RPi - cross-compile RPi vs BBBlack Sure GPS board Timestamp issues TSC Interpolation Vista & Windows-7/8 Wi-Fi warning Windows after reboot Win-7/8 & Internet Win-7 to Win-10 gains New versions

 

Raspberry Pi 5 bookworm notes - April 2025

My previous Raspberry Pi notes were getting a little date so I have prepared this update.  You may need to refer to these quickstart notes or these earlier notes notes for more detail.  The steps I took were:

Installing NTP on the RPi
Modifying the ntp.conf file to suit my network
Adding an Uputronics GPS/PPS HAT.
Getting the PPS working
Updating the ntp.conf file for PPS
Getting the serial port working
Updating the ntp.conf file again
Updating the startup of the RPi
The final ntp.conf

Installing NTP on the RPi

As supplied, the bookworm OS comes with NTPsec rather than plain NTP.  As I'm not familiar with NTPsec, a simple "sudo apt install ntp" took care of that.
Check that "ntpq -pn" now works as expected.
 
 

Modifying the ntp.conf file to suit my network

I needed to edit the configuration of NTP to suit my own network, where I have several NTP stratum 1 servers already installed, and I prefer to European pool servers.  To be ready for adding a PPS source, I added the "prefer" qualifier to the local servers.  I left the original "driftfile" although with it being in /var/lib/ntpsec/ I'm unsure whether it lasts over restarts?  Note that the file location is now:

    /etc/ntpsec/ntp.conf

# /etc/ntpsec/ntp.conf, configuration for ntpd; see ntp.conf(5) for help 

driftfile /var/lib/ntpsec/ntp.drift

# Use local NTP servers
server 192.168.0.20 iburst maxpoll 5 prefer # LeoNTP
server 192.168.0.3 iburst maxpoll 5 prefer # PC Pixie
server 192.168.0.71 iburst maxpoll 5 prefer # RasPi-1, LAN

# Use UK & NL pool NTP servers
pool uk.pool.ntp.org minpoll 6 maxpoll 7
pool nl.pool.ntp.org minpoll 6 maxpoll 7

# Suggestions for NTP restrictions (accepting ntpq commands):
restrict source notrap nomodify nopeer
restrict 127.0.0.1
restrict ::1
restrict 192.168.0.0 mask 255.255.255.0

 
Adding an Uputronics GPS/PPS HAT.

With the RPi powered down, of course, I added an Uputronics GPS/RTC expansion board and rebooted.  
Once the PPS light is flashing you know the board is working - this can several minutes from a fresh start.

Getting the PPS working

This follows the steps in the earlier documents:

  • Install the PPS software:
        sudo apt install pps-tools
  • Edit /boot/config.txt
        Add dtoverlay=pps-gpio,gpiopin=18 on a new line.
  • Edit /etc/modules:
        Add pps-gpio on a new line, if it is not already present.
  • Reboot
  • Check for install
       lsmod | grep pps
  • Check for "Registered IRQ"
        dmesg | grep pps
  • Check for "assert" values:
         sudo ppstest /dev/pps0 

     

Update the ntp.conf file for PPS

You can now add the lines to access a type 22 NTP driver, which should enable the PPS.

.
.
driftfile /var/lib/ntpsec/ntp.drift

# Type 22 mode PPS
server 127.127.22.0 minpoll 4 maxpoll 4 
fudge 127.127.22.0 refid PPS
.
.

Look for the line starting with an "o" tally code in the output of "ntpq -pn"

    oPPS(0) .PPS. 0 l 7 16 377 0.0000 0.0021 0.0001

Getting the serial port working

This is, perhaps, the most complicated part of the task!

  • Using the sudo raspi-config command:
        Interface options
            Serial port
                Login shell - No
                Serial port hardware enabled - Yes
    Reboot.
  • Check that you have a device named ttyAMA0
        ls /dev/ttyAMA*
    Likely you will see ttyAMA0 and ttyAMA10.
    ttyAMA0 is the one you need.
  • To check that your seeing serial data:
        sudo apt install minicom
        minicom -b 115200 -o -D /dev/ttyAMA0
    (Ctrl-A x exits minicom)
  • If your serial device doesn't use 115200 specify it in the minicom line.


Update the ntp.conf file for PPS

NTP has a serial support - it's the type 20 driver.  However, it looks for device /dev/gps0.
You need to create a link do that gps0 points to your actual serial device - ttyAMA0 here.

  • sudo ln -sf /dev/ttyAMA0 /dev/gps0

You can now add a couple of lines to the ntp.conf adding NMEA suport:

.
.
# Coarse time from serial GPS
server 127.127.20.0 mode 81 minpoll 4 maxpoll 4 iburst prefer # 115,200 baud 
fudge 127.127.20.0 time2 +0.058 refid NMEA
.
.

Now you should see both the PPS and the NMEA/GPS listed in an "ntpq -pn"

    oPPS(0) .PPS. 0 l 7 16 377 0.0000 0.0021 0.0001
    *NMEA(0) .NMEA. 0 l 6 16 377 0.0000 -0.5643 1.4402

Updating the startup of the RPi

But we're not done yet!

It seems that the link we made between ttyAMA0 and GPS0 won't persist over a reboot - what a pain!
there are several ways you can work round this errror/bug.  I chose to edit /etc/rc.local which is run at
boot time to include a command to recreate the link, and restart the ntp service in case it was already
running so that it can detect the GPS/NMEA source.  I added before the "exit 0" command:

sleep 1
sudo ln -sf /dev/ttyAMA0 /dev/gps0 
sleep 1
sudo service ntp restart

 

The final ntp.conf

# /etc/ntpsec/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntpsec/ntp.drift

# Kernel mode PPS
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0 refid PPS

# Coarse time from serial GPS
server 127.127.20.0 mode 81 minpoll 4 maxpoll 4 iburst prefer # 115,200 baud 
fudge 127.127.20.0 time2 +0.058 refid NMEA

# Use local NTP servers
server 192.168.0.20 iburst maxpoll 5 prefer # LeoNTP
server 192.168.0.3 iburst maxpoll 5 prefer # PC Pixie
server 192.168.0.71 iburst maxpoll 5 prefer # RasPi-1, LAN

# Use UK & NL pool NTP servers
pool uk.pool.ntp.org minpoll 6 maxpoll 7
pool nl.pool.ntp.org minpoll 6 maxpoll 7

# Suggestions for NTP restrictions (accepting ntpq commands):
restrict source notrap nomodify nopeer
restrict 127.0.0.1
restrict ::1
restrict 192.168.0.0 mask 255.255.255.0

 

 

 

Corrections welcomed!

 

 


 

 
Copyright © David Taylor, Edinburgh   Last modified: 2025 Apr 20 at 08:51