01-11-2018, 01:25
(31-10-2018, 19:46)engolling Wrote: Hi Werk,
do you really think that the reason for the misbehavior is, that the RTC is set wrong in association with the new version of AVR board?
Yes, the RTC was being set wrongly. I will try to explain what I think about it below.
(31-10-2018, 19:46)engolling Wrote: My assumption is, that somewhere is a hidden memory overflow somewhere in the sketch and the compiler optimizes differently when writing different code or having some changed code for the board functions.
Another point might be that I did not understand the problem
Usually a memory overflow problem will cause random error, and/or a software crash, in this case only a function was affected.
(31-10-2018, 19:46)engolling Wrote: Because in compiling with boards manager AVR Board 1.6.22 only the unixtime() function was faulty but the day(), month() and year() function were working properly. So I'm not convinced that this is the main reason. Moreover all functions were working fine with the example sketch provided by RTClib.
I think the culprit of this problem was myself and not the boards manager version. I was using a wrong method to adjust the RTC, which perhaps was work before, due to the forgiveness of the Arduino IDE compiler.
Adjusting the RTC clock using RTC.adjust(local), being the local variable a time_t variable is wrong. If you look at the RTClib, the function is expecting a DateTime object not a time_t var.
A DateTime is a full class with lots of methods to it, where time_t is just an unsigned long, used to store the number of seconds since the epoch (normally 01/01/1970)
The Arduino Time library returns a time_t to the now() function, but RTCLib (RTC.now() ) returns a DateTime object (and expect it at RTC.adjust(DateTime) .
I think this explains the problem.
The example sketch provided by RTClib works with both boards manager versions because it is well written. The argument passed to the rtc.adjust function is a DateTime object, not a time_t variable as I stupidly did.
Code:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
More and more the Arduino IDE is becoming less permissive regarding coding errors, which is good! It isn't the first time that an IDE upgrade broke the code, and surely it will not be the last. After all, this can be seen as an opportunity to learn a little more.
If you have found or will find any other cause for the issue that we are talking about, just tell me, I'm always open to be corrected and to correct things too.
One more time I would like to thank you for the help given during the last night, without it, most probably I still was fighting to find a solution.