RTC adjustment to include compile time

Hi All,

I'm using an Ardunio Uno Rev3 and an adafruit data logging shield. I've used a sample program from https://www.pjrc.com/teensy/td_libs_DS1307RTC.html to set the time of the real time clock.

This works fine except it sets the RTC to the time at which the program was complied, not when it was uploaded so the time is always about a minute out.

Is there anyway to compile first and then upload later if i set the time manually to say 16:00 and press upload at exactly 16:00 so i can finally get the current time on my RTC?

Cheers Steve

This works fine except it sets the RTC to the time at which the program was complied, not when it was uploaded so the time is always about a minute out.

When I compile and upload, the difference is on the order of 5 seconds or less.

How do you intend to upload without compiling?

megamef: This works fine except it sets the RTC to the time at which the program was complied, not when it was uploaded so the time is always about a minute out.

You could change the date/time setting of your PC for time compensation before doing so.

But: When doing so, the time will always be set to the compile time - at the time the program executes. So if you upload such a program, and later do a RESET (i.e. by opening the serial monitor or a power-on), the program will start and set the RTC to date/time when it was compiled. Pretty useless, isn't it?

megamef: Is there anyway to compile first and then upload later if i set the time manually to say 16:00 and press upload at exactly 16:00 so i can finally get the current time on my RTC?

In normal cases you would provide a "set time" function in your software which allows setting time (and perhaps date). In my programs I usually use "Serial" for time setting. So while the firmware is running, I can open the serial monitor, enter the date and time as I want it, and as soon as I hit the RETURN key on my PC to send the string, containing command and new setting, the RTC time will be set to the date and time entered in the Serial monitor.

Opening Serial Monitor causes the Arduino to reset. Set the date and time in your sketch ahead of time, upload it and a second or so before time open Serial Monitor. Then upload a new sketch that doesn't reset the clock.

Remove all time setting from your sketch. Instead, use another RTC sketch that has a serial set function to set the time. Those come in the example folders of many RTC libraries.