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);
}
}