// Create an object: VirtuabotixRTC(clkPin, datPin, rstPin) // Make sure pins match your wiring VirtuabotixRTC myRTC(6, 7, 8);
VirtuabotixRTC myRTC(6, 7, 8); const int ledPin = 13;
: Provides specific functions like updateTime() to refresh the current clock data and individual member variables (e.g., myRTC.hours , myRTC.minutes ) for easy access. Common Functions virtuabotixRTC(SCLK, IO, CE) virtuabotixrtc.h arduino library
Combine the RTC with an SD card module.
Constructor to define the pins used for the clock, data, and reset/chip enable. setDS1302Time(sec, min, hr, dayW, dayM, mon, yr) Sets the current date and time on the module. updateTime() setDS1302Time(sec, min, hr, dayW, dayM, mon, yr) Sets
The library is an essential software component for Arduino developers looking to integrate the DS1302 Real-Time Clock (RTC) module into their projects . Originally based on code from the Arduino Playground, it was refined and packaged by Virtuabotix, LLC to provide a streamlined, object-oriented interface for tracking date and time. Core Functionality
// Print the date Serial.print("Date: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/20"); Serial.print(myRTC.year); Core Functionality // Print the date Serial
There are several libraries available for RTC modules, such as the standard RTClib from Adafruit or the DS3231 library. However, the VirtuabotixRTC library offers specific advantages that make it a favorite for many hobbyists and developers:
| Feature | VirtuabotixRTC (DS1302) | RTClib (DS1307/DS3231) | |---------|-------------------------|-------------------------| | Interface | 3-wire (any pins) | I2C (A4/A5 on Uno) | | Accuracy | ±2 minutes/month | DS3231: ±2 minutes/year | | Battery life | ~5 years | ~10 years | | Ease of use | Very simple | Simple, more features |
To use the VirtuabotixRTC.h library, you need to correctly connect your RTC module to the Arduino. Most RTC modules utilize the I2C interface, which uses two specific pins for communication (SDA and SCL) and two for power (VCC and GND).