Synchronize RTC DS1302 with PC

Hi there!
I have an ArduinoUNO and I want to synchronise the RTC DS1302 with my PC.
Is this possible?

Thanks :slight_smile:

I don't know of a way to get the current PC system time with a request triggered by an Arduino. However, if you are doing this manually, you can use a Windows .vbs script to insert the PC's current date/time stamp into the serial monitor's keyboard input buffer. That would have to be in a format that your library can interpret properly. Below is an example. This method may not work with version 2 of the IDE. I use it with V1.8, which opens the serial monitor as a separate process. You would want to sync your computer to an NTP server just before doing this.

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate "COM"     'Arduino IDE v1.8, not v2

oldTime = Time                 'wait until new second begins
do while Time = oldtime
loop

WshShell.SendKeys TimeStamp(Now)


Function TimeStamp(dtStamp)
    TimeStamp = right("0"&Second(dtStamp),2)&right("0"&Minute(dtStamp),2) _
    &right("0"&Hour(dtStamp),2)&Weekday(dtStamp,1)&right("0"&Day(dtStamp),2) _
    &right("0"&Month(dtStamp),2)&right(Year(dtStamp),2)&"{ENTER}"
End Function

'Serial monitor must not be minimized, or AppActivate will not find it.

Edit: There was an error in the original script, now corrected.

You can get the compile date and time, but that implies you need to reflash every few months as the clock drifts. Better clocks drift less, but all local oscillator types drift, just at different rates, so resetting occassionally is required.
I built in a set mechanism using a 10k pot on A15 as an input device and a button for ENTER. i have an LED 8x32 display to prompt the user with.

WiFi to get to the internet also works but is a bit harder to implement.
Code for the set function is in my projects section.

Edit - this post is no longer relevant now that GoForSmoke has deleted post #4.

With an UNO, you would likely need a script running on the computer to send the time using the serial port.

There was an error in my script in post #2, which I have now corrected.

You can test the script by replacing "COM" in the second line with "NOTEPAD", and have Notepad running when you run the script. Also, you can use any terminal program to communicate with the Arduino. It doesn't have to be the Serial Monitor. So for example, you could replace "COM" with "TERMITE". Just make sure whatever you use isn't minimized. It can be in the background, but if it's minimized, the script won't find it.

I once took a job that others had failed a kind of self-administered X-Y Problem Test.

They told me that the job was to synchronize 6 different clocks so I asked for more amd eventually we got down to WHAT they wanted instead of HOW they thought it had to be done. They wanted to be able to reconstruct transactions at cash registers with video of same and limited sensing with led cues on the video.
So okay, fine. I told them I'd do that to the second and until it worked they didn't believe me. What I did was log everything with the 4 byte Unix Time stamp as 8 hex digits. Any gas pump event time logged as PC time.

Run by your clock, "synchronize" the others by tracking the difference and apply that if you have to say what happened when a receipt printed with a time printed on it or a pendulum passes a magnet or the sun shade needs adjusting.