Repository navigation
Description
I noticed that if the Due is programmed using this library, the date will only be correct if the unit is not powered down. If you program the time in by uncommenting out the rtc_clock.set lines to 'burn' the current time to the RTC, then commen them out to burn the rest of the program onto the chip, then upon restart of the unit the time reverts to 1/1/2007 0:0:0.
Expected behavior is rtc_clock.get should return the current time, regardless of how long the due has been powered down. My test code is below, and it's likely that I'm doing something wrong or not understanding something about the library!
include <SPI.h>
include <SD.h>
include <rtc_clock.h>
// Select the Slowclock source
RTC_clock rtc_clock(XTAL);
unsigned int currentTime = 0;
unsigned int prevTime = 0;
unsigned int prevSerialTime = 0;
/////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
//rtc_clock.init();
//rtc_clock.set_time(TIME);
//rtc_clock.set_date(DATE);
//Only run these once to setup the RTC clock (assuming the clock has a good battery)
}
/////////////////////////////////////////////////////////////////////////
void loop() {
currentTime = millis();
if (currentTime - prevSerialTime > 5000) {
prevSerialTime = currentTime;
String dataString = "";
dataString += rtc_clock.get_months();
dataString += "/";
dataString += rtc_clock.get_days();
dataString += "/";
dataString += rtc_clock.get_years();
dataString += " ";
dataString += rtc_clock.get_hours();
dataString += ":";
dataString += rtc_clock.get_minutes();
dataString += ":";
dataString += rtc_clock.get_seconds();
dataString += ",";
dataString += "data1";
dataString += ",";
dataString += "data2";
Serial.println(dataString);
}
}
Activity
MarkusLange commentedon Apr 21, 2015
Yes I know, there are 2 problems at this piont.
JamesSidell commentedon Apr 21, 2015
OK, I thought it was something I was doing wrong in the sketch! Thanks for putting this library together, and I'll look for changes in the future!
kapyaar commentedon Jun 19, 2015
If I do
rtc_clock.set_clock(0, 0);
then the year is printing as 2070 instead of 1970. I am using Arduino IDE 1.6.4.
MarkusLange commentedon Jun 20, 2015
Did you want to set an unixtime oder date and time from compiler?
Can you post the complete sketch?
kapyaar commentedon Jun 20, 2015
I want to set unitTime (0). When I start the code, it will check to sync
with time from the internet. If not reachable, I want to to set it as
unitTime 0, which should be the 1970 year, etc.
I doubt that it has something to do with SECONDS_FROM_1970_TO_2000
Bcz if I set the time 946684800, the year shows ok as 2000, but if I set it
as 946684799, the year shows as 2099 instead of 1999.
Avarachan
On Sat, Jun 20, 2015 at 1:08 PM, MarkusLange notifications@github.com
wrote:
MarkusLange commentedon Jun 20, 2015
Can I get the complete sketch
kapyaar commentedon Jun 20, 2015
I am playing with one of your example sketches
Due_RTC_Simple_Sample_oneline_time_and_date.ino
https://github.com/MarkusLange/Arduino-Due-RTC-Library/blob/master/examples/Due_RTC_Simple_Sample_oneline_time_and_date/Due_RTC_Simple_Sample_oneline_time_and_date.ino
My tests
void setup() {
Serial.begin(115200);
rtc_clock.init();
//rtc_clock.set_clock(DATE, TIME);
//rtc_clock.set_clock(0,0);
//rtc_clock.set_clock(946684799,0);
rtc_clock.set_clock(946684800,0);
}
Avarachan
On Sat, Jun 20, 2015 at 2:37 PM, MarkusLange notifications@github.com
wrote:
MarkusLange commentedon Jun 21, 2015
Ah I understand, yes you are right, I will rewrite it so that so that it works without the define SECONDS_FROM_1970_TO_2000 that it will count the ticks from the 1.01.1970 to the actuall date, so that every date from the start of the unixtime will shown correct.
MarkusLange commentedon Jun 22, 2015
New version up should work for you purpose
kapyaar commentedon Jun 23, 2015
Downloaded the new lib, and tested (same as my previous post). rtc_clock.set_clock(0,0) still prints 2070.
MarkusLange commentedon Jun 23, 2015
I will take a closer look at the end of the week, may I need to seperate there something with set_clock you can set ntp and unixtime looks like it doesn't work the way I want
colesnicov commentedon Jan 25, 2018
Bckup battery