Reeve GpsNtp-Pi Operating instructions

GpsNtp-Pi
~
Installation
and
Operation Guide
See last page for copyright and document information

See last page for copyright and document information, File: Reeve_GpsNtp-Pi_Setup.doc, Page
GpsNtp-Pi ~ Installation and Operation Guide
Table of Contents
1 Introduction 1
2 Hardware Assembly 2
3 Operating System Installation 6
4 Install a Secure Shell Terminal Program 10
5 Basic RPi Setup 12
6 Install and Verify Pulse Per Second ~ PPS 15
7 Install GPS Daemon and Associated Tools 17
8 Enable PPS/ATOM Support in NTP Daemon 20
9 Leap Seconds 24
10 Final Adjustments and Checks 25
11 Provisioning NTP Server Pool 27
13 References, Web Links and Further Reading 28
Document Information 29

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 1
GpsNtp-Pi Time Server Installation and Operation Guide
Whitham D. Reeve
1 Introduction
This document describes the installation and operation of the GpsNtp-Pi time server using the Raspberry Pi
computer platform, a GPS receiver and the Network Time Protocol (NTP). An accompanying document, GPS
Network Time Server on Raspberry Pi: GpsNtp-Pi {GpsNtp-Pi}, provides a general description. The system may
operate as a standalone time server or in conjunction with external time servers and is used to synchronize PC
real-time clocks to Coordinated Universal Time (figure 1).
AC Power
Adapter
Local Area
Network
Ethernet
Power
Internet
NTP Server using
Raspberry Pi
Model B+
Internet
Router
NTP
Client
5 V
Optional
WLAN
GNSS Receiver
PPSNMEA3.3 V
External
NTP
Servers
NTP
Client
NTP
Client
GNSS
Satellite
External
NTP
Servers
Figure 1 ~ Raspberry Pi time server block diagram. The Raspberry Pi platform with a GPS receiver on the left provides time
service to PCs both on the local area network and on a wide area network such as the internet. The system can be operated
with or without external time servers, but operation with external servers is recommended to improve system performance
and reliability. The only connections required between the RPi platform and the GPS receiver are power, ground, serial
transmit and receive and PPS.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 2
2 Hardware Assembly
This project was developed on an unmodified Raspberry Pi model B+. It most likely will work on the model B but
has not been tested. The RPi is operated “headless”; that is, it is used without a directly connected keyboard,
mouse or monitor. All provisioning is done from a PC running an SSH terminal program and connected to the
same LAN as the RPi. The hardware requirements and costs are shown in table 1.
Table 1 ~ Hardware Requirements and Costs
Description Adafruit HAB Supplies Notes
Base system Raspberry Pi B+, 35 USD Raspberry Pi B+, 35 USD Note 1
GPS receiver assembly Ultimate GPS Hat for Raspberry Pi
{GPSHat}, 45 USD
Raspberry Pi+ GPS Expansion
Board {GPSHAB}, 7 USD Note 1
Battery for GPS RAM CR122 , 2 USD CR2 32, 2 USD Note 3
Onboard antenna connector U.FL-M SMA-F
External active antenna Optional, 13 USD Required, 15 USD Note 4
Internal patch antenna Yes No
Flexible jumper cable Optional, 4 USD Not required Note 5
Soldering required Yes Yes Note 6
Mounting hardware required See hardware list See hardware list Note 2
RPi power supply 5 Vdc 5 W 5 Vdc 5 W Note 7
Table 1 notes:
1. Prices are as-of February 2 15 and do not include shipping. The HAB Supplies price includes an active antenna.
2. The Adafruit product does not include any hardware for rigidly mounting the GPS daughterboard to the RPi or for
mounting the RPi to a chassis. The HAB Supplies product includes only 2 of 4 spacers needed for the GPS board
and none for the chassis mounting. See Table 2..
3. Batteries are user supplied. The HAB Supplies GPS board is incorrectly marked CR2 23.
4. Each vendor has related antenna products that can be purchased with the receiver.
5. A flexible jumper is needed between the RPi board connector and an external antenna cable to reduce stress on
the connectors.
6. Soldering requirements are minor and described in more detail below.
7. The RPi uses a micro-USB connector for power but it cannot be powered from a PC USB port. Both GPS boards
require 3.3 Vdc, which is obtained from the RPi onboard power supply.
Table 2 ~ Hardware list
Item Qty Remarks
M2.5 x 11 mm stud spacer 4 Note 1
M2.5 x 6 mm stud spacer 4 Note 2
M2.5 hex nut 4
Flat washer, 2.5 mm 8
Lock washer, 2.5 mm 8
M2.5 x 4 mm flat head screw 4
Chassis, 1 x 7 x 1.6 mm 1 Aluminum
Rubber feet 4
Hardware List Table notes:
1. Qty can be reduced to 2 if the additional spacers exactly
match the length of the spacers supplied.
2. These spacers may be any convenient length to ensure
adequate spacing from the aluminum chassis.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 3
Preliminary assembly: Prior to attaching the GPS daughterboard to the RPi board:
Do not insert the battery until instructed
Adafruit GPS board: Solder the 2 x2 connector to the bottom of the PCB. Test fit the connector and
when soldering, make sure the connector is flush to the board
HAB Supplies GPS board: Plug the intermediate connector supplied with the board into the bottom of
the board; the connector is not soldered. It is necessary to remove a jumper so the battery may be used
to retain RAM data. The battery jumper is a blob of solder covering two small pads. It is circled in the
images below before (left) and after (right) removal with a soldering iron and solder wick. Note the
incorrect silkscreen text below the battery holder; it should read CR2 32
Final platform assembly: Attach the GPS daughterboard to the RPi using M2.5 hardware and 11 mm threaded
stud standoffs between the two boards. Use M2.5 hardware and 6 mm threaded stud standoffs to mount the
RPi board on an aluminum chassis. The assembly should be mounted in a metal enclosure as discussed later.
Battery: After board assembly, insert the battery into the holder on the GPS board. The battery is oriented with
the + terminal away from the board. Do not force the battery. It should easily snap or slide in.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 4
Antenna: An outdoor external antenna is recommended but initial setup and testing can be performed indoors.
For testing, the antenna should be placed on or near a window, preferably a south-facing window. If the Adafruit
Hat is used with its internal patch antenna, the RPi assembly should be placed near a window or on a windowsill.
The antenna must have a clear view of the sky. Generally, GPS performance is higher if it is installed to minimize
multipath interference caused by reflections from rooftops and walls. The internal patch antenna and external
antennas that may be purchased with the Adafruit and HAB Supplies GPS receivers are far from optimum for
timing applications because of their irregular gain patterns and nonexistent multipath suppression capabilities.
On the other hand, they are cheap and adequate for amateur radio astronomy applications.
The HAB Supplies antenna is shown in the image on
the left side and the optional Adafruit antenna is
shown right. Antenna dimensions are approximately
5 x 35 x 15 mm. Both antennas have a magnetic base
for mounting to a ferromagnetic surface but neither is
rated for outdoor service. Both are patch antennas
with small coaxial cables and SMA-M connectors.
Their manufacturers and specifications are not given
by the vendors.
If a different antenna is contemplated, the following guide may be used to select it:
Polarization: Right-hand circular
Mode: Active
Impedance: 5 ohm
Voltage: 3. to 3.6 Vdc (supplied by receiver)
Current: < 2 mA at 3.3 Vdc (the GTop receiver current limits the antenna bias-tee to 28 mA at 3.3 V)
Gain: 15 to 5 dBi
Noise figure: < 1.5 dB
Connecting an external antenna: If an external antenna is to be connected to the Adafruit GPS receiver board,
use a 15 ± mm long flexible jumper between the onboard U.FL-M connector and the SMA-M antenna cable
connector (a jumper is available from Adafruit). The flexible jumper is necessary so that no significant force is
placed on the onboard connector during operation. If the optional antenna from HAB Supplies is used with their
GPS board, there is no need for a flexible jumper (the supplied antenna has RG-174 coaxial cable, already quite
small and flexible).
Network: Connect a high-quality Cat5 network cable between the RPi LAN connector and a LAN switch or router.
The wired connection is used for provisioning. A WLAN connection can be installed later.
Power Supply: Before connecting a 5 V power supply, read this first: DO NOT attempt to power GpsNtp-Pi using
a USB port on a desktop or laptop PC or handheld device. Power measurements of GpsNtp-Pi on the RPi model
B+ showed < 1.5 W average dc load. However, when the RPi is booting and depending on connected peripherals,
the measured load current can be > 67 mA (3.4 W), too high for a PC USB port.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 5
The system should be powered by a well-regulated, low ripple, electrically quiet power source rated ≥ 1. A at
5. Vdc (≥ 5 W). Using a poor quality power supply will lead to unreliable operation so be sure it meets these
requirements. One of the most common problems users have with the RPi is inadequate power supply current.
To minimize electrical noise, it is recommended that ferrite beads be installed on the power cable (image
below).
AC wall power adapter rated 12 W at 5 Vdc with North American ac
input plug. One or more clamshell ferrite beads on the dc power lead
may help reduce radio frequency interference from the switch-mode
power supply. This image shows one bead on the right with three
windings of the power lead. The Raspberry Pi uses a micro-USB
connector for power. (Image © 2 14 W. Reeve)
Enclosure: If the GpsNtp-Pi is to be used in a sensitive RF environment, the circuit board assembly should be
installed in a metal enclosure. Some considerations are:
When inside an enclosure, the LED indicators on the RPi and GPS circuit boards will be hidden. One way
to handle this is to drill a small hole (~ 2 mm) in the enclosure above the GPS LEDs, so they will be visible
through the hole.
The 5 Vdc power input to the RPi is through a micro-USB connector, which will be inaccessible after the
boards are enclosed. Use a jumper from the RPi board to the rear panel where a power connector is
installed.
A small dc-dc converter may be installed in the enclosure to convert from, say, 12 Vdc input to 5 Vdc for
the RPi. This normally will require an input pi filter for the converter. As above, a jumper will be required
from the RPi board to the converter board. If a converter is used, it will be necessary to check its
specified maximum output filter capacitor size. The RPi board has a 22 μF power input filter capacitor,
so the converter will have to handle at least that much. In addition to the pi filter at the converter input,
MLCC capacitors rated 1 nF should be placed in parallel with the converter input and output.
The RPi circuit board will have to be positioned in the enclosure so the USB and Ethernet connectors are
accessible. A rectangular cutout in the front panel will allow the board to be installed flush with the
panel.
The antenna input on the GPS board will have to be extended to the front panel.
Below are pictures of the GpsNtp-Pi installed in a Box Enclosures B3-16 extruded aluminum enclosure and dc-
dc converter power supply. Enclosure dimensions are 16 long x 1 8 mm wide x 45 mm high. All holes in the
enclosure were cut using engineering drawings produced specifically for the enclosure. A 5 W dc-dc converter
was installed on a CPS-1 printed circuit board with filter components and PTC resettable fuse and polarity guard
diode. Power input at 12 Vdc is through a 2.1 x 5.5 mm coaxial dc power connector.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 6

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 7
3 Operating System Installation
The system uses the Raspbian distribution, which is a version of Linux. It is necessary to download and install the
distribution image and install it on a memory card in a format that is compatible with the RPi. It is not possible to
simply copy the distribution image from a Windows PC to a memory card; instead, a special image writer
program is needed. Suitable programs are Win32 Disk Imager {WDImg} and HDD Raw Copy Utility {HDDRaw}.
This guide is based on Win32 Disk Imager. Download and install the program, and place a shortcut to the
program on the Desktop. Mark the shortcut to run as Administrator.
Now, download the Raspbian distribution from {Raspbian} and extract it to the Desktop. Write this image to a 4
GB or larger micro-SD memory card as follows:
Connect a card reader/writer suitable for a micro-SD memory card to the PC. Insert
the SD or micro-SD memory card into the card reader/writer. Some older micro-SD
cards and card reader/writers are incompatible, so it may be necessary to install the
micro-SD card in a full-size SD card carrier or adapter and insert the carrier into the
reader. Now, determine the memory card’s drive letter from My Computer or
Explorer. Open Win32 Disk Imager.
A drive letter is shown in the Device field in upper-right of Win32 Disk Imager. If you have more than one device
plugged into the PC, select the letter corresponding to your memory card (drive letter E: in example above).
Click the folder icon to right of the Image File input field. Windows Explorer will open (below). Navigate to the
location where the Raspbian image is located and select the file. In the example below, the image file is located
on the Desktop but it has not yet been selected. Click Open.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 8
At this time you will be returned to the Win32 Disk Imager user interface. Click the Write button. After a
moment the Progress bar will show the Write operation, which requires several minutes. Be patient.
When the Write process finishes, a Success window will pop up.
Eject the memory card by right-clicking the drive letter in My Computer or Explorer and selecting Eject. Remove
the memory card from the reader/writer.
Memory card installation: Insert the micro-SD memory card into the slot connector on the
bottom of the RPi board. The side of the memory card with the contacts (see right) should face
the board. The connector is push-to-insert/push-to-release and is self-latching. The card cannot be inserted the
wrong way. Gently push the card all the way in and release finger pressure; the card should remain in the holder
and not spring out. To release, push again and the card will spring out.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 9
Power connection: Connect the 5 V power supply to the micro-USB connector on the RPi. Refer to table 2 and
watch the LEDs on the RPi board. If the red LED does not illuminate, there is a problem with the power supply. If
the green Activity LED turns on and stays on, the memory card may be corrupted.
Table 2 ~ RPi LED Indicators
Condition
Power off Power LED, Red: OFF Activity LED, Green: OFF
Power on, Boot Power LED, Red: ON Activity LED, Green: Flashes during boot
Power on, Ready Power LED, Red: ON Activity LED, Green: Occasional flash
Ethernet connector Left LED, Yellow:
ON 1 Mb/s, OFF 1 Mb/s
Right LED, Green:
ON link established, Flashes activity OFF if no link
The GPS receivers operate autonomously and will try to acquire satellites as soon as power is available from the
RPi board. Even if the RPi itself is not setup to use the GPS receiver outputs, the receivers will operate in a
normal way. The GPS receiver boards have one (Adafruit) or two (HAB Supplies) LED indicators. See table 3.
Table 3 ~ GPS Receiver LED Indicators
Receiver condition Adafruit ~ GTop Receiver HAB Supplies ~ uBlox Receiver
Power off Status LED, Red: OFF Power LED, Red: OFF
Timepulse LED, Green: OFF
Power on,
Acquiring satellites Status LED, Red: Flash 1 per second Power LED, Red: ON
Timepulse LED, Green: OFF
Power on,
Fix obtained, tracking Status LED, Red: Flash 1 per 15 seconds Power LED, Red: ON
Timepulse LED, Green: Flash 1 per second
All LED indicators on the RPi board except the red power LED will extinguish when the shutdown is complete,
requiring only a moment. The LEDs on the GPS receiver boards will not change. Power may then be removed
from the RPi board.
Provisioning: In the following sections, the RPi will be provisioned over a wired network connection using an SSH
terminal program. The network connection type can be changed later to a wireless connection as described in
{WLAN}. However, it is expected that the jitter performance will be much worse when the time server is
operated over a wireless connection. This caution would apply both when the GpsNtp-Pi uses a server pool for
synchronization and when an NTP client on a PC accesses the GpsNtp-Pi for synchronization.
Each software function in the RPi software has a “manual”, which can be accessed by typing at the prompt
man
followed by the function name. For example, to read the manual for the NTP daemon, type
man ntpd
and for
the GPS daemon, type
man gpsd
. These manuals will help you understand the changes specified.
This operating system and software is modified and provisioned as described in the following sections.
Text in Blue is typed at the RPi prompt
Text in Red indicates editing inside a configuration file
Backup your RPi software images after provisioning. See {BkRsRPi} for procedures.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 1
4 Install a Secure Shell Terminal Program
This guide is based on PuTTY {PuTTY}, which should be downloaded and installed now. Open PuTTY and enter
the RPi IP address into the Host Name or IP address field. Do not change the port (22) or Connection type (SSH).
You can determine the RPi’s IP address from your router LAN status screen or by using a program like Netscan
{Netscan}. Enter a name for the session (example, GpsNtp-Pi) in the Saved Sessions field. You also can customize
the user interface by clicking on the various entries in the Category window but you can do this later. Click the
Save button to save the session settings.
Upper-left: Screenshot of PuTTY configuration window with
the IP address for a test setup. Your installation will have
use a different address. Upper-right: Upon first connection,
PuTTY asks for authentication; click Yes. Lower-left: When
PuTTY is connected, the window changes to a simple
command line interface. After login, you can make changes
to the RPi as described in this guide. (Images © 2 14 W.
Reeve)
Click Open. After authentication you will see the RPi login prompt in the command line interface. Enter the
username and then the password. You will not see characters on the console as you enter the password.
Default username: pi
Default password: raspberry
After logging into RPi, you will see the prompt
pi@raspberry - $
At any time you can right-click the bar at the top of the PuTTY window to see the PuTTY menu. Click Change
Settings ... if you would like to revise the user interface and session settings.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 11
In the next section, you will change the default password. You will need the new password to log into RPi for all
setup and provisioning activities.
Note: If it becomes necessary to remove power from the RPi, the RPi must be properly shutdown before
removing power (just like a Windows PC). Never remove power without first shutting down the RPi. To
shutdown, log into RPi as described later using the SSH terminal. At the prompt enter:
sudo halt
or
sudo shutdown –h now
The next several sections install GPS and NTP software on the Raspberry Pi. This process requires approximately
2 hours, of which most time is absorbed by compiling operations.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 12
5 Basic RPi Setup
The basic setup includes changing the host name and password and updating the operating system software.
Log into the RPi using PuTTY. First, set the default keyboard layout. Using the nano editor, replace the
xkblayout=”gb” with xkblayout=”us”:
sudo nano /etc/default/keyboard
Type CTRL-X (Exit), Y (yes), Enter to save and close the editor.
Change host name: To change the host name to GpsNtp-Pi, edit the /etc/hosts file:
sudo nano /etc/hosts
Change the name associated with address 127. .1.1 (do not change 127. . .1), as in:
127.0.1.1 GpsNtp-Pi
Type CTRL-X (Exit), Y (yes), Enter to save and close the editor.
Similarly, replace the name in the /etc/hostname file:
sudo nano /etc/hostname
Change the name from raspberry to GpsNtp-Pi, as in
GpsNtp-Pi
Type CTRL-X (Exit), Y (yes), Enter to save and close the editor.
Change password: Log into the RPi using the defaults:
User: pi
Password: raspberry
At the prompt enter the following command:
passwd
RPi responds with:
Changing password for pi
(current) UNIX password:
Enter the current (default) password (the default Raspberry Pi password is “raspberry” without quotes). No
characters will be displayed. Enter the new password (the default GpsNtp-Pi password is “GpsNtp-Pi” without
quotes) and confirm it when RPi responds with:
Enter new UNIX password:
Retype new UNIX password:
After RPi accepts the new password you will see the following. The new password will take effect immediately:
passwd: password updated successfully

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 13
Enter the following command at the prompt. After a moment a window will appear with a list of settings. Use
the arrow keys to select the desired option, press Tab to Select and then Enter:
sudo raspi-config
Select Option 1. Expand filesystem
Select Option 4. Internationalization Options – Option 11. Change Locale – en_US.UTF-8 UTF-8. Use the
spacebar to deselect en_GB.UTF-8 UTF-8. Scroll down to en_US.UTF-8 UTF-8 and select it with the
spacebar. Scroll through the entire list to make sure only one Locale is selected
Select Option 4. Internationalization Options – Option 13. Change Keyboard Layout
Select Option 8. Advanced Options – A8 Enable or Disable Serial Shell – Accessible – No
Finish
Example screenshots are shown below.

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 14
After initial setup:
sudo reboot
Now it is necessary to update the software and operating system. These steps may require several minutes:
sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update
sudo reboot

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 15
6 Install and Verify Pulse Per Second ~ PPS
Install software to support PPS:
sudo apt-get install pps-tools
sudo apt-get install libcap-dev
Configure the RPi to use the general purpose input/output (GPIO) for the PPS input from the GPS receiver:
sudo nano /boot/config.txt
Add a new line as shown below. The value X = 4 or 18 depending on GPS board. The HAB GPS uses GPIO pin 18
and the Adafruit GPS uses GPIO pin 4.
dtoverlay=pps-gpio,gpiopin=X
The PuTTY window should look similar to this (this example shows the pin used with the Adafruit GPS board):
Type CTRL-X (Exit), Y (yes), Enter to save and close the editor.
Additional changes are required to use PPS
sudo nano /etc/modules
Add a new line
pps-gpio
The PuTTY window should look similar to this:

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 16
Type CTRL-X (Exit), Y (yes), Enter to save and close the editor, and then reboot:
sudo reboot
After reboot, log into the RPi and check that the module is loaded:
lsmod | grep pps
The output should be similar to:
pps_gpio 2529 1
pps_core 7943 2 pps_gpio
To determine if PPS is working, first ensure the GPS receiver is in the satellite tracking mode. This may require
up to 15 minutes from a cold start:
On the HAB Supplies GPS board, the green PPS LED flashes about 1 per second when tracking
On the Adafruit GPS, the red GPS status LED flashes once every 15 seconds when tracking
Next, enter:
dmesg | grep pps
Output should be similar to shown below, indicating that the PPS software module is loaded. Your window may
show only the first three lines. The third line indicates there is a new PPS source pps.-1:

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 17
Also, check:
sudo ppstest /dev/pps0
If the PPS software module is working, output should be similar to shown below with the source lines scrolling
1 line/s. Press CTRL-C to quit:

See last page for copyright and document info, File: Reeve_GpsNtp-Pi_Setup.doc, Page 18
7 Install GPS Daemon and Associated Tools
Install GPSD and GPSD-Clients:
sudo apt-get install gpsd gpsd-clients
After installation, configure GPSD:
Sudo dpkg-reconfigure gpsd
Follow the prompts to:
Start gpsd automatically: Yes
Automatically handle USB devices: No
Assign GPS device: /dev/ttyAMA (trailing zero not “O”)
Add option: -n
Assign GPSD control socket location: /var/run/gpsd.sock
Table of contents