Virtuabotixrtch: Arduino Library

This library is specifically designed for the DS1302 Real Time Clock chip (often sold in a module with a battery and crystal oscillator). Unlike the more common DS1307 (I2C) or DS3231, the DS1302 uses a 3-wire interface similar to SPI.

Crucial Tip: If your module has separate DS and SCLK pins (common on old DS1302 modules), do not use VirtuabotixRTC. That library is for I2C modules only (DS1307/3231). For DS1302, you need the DS1302 library. virtuabotixrtch arduino library

Common values:

  1. DS1307: Low power, full binary-coded decimal (BCD) clock/calendar. Accuracy: ~±5 minutes per month.
  2. DS3231: Extremely accurate temperature-compensated crystal oscillator (TCXO). Accuracy: ~±2 minutes per year.
// Set the current date and time myRTC.setDS1302Time(0, 0, 0, 1, 1, 2023, 0);

: Unlike some libraries that require complex structures, you can access time components directly (e.g., myRTC.seconds myRTC.minutes ) after calling updateTime() Getting Started This library is specifically designed for the DS1302

Serial.print("Time: "); Serial.print(myRTC.hour); Serial.print(":"); Serial.print(myRTC.minute); Serial.print(":"); Serial.println(myRTC.second); // Set the current date and time myRTC

9. Troubleshooting Common Issues

| Problem | Likely Cause | Solution | |---------|--------------|----------| | Reads 85:85:85 | RTC not initialized or first boot | Run the set-time sketch once. | | Time resets on power loss | Backup battery dead | Replace CR2032 battery on module. | | No Serial output | Wrong baud rate | Ensure Serial.begin(9600) matches monitor. | | Compilation errors | Wrong library installed | Remove other DS1302 libraries (e.g., DS1302RTC). | | Garbage values | Floating pins | Add 10k pull-up resistors on CLK/DAT/RST or use shorter wires. |

Serial.print(2000 + myRTC.year);