DS1307 timestamp difficulties

Howdy folks! I’m trying to get my DS1307 to give an accurate timestamp when called, but it just gives the following:

RTC is NOT running!
2165/165/165 (Sunday) 165:165:85
since midnight 1/1/1970 = 2090769489s = 24198d
now + 7d + 30s: 2036/4/10 5:48:15

2165/165/165 (Sunday) 165:165:85
since midnight 1/1/1970 = 2090769489s = 24198d
now + 7d + 30s: 2036/4/10 5:48:15

2165/165/165 (Sunday) 165:165:85
since midnight 1/1/1970 = 2090769489s = 24198d
now + 7d + 30s: 2036/4/10 5:48:15

I’m using the default testing code built into the library, and this is what comes back.

I tested the voltage going to the I2C board, and it comes back a little above 4.5V - which should be within range, if I’ve read correctly.

I’ve also tested my button cell battery, and it comes in at ~3.1V - Also within range, I think?

Here’s the code I’m using to test the I2C:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  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(daysOfTheWeek[now.dayOfTheWeek()]);
    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 + TimeSpan(7,12,30,6));
    
    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);
}

If I’ve left out any information that will help, please let me know.

Thank you for reading (and helping)!

Here's a pastebin of the code, in case it helps.

No, please don't give us a wastebin link. Please read the post: How to use this forum - please read. and then post the code using code tags.

You should run an I2C scan sketch to see if the RTC is visible. Triple check all your hardware connections.

Thanks for your response!

I ran the I2C scanner and found zero devices. I used a second board of the same type I ordered at the same time, and it also found zero at the time. I triple-checked my connections in hopes it was that, but they seem correct.

Is it possible I have two bad boards? I'm not sure how to interpret this, honestly.

Thank you again

Well, we're in hardware territory now. So we need complete information about which Arduino, which RTC, photos of your setup, diagrams, links, any and all information that you can provide.

It's probably a wiring error.

Is it possible I have two bad boards? I'm not sure how to interpret this, honestly.

It's not likely that you have two bad devices. "Found 0 device(s)" is usually due to an open on SDA or SCL. It should be easier to trouble shoot than if the scanner had hung up and made no return.

First as aarg says, verfiy there is no wiring error, and that you are using the correct pins for i2c on the Arduino you are using.

If you are using jumper wires, change them. Verify the soldering on the pins going to the module. If the pins are plugged into a breadboard, try different holes.

If you have no success, go to the datasheet for the ds1307 and verify, unpowered, with a multimeter that you have continuity from the Arduino to the legs on the chip with SDA.SCL, Power and Gnd.

Do you have pullups on the SCL & SDA pins also?

CrossRoads:
Do you have pullups on the SCL & SDA pins also?

+1, but OP, this question can often be answered with knowledge of the RTC module that you give us. So again please do post…

aarg:
Well, we’re in hardware territory now. So we need complete information about which Arduino, which RTC, photos of your setup, diagrams, links, any and all information that you can provide.

It’s probably a wiring error.

Sure thing!

Hardware:

Arduino Yun
Breadboard
DS1307 Real Time Clock Breakout Board Kit
USB connection
No pullups(not sure exactly what these are, though I’m googling!), though I didn’t know I’d need them.

Ideally I’ll be able to pull a timestamp from the I2C for other readings. I just need to get this going to complete other projects I’m working on.

Thank you!

Capture.JPG

The Yun has SDA and SCL on pins 2 and 3.

Difficult to tell as the Fritzing is useing A4 and A3.

Edit D2 D3 for Yun

aarg: The Yun has SDA and SCL on pins 2 and 3.

I swapped these on the Yun, and didn't see a change after re-upping the code.

The scanner still shows zero devices.

LarryD: Difficult to tell as the Fritzing is useing A4 and A3.

I also tried using the A4 and A3, but the scanner didn't change.

SDA is D2 and SCL is D3 on Yun

No pullups(not sure exactly what these are, though I'm googling!), though I didn't know I'd need them.

The pullups are built into the board, That's what R1 and R2 are.

https://github.com/adafruit/DS1307-breakout-board/blob/master/ds1307.png

LarryD: SDA is D2 and SCL is D3 on Yun

Awesome! It seems either I didn't read the instructions properly, or they weren't clear. I'm blaming myself on this one, however(had the connectors in analog ports).

I want to thank EVERYONE who took the time to reach out and help me with this project! I'm not sure how long it would've taken me to figure this out otherwise.

THANK YOU!!

RTC is NOT running! 2016/4/10 (Sunday) 19:54:40 since midnight 1/1/1970 = 1460318080s = 16901d now + 7d + 30s: 2016/4/18 8:24:46

2016/4/10 (Sunday) 19:54:42 since midnight 1/1/1970 = 1460318082s = 16901d now + 7d + 30s: 2016/4/18 8:24:48

2016/4/10 (Sunday) 19:54:45 since midnight 1/1/1970 = 1460318085s = 16901d now + 7d + 30s: 2016/4/18 8:24:51