Download Print this page

sparkfun RV-8803 Hook-Up Manual page 16

Real time clock module (qwiic)

Advertisement

if (rtc.setToCompilerTime() == false) {
Serial.println("Something went wrong setting the time");
}
//Uncomment the below code to set the RTC to your own time
/*if (rtc.setTime(sec, minute, hour, weekday, date, month, year) == false) {
Serial.println("Something went wrong setting the time");
}*/
If everything goes correctly here your RTC's internal clock will either be set to the compiler time or your custom time using the variables defined earlier in
the sketch. Open the Arduino Serial Monitor, set the baud rate to 115200 and the code will print out over serial whether or not this was successful. If you
have never worked with the Arduino Serial Monitor or other serial terminal programs, check out our Serial Terminal Basics tutorial. You can check the
accuracy of the time set here by running the second example.
Note: The compiler time is not set every time the code compiles. In order to ensure the proper time is loaded, re-open the IDE and then upload the
code. Also note that due to upload times, the compiler time may be off by several seconds/hundredths of seconds. The Set Hundredths examples
below can help with more accurate time-keeping.
Example 2 - Print Time
This example shows how to request the time from the RTC after it has been set. The code starts by initializing the RV-8803 on the I C bus then attempts
to to move the values from the RV-8803's time registers to the microcontroller's
successful, the code prints the time data (date, hour, mins, etc.) over serial. Open up the Serial Monitor and set the baud to 115200 and watch the time fly
by, literally!
The code defaults to printing the date in the US format (mm/dd/yyyy) so if you'd like to switch it to the more commonly used dd/mm/yyyy format, adjust
this section of the code:
String currentDate = rtc.stringDateUSA(); //Get the current date in mm/dd/yyyy format
//String currentDate = rtc.stringDate()); //Get the current date in dd/mm/yyyy format
Note: If you are modifying or writing your own code remember the
the RV-8803.
Example 3 - Set Hundredths
array using the
_time
function must be called before attempting to read the time from
updateTime();
2
function. If that retrieval is
updateTime();

Advertisement

loading
Need help?

Need help?

Do you have a question about the RV-8803 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Bob-16281