Datalogger Sheild RTC issue

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
making
 
Posts: 7
Joined: Sat Jul 26, 2014 7:01 pm

Datalogger Sheild RTC issue

Post by making »

Hello,

A couple of months ago, I had ordered the Adafruit Datalogger shield with the DS1307 RTC on-board.

I went through the tutorial: https://learn.adafruit.com/adafruit-dat ... time-clock which include the method to reset the RTC. When I did this the clock was within 10 seconds compared to the clock on the PC that the code was compiled on. I believed that was acceptable and so let it run.

Now that I have acquired everything for my project and have coded everything I started to put it all together. I checked the RTC and noticed it was 2 minutes ahead of the computer's time. Thinking a simple reset of the time was all that was needed I run the code on the tutorial page again. Check again and no difference, still 2 minutes ahead. Very confused, I decided to try a full reset of the RTC by taking the coin cell battery out than slip it back in after a moment. Attempt the code reset again and now its over 5 minutes behind the computer.

I have no idea what is going wrong, any one have any pointers that I am missing here.

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Datalogger Sheild RTC issue

Post by Franklin97355 »

What code are you running to set the clock?

User avatar
making
 
Posts: 7
Joined: Sat Jul 26, 2014 7:01 pm

Re: Datalogger Sheild RTC issue

Post by making »

This code is both used to reset the clock and check what it is writing through the serial terminal:

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

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

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
// uncomment it & upload to set the time, date and start run the RTC!
RTC.adjust(DateTime(__DATE__, __TIME__));
}

}

void loop () {
DateTime now = RTC.now();
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();
Serial.print(" since 1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
delay(3000);
}

User avatar
making
 
Posts: 7
Joined: Sat Jul 26, 2014 7:01 pm

Re: Datalogger Sheild RTC issue

Post by making »

I figured out the time reseting problem, the reset command was stuck under the ! RTC.isrunning() if statement.

But this now leads me to the question of how a RTC clock can be off by so many seconds in a couple months time, and if there is anything that can be done to prevent it. Has anyone encountered this issue?

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Datalogger Sheild RTC issue

Post by Franklin97355 »

From the RTC breakout board page
The DS1307 is simple and inexpensive but not a high precision device. It may lose or gain up to 2 seconds a day. For a high-precision, temperature compensated alternative, please check out the ChronoDot.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”