I'm having trouble understanding the connection between Time.h and the GPS. I have a working GPS and RTC. Using the setSyncProvider(RTC.get) method of Time.h, it connects to the RTC and gets the time.
I don't know how to accomplish the same thing with TinyGPS. Looking through TinyGPS.h I don't see anything similar.
I'd really appreciate some help with this. Thanks!
MitchSF:
I'm having trouble understanding the connection between Time.h and the GPS. I have a working GPS and RTC.
Is it a very old-fashionded GPS module?
Modern GPS modules, even cheap ones like the Ublox Neo-6m, have an RTC module built into the GPS module. If the module is on a small PCB, most likely there is also some small rechargable backup battery on the PCB that is able to buffer the GPS-RTC for several days.
So one second after the module is powered on normally, you can have the actual RTC time in the $GPRMC NMEA sentence, even if the fixing tells 'V' like 'void' (invalid). But the time is valid RTC time, if your battery backup did not run out of power since you powered the system off.
So check the datasheet of your GPS chipset and the schematics of the actual GPS module, normally you don't need an extra RTC module: Just use the RTC built into the GPS chipset!
Thanks. I'm using a new Ultimate GPS from Adafruit. I didn't know that, but I already have a DS3231 chip on the board and it will not always be connected to the GPS, so it needs to switch when necessary.
MitchSF:
Thanks. I'm using a new Ultimate GPS from Adafruit. I didn't know that, but I already have a DS3231 chip on the board and it will not always be connected to the GPS, so it needs to switch when necessary.
The datasheet of the Ultimate GPS tells that this module also has an internal RTC, but the backup battery is missing on the module. So you could have an RTC with the Ultimate GPS if you add the backup battery. If you don't, then you have no RTC in your GPS and will have to wait until valid time is received by GPS.
So if the GPS is only "sometimes connected" and the DS3231 is "always connected" to your system, you most likely want a setup like that:
include the RTC and time libraries as if there was only the DS3231 providing real time in your system
then check for valid GPS time regularly
if GPS and DS3231 time differ for 2 seconds or more ==> use GPS time to adjust DS3231 time
That's what I want to do, checking the GPS periodically to update the time library. How often I'm not sure yet. The software is for a Nixie clock. There isn't much time between 1/10 second display updates and I don't yet know how long it takes to read NMEA strings at 9600 baud to get the correct one, and then to parse it using TinyGPS. I'll run some tests, but I'm not sure that it can be done in 100ms. We'll see. If not, there is a five second period while the date displays that will work. Thanks again for the advice.
MitchSF:
That's what I want to do, checking the GPS periodically to update the time library.
The libraries and RTC hardware you are planning to use work like that:
the time.h library keeps an internal time accurate from the Arduino 16 MHz frequency
from time to time the library synchronizes its time from the RTC time reading
If you now want to have the GPS as a secondary time source, then you would additionally:
from time to time synchronize the RTC time from the GPS time reading
That is no problem in general.
But in detail you want a timing display with a 0.1 second resolution, while your time.h library provides an one second time resolution only.
Due to differences in the 16 MHz frequency, this may lead to the following consequences after synchronizing the time between "library time" and "RTC time":
if the Arduino timing is slow, from time to time one second is skipped in the display
if the Arduino timing is fast, from time to time the same second is running twice in the display
You can estimate how often this may happen:
Arduino boards with a "ceramic resonator" like the modern R3 design boards might be off 4000 ppm, which is 4000 seconds in one million seconds. So every 1000000/4000= 250 seconds the time needs a one second adjustment against the RTC time.
Old Arduino boards with a "crystal oscillator" will be much more accurate in board timing, they might be off only 50 ppm, which is 50 seconds in ine million seconds. So every 1000000/50= 20000 seconds the Arduino timing needs to be adjusted by one second against the RTC. This is five and a half hours.
So when using the libraries you are planning to use with its timing functions, every 5 minutes or every 5 hours or so, one second either is skipped in the display or running twice in the display.
If that would be a problem if it occurs, you need a better synchronizing strategy than your time.h and RTC libraries provide by default.
Thanks again. I will consider that, but I'm not sure it's worth the effort to try to get beyond that issue. I've made progress to the point where GPS time data through TinyGPSPlus, is in the gps.* variables, but I don't seem to be able to set Time.h with GPS time. adjustTime(gpsoffset) does work, but only the RTC is setting the time in Time.h. The problem is with my understanding of structure and time variables, I think. I appreciate any help you can provide.