DS1307 RTC Setting issue

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

DS1307 RTC Setting issue

Postby mdn15 » Sat Jan 07, 2012 5:56 pm

I recently purchase the DS1307 RTC breakout board and am having an issue. I have followed the tutorial and am using the code listed on this site. My RTC (even directly after reset) is always a few mins off. I am using the setting script listed on the site to set the clock to my computers time. I do understand that this clock will eventually become inaccurate, but i am confused as to why it is off immediately after resetting.

Here is the code I am using in the setup section of the sketch to set the clock
Code: Select all
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__));
  }

has anyone else encountered this issue and have a fix?

Thanks
mdn15
 
Posts: 14
Joined: Sat Jan 07, 2012 5:48 pm

Re: DS1307 RTC Setting issue

Postby mdn15 » Sat Jan 07, 2012 7:12 pm

So i figured out the issue is of why the clock was off. It is taking the time based on when I compiled the source. If the clock gets reset and the code is not re-uploaded prior to the clock getting power, it will reset to the same time as the previous sketch and will no longer be correct.

This poses a new question. Is there a way to reset the time only when the sketch is uploaded so if the Arduino looses power, the clock will still be correct.

Thanks
mdn15
 
Posts: 14
Joined: Sat Jan 07, 2012 5:48 pm

Re: DS1307 RTC Setting issue

Postby rob drizzle » Sat Jan 07, 2012 8:41 pm

The clock should always be correct (relatively) even if the arduino looses power. The coin cell ensures that the RTC always has power. The only time the RTC time should reset is when you up-load a new sketch.
rob drizzle
 
Posts: 101
Joined: Wed May 04, 2011 5:14 pm

Re: DS1307 RTC Setting issue

Postby mdn15 » Sat Jan 07, 2012 8:45 pm

I mean it was literally off by 2+ mins.

Is there any way to only execute code when a sketch is uploaded the arduino?
mdn15
 
Posts: 14
Joined: Sat Jan 07, 2012 5:48 pm

Re: DS1307 RTC Setting issue

Postby floresta » Sat Jan 07, 2012 9:26 pm

I have followed the tutorial and am using the code listed on this site.

Even if we take the time to search for 'the' tutorial and 'the' code how can we be sure that we found the same tutorial and code that you used?

Generally speaking you should use one program to set (and perhaps initially read) the RTC and a different program to subsequently read the RTC.

Don
floresta
 
Posts: 214
Joined: Thu Jul 31, 2008 9:27 am
Location: Western New York, USA

Re: DS1307 RTC Setting issue

Postby mdn15 » Sat Jan 07, 2012 9:33 pm

Tutorial I followed: http://www.ladyada.net/learn/breakoutpl ... 07rtc.html

And I guess it does make sense to have 2 separate sketches to do this. I was just wondering if it were possible to combine it into one
mdn15
 
Posts: 14
Joined: Sat Jan 07, 2012 5:48 pm

Re: DS1307 RTC Setting issue

Postby adafruit_support_bill » Sun Jan 08, 2012 5:07 am

You can use the following code snippet from the example sketch in the DS1307 library. It will only set the time if the RTC is not running. If you pull the battery to stop the RTC, the next time you upload it will set the time. On subsequent runs, the RTC will already be running.

Code: Select all
  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__));
  }
User avatar
adafruit_support_bill
 
Posts: 15909
Joined: Sat Feb 07, 2009 9:11 am

Re: DS1307 RTC Setting issue

Postby mdn15 » Sun Jan 08, 2012 11:31 am

I used that snippet, but it ended up setting it slow by approx 2 mins. (Im guessing the time it took me to get the actual battery since the clock will not run without the battery)

It is now properly set
mdn15
 
Posts: 14
Joined: Sat Jan 07, 2012 5:48 pm

Re: DS1307 RTC Setting issue

Postby boomerang » Mon Feb 13, 2012 7:28 am

mdn15 wrote:it ended up setting it slow by approx 2 mins.


The compile/upload delay perhaps?
boomerang
 
Posts: 5
Joined: Wed Feb 08, 2012 7:02 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 6 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]