Raspberry Pi and TheSkyX: GPSD and NTP setup

Raspberry Pi 3 Model B showing pinout

So I finally set some time aside to make this remote imaging computer called a Raspberry Pi (hereafter referred to as RPi) available for field use.  To say the process was laboring would be the understatement of the year!  It took me a solid day researching across a dozen or more websites, trial and error, excessive profanity, and alcohol to produce a reliable platform that could be used in the field with no network!  The downside to the RPi is the lack of a realtime clock.  Good news though, there is a nifty little GPS module that can be added…if you can make it work!

Adafruit Ultimate GPS breakout module ver 3, also showing pinout.

The goal: extremely portable remote imaging computer, with minimum power requirements to control all aspects of imaging including telescope mount control, focus control, and ccd imager.

Requirements for this guide: Raspberry Pi 3 model BAdafruit Ultimate GPS ver 3, wires to make connections to the RPi GPIO, a 32 GB microSD card, 2.5 A power supply for RPi, monitor with HDMI cable, USB keyboard (or I use a Logitech k830 with USB wireless adapter), accessible active network connected to the internet (can be wired or wireless…I was at home on my wi-fi network), and diligence.

Optional:  A computer set up next to you while configuring which will enable quick reference to the steps and websites (my trusty laptop was by my side the whole way), patience, full head of hair, alcoholic beverage of choice.

Warning: you will be working near exposed energized electrical circuits.  Proceed at your own risk!

Caution: interrupting power to the RPi prior to shut down may corrupt your Raspbian OS requiring re-image of microSD.

Caution: there are many things going on here.  Feel free to read through, study the reference websites, and learn something!  None of the reference websites put everything together like I have done, and some reference older information, or used different GPS devices.  If you are not semi-proficient in the syntax of Linux or Raspbian, or how to use the console, again, feel free to learn something.  Remember after all, the Raspberry Pi is designed to teach grade schoolers how to program.  How hard could it be?!

NOTE: Ensure the GPS module has either a clear LOS to the sky (mine was in a window), or external antenna while setting up!

First off, create your operating disk.  I downloaded the latest Raspbian Stretch with Desktop (the guide there will walk you through), and used Win32DiskImager to flash the microSD card (I also used SD Card Formatter to prepare the microSD card).  Once you have built your RPi, insert the microSD card.

Connect the RPi to the GPS module using this pinout (and reference pictures above):

RPi GPIO: Red to Pin 2 aka 5v, Black to Pin 6 aka GND, Yellow to Pin 8 aka GPIO14/TX, Green to Pin 10 aka GPIO15/RX, and Orange to Pin 7 aka GPIO4.

GPS Board: Red to Vin, Black to GND, Yellow to RX, Green to TX, Orange to PPS.

Finish connecting keyboard (or dongle), connect monitor, and then power cable.

Upon initial boot, there is a walkthrough that is very convenient for first time RPi users.  After initialization and restart, the RPi will look for a internet connection.  Either have connected an ethernet cable as an option in the above steps, or use the built in wi-fi adapter to connect wirelessly.  After connecting, the OS will perform updates.  This will take a few minutes based on your internet connection speed…have a drink!  Once this is done, hold on to your hat, ensure small children and those easily offended by profanity are not around, and let’s begin!

I recommend opening the following websites, and set the tabs up in your browser in the following order to use as reference:

Website A: Adafruit Ultimate GPS Hat

Website B: DesignSpark Add GPS to RPi Project

Website C: Unixwiz (aka epic heavy lifter!)

Website D: Frillip.com

Website E: SatSignal

This could not have happened without all the work the individuals who put together the above sites have done…thank you and dilly dilly!


Using Website A


Step 1: set RPi to release console pins.

type: sudo raspi-config

select interfacing options

select serial

select NO

select YES

select OK to reboot, then proceed to basic and serial test part of Website A

Step 2: verify GPS fix by watching red light blink.  Every second=no fix, every 15 seconds=good to go!

Step 3: serial test…verify response.

Step 4: install gpsd.


Using Website B


Step 5: type: sudo nano /boot/config.txt

verify: enable_uart=1, if not there, add it (it was already present for me)

add line: dtoverlay=pi3-miniuart-bt

Step 6: type: reboot

Step 7: check: ls -l /dev/ser*

Step 8: type cat /dev/ttyAMA0

NOTE: ctrl+c to end response

Step 9: type: sudo nano /etc/default/gpsd

edit line: USBAUTO=”false”

edit line: DEVICES=”/dev/ttyAMA0″

edit line: GPSD_OPTIONS=”-n”

Step 10: type: sudo service gpsd start

Step11: type gpsmon

NOTE: gpsmon should be reporting data, but the PPS offset will be blank in the GSA + PPS block for now, ctrl+c to stop

Step 12: type: sudo apt-get install pps-tools

Step 13: type: sudo nano /boot/config.txt

add line: dtoverlay=pps-gpio,gpiopin=4

Step 14: type: reboot

Step 15: type: sudo ppstest /dev/pps0

NOTE: ctrl+c to stop


Using Website C


Step 16: type: sudo nano /etc/default/gpsd

edit line: DEVICES=”/dev/ttyAMA0 /dev/pps0″

Step 17: type: reboot

Step 18: type: gpsmon

NOTE: the PPS offset should now be seen in the GSA + PPS block, ctrl+c to stop

My added steps not in website guides

Step 19: type: sudo apt-get update && sudo apt-get -y install ntp


Using Website D


Step 20: type: sudo nano /etc/modules

add line: pps-gpio

Step 21: type: reboot

Step 22: configure udev by typing: sudo nano /etc/udev/rules.d/10-pps.rules

add lines:

KERNEL==”ttyS0″, SYMLINK+=”gps0″
KERNEL==”pps0″, OWNER=”root”, GROUP=”tty”, MODE=”0660″, SYMLINK+=”gpspps0″

Step 23: enable source repositories by typing: sudo nano /etc/apt/sources.list

uncomment line containing deb-src

type: sudo apt-get update

type: sudo apt-get build-dep ntp


Website E and D


BIG STEP 24: Using a blend of Website E and D (with some tweaks) follow each line below to enable PPS support in NTPD (slightly modified steps)…takes time…get a drink!  This was a challenge as there is a lot going into the deeper steps.  YMMV!

wget http://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz
tar zxvf ntp-4.2.8p12.tar.gz
cd ntp-4.2.8p12
./configure –enable-linuxcaps –prefix=/usr
make -j5

sudo service ntp stop
sudo make install
sudo nano /etc/ntp.conf

add lines:

# GPS PPS reference

server 127.127.28.2 prefer

fudge 127.127.28.2 refid PPS

# get time from SHM from gpsd

server 127.127.28.0 mode 17 minpoll 4 maxpoll 4 iburst true prefer

fudge 127.127.28.0 flag1 1 refid GPS

Step 25: type: sudo nano /etc/apt/sources.list

comment out the line containing deb-src from Step 23

Step 26: Configure NTPD

type: sudo ln -s /lib/systemd/system/gpsd.service /etc/systemd/system/multi-user.target.wants/

type: reboot

Step 27: Moment of truth!  If all went well, and you typed everything exactly right, this thing should work.

Try typing: systemctl status gpsd

The system should report its running and active.  If not, try:

systemctl daemon-reload

systemctl enable gpsd

systemctl start gpsd

Other useful tools are:

systemctl restart ntp

ntpq -p


Further Testing and Verification

To really test if the RPi is getting time data from the GPS and NTP, disable the wi-fi, shutdown the RPi, wait ten minutes or so, power back up, and see what happens to the system time.  If it updates to the current time, you are good.  Otherwise, the auto startup of gpsd and ntp are not happening, and the settings will need to be verified.  Again, Website C: Unixwiz RPi GPS time was a tremendous help, and goes into great detail about what all the information being reported by the module means.

Looking at the gpsmon GSA + PPS window really gives a sense of how the data is coming in.  Initially the TOFF will be about .5 secs off, but PPS will be pretty on with system time.  As the NTP algorithm runs a few minutes, you will probably notice a flip-flop, with TOFF being less than .05 secs off.  You won’t be doing critical astro-physics with this, but not too bad for a $30 SBC and $30 GPS module!

Hope this helps!  Let me know by filling out the contact form below.  Part 2: Installing TheSkyX and configuring equipment!