Orange Pi Zero NTP Stratum 1 PPS GPS Server with Armbian OS.
by Kevin Schwartzel.  

This tutorial is for the Orange Pi Zero, but will probably work for other boards.
I will assume that you know what a GPS PPS disciplined NTP server is.  If you don't know, then please Google it.
 
We will use NTPsec instead of NTP or Chrony.
NTPsec is a more secure and lighter version of NTP and it works well without GPSD.  I would imagine that NTP would also work.

Chrony seems to be preferred by some users.  I tried to use it on the Orange Pi Zero, but it required GPSD to interface with the GPS module, and although it worked, GPSD was unstable, and would just stop communicating and would require a restart about once a day. I didn't know of a way to make Chrony work without GPSD, so I uninstalled it and used NTPsec instead.

Components:

1.       Orange Pi Zero Set4: Orange Pi Zero512MB+Protective White Case H2 Quad Core Open-source development board.  


2.       A 5V 3A power supply with the correct plug type for your country with a micro-usb connector


 

3.       A small NMEA capable GPS module with ttl serial port, built in antenna and PPS output that can run on 3.3V.  I managed to fit it inside the top of the Orange Pi case.
GPSPPS.jpg 


 

4.         A small heat-sink.   I cut up a larger one that I had lying around.  I used heat sink compound and a rubber band to hold mine on.

Heat Sink.jpg


 

5.       A MicroSD card 4GB or more at least class 10.


6.       A Windows, Linux or Mac computer with a MicroSD card port or a MicroSD card adapter.  Instructions are for Windows.

 

7.       USB to serial TTL adapter 3.3V (and 5V). 
Careful donít buy one with a PL2303HX chipset because even with a working driver mine was unstable on Windows 7, 8 and 10.   PL2303TA is okay.


8.       Software to install the OS image on the SD card.  Balena Etcher is available for Linux, Windows, Mac and more
https://www.balena.io/etcher/
Another simpler and easier Windows program also suitable for older versions of Windows,  Win32 disk imager.  I had no success with Win32 disk imager on Windows 10 (it is claimed to work).  It worked on XP, Windows 7 & 8.

 

9.       7Zip to unzip the Armbian OS image.

 

10.   Putty or another serial terminal program.  

 

11.   Putty or another SSH terminal program.  

 

12.   WinSCP file manager for sftp file transfer and manipulation.  I use this for file editing in the tutorial. You can if you wish use a Linux text editor instead.  

 

13.   Optional USB thumb drive Ė can be used as root drive with SD used for boot (via armbian Ėconfig) or can be used as root drive with boot from onboard SPI. (advanced).  This tutorial does not cover this.

 

14.   Optional software to configure the GPS module.   If using Windows and TOPGNSS GN-701 or any other u-blox based module then u-blox u-center. (you can use this to disable unneeded message types and leave only NMEA GPRMC).  U-blox instructions at the end of the tutorial.   

 

Instructions:

Download the Orange Pi Zero OS from https://www.armbian.com/orange-pi-zero/ 

Armbian Bionic mainline kernel 4.19.y for Orange Pi Zero (other versions should also work)

Use 7Zip to extract the .img file


 

Write the Armbian OS image to the MicroSD card. Use Etcher or Win32 Disk Imager.

Win 32 Disk Imager on old Windows XP

Etcher on Windows 10

 

Insert the MicroSD card into the Orange Pi Zero.

Connect the Ethernet cable from your switch to your Orange Pi Zero.  (if you donít use Ethernet you may possibly configure WiFi later).  This tutorial assumes that you are using Ethernet and that you have DHCP running to supply devices with IP addresses.  I have not used WiFi for this so I donít know if or how it will work.


 

Connect the USB to serial TTL adapter to the Orange Pi Zero:

The UART0 connector is three pins besides the network port.

RX to TX and TX to RX and GND to GND.  Do not connect VCC.

On my adapter (yours may be different. Check the manufacturerís instructions):

GND is black (connects closest to the edge of the board)

TX is green (connects to the middle connector)

RX is white (connects furthest from the edge of the board)



Note: Iíve soldered on some pins to connect the GPS.   Itís best to use pins and plugs to connect the GPS module to the Orange Pi Zero rather than soldering it, so that you can unplug it and connect to a PC if you want to change settings. (To connect to a PC. Plug the USB to serial TTL adapter into a USB port on your computer.   Load up drivers if necessary).

 

Fire up Putty and connect to the serial port of the USB to serial TTL adapter:
Baud rate is 115200.
On my computer the USB to serial TTL adapter is on COM6 (Yours is likely to be on another port).  Check in device manager to find which port.


Now when you power up the Orange Pi Zero, you will see debug info and you will be able to communicate with the Orange Pi Zero through Putty until you have configured the Orange Pi Zero, after which you can connect using Putty SSH via the network rather than the USB to serial TTL adapter.

Plug the power supply into the mains, and plug the micro-usb end into the Orange Pi Zero.
As the board boots, you will see debug info scrolling on Putty. 

Eventually the process will ask you to log in.
The user is root and the password is 1234.

You will now be asked to change the (root) password immediately.  There are complexity rules, so choose a password longer than 8 characters.

First you will be required to input the old password 1234, and then the new password twice.

The Orange Pi Zero session logo and information will display.

NOTE:  Record the IP address.  You will need it later to connect using SSH.

You will now be required to set up a sudo user.  Choose your preferred login name and enter any personal data that you want to (I leave most of this blank) and type your new users password twice.


After this point, you will be able to use SSH to connect to the Orange Pi Zero 
(assuming that your device obtained an IP address via DHCP).

Open a new putty session
and use SSH to connect via the network to the Orange Pi Zero at the IP address that you noted earlier.

If it works, you will get a security warning the first time you connect.  Click Yes then Log in to the new session.  

 

Use armbian-config to set up  GPS PPS and uart 

Note: If you are logged in as root, you can leave off sudo on all commands.

sudo armbian-config

Select System and click on OK

Click on hardware and click OK

 

Click on Edit Boot Environment   (you can also edit this file directly /boot/armbianEnv.txt)



Add two lines to tell the Orange Pi Zero to use PA7 for PPS and uart1 for GPS NMEA messages

overlays=uart1 pps-gpio

param_pps_pin=PA7


Use armbian-config to set up your host name if you want to change it from the default

This is fairly intuitive, so I' won't give instructions.  Google if you get stuck.
You can also set up a fixed IP if you want to.  (I just reserve the IP on my DHCP server). 

Then get your OS up to date:

sudo apt-get update

sudo apt-get upgrade

Once this is finished:

Remove the default NTP ( or you can use this instead of NTPsec if you want to)

sudo apt-get remove ntp

When NTP has been removed install NTPsec in itís place.

sudo apt-get install ntpsec

You can use vi or another editor to edit the /etc/ntp.conf file, but I prefer to use WinSCP to connect to the Orange Pi Zero and edit the files through it.

Winscp uses the same credentials and settings as putty.  (Log in as root to change protected files).

Navigate to /etc
Right click on ntp.conf and select edit.

Edit /etc/ntp.conf  

At the top of the servers section

between         # Specify one or more NTP servers.
and            
# Use servers from the NTP Pool Project

 

add these two lines:

server 127.127.20.1 mode 17 minpoll 4 iburst prefer true

fudge 127.127.20.1 flag1 1 flag2 0 flag3 0 refid oGPS

 

It should look something like this:

---------------------------------------------------------

# Specify one or more NTP servers.


server 127.127.20.1 mode 17 minpoll 4 iburst prefer true

fudge 127.127.20.1 flag1 1 flag2 0 flag3 0 refid oGPS

 

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board

# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for

# more information.

pool 0.ubuntu.pool.ntp.org iburst preempt

pool 1.ubuntu.pool.ntp.org iburst preempt

pool 2.ubuntu.pool.ntp.org iburst preempt

pool 3.ubuntu.pool.ntp.org iburst preempt

 

---------------------------------------------------------

Shut down the Orange Pi Zero 

sudo shutdown 0

Note: Wait for the LED to extinguish before unplugging the power.

Connect the GPS as follows:

I used plugs and pins, (but strait soldering is also okay).

Connect the GPS module to UART1 and PPS to PA-07

 GPS      Orange Pi Zero

-----------------------------

   TXD   UART1_RX  PIN10

   RXD   UART1_TX  PIN8

   PPS   PA-07      PIN12

   VCC   3.3V        PIN1  (careful this is not 5V)

 

A diagram of the pinouts from oshlab.com

https://oshlab.com/orange-pi-zero-pinout/

 

 

Log in to a new putty session (takes about a minute to boot before SSH is available)

Test that the PPS config is correct:

dmesg | grep pps

Ensure that the GPS is pulsing then test the PPS as follows:

sudo apt-get install pps-tools

sudo ppstest /dev/pps0

Control C to exit.

Test the GPS NMEA messages as follows:

sudo apt-get install gpsd-clients  (this is huge. If you are low on space skip it or remove when done)

gpsmon /dev/ttyS1

The screen will blank then print a layout followed by NMEA strings


$GPRMC strings visible in the image.

Control C to exit

In order for NTPsec to recognise the GPS PPS combo we need to create some symlinks in /dev

sudo ln -sF /dev/ttyS1 /dev/gps1

sudo ln -sF /dev/pps0 /dev/gpspps1

Test NTP GPS PPS:

sudo service ntp restart

sudo ntpq Ėp

+NMEA(1) is our GPS.  

When NTP is happy with the PPS, the + will change to o.  If it changes to * and stays that way then PPS is not working but NMEA is working.


There is however a problem.  /dev is transient, it is regenerated at every reboot.

To ensure that our symlinks get regenerated every time, we need to:

Create a new file in /etc/udev/rules.d called 99-gps.rules with the following:

KERNEL=="pps0",SYMLINK+="gpspps1",GROUP="dialout", MODE="0660"

KERNEL=="ttyS1", SYMLINK+="gps1",GROUP="dialout", MODE="0660"

Use WinSCP to navigate to the directory right click on a blank spot, select  New, File

Save the file.

sudo udevadm control --reload-rules

sudo reboot  (you may need to reboot more than once, I donít know why).

Wait for reboot about a minute.

Open a new putty session:

ntpq Ėp

Success it works!

You can now connect to this NTP server and get really accurate time.

 Construction:

I used a few drops of hot glue to mount my GPS module in the top of the Orange Pi Case, well clear of the heat-sink.

The completed project. 
I flashed the boot loader onto the onboard SPI and the small silver thumb drive holds the OS, so there is no microSD card needed.


 

If you want to take it further and get a cleaner time stamp NMEA message:

Install the GPS software on windows and configure the module to only send the GPRMC message and configure the PPS for one pulse per second.  Use the USB to serial TTL adapter to connect your module.

Select the port and the baud rate (for u-blox usually 9600)

Select View, Messages view

Disable all messages except GPRMC

When this is complete the only data updated on the display will be the clock.

Configure the time pulse


Click send

Select CFG (Configuration)

Select save current configuration and click send.  

Disconnect the module.  If the module has a viable battery or non-volatile memory then it will remember these settings.