Is there a Library available for using a Real Time Clock shield

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
Steve_Elves
Posts: 22
Joined: 07 Aug 2022 21:54

Is there a Library available for using a Real Time Clock shield

Post by Steve_Elves »

I'd like to use a RTC for accurate timestamping of pulses from a rain gauge that I am building. Has anyone come across a library that works with the ZUNO for this purpose?
The RTC I'm looking to use is a PCF8563.
User avatar
PoltoS
Posts: 7601
Joined: 26 Jan 2011 19:36

Re: Is there a Library available for using a Real Time Clock shield

Post by PoltoS »

It might be enough to use Clock command class and use internal timer. Clock has to be implemented in Z-Uno 2, but it is rather simple
Steve_Elves
Posts: 22
Joined: 07 Aug 2022 21:54

Re: Is there a Library available for using a Real Time Clock shield

Post by Steve_Elves »

Thanks for the reply and suggestion!

I would prefer to use a dedicated RTC module, because it will retain its settings and keep time even if there is a power interruption. I also believe that the RTC modules will be slightly more accurate, although for the purposes of this application, extreme accuracy is not required.
KGBEl
Posts: 37
Joined: 21 Feb 2023 00:37

Re: Is there a Library available for using a Real Time Clock shield

Post by KGBEl »

PoltoS, there is a library for DS3231 & DS3232 called ZUNO_DallasRTC.

Isn't it possible to use ZUNO_DallasRTC to work with Z-Uno V2?
If not, what has to be done to make it work with Z-Uno v2?
User avatar
PoltoS
Posts: 7601
Joined: 26 Jan 2011 19:36

Re: Is there a Library available for using a Real Time Clock shield

Post by PoltoS »

At the first glance it looks compatible. We will check it, but you can also try on your sidee
KGBEl
Posts: 37
Joined: 21 Feb 2023 00:37

Re: Is there a Library available for using a Real Time Clock shield

Post by KGBEl »

Thanks for answer.
I’m waiting for my rtc-order to arrive, after that that I’ll come back.
KGBEl
Posts: 37
Joined: 21 Feb 2023 00:37

Re: Is there a Library available for using a Real Time Clock shield

Post by KGBEl »

Hi, sorry for 3 month delay.

I bought and tried two DS3231 of different brands because there was this problem reading from RTC and
I first thought that there was something wrong with the first RTC.
I bought another but the problem remaines.

This is my program:

// ****************************************** TimeRTC_2_20240608131402 ***********************************************

#include <ZUNO_DS3232RTC.h>
#include <Time.h>

#define Serial Serial

// Arduino DS3232RTC Library
// https://github.com/JChristensen/DS3232RTC
//
// Example sketch illustrating Time library with Real Time Clock.
// This example is similar to the example provided with the Time Library.
// The #include statement has been changed to include the DS3232RTC library.

/*
******************** In ArduinoTypes.h *****************
struct tmElements_s {
byte Second;
byte Minute;
byte Hour;
byte Wday; // day of week, sunday is day 1
byte Day;
byte Month;
byte Year; // offset from 1970;
};
*/

DS3232RTC myRTC;

tmElements_t te, te_r;

time_t ts; // secs since 1900.

void setup()
{
Serial.begin(9600);

Serial.printf("\n\n****************************************** TimeRTC_2_20240608131402 ***********************************************\n\n");

te.Second = 30;
te.Minute = 32;
te.Hour = 13;
te.Wday = 6;
te.Day = 8;
te.Month = 6-1;
te.Year = 2024 -1900;


myRTC.write(&te);


}

void loop()
{

myRTC.read(&te_r);

disp();

delay(10000);

}

void disp(void){


Serial.printf("\n*************\n%04d-%02d-%02d %02d:%02d:%02d : Weekday = %d.\n", te_r.Year + 1900, te_r.Month + 1, te_r.Day, te_r.Hour, te_r.Minute, te_r.Second, te_r.Wday);

}

and this is the result.


****************************************** TimeRTC_2_20240608131402 ***********************************************


*************
2024-06-08 13:32:30 : Weekday = 6.

*************
2024-06-08 13:32:40 : Weekday = 6.

*************
2024-06-08 13:32:50 : Weekday = 6.

*************
2024-06-08 13:33:00 : Weekday = 6.

*************
2024-15-05 06:13:43 : Weekday = 0.

*************
2024-15-05 06:13:53 : Weekday = 0.

*************
2024-15-05 06:14:03 : Weekday = 0.

*************
1935-01-06 06:14:13 : Weekday = 4.


As you can see it works well until time changes at 13:33:00, after that the result is unpredictable
with month 15, weekday 0 and changes time to before world war 2.

This happens all the time, even if I change delay to one minute, 30 minutes or 1 hour, sooner or later the time reading is corrupt.

I have an Arduino Uno R3 too and when using the same RTC on Uno, with Uno:s library, it works very well
for weeks. As I see it never went wrong.

I don't know what to do, can you help?
Post Reply