RTC clock never returns as isrunning

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Hassurunous
 
Posts: 4
Joined: Tue Oct 14, 2014 12:23 pm

RTC clock never returns as isrunning

Post by Hassurunous »

I'm currently working on a project, and I noticed that every time the arduino loses power, when it powers back on, the rtc has been reset. My code is extremely long, so instead of trying to debug a few thousand lines of code, I decided to try ou the ds1307 example from the RTClib, and it is doing the same thing. I'll list what I'm using first, then post the code.

Parts:
Mega 2560 Arduino Board
Adafruit Mega 2560 protoboard
Adafruit DS1307 Breakout board

Code from Example:

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);
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  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(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

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);
}
This is the serial read. Each time I hit the reset button, I get the message RTC is not running, as you can see.

Code: Select all

RTC is NOT running!
2165/165/165 165:165:85
 since midnight 1/1/1970 = 2217973585s = 25670d
 now + 7d + 30s: 2040/1/111 23:46:55

RTC is NOT running!
2165/165/165 165:165:85
 since midnight 1/1/1970 = 2217973585s = 25670d
 now + 7d + 30s: 2040/1/111 23:46:55

RTC is NOT running!
2165/165/165 165:165:85
 since midnight 1/1/1970 = 2217973585s = 25670d
 now + 7d + 30s: 2040/1/111 23:46:55
I can't submit pictures at the moment, but I've triple checked the connections, and I can read from and set the RTC in real time, without any errors, except for this one. I currently have the rtc soldered to the protoboard, using headers, with wires going from the SCL and SDA headers to the SCL and SDA pins on the arduino.

I haven't tested the battery yet, but I'm going to grab one in the morning to try that. Any other ideas?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RTC clock never returns as isrunning

Post by adafruit_support_rick »

Not sure. We have seen similar problems with a bad ground connection to the RTC. You might check your soldering on that.

User avatar
Hassurunous
 
Posts: 4
Joined: Tue Oct 14, 2014 12:23 pm

Re: RTC clock never returns as isrunning

Post by Hassurunous »

That's a definite possibility. The soldering looks good, but I do have it connected to the ground rail on the protoboard. https://www.adafruit.com/product/192

I'll try wiring directly to the arduino ground, to see if that helps. I suppose I might have gotten a faulty protoboard.

User avatar
Hassurunous
 
Posts: 4
Joined: Tue Oct 14, 2014 12:23 pm

Re: RTC clock never returns as isrunning

Post by Hassurunous »

Wired directly to Mega 2560 (using jumpers on the headers) to 5V, GND, SDA, and SCL. Still getting the same message. Forgot to grab that battery, but that's just about the last thing I can think of. Well, that or a defective RTC breakout board.
Last edited by Hassurunous on Wed Nov 19, 2014 4:36 pm, edited 1 time in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: RTC clock never returns as isrunning

Post by adafruit_support_rick »

Battery is worth a try, but it should still work without it.

User avatar
Hassurunous
 
Posts: 4
Joined: Tue Oct 14, 2014 12:23 pm

Re: RTC clock never returns as isrunning

Post by Hassurunous »

It wouldn't hold the time after the board lost power without the battery, though, correct? I'll try the battery tomorro and report back. Otherwise, I'll get some good pictures of the board and the protoboard and post them tomorrow evening. Thanks for the help!

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

Return to “Other Arduino products from Adafruit”