Go Down

Topic: Arduino due DS1307 RTC library (Read 7902 times) previous topic - next topic

Liad

Hi,

I've tried using RTClib and DS1307RTC libraries but they aren't compatible with the Arduio Due.
I've found this library, but it doesn't use an external RTC.


Any help?



Markus_L811


Hi,

I've tried using RTClib and DS1307RTC libraries but they aren't compatible with the Arduio Due.
I've found this library, but it doesn't use an external RTC.

Any help?

Hello Liad

Did you have an external crystal?

Witch line did you use?

RTC_clock rtc_clock(RC);
or
RTC_clock rtc_clock(XTAL);

The RTC_clock rtc_clock(RC) should work allways.

Markus

Liad

Hi Markus,

I'm using an external XTAL.

I uploaded the Due_Rtc_Simple_Sample once and all worked fine.
When I commented out:

Code: [Select]
//rtc_clock.set_time(10, 29, 9);
  //rtc_clock.set_date(22, 10, 2012);


The date was 1.1.2007


Am I missing something?

Markus_L811


Hi Markus,

I'm using an external XTAL.

I uploaded the Due_Rtc_Simple_Sample once and all worked fine.
When I commented out:

Code: [Select]
//rtc_clock.set_time(10, 29, 9);
  //rtc_clock.set_date(22, 10, 2012);


The date was 1.1.2007

Am I missing something?


No you missed nothing the 1.1.2007 is the the Resetvalue in the Calenderregister (look at the SAM3X Manuel on page 251) so this Date is set after Powering on. I don't know why this Date is set, but there is nothing wrong if it shown.

Liad

So how do I set the time on the DS1307?
I want to set it once, and read the time from it.

Markus_L811


So how do I set the time on the DS1307?
I want to set it once, and read the time from it.


Btw. there is no DS1307 on the Due Board. the SAM3X has an RTC on Die.

Code: [Select]
#include <rtc_clock.h>

// Select the Slowclock source
//RTC_clock rtc_clock(RC);
RTC_clock rtc_clock(XTAL);

char* daynames[]={"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

void setup() {
  Serial.begin(9600);
  rtc_clock.init();
  rtc_clock.set_time(10"hours", 29"minutes", 9"seconds");                <- this line set the time you set the hours, minutes and seconds with that
  rtc_clock.set_date(22, 10, 2012);
}

void loop() {
  Serial.print("At the third stroke, it will be ");
  Serial.print(rtc_clock.get_hours());                                            <- with rtc_clock.get_hours() you get the hours as an int
  Serial.print(":");                                                                          same for the fowolling minutes and seconds.
  Serial.print(rtc_clock.get_minutes());
  Serial.print(":");
  Serial.println(rtc_clock.get_seconds());
  Serial.print(daynames[rtc_clock.get_day_of_week()-1]);
  Serial.print(": ");
  Serial.print(rtc_clock.get_days());
  Serial.print(".");
  Serial.print(rtc_clock.get_months());
  Serial.print(".");
  Serial.println(rtc_clock.get_years());
}


May I had to set more comments in the sample.

Liad

We're talking on 2 different things.

I didn't know that the SAM3X has an RTC built in it.
I've tried to connect a DS1307 to the Arduino Due.
That is why I didn't understand how your library can help me with my project.

If there is a RTC built-in, how can I save the time there. is there a way to connect a battery to the SAM3X, like the one connected to a DS1307 circuit?


Thanks.

Markus_L811


We're talking on 2 different things.

I didn't know that the SAM3X has an RTC built in it.
I've tried to connect a DS1307 to the Arduino Due.
That is why I didn't understand how your library can help me with my project.

If there is a RTC built-in, how can I save the time there. is there a way to connect a battery to the SAM3X, like the one connected to a DS1307 circuit?

Thanks.

The SAM3X has connections for an backup-batterie to power the RTC if the "core" is powered of but the Arduino Due doesn't has Pins for that option.

Sorry for that, but this library is only for the build in RTC for an DS1307 you can use any library from the playground or else (so I think) the wire library is allready portet for the Due so they should work.

Liad

1. Assuming I'll manage to solder a battery to the apropriate pins, is there anything else I should do? [force the SAM3X to enter sleep mode or such] or is it enough to connect the battery?

2. Those RTC libraries I mentioned before doesn't work with an Arduino Due. anyone knows how to fix it?



Liad

While trying to use the Time library from the playground [TimeRTC example] I get the following errors:

Code: [Select]
In file included from TimeRTC.pde:9:
/Applications/Arduino/Arduino 2.app/Contents/Resources/Java/libraries/DS1307RTC/DS1307RTC.h:19: error: 'tmElements_t' has not been declared
/Applications/Arduino/Arduino 2.app/Contents/Resources/Java/libraries/DS1307RTC/DS1307RTC.h:20: error: 'tmElements_t' has not been declared
/Applications/Arduino/Arduino 2.app/Contents/Resources/Java/libraries/DS1307RTC/DS1307RTC.h:27: error: expected ')' before '*' token
/Applications/Arduino/Arduino 2.app/Contents/Resources/Java/libraries/DS1307RTC/DS1307RTC.h:27: error: expected ')' before '*' token
TimeRTC.pde: In function 'void setup()':
TimeRTC:13: error: request for member 'get' in '1074666080u', which is of non-class type 'Rtc*'
TimeRTC:13: error: 'setSyncProvider' was not declared in this scope
TimeRTC:14: error: 'timeStatus' was not declared in this scope
TimeRTC:14: error: 'timeSet' was not declared in this scope
TimeRTC.pde: In function 'void digitalClockDisplay()':
TimeRTC:28: error: 'hour' was not declared in this scope
TimeRTC:29: error: 'minute' was not declared in this scope
TimeRTC:30: error: 'second' was not declared in this scope
TimeRTC:32: error: 'day' was not declared in this scope
TimeRTC:34: error: 'month' was not declared in this scope
TimeRTC:36: error: 'year' was not declared in this scope




SomeRandomGuy

#10
Jan 20, 2013, 05:07 am Last Edit: Jan 20, 2013, 05:19 am by SomeRandomGuy Reason: 1
Good evening,

I just finished sorting through the DS1307 RTC library that is incombatable with the Due, and I have successfully ported it to the due.

I ran one of the examples and was happily reading today's date and time from the external chip.

I have attached the modified library folder.

Also, I believe the examples are all in the old Arduino Sketch format. You may have to open them and do a save-as to a different location in order to get them to compile.

P.S, if you are using adafruit's DS1307 shield, be careful about the voltage being outputted on the I2C pins. I actually removed the pull-up resistors from mine and used my own resistors on a protoboard so that I could run 3.3V to the data pins.

Good Luck!

shteii01

SRG, thank you very much for the library.  Thank you, thank you, thank you, thank you...

I did have to do one modification to get it to compile:
Code: [Select]

RTC_DS1307 RTC;
RTC.begin();
if (! RTC.isrunning())
RTC.adjust(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();

I changed RTC to rtc

Code: [Select]

RTC_DS1307 rtc;
rtc.begin();
if (! rtc.isrunning())
rtc.adjust(DateTime(__DATE__, __TIME__));
DateTime now = rtc.now();


I think Marcus in another thread said that compiler does not like the all capital letters variables.  I got your library, compiled it, it gave errors.  I changed the RTC to rtc, compiled it, it worked.  Uploaded to the Adafruit DS1307 board and it worked.

I got a question about the voltage levels for the i2c for the Adafruit DS1307 board and the Due.  Could you chime in.  I read your post, but I am not sure which resistors you changed.  My thread: http://arduino.cc/forum/index.php/topic,149030.0.html

jake1981

Here's updated version:

Nothing else expect what you said..


jake1981

And here's even better..

I've combined Henning Karlsen's library with RTClib and fixed day of week calculation as well. Library does not require wire.h and works just like RTClib except, you can set alternative sda and scl pins if you like.
Library is available here: https://github.com/oskarirauta/RTCdue


Go Up