Pages: [1]   Go Down
Author Topic: Arduino due DS1307 RTC library  (Read 6973 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?


Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//rtc_clock.set_time(10, 29, 9);
  //rtc_clock.set_date(22, 10, 2012);

The date was 1.1.2007


Am I missing something?
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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


Logged

Cookeville, TN
Offline Offline
Newbie
*
Karma: 3
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

* RTClib.zip (5.54 KB - downloaded 92 times.)
« Last Edit: January 19, 2013, 11:19:52 pm by SomeRandomGuy » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
RTC_DS1307 RTC;
RTC.begin();
if (! RTC.isrunning())
RTC.adjust(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();
I changed RTC to rtc

Code:
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
Logged

Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's updated version:

Nothing else expect what you said..


* RTClib.zip (11.48 KB - downloaded 104 times.)
Logged

Finland
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 3
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not working
Logged

Pages: [1]   Go Up
Jump to: