{"id":734,"date":"2016-10-26T15:47:53","date_gmt":"2016-10-26T15:47:53","guid":{"rendered":"http:\/\/blog.stmellion.org\/?p=734"},"modified":"2021-04-17T09:26:46","modified_gmt":"2021-04-17T09:26:46","slug":"raspberry-pi-gps","status":"publish","type":"post","link":"https:\/\/blog.stmellion.org\/?p=734","title":{"rendered":"Raspberry Pi &#8211; GPS"},"content":{"rendered":"<p>I recently wanted to set up a Stratum 1 time source using a Raspberry Pi (running Arch Linux).\u00a0 I bought the excellent <a href=\"https:\/\/www.adafruit.com\/product\/2324\">Adafruit Ultimate GPS Hat<\/a> and dutifully soldered on the connector.\u00a0 So far so good.\u00a0 Unfortunately, from that point on, I found lots of conflicting information.\u00a0 Not, I hasten to add, because the sources were wrong, but rather that evolving kernels and NTP versions rapidly obsolete instructions.\u00a0 Here is my version of requirements, as of October 2016.<\/p>\n<p>Remove console from ttyAMA0. \u00c2\u00a0The GPS wants this serial port for talking to the Pi.<br \/>\n\/boot\/cmdline.txt:<\/p>\n<pre>root=\/dev\/mmcblk0p2 rw rootwait console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 elevator=noop\n<\/pre>\n<p>Add Pulse Per Second modules to the kernel.<br \/>\n\/boot\/config.txt &#8211; Add new line:<\/p>\n<pre>dtoverlay=pps-gpio,gpiopin=4<\/pre>\n<p>Note: gpiopin=4 represents the pin number on the module that PPS is on.<br \/>\nLoad the PPS module on boot.<br \/>\n\/etc\/modules<\/p>\n<pre>pps-gpio<\/pre>\n<p>At this point, it&#8217;s useful to be able to test PPS is working. There&#8217;s an excellent tool for this <a href=\"https:\/\/www.vanheusden.com\/time\/rpi_gpio_ntp\/\">here<\/a>.\u00a0 Just run make and then run the tool from whatever directory you extracted it into. If all is well, you&#8217;ll see something like this:<\/p>\n<pre>root@ticktock:pps-tools# .\/ppstest \/dev\/pps0\ntrying PPS source \"\/dev\/pps0\"\nfound PPS source \"\/dev\/pps0\"\nok, found 1 source(s), now start fetching data...\nsource 0 - assert 1477494632.000003379, sequence: 1210414 - clear  0.000000000, sequence: 0\nsource 0 - assert 1477494633.000001527, sequence: 1210415 - clear  0.000000000, sequence: 0<\/pre>\n<p>Now install the gpsd package:<\/p>\n<pre>pacman -S gpsd<\/pre>\n<p>And configure it in \/etc\/gpsd:<\/p>\n<pre>START_DAEMON=\"true\"\nGPSD_OPTIONS=\"-n -D 2\"\nDEVICES=\"\/dev\/ttyAMA0\"\n#USBAUTO=\"true\"\n<\/pre>\n<p>At this point, everything is there and working. Unfortunately, the packaged version of NTP isn&#8217;t configured to use a PPS time source so it&#8217;s necessary to download and compile a local version:<\/p>\n<pre>.\/configure --enable-all-clocks --enable-parse-clocks --enable-SHM \\\n            --disable-debugging --without-ntpsnmpd --disable-local-libopts \\\n            --enable-ATOM\n<\/pre>\n<p>I&#8217;ve no idea if all these switches need to be enabled and I have no plans to perform a process of elimination. As of ntp-4.2.8, these work for me.<\/p>\n<p>Finally, configure NTP to use the GPS and PPS time sources:<\/p>\n<pre>server 127.127.28.0 prefer\nfudge 127.127.28.0 time1 +0.520 flag1 1 refid GPS stratum 1\nserver 127.127.22.0 minpoll 4 maxpoll 4\nfudge 127.127.22.0 time1 +0.0 flag2 0 refid PPS\n\n# Associate to Arch's NTP pool\nserver 0.arch.pool.ntp.org\nserver 1.arch.pool.ntp.org\nserver 2.arch.pool.ntp.org\nserver 3.arch.pool.ntp.org\n\nrestrict default kod limited nomodify nopeer noquery notrap\nrestrict 127.0.0.1\nrestrict ::1\n\n# Location of drift file\ndriftfile \/var\/lib\/ntp\/ntp.drift\n<\/pre>\n<p>This retains the default NTP pool which provides some sanity that the local clock is accurate. A query of the NTP should produce something like this:<\/p>\n<pre>root@ticktock:~# ntpq -pn\n     remote           refid      st t when poll reach   delay   offset  jitter\n==============================================================================\n*127.127.28.0    .GPS.            1 l   59   64  377    0.000   53.155  21.298\no127.127.22.0    .PPS.            0 l    9   16  377    0.000    0.002   0.004\n+46.36.198.130   185.53.93.157    3 u   33   64  377   30.713   -3.681   0.170\n+85.119.80.233   20.139.208.232   3 u   42   64  377   20.914   -3.539   0.348\n+2001:418:3ff::5 249.224.99.213   2 u   52   64  377   20.722   -3.742   0.090\n+176.58.109.199  241.76.5.73      2 u   63   64  377   21.381   -3.664   0.346\n<\/pre>\n<p>The GPS clock is pretty inaccurate, thanks to serial connectivity, but it doesn&#8217;t matter as the PPS provides very accurate pulses per second to provide the fine granularity. It&#8217;s only important that GPS is accurate to within 500ms to ensure NTP can ascertain which second the pulses relate to. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently wanted to set up a Stratum 1 time source using a Raspberry Pi (running Arch Linux).\u00a0 I bought the excellent Adafruit Ultimate GPS Hat and dutifully soldered on the connector.\u00a0 So far so good.\u00a0 Unfortunately, from that point on, I found lots of conflicting information.\u00a0 Not, I hasten to add, because the sources&hellip; <a class=\"more-link\" href=\"https:\/\/blog.stmellion.org\/?p=734\">Continue reading <span class=\"screen-reader-text\">Raspberry Pi &#8211; GPS<\/span><\/a><\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-734","post","type-post","status-publish","format-standard","hentry","category-pc-stuff","entry"],"_links":{"self":[{"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/posts\/734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=734"}],"version-history":[{"count":5,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/posts\/734\/revisions"}],"predecessor-version":[{"id":753,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=\/wp\/v2\/posts\/734\/revisions\/753"}],"wp:attachment":[{"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.stmellion.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}