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 minimize the power consumption by shutting down the GPS, Si5351A and MCU 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 is 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.
RTC example
Below is an example of using the RTC. Hours, minutes and seconds are printed once per second on the USB port.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#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 for RFzero int hours = 12; int minutes = 0; int seconds = 0; void setup() { RFzero.init(EEPROM_TYPE_24LC08B); // For RFzero v.1.x or EEPROM_TYPE_M24128 for RFzero v.2.x // Initialize and wait for the USB to be ready SerialUSB.begin(9600); delay(2000); // Wait 2 s to make sure the USB is up and running // Initialize the RTC rtc.begin(); rtc.setTime(hours , minutes, seconds); } void loop() { char buf[20]; sprintf(buf, "RTC: %02d:%02d:%02d\n", rtc.getHours(), rtc.getMinutes(), rtc.getSeconds()); SerialUSB.print(buf); delay(1000); } |
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.