Even though the RFzero has a GPS receiver onboard that can be used for time keeping there may be situations where a Real Time Clock (RTC) may be useful, e.g. to save power by shutting down the GPS, Si5351A and MCU to an absolute minimum and then wake up later on.
The Arduino RTC reference has an overview of most of the RTC functions available.
Installing the RTC library
It might be that the RTC library is not installed in your Arduino IDE. If this the case you will get a compiler warning when you try to compile the RTC example below. If so then from the Arduino IDE select Menu | Sketch | Include Library | Manage Libraries … Then type “rtcz” next to the Topic ALL to narrow the search result and select the RTCZero by Arduino library.
The RTC is fairly simple to include, setup and use once the RTC library has been installed.
Below is an example of using the RTC. Hours, minutes and seconds are printed once per minute on the USB port.
#include <RTCZero.h> // Must be included for RTC use
RTCZero rtc; // Create the rtc object
// RFzero include and object creation
#include <RFzero.h> // MUST ALWAYS be included
int hours = 12;
int minutes = 0;
int seconds = 0;
// Initialize and wait for the USB to be ready
delay(2000); // Wait 2 s to make sure the USB is up and running
// Initialize the RTC
rtc.setTime(hours , minutes, seconds);
sprintf(buf, "RTC: %02d:%02d:%02d\n", rtc.getHours(), rtc.getMinutes(), rtc.getSeconds());
The above example can be used without a GPS receiver e.g. on Arduino Zero or Arduino M0 boards. If so then remove the GPS receiver function and the calling of any RFzero relations.