From Brandon's Tinkerings
Jump to: navigation, search
(adjusted text/picture)
Line 36: Line 36:
* [ NavSpark GPS+GLONASS Module]
* [ NavSpark GPS+GLONASS Module]
* [ Maxim DS3231 i^2c TCXO RTC (Temperature Compensated Oscillator)]
* [ Maxim DS3231 i^2c TCXO RTC (Temperature Compensated Oscillator)]
== The Code ==
== The Code ==

Revision as of 18:44, 21 October 2014


Here are my notes for getting a NavSpark GPS+GLONASS module working with a Raspberry Pi (Model B) for Timing/NTP purposes. They have since come out with a specific timing module that would probably be better suited for this. But alas, it's not what I have right now :)

What is this all about?

For a long time now, I've wanted to setup a Stratum 1 time source. It allows better matching of logs for debugging, and allows a more accurate time source for local network devices.

This page goes over the module, getting it wired up to a Pi, then getting the Pi working with the module. I've also added a i^2c TCXO RTC (DS3231) for timekeeping while the unit does not have power. This was added as the Pi does not have an RTC built in, and it may take some time for the Pi to sync with peers and/or GPS to get time set.

This will give me a time source on my network that is extremely accurate for my needs.

I created a custom PCB for attaching the NavSpark module, DS3231, and associated parts to the Pi. This makes it nice and compact to put to the side to just run. Gives it a nice SAF. (Spouse Approval Factor)

What does this page assume?

  • You have a NavSpark (or similar) GPS Module that outputs RS232 NEMA GPS code, as well as a 1PPS (Pulse per second) output.
  • You have a Raspberry Pi (B or B+ preferred, since it has the wired network interface already on it)
  • You know how to wire/breadboard stuff to the Pi


  • Logic Level Converter - If your GPS module outputs 5v, as the Pi need 3v in. (Note: The NavSpark outputs 3v)
  • Solder
  • Soldering Iron
  • Materials in BOM below if using custom adapter board
  • Pi Case
  • Good, solid output, 5v USB Power Supply (a good quality power supply can make a big difference when used in timing situations)

My Testing Environment


The Code


Resources Used to Complete this


Random Notes (The building blocks)

set userpassword

set hostname - NTP1

Change GPU memory to 16M (not used for NTP, more memory available to the system)

Enable Kernel i2c

Disable Kernel/Shell over Serial

finish, reboot. login as pi sudo -s set root password

Update Pi

apt-get update apt-get distupgrade rpi-update


apt-get install pps-tools snmp libcap-dev i2c-tools

edit /boot/cmdline.txt, remove serial references (AMA0) (only needed if you don't select to turn off serial console above) edit /etc/inittab, remove serial console (only needed if you don't select to turn off serial console above)


Build Machine crossdev -S -v -t arm-unknown-linux-gnueabi

Recommend to compile kernel on another system -- export CCPREFIX=arm-unknown-linux-gnueabi-

get kernel source: git clone --depth 1 git:// pikern

grab default /proc/config.gz from Pi, uncompress and copy to pikern/.config

make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

modify kernelmake ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig

(Required!)General -> Default Hostname (NTP1)General -> Timers Subsystem -> Timer Tick Handling (Idle Dynticks System (Tickless Idle)) -> Periodic Timer Ticks (Constant rate, no dynticks) -- This is needed for NTP_PPSGeneral -> Timers Subsystem -> Deselect "Old Idle Dynticks Config"Boot Options -> Default Kernel Command -> Remove "console=ttyAMA0,115200"Device Drivers -> PPS Support (*)-> (*) PPS Client using GPIO-> (*) PPS Kernel Consumer Support (Will not show up if the timer subsystem options above are not set)Device Drivers -> Real Time Clock -> (*) Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSon RX-8025 (For RTC 3231 option below)

(Optional)Kernel Features -> memory split -> 2G/2GPreemption Model -> No forced preemption (Server)CPU Power Management -> CPU Frequency Scaling -> Default CPU Freq Governor -> Performance

Patch Kernel: - Note: Line numbers are different with newer kernel. Provide updated patch....

Custom PCB uses GPIO23


mkdir modtmp make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=./modtmp modules_install tar -cjf modules.tar.bz2 modtmp/ scp modules.tar.bz2 root@ntp1:~/ scp arch/arm/boot/Image root@

tar -xjf modules.tar.bz2 mv /lib/modules/<version> /lib/modules/<version>-orig mv modtmp/lib/modules/<version> /lib/modules cp -R modtmp/lib/firmware/* /lib/firmware

Grab latest NTP from:, for compile computer extract ./configure --prefix=/usr --enable-ATOM --enable-NMEA --enable-GPSD --enable-SHM --enable-WWV --with-ntpsnmpd --enable-ipv6 --enable-linuxcaps --enable-clockctl make now wait ~20minutes rm /var/lib/ntp/ntp.conf.dhcp if DHCP, static recommended

    1. Cross-compile NTP:
    2. mkdir tmpinstall##make -j2##make install
    3. tar -cjf ntp.tar.bz2 tmpinstall
    4. copy files out cp bin/ntpd bin/ntp-wait bin/ntptime /usr/sbin

create /etc/udev/rules/09-gps.rules file contents:

  1. Adds symlink from serial interface to /dev/gps0 for ntpd

KERNEL=="ttyAMA0", SYMLINK+="gps0"

Edit /etc/ntp.conf enable calibrate enable kernel

  1. GPS Module

server mode 82 minpoll 4 maxpoll 6 fudge time2 +0.1939

  1. PPS of GPS Module

server minpoll 4 fudge flag3 1

Add other servers/peers, set one as prefer (needed to get PPS lock, see

Tune the offset

    1. RTC

modules/i2c already enabled in kernel from above i2cdetect -y 1 - verify on 68 echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device set timezone - ln -s /usr/share/zoneinfo/America/New_York /etc/localtime edit /etc/default/hwclock HWCLOCKACCESS=YES HCTOSYS_DEVICE=rtc0

edit /etc/init.d/, line 64, comment out if statement for udev The RTC isn't handled by udev, so this check needs to be removed.

Add after unset TZ modprobe i2c-bcm2708 modprobe i2cdev modprobe rtc-ds1307 echo "ds3231 0x68" > /sys/class/i2c-adapter/i2c-1/new_device

  1. Static IP

Edit /etc/networking/interfaces iface eth0 inet static address netmask gateway


dpkg --purge fake-hwclock cd /etc/rcS.d update-rc.d enable

update-rc.d alsa-utils disable update-rc.d x11-common disable

    1. OLD

apt-get install gpsd gpsd-clients python-gps

edit /etc/defaults/gpsd start_daemon = true devices="/dev/ttyAMA0" flags -b -n stty -F /dev/ttyAMA0 115200 set base_baud before gpsd starts, scans faster.

service gpsd enable reboot, confirm with cgps -s

apt-get install libncurses5-dev bc

edit modules, include pps-gpio

Instead of gpsd - symlink /dev/ttyAMA0 to /dev/gps0, use mode 82 in ntp config, adds GPS_NEMA driver

Uninstall existing ntp, compile/install latest ntp