Skip to content

Instantly share code, notes, and snippets.

@pingud98
Created February 7, 2018 07:41
Show Gist options
  • Save pingud98/3c8b4742ffc6763fc5ce9c74800d57b8 to your computer and use it in GitHub Desktop.
Save pingud98/3c8b4742ffc6763fc5ce9c74800d57b8 to your computer and use it in GitHub Desktop.
arduino code from SEEED for precision i2c realtime clock with corrected calibration constant.
/****************************************************************************/
// Function: Set time and get the time from RTC chip(PCD85063TP) and display
// it on the serial monitor.
// Hardware: Grove - RTC v2.0
// Arduino IDE: Arduino-1.6.6
// Author: lambor
// Date: June 14,2016
// Version: v1.0
// by www.seeedstudio.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later verscion.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/****************************************************************************/
#include <Wire.h>
#include "PCF85063TP.h"
PCD85063TP xclock;//define a object of PCD85063TP class
void setup()
{
Serial.begin(9600);
xclock.begin();
xclock.stopClock();
xclock.fillByYMD(2018,2,7);//Jan 19,2013
xclock.fillByHMS(00,25,45);//15:28 30"
xclock.fillDayOfWeek(WED);//Saturday
xclock.setTime();//write time to the RTC chip
xclock.startClock();
xclock.setcalibration(1, 32768); // Setting offset by xclock frequency
uint8_t ret = xclock.calibratBySeconds(0, -0.000041);
Serial.print("offset value: ");
Serial.print("0x");
Serial.println(ret, HEX);
}
void loop()
{
printTime();
delay(1000);
}
/*Function: Display time on the serial monitor*/
void printTime()
{
xclock.getTime();
Serial.print(xclock.hour, DEC);
Serial.print(":");
Serial.print(xclock.minute, DEC);
Serial.print(":");
Serial.print(xclock.second, DEC);
Serial.print(" ");
Serial.print(xclock.month, DEC);
Serial.print("/");
Serial.print(xclock.dayOfMonth, DEC);
Serial.print("/");
Serial.print(xclock.year+2000, DEC);
Serial.print(" ");
Serial.print(xclock.dayOfMonth);
Serial.print("*");
switch (xclock.dayOfWeek)// Friendly printout the weekday
{
case MON:
Serial.print("MON");
break;
case TUE:
Serial.print("TUE");
break;
case WED:
Serial.print("WED");
break;
case THU:
Serial.print("THU");
break;
case FRI:
Serial.print("FRI");
break;
case SAT:
Serial.print("SAT");
break;
case SUN:
Serial.print("SUN");
break;
}
Serial.println(" ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment