7 Replies Latest reply on Feb 4, 2013 3:35 PM by vk3pb

    Difficulties using NTP with a GPS + Raspberry Pi (HELP!)


      Hi all


      I have been asking around for help on other forums with this problem but noone has come up with a solution thus far. I hope that someone out there can help.


      I am trying to get my model B pi to work with a bu-353 GPS. I have achieved some success but I can't get ntp to automatically fetch the time on boot.


      I followed the instructions here




      but found that I needed to make a few modifications to get cgps working


      Here's what I did


      sudo apt-get install gpsd gpsd-clients python-gps


      I then ran


      sudo dpkg-reconfigure /etc/gpsd


      to set gpsd to automatically boot. I added -n in the options but didn't put in  /dev/ttyUSB0 as the port but rather left it to automatically find the USB plug.


      I then manually edited GPSD and added in


      chmod a+rw /dev/ttyUSB0


      The reason for these two tweaks is that the gps was not loading up properly and cgps -s just waited a few seconds and went back to the command line. The tweaks seem to have fixed that.


      Now if I start my pi and then put in the comamnd line


      cgps -s


      I can see what the gps is seeing, location information sats etc all in text format. If I run xgps I can see a graphical version of this. This works every time although can take a coupel of seconds to get a fix.


      So far so good.


      Per the web page I now proceed to try and set up ntp


      sudo apt-get install ntp

      Installation is probably unnecessary as ntp is already installed.


      Now I go to the /etc directory and sudo nano ntp.conf and add in the following lines


      # gps ntp
      server minpoll 4
      fudge time1 0.183 refid NMEA
      server minpoll 4 prefer
      fudge refid PPS


      and then type


      sudo service ntp restart


      Ntp restarts. cgps-s continues to work ok but my time does not update like it should. Although I can get a fix on satellites and can see the time in cgps it doesn;t get picked up by NTP like it should.


      How can I get NTP to load up the time from satellites at boot properly with the above setup? I would be grateful for some help as I am a beginner at Linux and I think a lot of people out there would like to know how to set up a cheap gps like this with the Pi.


      Thanking you



        • Re: Difficulties using NTP with a GPS + Raspberry Pi (HELP!)

          While most of what you've done looks ok-ish, you're really not going to want to use PPS with a USB device. The reason for this is that the PPS signal needs to be reasonably accurate otherwise ntp will mark it as a falseticker and ignore it as a time source. The original idea for PPS is that it comes in on DTR or another line on a real RS232 port, however your USB device isn't a 'real' anything, it's just emulating a serial port and USB has it's own latency issues making an emulated PPS signal not quite the same.. (forgetting for a moment that the RPi brings it's own usb issues)


          You may get better results by removing the two lines with and only use the NEMA stream although you can't expect much accuracy this way.


          Another reason it may appear not to work is that ntp will take some time to sync with a particular source, possibly many minutes. With only NEMA data it'll be trying to sync with the start of the message, if that's subject to jitter it could take a lot longer.


          Also ntp will usually refuse to sync with a timesource that's more than 1000 seconds different from the local clock, so it may never sync.  As the RPi has no RTC then it's likely to be very much more than 1000 seconds out on boot, so in a situation like that you need something to read the stream from the gps and set the clock reasonably close, ntp can then handle getting you a more accurate sync assuming it's possible with a usb device.


          There are other ways to do this, you can use a gps that has a real rs232 interface and wire up a PPS signal to a gpio pin. The kernel has a pps-gpio driver that's suitable, but this may require a fair bit of knowledge of how to compile a kernel with appropriate platform (or devicetree) data to identify the gpio being used for pps.


          It really depends on what your goal is. Do you just want to set a date and reasonably close time on boot ?  Or do you want what ntp and PPS is really designed for, a clock with (potentially) microsecond or better accuracy to be used as an ntp server for other systems on your network ?

          • Re: Difficulties using NTP with a GPS + Raspberry Pi (HELP!)



            My requirements are to set the time to within 1 second so I presume that I can dispense with PPS as you say.


            The reason for setting the clock is fro 2 different projects:


            1. A car security system with cameras mounted behind the number plates so that if anyone steals the number plates the Pi will detect this and start filming using the camera thus giving footage for later use by the Police. The footage would be time stamped.


            Similarly if the car is stolen the Pi could be remotely contacted using amateur radio and send back its coordinates using the GPS and APRS (automatic Positioning Reporting System) over radio.


            2. A self steering wave powered buoy for the high seas. It would be GPS enabled and send and receive transmissions via amateur radio. Certain specialist radio transmission modes require timing within 1 second (JT-65A).


            The software for both will be written in python which I am learning. It sounds like I can read the NEMA data using Python and somehow manually set the clcok in Python.


            cheers Peter

            • Re: Difficulties using NTP with a GPS + Raspberry Pi (HELP!)

              It's been a while since I wrote that original blog post & there have been some who have reported problems depending on what GPS unit they are using.


              One issue has been the existing examples available online on setting this up.


              Someone did say about PPS & USB. One person did say that with a minor mod on some units you can get PPS running - I've not had any spare time to investigate that but even then with USB it wouldn't be as accutate as a native serial port.


              I've come across gpstime recently as well after someone commented about it http://blog.retep.org/2012/06/18/getting-gps-to-work-on-a-raspberry-pi/#comment-988 again a lack of time recently has meant I've not tried it yet.



              • Re: Difficulties using NTP with a GPS + Raspberry Pi (HELP!)

                Perhaps you may find something useful in my own notes about getting NTP working:




                I see you mention PPS, but it's not clear how you are getting the PPS signal into your device.


                  • Re: Difficulties using NTP with a GPS + Raspberry Pi (HELP!)

                    Thanks all


                    I have seen all these pages.


                    The good news is that I can now set my system clock from my gps but I do so using a python module called gps-time I found.In due course I'll publish how I got it working.


                    In the meantime I'm working on getting my gps to pass variables to python for use in steering my boat. I tried to run Peter Mount's code on my Pi but ran into problems. I have just got a reply to my a post I put on the main Raspberry Pi forums and it appears that I have fallen into teh 'naming trap' whatevr that is and i just need to rename my code.


                    Once I have ironed out this all I'll put a post up on both forums explaining how I was able to get it all working so that others dont have as much difficulty.