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?
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.
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.