Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Updating DS1307RTC with System Time - not compiled time
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Updating DS1307RTC with System Time - not compiled time

by tomcat on Wed Nov 25, 2015 5:39 pm

I've searched for a solution to simply replace the time in the DS1307RTC with system time (not time compiler was run) on a pc/mac through the serial bus, but haven't found anything. Here's my dilemma:

Using the SetTime file from the DS1307RTC library to update the RTC with the time (time compiler was run) works fine. My problem is when I remove power from the micro-controller (teensy 3.1), and power up from another timezone, the RTC time will be off. I'm hoping there's a way to update the RTC with local time by simply plugging in to a serial port, which powers the board and resets it.

Rather than reading the getDate(__DATE__) and getTime(__TIME__) which pulls the compiled time, I'm wondering how I pull pc/mac system time.

Thanks.

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Wed Nov 25, 2015 5:50 pm

You can send the time via the serial port and update it that way.

You will need to write some code to interpret the time sent via the serial port into the DateTime object expected by the RTC "adjust" function.

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Wed Nov 25, 2015 5:55 pm

Are you saying I'll need the RTClib library and use a function similar to the following:

RTC.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second()));

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Wed Nov 25, 2015 6:03 pm

You will need the library. But the DateTime constructor should be called with the values parsed from your serial connection.

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Wed Nov 25, 2015 6:05 pm

I'm still somewhat of a newbie, do you have any examples.

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Wed Nov 25, 2015 6:16 pm

Here is an example using a different version of the library: http://playground.arduino.cc/Code/DateTime

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Wed Nov 25, 2015 6:21 pm

Thanks very much, I really appreciate it! I'll give it a try.

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Sat Nov 28, 2015 6:41 pm

Unfortunately the Arduino IDE would not load the DateTime library - 'Specified folder/zip file does not contain a valid library'.

I'll deal with parsing later, I still have not been able to grab the current time from the pc/mac. I'm sure I could manipulate the time value later, I just need to get the date, but I haven't been having much success.

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Sat Nov 28, 2015 7:36 pm

'Specified folder/zip file does not contain a valid library'.

You need to unzip the folder and make sure it is installed correctly:
http://learn.adafruit.com/adafruit-all- ... nstall-use

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Sat Nov 28, 2015 8:16 pm

I've installed many libraries successfully. Is it possible this library is not compatible with the teensy 3.1 micro??

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Sat Nov 28, 2015 8:24 pm

It is possible that there is a compatibility issue. But the error message seems to indicate rather strongly that the library is not installed properly.

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Sat Nov 28, 2015 8:42 pm

I'll remove any copies of this library from my mac, copy the zip file to the library folder as required and unzip, but before I get carried away, I need to know that I'm heading down the right path. As I mentioned earlier, I need to sync the rtc with pc/mac time and need to know if this process is seamless once the device is connected via usb to a computer, without sending any commands via the keyboard or anything else.

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Sat Nov 28, 2015 8:58 pm

need to know if this process is seamless once the device is connected via usb to a computer, without sending any commands via the keyboard or anything else.

With the proper code, this is certainly possible to do.

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Re: Updating DS1307RTC with System Time - not compiled time

by tomcat on Sat Nov 28, 2015 10:33 pm

Do you happen to know if there's another library available that would allow me to pull time from a mac/pc to achieve my objective?

tomcat
 
Posts: 30
Joined: Thu Jan 26, 2012 9:50 am

Re: Updating DS1307RTC with System Time - not compiled time

by adafruit_support_bill on Sun Nov 29, 2015 6:56 am

This library can handle Ethernet NTP time-sync messages using an Ethernet shield.
http://playground.arduino.cc/Code/Time

adafruit_support_bill
 
Posts: 77924
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.