My old sketch was written for DS1307 which can give you unixtime and a great portion of my sketch used it. I have not found a way to get unixtime from the RTC on Due. Does anyone know how to do this?
If not, I will either re-write my sketch from scratch or just write a function to convert to unix time and use that.
I would rather be able to just get unixtime directly off the chip when i need it though. It actually makes certain calculations easier like if you wanted to track cycles that do not line up with months, days, weeks, etc... such as the lunar cycle. You just use modulus. To find out exactly what point you are during a cycle you simply :
current_cycle_position = now.unixtime() % total_cycle_length;
and you get what seconds you are at in any time period you want. It REALLY simplifies certain things.
I tried looking at the files buried in "C:...\arduino-1.5.2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include\component" named component_rtc.h and instance_rtc.h (in the \instance folder) but didn't see anything called or anything having to do with it unixtime. (but i admit i only quickly look at at it)
I was using #include "RTClib.h" from ladyada and everything was working great. After looking at the source code for that it seems that the DS1307 only gives you a timestamp from 2000 (which would also work just fine!) and to convert to unixtime they add the amount of seconds from 1970 to 2000.
uint32_t DateTime::unixtime(void) const {
uint32_t t;
uint16_t days = date2days(yOff, m, d);
t = time2long(days, hh, mm, ss);
t += SECONDS_FROM_1970_TO_2000; // seconds from 1970 to 2000
return t;
}
Now if i could only figure out how to do this with the sam3x rtc. I'm looking at the code for the rtc library for the due located here " https://github.com/MarkusLange/Arduino-Due-RTC-Library/blob/master/rtc_clock.cpp " and im having troubles figuring out how it works.
help please!
I do see this part :
uint32_t RTC_clock::current_time()
{
uint32_t dwTime;
/* Get current RTC time */
dwTime = RTC->RTC_TIMR ;
while ( dwTime != RTC->RTC_TIMR )
{
dwTime = RTC->RTC_TIMR ;
}
return (dwTime);
}
There is also this line in the ladyada lib that was super convenient!
RTC.adjust(DateTime(__DATE__, __TIME__));
putting that in the setup function would set the current time to the time the sketch was compiled. Very nice feature I want to figure out how to get to work on the due.
Actually been searching the entire time while typing this thread, but its time to eat dinner now, so i'm hitting the post button. Will update thread if/as i solve these problems, after dinner.