RTC Code Not Working

Hi everyone,

Has anyone tried using the timeRTC code from the Arduino playground http://playground.arduino.cc/Code/Time? I set it up using an Uno and DS1307 real time clock. Without making any code modifications, the minutes value starts at 18, ticks away to 23, then resets back to 18. Has anyone seen this and been able to fix it? I plan to dissect the code, but wanted to see if anyone else has fixed it already. Here’s the code, thanks for looking!

/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

void setup()  {
  Serial.begin(9600);
  while (!Serial) ; // wait until Arduino Serial Monitor opens
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } else {
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(4000);
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Try this.

http://bildr.org/2011/03/ds1307-arduino/

It is well-explained, and works

That works! I'll abandon the previous code and go with this one. Thanks a lot!

Glad to hear that.

Note that, while it just tells the time, it seems to be very efficient too. I got to the the stage where is was obliged to use a library in order to get the date as a filename. I assumed that I might as well use the library to tell the time too. Wrong. I used less memory by sticking with this method to tell the time and extra libraries to do time-related things.