View unanswered posts | View active topics It is currently Wed Aug 21, 2019 2:33 am

Reply to topic  [ 3 posts ] 
 Equip Fitlet With A GPS Time Source 
Author Message

Joined: Mon May 28, 2012 12:25 pm
Posts: 105
Post Equip Fitlet With A GPS Time Source

Typically, fitlet is connected to a network and, as a result, has access to standard network time sources. However, there may be fitlet applications where network connectivity and standard time sources are unavailable. For those cases, it is possible to provide fitlet with a time source that should be superior to the free running system clock. An inexpensive, USB connected GPS receiver can be utillized as a time source which will provide relatively decent accuracy.

Clock.gif [ 751 KiB | Viewed 2664 times ]

GPS Satellites as a Source of Accurate Time

The earth is enveloped in a baseline constellation of 24 GPS satellites. Each of these satellites carries an onboard complement of 4 atomic clocks which are either cesium or rubidium based. The typical GPS atomic clock has an accuracy on the order of 20 - 30 nanoseconds.

In addition to broadcasting position data, GPS satellites also broadcast accurate time data. It is this broadcast time data we can use as a time source for fitlet.

GPS Constellation
ConstellationGPS.gif [ 485.5 KiB | Viewed 2664 times ]


The hardware required for this application is:

1. fitlet
2. GPS Receiver - USB type (I am using GlobalSat BU-353)

The GPS unit receives highly accurate time broadcasts from GPS satellites and in turn provides this time information to Fitlet.

Hardware.jpg [ 40.75 KiB | Viewed 2641 times ]

About GPS Receiver Output Data

Most USB based GPS receivers have the ability to output serial data which adheres to the NMEA 0183 protocol. The output data consists of a repeating series of sentences. Each of those sentences is in comma delimited form and consists of a $"Header" followed by data. A general description of each sentence type is included in the following key.

NMEA 0183 Sentence Key
$GPBOD - Bearing, origin to destination
$GPBWC - Bearing and distance to waypoint, great circle
$GPGGA - Global Positioning System Fix Data
$GPGLL - Geographic position, latitude / longitude
$GPGSA - GPS DOP and active satellites
$GPGSV - GPS Satellites in view
$GPHDT - Heading, True
$GPR00 - List of waypoints in currently active route
$GPRMA - Recommended minimum specific Loran-C data
$GPRMB - Recommended minimum navigation info
$GPRMC - Recommended minimum specific GPS/Transit data
$GPRTE - Routes
$GPTRF - Transit Fix Data
$GPSTN - Multiple Data ID
$GPVBW - Dual Ground / Water Speed
$GPVTG - Track made good and ground speed
$GPWPL - Waypoint location
$GPXTE - Cross-track error, Measured
$GPZDA - Date & Time

In the sentences listed below, those beginning with $GPRMC contain the time and date data we are interested in. The sentences beginning with $GPGGA also contain time data. The time is shown using red letters and the date is shown with green letters.

Sample NMEA 0183 Output FROM GPS Receiver

About GPS Receiver Time Source Accuracy

The most accurate terrestrial GPS based time sources feature a Pulse Per Second (PPS) output. While it is likely possible to interface a PPS output to fitlet using fitlet's GPIO capability, this would require an extra bit of interfacing and programming. A simpler, non-PPS, USB based solution is featured in this application note. In initial tests of the non-PPS solution featured here, fitlet's clock is running less than 1 second different from the official time provided by WWV. Such accuracy should be adequate for all but the most demanding applications.

Sat Jan 30, 2016 10:44 pm

Joined: Mon May 28, 2012 12:25 pm
Posts: 105
Post Equip Fitlet With A GPS Time Source

The following software is required for the GPS Time Source application. It is all available in the Linux package repositories.

1. ntp
2. ntpdate
3. gpsd
4. gpsd-clients
5. python-gps

About GPSD

GPSD is a service dameon which monitors the GPS units connected to your system and makes the data they provide available to other applications. It is more or less an indispensable application for working with GPS systems in Linux.

Software and System Configuration

1. Connect gps to fitlet
2. Navigate to /dev directory and find GPS port (my case port = ttyUSB0)
3. Connect to GPS using a terminal program such as minicom. Look for NMEA
output from GPS - will resemble the following:


4. Configure gpsd using the terminal command sudo dpkg-reconfigure gpsd as follows:
...A. Start gpsd automatically? yes
...B. Handle gps receivers automatically? yes
...C.Device gps receiver is attached to: /dev/ttyUSB0 in my case
...D. Options to gpsd: -b --n
...E. gpsd control socket path: /var/run/gpsd.sock

5. Run cgps to confirm operation of gpsd. Pay special attention to the parameter Time Offset. It is typically less than 1. If it is a huge number, there is a problem.

cgps.png [ 100.31 KiB | Viewed 2654 times ]

6. Using an editor such as nano, edit the NTP configuration file /etc/ntp.conf as follows:

# gps ntp
server minpoll 4 maxpoll 4
fudge time1 0.183 refid NMEA

7. Execute the following commands as su:

...A. killall -9 gpsd ntpd
...B. ntpd -gN
...C. gpsd -b -n /dev/ttyUSB0
...D. cgps

8. If cgps returns active, normal output then querry ntp using the command ntpq -p
You should get a listing similar to:

ntpq -p.png
ntpq -p.png [ 50.07 KiB | Viewed 2654 times ]

The above screenshot shows all of the time sources available to fitlet at the time of the query. The line

SHM(0) .NMEA. 0 l 11 16 77 0.000 -7.112 4.471

indicates the GPS receiver is providing time data to the NTP dameon.

An Important Note

Shortly after bootup, Fitlet uses ntpdate to initially set the system clock. Thereafter, the ntp dameon keeps the clock synchronized to ntp servers including your GPS. Unfortunately, ntpdate will not accept time data from a gps - it only uses ntp servers. Therefore, if you operating where internet service is unavailable, you must manually set the clock to within 4 hours of actual time after bootup. After you initially set the linux system clock, the ntp dameon takes over and uses the GPS time to synchronize the system clock. Please note that if your initial time setting is 4 hours or more different from the actual time, the ntp dameon will not correct the linux system clock to GPS time. The initial setting must be less than 4 hours different form the actual time.

Sat Jan 30, 2016 11:28 pm

Joined: Mon May 28, 2012 12:25 pm
Posts: 105
Post Equip Fitlet With A GPS Time Source
Fitlet Not Connected To A Network

Without a GPS Time Source

The following screenshot shows the time sources available when fitlet is not connected to a network and is also not connected to a GPS receiver. Even thought the GPS source is listed, no data is available due to the absence of a GPS receiver- all values are 0. This means that fitlet's system clock runs free and is not corrected by an external source. Over time, the internal clock will drift.

ntpq -p no sources.png
ntpq -p no sources.png [ 45.04 KiB | Viewed 2652 times ]

With a GPS Time Source

The following screenshot shows the time sources available when fitlet is not connected to a network, but is connected to a GPS receiver. The single GPS time source is listed and is supplying data. In this case, fitlet's internal clock is corrected to GPS time on a repetitive basis. System clock drift is eliminated.

ntpq -p gps only.png
ntpq -p gps only.png [ 46.53 KiB | Viewed 2654 times ]


1. The results of using an inexpensive GPS receiver as an external time source for fitlet were good. In general, fitlet's system clock was maintained to within 1 second of the official U.S. time provided by WWV.

Time Comparison.png
Time Comparison.png [ 408.44 KiB | Viewed 2645 times ]


1. A simple GPS receiver can serve as an accurate and effective time source for those cases where fitlet must operate without a network connection or without access to other time sources.

2. Fitlet again demonstrates is adaptability and versatility.

Sun Jan 31, 2016 1:44 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.