I'm trying to get my Arduino to communicate with a DS3231 RTC, but am running into an issue.
When I upload my sketch:
#include <Wire.h>
#include <SPI.h>
#include <RTClib.h>
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
if (! RTC.isrunning())
Serial.println("RTC is NOT running!");
}
byte lastSec=0;
void loop ()
{
DateTime now = RTC.now();
if(lastSec!=now.second())
{lastSec=now.second();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
}
and check the serial monitor, it reports the time correctly. However when I unplug the USB from the Arduino (Still supplied with power via power jack) and then plug it back in sometime later and open the serial monitor (without having uploaded the sketch again, it prints out what the time WAS when I first uploaded the sketch, and starts reporting the time starting from then.
I'm very new to Arduino, and feel like I may be missing something obvious.
Any help is greatly appreciated!
Thanks!