Sam Hetchler
Published © GPL3+

LinkIt ONE RTC Example Code

I made a complete example for anyone else out there who wants to use the LinkIt’s onboard RTC.

IntermediateProtip1,220
LinkIt ONE RTC Example Code

Things used in this project

Story

Read more

Code

Code

C/C++
#include
#include

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

void setup() {
  Serial.begin(115200);
}

void loop() {
  LDateTime.getTime(&t);
  LDateTime.getRtc(&rtc);
  Serial.print("Current GMT: ");
  Serial.print(t.mon);
  Serial.print("/");
  Serial.print(t.day);
  Serial.print("/");
  Serial.print(t.year);
  Serial.print(" ");
  Serial.print(t.hour);
  Serial.print(":");
  Serial.print(t.min);
  Serial.print(":");
  Serial.print(t.sec);
  Serial.print(" Seconds since 1/1/1970 GMT: ");
  Serial.println(rtc);
  
  //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...");
    LGPS.powerOn();
    gps_on = 1;
  }

  //If the GPS has synced the RTC, the year will be 2015 or greater.
  if ((gps_on == 1) && (t.year >= 2015))
  {
    LGPS.powerOff();
    Serial.println("Synced! Turning off GPS. Please wait...");
    gps_on = 0;
  }

  //Wait one second before getting new time.
  delay(1000);
}

Credits

Sam Hetchler

Sam Hetchler

10 projects • 31 followers
I am a tinkerer, developer, and concept hacker. I find it fun to push the boundaries of what's possible.

Comments

Add projectSign up / Login