Accurately setting Ds1307 with RTClib after compiling sketch

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Accurately setting Ds1307 with RTClib after compiling sketch

Post by Woodcutter »

I am using the RTClib library to talk to a DS1307 RTC circuit connected to an Arduino. The library makes it a breeze to time stamp data and perform tasks at fixed times. Hats off to the author of RTClib.

The only thing that I can't resolve is this: The RTC time is set to the PC time when the sketch is compiled. By the time the program is uploaded there can be a 20-40 second difference between PC time and RTC time. This can start to make some datasets look a little screwy.

I understand the RTC can be set on the fly with an ethernet shield, but I don't have one. Can anyone think of a way the RTC be reset/adjusted while the Arduino code is running to get it exactly right (well, to within 1 second)?

Any advice much appreciated.

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

Re: Accurately setting Ds1307 with RTClib after compiling sketch

Post by Franklin97355 »

You could put a check in the start of the program to see if a pin was pulled low and if so ask for the date and time.

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Accurately setting Ds1307 with RTClib after compiling sketch

Post by fat16lib »

The softDS1307 example in my I2cMaster library allows you to accurately set the DS1307. It will work with the Data Logging shield on a Mega or 328 Arduino.

You can download it from this post http://forums.adafruit.com/viewtopic.php?f=25&t=13722. The file is i2cv2.zip.

Here is the menu and entries for setting the time:
The current time is 12/18/2011 Sun 13:49:06
Control: 00

Options are:
(0) Display date and time
(1) Set time
(2) Set date
(3) Set Control
(4) Dump all
(5) Set NV RAM
Enter option: 1

Enter hours (00-23): 13
Enter minutes (00-59): 50
Enter seconds (00-59): 00

The current time is 12/18/2011 Sun 13:50:00
Control: 00

User avatar
boomerang
 
Posts: 7
Joined: Wed Feb 08, 2012 8:02 am

Re: Accurately setting Ds1307 with RTClib after compiling sketch

Post by boomerang »

franklin97355 wrote:You could put a check in the start of the program to see if a pin was pulled low and if so ask for the date and time.
Would this involve sending the time over serial? I would love to be able to do this. I could be poised to hit 'enter' while watching the clock for the time I've set to come by.

Is there a library for this?

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

Return to “Arduino”