: The updateTime() function must be called within the loop() to refresh the local variables before reading them. Basic Code Structure A standard implementation typically follows this pattern:
// Comment this line out after the first upload to avoid resetting time myRTC.setDS1302Time( // Update library variables with current RTC time myRTC.updateTime(); // Print current time Serial.print(myRTC.dayofmonth); Serial.print( ); Serial.print(myRTC.month); Serial.print( ); Serial.print(myRTC.year); Serial.print( ); Serial.print(myRTC.hours); Serial.print( ); Serial.print(myRTC.minutes); Serial.print( ); Serial.println(myRTC.seconds); virtuabotixrtc.h arduino library
This rigid pin mapping is critical: the library does not use any hardware SPI peripherals; it bit-bangs the protocol entirely in software. : The updateTime() function must be called within
: After calling updateTime() , you can access individual elements directly: myRTC.seconds , myRTC.minutes , myRTC.hours myRTC.dayofmonth , myRTC.month , myRTC.year Hardware Wiring (DS1302) The DS1302 typically uses five pins: VCC : 3.3V or 5V. GND : Ground. CLK (SCLK) : Serial Clock. DAT (I/O) : Data line. RST (CE) : Reset/Chip Enable. Setup Guide Create an Arduino Library (Step by Step) GND : Ground
. While it is a popular legacy choice for hobbyists, it is primarily a community-maintained wrapper that simplifies the process of setting and reading time from the DS1302 chip. Arduino Forum Core Functionality
// Set the time and date manually // Syntax: setDS1302Time(seconds, minutes, hours, dayOfMonth, month, dayOfWeek, year) // NOTE: dayOfWeek: Sunday=1, Monday=2 ... Saturday=7