LinkIt ONE RTC Example Code


When I was trying out all the different parts of the LinkIt, I wondered if there was an RTC onboard. Loovee told me there was, but that the example was not complete at this point in time.

I took this situation upon myself to make a complete example for anyone else out there who wants to use the LinkIt’s onboard RTC. In this discovery of things, I found that the RTC can be set back to 1/1/2004 if the battery and USB power supply are both disconnected. I made a loop in my code that will turn on the GPS to resync the GMT automatically in the background, the only thing that needs to happen is for the GPS to turn on. This is why in my more complex programs, I didn’t see the resetting behavior.

Here is a screenshot of what it looks like when the GPS has finally synced the time:

LDateTime working demo

And here is the code that runs the whole thing:

#include <LDateTime.h>
#include <LGPS.h>

datetimeInfo t;
unsigned int rtc;
int gps_on=0; //This is used to check if the GPS needs to be turned off

void setup() {

void loop() {
 Serial.print("Current GMT: ");
 Serial.print(" ");
 Serial.print(" Seconds since 1/1/1970 GMT: ");
 //Turning on the GPS syncs up the RTC with the GPS time.
 //If the battery is pulled, the RTC goes back a couple years.

 //Turning on the GPS syncs up the RTC with the GPS time.
 //If the GPS is needed, t.year will be 2004. This will start this loop.
 if ((gps_on != 1) && (t.year < 2010))
 Serial.println("Using GPS to sync GMT. Please wait...");
 gps_on = 1;

 //If the GPS has synced the RTC, the year will be 2015 or greater.
 if ((gps_on == 1) && (t.year >= 2015))
 Serial.println("Synced! Turning off GPS. Please wait...");
 gps_on = 0;
 //Wait one second before getting new time.

4 thoughts on “LinkIt ONE RTC Example Code

  1. Gilbs

    Hi, I tried your example but it seems my LinkIt One’s RTC won’t sync with the GPS even if its getting the right readings :(, do you have any insights on this?


  2. I haven’t tried it this yet but when the code cross posted from your personal blog to the Seeed Studio website it suffered badly. The libraries that are called did not post so there are two #includes at the top of the sketch not including anything.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s