// Open file and log dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) dataFile.print(myRTC.getDateStr()); dataFile.print(","); dataFile.print(myRTC.getTimeStr()); dataFile.print(","); dataFile.println(temperatureC); dataFile.close();
| Function | Syntax Example | Description | | :--- | :--- | :--- | | | VirtuabotixRTC(int clk, int dat, int rst) | Initializes the library with the three Arduino pins connected to the DS1302's CLK, DAT (I/O), and RST (CE) pins. | | updateTime() | rtc.updateTime(); | Reads the current time from the RTC chip and stores it in the object's internal variables. Must be called before reading time. | | setDS1302Time() | rtc.setDS1302Time(seconds, minutes, hours, dayOfWeek, date, month, year); | Writes a new time/date to the RTC chip. Typically called once during setup. | | Accessing Time | rtc.hours , rtc.minutes , rtc.seconds , rtc.dayofmonth , rtc.month , rtc.year , rtc.dayofweek | After updateTime() , these integer variables hold the current time components. |
The library is lightweight and focused solely on DS1302 functionality, making it ideal for microcontrollers with limited memory. Hardware Wiring