First, it doesn't seem to be keeping the correct time. I had the program ( a simple dim on/off program for LED's, trying to simulate sunrise/sunset) working perfectly last night, then when I wake up this morning they haven't started their dim on cycle like they should have. I plug the usb cable into the computer and open the serial monitor it reads the time as 10:47 a.m. instead of 11:36 a.m. This leads me to my second problem.

Every once in a while when I try to recompile and upload it, when I open the serial monitor it gives a completely different time than the computer, which is what it should be setting itself off of. For example it's 11:36 a.m. right now (correct on my computer) and after recompiling and re-uploading the program still thinks it is 10:47 a.m.

Additionally I watched the serial monitor for a moment and caught this:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>#include "RTClib.h"

// Declarationsint led = 2;float brightness = 0;float fadeAmount = 0;

RTC_DS1307 RTC;

void setup () { Serial.begin(57600); Wire.begin(); RTC.begin();

if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } pinMode(led, OUTPUT);

And now, not only has it been unstuck from 17:18:39, but it's the correct time, as opposed to earlier when it was counting correctly but about an hour and ten minutes off. Again, I changed nothing except re-uploading the program.

Since the whole system is still in the early stages and experiencing lots of unplugging I decided to remove the battery from the circuit to prevent it from draining. The pin for the battery is currently wired to ground, which is a note on ladyada:

"You MUST have a coin cell installed for the RTC to work, if there is no coin cell, you should pull the battery pin low."

Your code does take quite some time to do all those the serial prints. Add that time to the delay(1000) and the time between 2 prints will be definitely more than 1 second (say ~1.1 second) so once in about 10 times it will skip a second.

instead of using delay(1000) you better check if 1000 millisec have gone by.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>#include "RTClib.h"

// Declarationsint led = 2;float brightness = 0;float fadeAmount = 0;

unsigned long prevTIme = 0; // must be global to keep value over multiple calls of loop()

RTC_DS1307 RTC;

void setup () { Serial.begin(57600); Wire.begin(); RTC.begin();

if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } pinMode(led, OUTPUT);

First of all, thanks a bunch to everyone. I can't thank you enough for helping, it's gotten to the point of hair-pulling.

robtillaart,

I tried your code, at first I got an error on prevTime being undeclared. In the declarations it was prevTIme so I just changed the 'I' to a lowercase and it fixed that. But now I'm getting this:

sketch_oct13a.cpp: In function 'void loop()':sketch_oct13a:41: error: 'printTime' was not declared in this scopesketch_oct13a.cpp: At global scope:sketch_oct13a:75: error: ISO C++ forbids declaration of 'printTime' with no type

Well, I put the battery back in the circuit, re-uploaded everything and at first instead of printing "RTC is NOT running" or some garbage text like " #Râ¨Mâò:'Ï@Çbâ¨Iâò:'Í@Ë " on the first line, it printed "#" , and then the time/date. But it was the wrong time/date. So I re-uploaded it and this time it printed what is below:

My guess now is that perhaps it has something to do with the wiring, as I did have some confusion there.

My confusion was the datasheet at the top has a picture of a 'typical operating circuit', which has both SDA and SCL with a pullup resistor to Vcc, however further down the datasheet it says only SDA needs the pullup resistor and SCL doesn't say anything about the resistor, only that it should have a pullup voltage of 5.5V?