Hi,
I spend over 15 hours fighting to get my RTC module one like thishttp://www.emartee.com/product/42059/Tiny%20RTC%20DS1307%20Shield%20V2.0) to work. I checked at least 100 times connectors - set as on webpage, red 100 topics on this forum but still cant make it run. I'm using IDE 1.0.3 with this sketch:
// Date and time functions using just software, based on millis() & timer
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime(__DATE__, __TIME__));
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" seconds since 1970: ");
Serial.println(now.unixtime());
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}
in serial monitor comes out my time:
2013/3/3 20:40:36
seconds since 1970: 1362343236
now + 7d + 30s: 2013/3/10 20:41:6
2013/3/3 20:40:39
seconds since 1970: 1362343239
now + 7d + 30s: 2013/3/10 20:41:9
2013/3/3 20:40:42
seconds since 1970: 1362343242
now + 7d + 30s: 2013/3/10 20:41:12
but after I close serial monitor and open it later it starts on same time. When I upload this code with no RTC attached happens same thing - as RTC wouldn't be there anytime.
I changed the battery - same thing. Is there any code to check if RTC module is good? Can be this affected with many different libraries for DS 1307 i have in Libraries folder(I think I downloaded and tried all of them :))
THANKS a lot I'm desperate...
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime(__DATE__, __TIME__));
}
The whole point of the RTC is that you don't need to set the "right" time. It remembers it.
I suggest two sketches. One which does the initial setting of the time and storing it in the RTC, and the other "working" sketch which uses the time in the RTC.
The way you have it at the moment won't even remotely work. Every time you connect to the serial port the Arduino resets. That will reset the time in the RTC to the time the sketch was compiled.
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime("Mar 04 2013","20:20:20"));
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
.
.
.
serial print was ok like:
2013/3/4 20:20:20
seconds since 1970: 1362428420
now + 7d + 30s: 2013/3/11 20:20:50
After that I remarked RTC setup
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
//RTC.begin(DateTime("Mar 04 2013","20:20:20"));
}
void loop () {
and the serial monitor shows
2106/2/6 6:28:16
seconds since 1970: 0
now + 7d + 30s: 2106/2/13 6:28:46
sketch_mar04a.ino: In function 'void setup()':
sketch_mar04a:12: error: no matching function for call to 'RTC_Millis::begin()'
D:\Arduino\arduino-1.0.3\libraries\RTClib/RTClib.h:41: note: candidates are: static void RTC_Millis::begin(const DateTime&)
Aha... You're not actually using your RTC module at all.
RTClib.h:
// RTC using the internal millis() clock, has to be initialized before use
// NOTE: this clock won't be correct once the millis() timer rolls over (>49d?)
class RTC_Millis {
You need to be using the RTC_DS1307 class instead. You then have RTC.begin(); and RTC.adjust(DateTime(DATE, TIME));
The begin() call turns the module on, and the adjust(...) call sets the time and date in the RTC module itself - only ever needs doing once to set the time initially.
Those figures are typical of no communication between the Arduino and the RTC. The RTC is an I²C device, so it must be connected correctly to the right I²C pins (depending on your board), and have pull-up resistors on the lines of typically 4.7K?.
Do you have that?
Can you provide some good clear photographs of your setup?