Virtuabotixrtc.h Arduino Library -
// Define your pins: (CLK, DAT, RST) // Using pins 7, 6, 5 as wired above virtuabotixRTC myRTC(7, 6, 5);
This means virtuabotixRTC.h is the correct choice for your DS1302 module, as I2C-focused libraries will not work with it.
void loop() myRTC.updateTime(); // This line is crucial! It updates the variables below. virtuabotixrtc.h arduino library
Originally written and released by the Virtuabotix team (now maintained in legacy and community forms), this library provides a lightweight, straightforward interface to read and write time data from the DS1302 via a simple 3-wire interface. Unlike its I2C-based cousins, the DS1302 uses a proprietary synchronous serial protocol that this library handles natively.
Communicates with the DS1302 using only SCLK (Clock), I/O (Data), and CE (Chip Enable/RST) pins. Easy Time Setting: Includes the setDS1302Time() // Define your pins: (CLK, DAT, RST) //
Many modern RTC modules use the DS1307 or DS3231 chips, which communicate via the I2C protocol. However, the DS1302 chip uses a 3-wire serial interface.
This library provides a straightforward interface to control the popular and cost-effective . Developed by Joseph Dattilo of Virtuabotix LLC, with a version as early as 0.4.5 released in 2011, it has become a go-to solution for hobbyists and educators looking to add real-time clocks to their Arduino-based devices. Originally written and released by the Virtuabotix team
: It allows users to define which Arduino pins are connected to the DS1302’s Data (DAT), Clock (CLK), and Reset (RST) pins through a simple object constructor, such as virtuabotixRTC myRTC(clk, dat, rst) .
// Only print to the Serial Monitor once per second to avoid clutter if (lastReportedHour != myRTC.hours) // A simple conditional Serial.print("The time is: "); Serial.print(displayHour); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); lastReportedHour = myRTC.hours;
: Once the time is set, you should comment out this line and re-upload the sketch to prevent the clock from resetting every time the Arduino restarts.
Here is the most common wiring scheme: