Pages: [1] 2   Go Down
Author Topic: RTC Gurus please Help me  (Read 1900 times)
0 Members and 1 Guest are viewing this topic.
Slovakia
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
// 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:
Code:
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  smiley)
THANKS a lot I'm desperate...
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What does this say to you?

Code:
void setup () {
    Serial.begin(57600);
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.begin(DateTime(__DATE__, __TIME__));
}
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

But how can I modify this sketch to set the right time?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Alright, Can you give me clue what sketches to use, please?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, you could use a sketch of the Mona Lisa...

Or you could simply split your current sketch in two - remove the bit that sets the time from the existing sketch and put it in a new sketch.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Well, this didn't help me a lot.I cant compile Mona Lisa smiley(not declared in this scope smiley), and I'm beginner, need more dummies like stuff. Sorry 
Logged

Leeds, England, (dis)UK
Offline Offline
God Member
*****
Karma: 16
Posts: 708
Quick, chuck it in the bin before the boss finds out...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Compile and upload your program again. When you do this it replaces the tokens __DATE__ and  __TIME__ with the current date time.

Then without unplugging the Arduino, remark out the line

RTC.begin(DateTime(__DATE__, __TIME__));

And compile and upload the sketch again.
Logged

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

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

Thanks Dannable,
I loaded code
Code:
#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:
Code:
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
Code:
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
Code:
2106/2/6 6:28:16
 seconds since 1970: 0
 now + 7d + 30s: 2106/2/13 6:28:46


Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You still need an RTC.begin in your second version of the code to enable the RTC module.

Try replacing
Code:
   RTC.begin(DateTime("Mar 04 2013","20:20:20"));
with a simple
Code:
  RTC.begin();
in the second version.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Hi majenko,
cant compile, I'm getting
Code:
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&)
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post a link to the RTC library you are using?
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Its the one from adafruit tutorial on github:https://github.com/adafruit/RTClib
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Aha...  You're not actually using your RTC module at all.

Quote from: 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.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 361
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Its the one from adafruit tutorial on github:https://github.com/adafruit/RTClib

If you compare the  "ds1307" example with the "softrtc" example from the library, it will become clear...

You want to use the "ds1307" example.  smiley

Cheers,
John
Logged

Pages: [1] 2   Go Up
Jump to: