Page 5 of 12


Posted: Sat Sep 01, 2012 1:32 am
by Paul Kennedy
I have figured out what the issue is with this device. It runs at a very slow baud of 4800. While that is not a problem in itself, the device appears to be hardwired to output various NMEA sentences. The first one it outputs is $GPGSA (the satellites in view).

Unfortunately, this sentence has a highly variable length. at 4800 baud, each char takes ~2millisecs to transmit, therefore when a new satellite comes or goes, the GPGSA string length will change, resulting in delays for RMC, GGA etc. Basically, if I cannot disable the unwanted strings, I might as well use this GPS as a doorstop.

Code: Select all

per epoch...
repeated on the next epoch...
See the commas in the string above - they get populated as satellites appear. :cry:


Posted: Thu Sep 06, 2012 4:11 pm
by aquarat
Hey Paul

Considering the price of the GPS a jitter of 5ms is fairly impressive :) .


Posted: Fri Sep 07, 2012 8:52 am
by Paul Kennedy
travelling this week, but I believe I can improve this. My goal is 1 millisecond. The GPS manufacturer kindly provided the instruction set to manage output sentences and baud rates. I will be able to test my theory next week. Will also seek out a static IP. If this all works, I will have a very cost effective solution in place for our operations.


Posted: Fri Sep 07, 2012 5:26 pm
by aquarat
Hey Paul

Revelation! The NMEA driver in ntpd reads the PPS too... so only one "server" line is required to get both NMEA and PPS data into ntpd.

Indeed ntpq -p now selects the NMEA source with an 'o' which indicates a PPS source.


Posted: Fri Sep 07, 2012 6:09 pm
by aquarat
And how about this :

Code: Select all

     remote           refid      st t when poll reach   delay   offset  jitter
oGPS_NMEA(0)     .GPS.            0 l    6    8  377    0.000    0.002   0.002
yay :D


Posted: Fri Sep 07, 2012 9:52 pm
by aquarat
The Raspberry Pi NMEA/PPS combination is proving to be more reliable than my x86/GPS-OCXO combination :
This graph is from The NTP Pool Project. I grabbed it at around 23:50 7th September 2012 GMT+2. I switched my NTP routing over to the Raspberry Pi at just after "18" on the graph on the right side. The result is far less jitter.


Posted: Sat Sep 08, 2012 3:37 pm
by aquarat
And a further update :
You can clearly see a very large improvement between the x86/GPS-OXCO combination and the Pi/GPS-PPS solution.

The x86 system read the PPS using the DCD line on the RS232 port.


Posted: Mon Sep 10, 2012 5:15 am
by peterwillcn
aquarat wrote:Pic : (hosted on a pi)
the gps module type ?


Posted: Mon Sep 10, 2012 7:34 am
by aquarat
peterwillcn wrote:
aquarat wrote:Pic : (hosted on a pi)
the gps module type ? plesae hardware wiring diagram, write a wizard, I also want to build a list in accordance with the practice as well as hardware.
I don't really understand what you're saying peterwillcn ? But I'll probably make a new thread with a guide on how I did it.


Posted: Mon Sep 10, 2012 7:55 am
by peterwillcn
hey aquarat
Thank you very much.


Posted: Mon Sep 10, 2012 8:15 am
by aquarat
Some hiccups, I don't know how to "elegantly" persistently link (ln) /dev/ttyAMA0 [target] to /dev/gps0 and ln /dev/pps0 to /dev/gpspps0.

At the moment I'm doing it with a cron job.


Posted: Mon Sep 10, 2012 8:31 am
by peterwillcn
aquarat wrote:Some hiccups, I don't know how to "elegantly" persistently link (ln) /dev/ttyAMA0 [target] to /dev/gps0 and ln /dev/pps0 to /dev/gpspps0.

At the moment I'm doing it with a cron job.
I hope the following reference can do for help you.

# /etc/udev/rules.d/09.oncore.rules
KERNEL==”ttyUSB[0-4]“, ATTRS{idVendor}==”067b”, ATTRS{idProduct}==”2303″, OWNER=”root”, GROUP=”dialout”, SYMLINK+=”oncore.serial.0″, MODE=”0666″
KERNEL==”pps0″, ATTR{name}==”pps_parport”, OWNER=”root”, GROUP=”root”, SYMLINK+=”oncore.pps.0″, MODE=”0660″

Fixme: But here udev often does not work (the plug the ttyUSB not appear oncore.serial.0) I sometimes direct ln-s then chmod solved.


Posted: Mon Sep 10, 2012 3:23 pm
by Paul Kennedy
Hi Aquarat,
Just got back from my work travels. I had another crack with this small dongle GPS (I received the manual form usglobalsat) and I managed to change bauds, remove superfluous sentences etc. So far the results are a significant improvement over my previous posts, but they are still at the millisecond level, whereas you have blown me away with your pps. very inspiring.

I am still awaiting a better quality GPS from the folks at Sure. My dongle does not appear to support pps.

Interesting the built-in NMEA is so good. I have had lots of comms with Dave Hart (the author of the NMEA driver under windows) and he steered me well away from it as runs in user-land, not kernel land. Therefore my burnign question is have you attempted to use this with regular raspian, or are you still using the custom kernel?

Looking fwd to getting my PPS/GPS.

Your plots look great. Well done.

btw, this is how I ensure the symbolic link form my USB to a serial device. I edited my /etc/init.d/ntp file with the following...

Code: Select all


# Provides:        ntp
# Required-Start:  $network $remote_fs $syslog
# Required-Stop:   $network $remote_fs $syslog
# Default-Start:   2 3 4 5
# Default-Stop:
# Short-Description: Start NTP daemon

#make the symbolic link before NTP starts so we can access the USB dongle GPS
if [ ! -e /dev/ttyUSB0 ]; then
    ln -s /dev/ttyUSB0 /dev/gps1
# end of hack from pkpk


Posted: Mon Sep 10, 2012 3:37 pm
by aquarat
Hey Paul

I'm currently using the custom kernel on the Raspbian distribution. I just connected an external GPS antenna to my Adafruit GPS receiver, so that might further improve the jitter (although I don't think ntpd can go below 0.002?) .

If it makes a difference I run ntpd as root.

The first time I tried running an ntpd server system I tried using a USB GPS Dongle. It tended to have very high jitter, your system seems to be fairing much better than that, well done :) .

Would you, by any chance, be willing to give me the code for your web interface? The graphs ? I promise I won't give it to anyone else if you wish and obviously I wouldn't remove your name from it. I'd love to have some stats on my server but I don't really have the motivation to go and work out how to do it :P (or rather it isn't a high enough priority at the moment).

On another note, this is my draft guide to re-creating this, so if peterwillcn would like to let me know if this works... that'd be great :

This is a short guide detailing how I got my Pi to act as a stratum 1 NTP server using an Adafruit GPS with PPS output. This same guide should work with almost any other TTL GPS with PPS output.

Firstly, buy a GPS with a TTL UART for NMEA and a PPS output on 3.3V : .
You might also want to buy a u.FL adaptor and GPS antenna.

Prepare a new Raspberry Pi with a Raspbian SD card installation.
Boot the Pi and prepare it to your liking (set up networking, ssh, etc.)
Download the following :
The above tar.gz files were provided by chrisrpt. They contain custom compiled modules and a kernel image which support PPS on one of the Pi's GPIO pins (GPIO23).

In a suitable directory, extract the contents of the kernel.tar.gz file and move the results into place :

Code: Select all

tar -xvf kernel.tar.gz
mv /boot/kernel.img /boot/kernel.img.old
mv Image /boot/kernel.img
Once again, extract the contents of the modules.tar.gz file :

Code: Select all

tar -xvf modules.tar.gz
mv lib /
Now you just need NTPd ;) .

Get the latest production source code of ntp : . At the time of this post's writing it was ntp-4.2.6p5 .

Extract this file : tar -xvf ntp-4.2.6p5.tar.gz
Change into the new directory : cd ntp-4.2.6p5
Configure : ./configure --enable-ATOM --enable-NMEA
Eventually : make
and finally : make install

You may be missing dependencies, if you are configure will tell you.

Edit the init.d script for ntp : nano /etc/init.d/ntp
and add hashes/lines so that you have the following lines :

Code: Select all

#if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
#       NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"

This prevents NTP from listening to your DHCP server, if you have one.
Change the "RUNASUSER" variable to "root".

Press Ctrl + X and press Y to exit and save.

Now remove any references to ttyAMA0 from your inittab :
nano /etc/inittab
Comment the following out so that it looks like this :

Code: Select all

#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Once again, Ctrl + X and then press Y to save.

nano /boot/cmdline.txt
Remove any arguments that reference "ttyAMA0" so that the conent of the file looks like this :

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Edit /etc/ntp.conf and add the configuration for your GPS as well as (optionally) another time source as a backup.
nano /etc/ntp.conf
Example ntp.conf file :

Code: Select all

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server mode 24 minpoll 3 iburst true prefer #use ZDA only!
fudge flag1 1 time2 0.350


restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict ::1
Mode 24 restricts ntp to using $GPZDA NMEA outputs only. Mode 24 also specifies the baud rate of the GPS at 9600bps, which is also the default of the Adafruit GPSs.

Finally, connect the following cables :

Code: Select all

GPS      PI
GND      GND (Pin 6          )
VIN      +5V (Pin 2          )
TX       RX  (Pin 10, GPIO 15)
RX       TX  (Pin 8 , GPIO 14)
PPS      PPS (Pin 16, GPIO 23)
Edit /etc/modules and add "pps-gpio" to the end of the file :
echo "pps-gpio" >> /etc/modules

Create a new file in /etc/udev/rules.d/09.pps.rules.
Populate this file with the following :

Code: Select all

KERNEL=="ttyAMA0", SYMLINK+="gps0"
KERNEL=="pps0", OWNER="root", GROUP="tty", MODE="0777", SYMLINK+="gpspps0"
Restart the Pi.


Posted: Mon Sep 10, 2012 8:58 pm
by bytecounter
aquarat, I can verify that what you posted works -- we are on the same track except for some minor differences. :mrgreen:

I was using Adafruit's modified Raspbian distribution to do this. I forked their kernel modifications and hacked on the gpio pps modifications which worked easily.. I will get around to making a neat tarball of the modules and kernel.img soon.

And just a quick note for anybody stuck with a v2: 1PPS output was there. I just soldered a small patch wire from the exposed pad after reading the datasheet (taking care to tape it down with something like polyimide tape).


Posted: Mon Sep 10, 2012 10:43 pm
by aquarat
Thanks bytecounter :)

I'm busy downloading the various tools/source to compile the kernel myself... but my objective is mdadm support :P .


Posted: Tue Sep 11, 2012 2:42 pm
by Paul Kennedy
I am busy tidying up some of my experimental code, and will provide it to yourself when I am happy with it. It has been running a couple of weeks without failure, but I have quite a few log files in place for monitoring purposes.
You will need a web server (I use nginx) php (I use php-fpm).



Posted: Tue Sep 11, 2012 2:43 pm
by peterwillcn
Thank you very much aquarat


Posted: Tue Sep 11, 2012 4:10 pm
by aquarat
Thanks Paul, there's no rush :) .

@ peterwillcn : I have a Motorola Oncore UT+, but as yet I haven't been able to get this working with ntpd. I haven't tried very hard. The GPS I'm using uses NMEA over ttyAMA0 whereas the Motorola GPSs use the Motorola Binary protocol... NTPd does support this but I have no idea how you'd try and configure it.

I don't remove the old ntpd before installing the new one. While this is probably very bad in principal, in practise the two packages are extremely similar and so apt-get remove ntp removes the result of "make install" quite nicely. In addition, leaving the old ntpd in place and just overwriting it retains all the default configuration and init.d scripts.


Posted: Sun Sep 16, 2012 1:53 am
by peterwillcn
:P wow...

Code: Select all

root@raspberrypi:/var/log/ntpstats# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
oGPS                       .GPS.            0 l   15   16  376    0.000   -0.435   0.041
+     3 u    5   64  377   90.431  -12.514  20.793       2 u    8   64  377  406.134    0.379  19.598
root@raspberrypi:/var/log/ntpstats# ntpdc -c peers
     remote           local      st poll reach  delay   offset    disp
=======================================================================      2   64  377 0.39742  0.003573 0.04735
=      3   64  377 0.08026 -0.006893 0.06621
*GPS                    0   16  377 0.00000 -0.000053 0.01524


Posted: Sun Sep 16, 2012 3:17 pm
by peterwillcn
i find ntp driver issues
3.1.9-pps+ kernel is not support HARDPPS Mode
ntpd source

Code: Select all

/* If HARDPPS is on, we tell kernel */

	if (instance->hardpps) {
		int	i;

		oncore_log(instance, LOG_INFO, "HARDPPS Set.");

		if (instance->assert)

		/* we know that 'i' is legal from above */

		if (time_pps_kcbind(instance->pps_h, PPS_KC_HARDPPS, i,
		    PPS_TSFMT_TSPEC) < 0) {
			oncore_log(instance, LOG_ERR, "time_pps_kcbind failed: %m");
			oncore_log(instance, LOG_ERR, "HARDPPS failed, abort...");
			return (0);
		pps_enable = 1;
} ... stallation


Posted: Mon Sep 17, 2012 12:03 am
by Paul Kennedy
Hi Peter,
your last post was rather confusing. I am not sure what you were attempting to state. My sure gps arrived on Saturday morning. The USB connectivity worked out of the box. I then wired up the serial RS232 and it also worked without trouble. I have contacted the manufacturers to see if I can enable the ZDA sentence, disable all other sentences, and increase the baud rate beyond 9600. I prefer to have a clean serial signal which contains exactly what I need rather than a hit and miss approach. The unit currently outputs several sentences, none of which provide the date.

I will then focus on the PPS. I need to sort out the correct wiring, and install the patched kernel. I intend to repeat the process of rebuilding the kernel so I fully understand the process Chris performed so well....


Posted: Mon Sep 17, 2012 3:02 pm
by Paul Kennedy
Had a bit of a win today. I have been waiting for my gps from sure for almost a month. One turned up on Saturday - at last. Guess what, another one turned up Monday. I guess it must have self replicated while on the long boat from China. I will ask them if they would like me to send it back. I have both working just fine in both serial and USB mode. Just prepping my macbook to compile raspi kernel from scratch...


Posted: Tue Sep 18, 2012 1:21 am
by peterwillcn
hi Paul Kennedy, your gps device models?


Posted: Tue Sep 18, 2012 2:33 am
by Paul Kennedy
my apologies. I am using the GPS from SureElectronics.

It is pretty easy to get up and running, but I am starting to find some limitations, specifically with the control of NMEA sentences. It looks like I cannot configure the sentences. All I need is ZDA, but I presently receive everything but ZDA.