Virtuabotixrtc.h Arduino Library ✧
If your DS1302 is running slow, check the voltage on pin 3.3V. Some modules have a diode that drops voltage. Powering the VCC pin with 5V and the backup battery with 3V can cause issues. Ensure the main power matches the chip's spec sheet.
Once the RTC is set, the real fun begins. The virtuobabotixRTC object updates its internal variables when you call updateTime() . Here are the most useful functions.
// 4. Day of week (as number) Serial.print("Day of week (1-7): "); Serial.println(myRTC.dayofweek); virtuabotixrtc.h arduino library
This library is known for being lightweight and beginner-friendly, making it an excellent starting point for projects like data loggers, automated control systems, alarm clocks, and time-stamping devices.
The library defines the virtuabotixRTC class with several key methods: If your DS1302 is running slow, check the voltage on pin 3
Once updateTime() is called, the library provides direct access to time components via public members of the object: myRTC.seconds myRTC.minutes myRTC.hours myRTC.dayofmonth myRTC.month myRTC.year myRTC.dayofweek Example Implementation
| | Arduino Connection | Description | |-----------------------|------------------------|-----------------| | VCC | 5V | Power supply | | GND | GND | Ground | | CLK (or SCLK) | Digital Pin 6 | Clock signal | | DAT (or I/O) | Digital Pin 7 | Data line | | RST (or CE) | Digital Pin 8 | Chip enable | Ensure the main power matches the chip's spec sheet
dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) dataFile.print(myRTC.month); dataFile.print("/"); dataFile.print(myRTC.dayofmonth); dataFile.print(" "); dataFile.print(myRTC.hour); dataFile.print(":"); dataFile.print(myRTC.minute); dataFile.print(" - Temp: "); dataFile.print(temperatureC); dataFile.println(" C"); dataFile.close();
: Push date/time values from the Arduino into the DS1302 registers.
: It uses a specific format for initial setup: (seconds, minutes, hours, day of week, day of month, month, year) .