Datalogger / RTC issue

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Chillermec
 
Posts: 23
Joined: Sun Mar 06, 2011 5:04 pm

Datalogger / RTC issue

Post by Chillermec »

I have successfully built and used the datalogger shield some months back on Uno platform. With the I/O limitations of the Uno, I moved the same logger shield to my Mega board. That proved to be somewhat challenging, and, I have tabled that for the time being. I proceeded to modify the Adafruit Lightemplogger sketch to suit my particular project. It is going well with one exception...... we are on daylight savings time now, and, I cannot get the RTC to sync with my PC. The RTC is keeping time just fine on EST. I am using the following code line from the Datalogger sketch, and, uncommenting it to sync the time.

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

No go with that. I loaded the board with the RTC test code to determine if there is a problem in my sketch, and still can't sync the time. It seems to me that if I am communicating with the RTC to retrieve time / date, it should be able to sync. I have looked over my boards for connection issues, and do not see anything that is obvious.
What is the probable direction I need to go in to troubleshoot at this point?
Thanks for any replies.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogger / RTC issue

Post by adafruit_support_bill »

Here is a logger sketch that works with the Mega: http://forums.adafruit.com/viewtopic.ph ... 18#p148718
Not sure what would prevent the RTC.adjust from working. Have you tried using a hard-coded DateTime like: "DateTime(2010, 1, 2, 3, 4, 5)"

Chillermec
 
Posts: 23
Joined: Sun Mar 06, 2011 5:04 pm

Re: Datalogger / RTC issue

Post by Chillermec »

I am not sure how to format that to write in a current date an time. Can you provide specific date / time change example? I assume that I simply compile and load after that.
I left out of my original post that I have returned the logger board to the Uno.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogger / RTC issue

Post by adafruit_support_bill »

You can hardcode a data/time like this:

Code: Select all

  RTC.adjust(DateTime(12/06/2012, 10:30:00));
Obviously, that doesn't adjust to the data/time of the actual compile. But we are just trying to test that the "adjust" function works at the moment.

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Datalogger / RTC issue

Post by bcook65 »

I am having issues with my RTC.. It gets the time right but is off on the date.. it gets the month and year ok just the day is several days off.. I have reset the rttc a few times and made sure my pc clock/date time were correct and updated.. but still the day is showing 7 days ahead of the actual day.
I have tried the

Code: Select all

RTC.adjust(DateTime(12/06/2012, 10:30:00));
But all that does is generate a lot of errors and fails to upload

Am I missing something??
If I use the original RTC adjust that came in the sketch I get no errors but here are the errors when I run the hard code date/time

sketch_nov21a.cpp: In function 'void setup()':
sketch_nov21a:17: error: invalid conversion from 'int' to 'const char*'
sketch_nov21a:17: error: initializing argument 2 of 'DateTime::DateTime(const char*, const char*)'
sketch_nov21a:17: error: expected primary-expression before '(' token
sketch_nov21a:17: error: expected `)' before ':' token

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Datalogger / RTC issue

Post by Franklin97355 »

bcook which library are you using? Could you post your code?

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Datalogger / RTC issue

Post by bcook65 »

franklin97355 wrote:bcook which library are you using? Could you post your code?
using ds1307

Code: Select all

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(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(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // 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);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”