Time and date resetting/changing on Makerverse RV3028 RTC

Hi, I’m having trouble with the Makerverse Real Time Clock (RTC) with Supercapacitor Backup RV-3028. The support threads here don’t really touch on this exact problem.

The date + time resets or goes backwards when disconnected from power source and using its backup power. It doesn’t seem to follow any pattern.
I’m using it with arduino.
The codes include <Wire.h> <RV-3028-C7.h>. from the library and CHatGPT code because I can’t write code. Why would the time reset or change? The documentation says it should retain power for up to a week.
Many thanks in advance.
2 codes are below. One for setting the time/date, and one for reading the current time/date.

SETTING TIME/DATE


#include <Wire.h>
#include <RV-3028-C7.h>

RV3028 rtc;
unsigned long previousMillis = 0;
const long interval = 60000;  // 1 minute interval

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

  if (!rtc.begin()) {
    Serial.println("RV-3028-C7 not detected. Please check wiring.");
    while (1);
  }

  // Set the time and date to 4:29:00 PM on Monday, 13th November 2024
   //rtc.setTime(0, 11, 17, 1, 25, 11, 2024);  // (seconds, minutes, hours, weekday, date, month, year)

  Serial.println("RV-3028-C7 RTC Initialized and Time Set");
}

void loop() {
  unsigned long currentMillis = millis();

  // Only read RTC time once every minute
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    rtc.updateTime();  // Update the time from the RTC module

    // Read current time
    int hours = rtc.getHours();
    int minutes = rtc.getMinutes();
    int seconds = rtc.getSeconds();

    // Read current date
    int day = rtc.getDate();  // Day of the month
    int month = rtc.getMonth();
    int year = rtc.getYear();

    // Print time and date to Serial Monitor
    Serial.print("Time: ");
    Serial.print(hours);
    Serial.print(":");
    if (minutes < 10) Serial.print("0"); // Add leading zero if needed
    Serial.print(minutes);
    Serial.print(":");
    if (seconds < 10) Serial.print("0"); // Add leading zero if needed
    Serial.println(seconds);

    Serial.print("Date: ");
    Serial.print(day);
    Serial.print("/");
    Serial.print(month);
    Serial.print("/");
    Serial.println(year);
  }
}

READING TIME/DATE

#include <Wire.h>
#include <RV-3028-C7.h>

RV3028 rtc;
unsigned long previousMillis = 0;
const long interval = 60000;  // 1 minute interval

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

  // Initialize RTC module
  if (!rtc.begin()) {
    Serial.println("RV-3028-C7 not detected. Please check wiring.");
    while (1);  // Stop the program if RTC is not detected
  }

  Serial.println("RV-3028-C7 RTC Initialized");
}

void loop() {
  unsigned long currentMillis = millis();

  // Only read RTC time once every minute
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    rtc.updateTime();  // Update the time from the RTC module

    // Read current time from RTC
    int hours = rtc.getHours();
    int minutes = rtc.getMinutes();
    int seconds = rtc.getSeconds();

    // Read current date from RTC
    int day = rtc.getDate();     // Day of the month (1-31)
    int month = rtc.getMonth();  // Month (1-12)
    int year = rtc.getYear();    // Year (e.g., 2024)

    // Print current time and date to Serial Monitor
    Serial.print("Time: ");
    Serial.print(hours);
    Serial.print(":");
    if (minutes < 10) Serial.print("0");
    Serial.print(minutes);
    Serial.print(":");
    if (seconds < 10) Serial.print("0");
    Serial.println(seconds);

    Serial.print("Date: ");
    Serial.print(day);
    Serial.print("/");
    Serial.print(month);
    Serial.print("/");
    Serial.println(year);
  }
}

Hi @Cam178275,

Welcome to the forums! There are a few causes for an RTC to jump about when it’s using its backup power. It’s not uncommon for it to drift a bit when using backup power. Can you shoot through some images of your setup please?

I haven’t used this specific module before but the code looks ok from what I can tell.

Hi Jack

Hi Cam,

It may be a logic-level issue. Arduino’s use 5V logic and the board is outputting 3.3V. Do the times look ok when you have the board running like that? When the board is disconnected from power how large would you say the jumps are in accuracy?

Hi Cam,

Welcome to the forum, I’ve thrown together an almost identical setup at my desk, and wasn’t able to replicate the issue. I did instead use a slightly different library straight from the Arduino IDE, below is the code that I used.

/*
  RV-3028-C7 Set Date Time Example

  Configures date and time to the RTC module via the serial console, and then
  prints the current date and time in ISO 8601 format every second.

  Copyright (c) 2020 Macro Yau

  https://github.com/MacroYau/RV-3028-C7-Arduino-Library
*/

#include <RV3028C7.h>

RV3028C7 rtc;

void setup() {
  Serial.begin(9600);
  Serial.println("RV-3028-C7 Set Date Time Example");
  Serial.println();

  Wire.begin();

  while (rtc.begin() == false) {
    Serial.println("Failed to detect RV-3028-C7!");
    delay(5000);
  }

  Serial.print("Enter current date and time in ISO 8601 format: "); // e.g., 2018-01-01T08:00:00
  while (Serial.available() == false);
  if (Serial.available() > 0) {
    String dateTime = Serial.readString();
    Serial.println(dateTime);
    rtc.setDateTimeFromISO8601(dateTime);
    rtc.synchronize(); // Writes the new date time to RTC
  }

  // Since ISO 8601 does not include day of week, the RTC cannot keep track of it unless input separately
  Serial.print("Enter day of week (0 for Sunday, 1 for Monday, and so on): ");
  while (Serial.available() == false);
  if (Serial.available() > 0) {
    int dayOfWeek = Serial.parseInt();
    Serial.println(dayOfWeek);
    rtc.setDateTimeComponent(DATETIME_DAY_OF_WEEK, dayOfWeek);
    rtc.synchronize();
  }

  Serial.println();
}

void loop() {
  Serial.println(rtc.getCurrentDateTime());
  delay(1000);
}

Hey @Cam178275,

@Dan has a fantastic response with a test setup that works. It may be work giving that library a shot instead and see what result you get?

Best of luck! :slight_smile:

1 Like

Thank you so much for all your help! It works. I’ll probably never understand why, but it works :slight_smile:

2 Likes

Hey @Cam178275,

Sometimes that’s how these projects end up working out. Just don’t look at it too hard!

Hopefully, it is smooth sailing from here! :slight_smile:

1 Like