RV 3028 rtc Makerverse arduino module

Hi theres so I have had a test for this module using a library from GitHub, on the Arduino uno, and this is just using an example: the code is attached below, however the problem is that that 1 second from the module is about 7-8 real seconds, when I was comparing it to stop watch in internet online timers, each second of this module takes 7-8 seconds in reality, are there any fixes for these? I have tried powering from both 5v and 3.3v from the Arduino. The Sda and Scl pins on the the module are connected to sda and scl pins on the Arduino, and gnd to gnd,. Thanks and Regards Divyansh.

Setting alarm interrupts at RV-3028-C7 Real Time Clock

By: Constantin Koch

Date: 7/31/2019

License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

Feel like supporting my work? Give me a star!

[https://github.com/constiko/RV-3028_C7-Arduino_Library](https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fconstiko%2FRV-3028_C7-Arduino_Library&data=05%7C01%7C%7C666be719d38d491cbdf908daf52a7d22%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638091860088171616%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mv%2F98UgoSUmOUQzVKAsjehsVbK81e9T2ZNpGG1bXsHQ%3D&reserved=0)

This example shows how to set alarm interrupts at RV-3028-C7 Real Time Clock.

Open the serial monitor at 115200 baud

*/

#include <RV-3028-C7.h>

RV3028 rtc;

//The below variables control what the date will be set to

int sec = 45;

int minute = 59;

int hour = 19;

int day = 5;

int date = 2;

int month = 8;

int year = 2019;

//The below variables control what the alarm will be set to

int alm_minute = 0;

int alm_hour = 20;

int alm_date_or_weekday = 2;

bool alm_isweekday = false;

uint8_t alm_mode = 0;

/*********************************

Set the alarm mode in the following way:

0: When minutes, hours and weekday/date match (once per weekday/date)

1: When hours and weekday/date match (once per weekday/date)

2: When minutes and weekday/date match (once per hour per weekday/date)

3: When weekday/date match (once per weekday/date)

4: When hours and minutes match (once per day)

5: When hours match (once per day)

6: When minutes match (once per hour)

7: All disabled – Default value

If you want to set a weekday alarm (alm_isweekday = true), set 'alm_date_or_weekday' from 0 (Sunday) to 6 (Saturday)

********************************/

void setup() {

Serial.begin(115200);

while (!Serial);

Serial.println("Read/Write Time - RTC Example");

Wire.begin();

if (rtc.begin() == false) {

Serial.println("Something went wrong, check wiring");

while (1);

}

else

Serial.println("RTC online!");

delay(1000);

//Enable alarm interrupt

rtc.enableAlarmInterrupt(alm_minute, alm_hour, alm_date_or_weekday, alm_isweekday, alm_mode);

//rtc.disableAlarmInterrupt(); //Only disables the interrupt (not the alarm flag)

}

void loop() {

//PRINT TIME

if (rtc.updateTime() == false) //Updates the time variables from RTC

{

Serial.print("RTC failed to update");

} else {

String currentTime = rtc.stringTimeStamp();

Serial.println(currentTime + " \'s\' = set time");

}

//Read Alarm Flag

if (rtc.readAlarmInterruptFlag()) {

Serial.println("ALARM!!!!");

rtc.clearAlarmInterruptFlag();

delay(3000);

}

//SET TIME???

if (Serial.available()) {

switch (Serial.read()) {

case 's':

//Use the time from the Arduino compiler (build time) to set the RTC

//Keep in mind that Arduino does not get the new compiler time every time it compiles. to ensure the proper time is loaded, open up a fresh version of the IDE and load the sketch.

/*if (rtc.setToCompilerTime() == false) {

Serial.println("Something went wrong setting the time");

}*/

if (rtc.setTime(sec, minute, hour, day, date, month, year) == false) {

Serial.println("Something went wrong setting the time");

}

break;

}

}

}

2 Likes

Tried to duplicate the 7 to 8 second error you are seeing, could not.
Connected Makerverse RV 3028 RTC to Arduino UNO.

Installed the Arduino Library by By: Constantin Koch.
Ran the example sketch “Setting alarm interrupts at RV-3028-C7 Real Time Clock”; which is the same as you listed.

Time ticks over every second as it should.
Unsure why you are seeing a difference of 7 to 8 seconds.

Regards
Jim

1 Like

Hi james thank you for trying to help me, so i ran the basic set time example from the library,(vcc to 3.3v, gnd to gnd,sda to sda,scl to scl) and the module 1second =real time 1 second, but in example for the alarm interrupt is when its taking about 8-10 seconds of real time for the module’s 1 second, the serial monitor is printing the same time for over 8-10 seconds and then moves froward by 1 second, however this problem is only happening with example 4. do you have any clue what might be happening?

Hi,

void Loop() of Example4-Alarm_Interrupt runs as fast as the Arduino micro can.
It produced 318 prints of the same second for me. This is not necessary and wastes processing time.
The code below is modified to print only when the second changes.
The output shows the alarm triggering and the 3 second delay of the trigger statement and then prints seconds again.

With this more reasonable display I then compared the seconds ticks with my PC time with the RTC by using the Show timestamp of the serial monitor. It clearly shows the RTC is losing time.

15:44:01.006 -> 2023-01-00  15:40:00     's' = set time
...
15:47:01.015 -> 2023-01-00  15:42:27     's' = set time

Elapsed Real Time = 3 min
Elapsed RTC Time = 2 min 27 secs

This is very bad.
I know the RTC module keeps reasonably accurate time because I have used it with a Pi Pico and Python drivers. The only thing left is the RTC driver RV-3028-C7.h. (or the RTC module may have become damaged)

At this time digging into how the driver works would be time consuming. The data sheet for the RTC chip should also be be checked to determine what parameters it should be programmed with.

So I’d look into the driver or maybe use a different one. There were two I found in the libraries for the Arduino IDE. Yet to test the second one. Understanding what the RTC chip requires will take some time.

Regards
Jim

/*
  Setting alarm interrupts at RV-3028-C7 Real Time Clock
  By: Constantin Koch
  Date: 7/31/2019
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  Feel like supporting my work? Give me a star!
  https://github.com/constiko/RV-3028_C7-Arduino_Library

  This example shows how to set alarm interrupts at RV-3028-C7 Real Time Clock.
  Open the serial monitor at 115200 baud
*/

#include <RV-3028-C7.h>

RV3028 rtc;

//The below variables control what the date will be set to
int sec = 45;
int minute = 59;
int hour = 19;
int day = 5;
int date = 2;
int month = 8;
int year = 2019;

//The below variables control what the alarm will be set to
int alm_minute = 0;
int alm_hour = 20;
int alm_date_or_weekday = 2;
bool alm_isweekday = false;
uint8_t alm_mode = 0;
/*********************************
  Set the alarm mode in the following way:
  0: When minutes, hours and weekday/date match (once per weekday/date)
  1: When hours and weekday/date match (once per weekday/date)
  2: When minutes and weekday/date match (once per hour per weekday/date)
  3: When weekday/date match (once per weekday/date)
  4: When hours and minutes match (once per day)
  5: When hours match (once per day)
  6: When minutes match (once per hour)
  7: All disabled – Default value
  If you want to set a weekday alarm (alm_isweekday = true), set 'alm_date_or_weekday' from 0 (Sunday) to 6 (Saturday)
********************************/

String previousTime = "";                                           // ADD
String currentTime = "";                                            // ADD

void setup() {

  Serial.begin(115200);
  while (!Serial);
  Serial.println("Read/Write Time - RTC Example");

  Wire.begin();
  if (rtc.begin() == false) {
    Serial.println("Something went wrong, check wiring");
    while (1);
  }
  else
    Serial.println("RTC online!");
  delay(1000);

  //Enable alarm interrupt
  rtc.enableAlarmInterrupt(alm_minute, alm_hour, alm_date_or_weekday, alm_isweekday, alm_mode);
  //rtc.disableAlarmInterrupt();  //Only disables the interrupt (not the alarm flag)

  previousTime = rtc.stringTimeStamp();                             // ADD
  currentTime = rtc.stringTimeStamp();                              // ADD

}

void loop() {

  //PRINT TIME
  if (rtc.updateTime() == false) //Updates the time variables from RTC
  {
    Serial.print("RTC failed to update");
  } else {
    currentTime = rtc.stringTimeStamp();                            // CHANGE - remove 'String'
    if (currentTime != previousTime)                                // ADD
    {
      Serial.println(currentTime + "     \'s\' = set time");        // ADD
      previousTime = currentTime;                                   // ADD
    }
  }
  
  //Read Alarm Flag
  if (rtc.readAlarmInterruptFlag()) {
    Serial.println("ALARM!!!!");
    rtc.clearAlarmInterruptFlag();
    delay(3000);
  }

  //SET TIME???
  if (Serial.available()) {
    switch (Serial.read()) {
      case 's':
        //Use the time from the Arduino compiler (build time) to set the RTC
        //Keep in mind that Arduino does not get the new compiler time every time it compiles. to ensure the proper time is loaded, open up a fresh version of the IDE and load the sketch.
        /*if (rtc.setToCompilerTime() == false) {
          Serial.println("Something went wrong setting the time");
          }*/
        if (rtc.setTime(sec, minute, hour, day, date, month, year) == false) {
          Serial.println("Something went wrong setting the time");
        }
        break;
    }
  }
}
2019-08-02 19:59:53 's' = set time
2019-08-02 19:59:54 's' = set time
2019-08-02 19:59:55 's' = set time
2019-08-02 19:59:56 's' = set time
2019-08-02 19:59:57 's' = set time
2019-08-02 19:59:58 's' = set time
2019-08-02 19:59:59 's' = set time
ALARM!!!!
2019-08-02 20:00:03 's' = set time
2019-08-02 20:00:04 's' = set time
2019-08-02 20:00:05 's' = set time
2019-08-02 20:00:06 's' = set time
2019-08-02 20:00:07 's' = set time
2019-08-02 20:00:08 's' = set time
2019-08-02 20:00:09 's' = set time
1 Like

Further investigation.
Post on Pimoroni forum stated:-

Having taken another look at the RV-3028 app manual there’s some mention of the UNIX Time counter increment being inhibited during I2C write access, and during read access there’s mention of “memorized” clock ticks during long reads. I guess this might imply a possibility of lost ticks.

The Example4-Alarm_Interrupt program reads the RTC every time through the loop which has no delay so it does a heap of reads every second.

These 3 statements read the RTC every time through the loop.

if (rtc.updateTime() == false) //Updates the time variables from RTC
String currentTime = rtc.stringTimeStamp();
if (rtc.readAlarmInterruptFlag()) {

Possibly this is the problem for loss of time.
In my Pi Pico Python program the RTC is only read to display the date time when that screen is selected. Alarm is not used in the program. If it was needed it should be through the output interrupt of the MakerVerse RTC not through continual reads of the RTC.

The datasheet gives a high specification for accuracy of the 32768KHz crystal. (plus minus 5 ppm)

Anyway, hope you get it working as you want.

Regards
Jim

1 Like

Further testing.

Added delay(1000); at the end of the void() loop so it only checks every second.
The RTC now keeps correct time with the PC time. (see output below)

Therefore the problem you are experiencing is because the RTC chip is being read too often.
I don’t know what your application is but if you keep reading to a minimum it should work ok.
At least only every second.

Cheers
Jim

13th second on PC corresponds to 00th second on RTC. Stable over 8 minutes.

Note: if the delay loop is set to 1000 (every second), the printout may not show every second.
Set it to 900 or so to ensure every second is displayed.

At the 4th minute you can see the PC is showing 14 and the RTC 00. You can also see the milliseconds for the PC display show an increasing amount. Therefore the RTC will eventually not match the PC time. There is an adjustment register in the RTC to allow for this. If you tested over a number of hours you could work out the value to change to make it more accurate.

06:34:13.343 -> 2023-01-01  06:00:00     's' = set time
...
06:35:13.565 -> 2023-01-01  06:01:00     's' = set time
...
06:36:13.746 -> 2023-01-01  06:02:00     's' = set time
06:36:13.746 -> ALARM!!!!
06:36:17.735 -> 2023-01-01  06:02:04     's' = set time
...
06:37:13.928 -> 2023-01-01  06:03:00     's' = set time
...
06:38:14.128 -> 2023-01-01  06:04:00     's' = set time
...
06:42:13.941 -> 2023-01-01  06:08:00     's' = set time
2 Likes

Hi Jim,

Seems like you may have narrowed in on the bug. It’s a little strange an example program for using interrupts would be polling the hardware continuously as that kind of defeats the point of an interrupt.

1 Like