5

My board.

Arduino Board

I think I have it wired correctly (the lights aren't, but the board is).

I've read through the first few Google results to no avail.

My sample code to test the chip:

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

RTC_DS1307 rtc;

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

void setup () {
  while (!Serial); // for Leonardo/Micro/Zero

  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);
}

Serial output:

`RTC is NOT running!
2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85    
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31
0

10 Answers 10

3

Had the same issue, however, my RTC was 1302 (not 1307) and yours seems to be as well, please check. If it's 1302, use this library: https://github.com/msparks/arduino-ds1302

Also, make sure you connect pins like this:

  1. Arduino Pin 7 goes to CLK
  2. Arduino Pin 6 goes to DAT
  3. Arduino Pin 5 goes to RST
  4. Arduino 5+ goes to VCC
  5. Arduino GND goes to GND
2

Your picure shows also another device on the bread board. Remove that and ensure that:

Uno Ground --> 1307 Ground

Uno 5Volt --> 1307 +5v

Uno A4 --> 1307 Data

Uno A5 --> 1307 Clock

If the 1307 has a power led indicator, it should be lit.

If that still does not work, then in the code, comment this line out:

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

and uncomment this line to set the 1307 with a specific time stamp:

// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
2

Put in the following line in void setup():

Wire.begin();

(Assuming Wire library has been included.) This will set up the I2C connection between the Master (Arduino) and the Slave (RTC).

For more generic use, the syntax is: Wire.begin(address);

The complete code is:

void setup () {
  Wire.begin();
  Serial.begin(9600);
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // UNCOMMENT TO SET TIME & DATE TO THAT AT COMPILATION.
  //rtc.adjust(DateTime(2017, 8, 31, 14, 45, 14 )); // UNCOMMENT TO SET TIME & DATE MANUALLY. (YEAR, MONTH, DAY, 24-HOUR, MINUTE, SECOND) 

}
2

On the DS3231 seems like the device can get unsynchronized with the microcontroller. Not sure if the same problem with DS1307 I think worth trying. My complete solution on stackoverflow for the same question

The I2C interface is accessible whenever either VCC or VBAT is at a valid level. If a microcontroller connected to the DS3231 resets because of a loss of VCC or other event, it is possible that the microcontroller and DS3231 I2C communications could become unsynchronized, e.g., the microcontroller resets while reading data from the DS3231. When the microcontroller resets, the DS3231 I2C interface may be placed into a known state by toggling SCL until SDA is observed to be at a high level. At that point the microcontroller should pull SDA low while SCL is high, generating a START condition.

2

I had the same "165" problem. Very intermittent. Turns out that I was drawing too much power from the Arduino rails for the circuit I was controlling. I was being lazy by not powering it independently when I started. Nick Gannon on arduino.cc showed where the 165 came from and solved my problem. He included the bcd math.
https://forum.arduino.cc/index.php?topic=184908.0

1

With the Arduino Due, the 165 problem came up intermittently with a knock off DS3231 (compatible with 1307 supposedly). Tried switching to a different RTC but it didn't help. Switching to an Arduino Mega 2560 seems to have resolved it. The Mega 2560 is a lot slower so maybe it was a clock speed issue? In any case, it was useful for resolving the intermittent issue.

That said, if you always get 165:165 it means your Arduino is not communicating with your RTC. This is a different problem and won't be solved by switching Arduinos.

0

I can verify that the 1302 does not work with the 1307 library. Very different chips. No I2C on the 1302. I'm trying to setup an autosync with the 1302 by studying how the 1307 does it... not having a lot of success. I did it once before, and it is driving me bonkers that I can't figure it out again.

0

I had the same exact issue and discovered that the Tiny RTC 1307 board. I found that the board I had was operating at 3.3v. Once I moved the board to a 3.3v pin on my Arduino Nano.

0

I had same issue. Put in setup rtc.begin();

1
  • rtc.begin is already in the OP's setup method. May 25, 2021 at 12:29
-1

I had the same problem 165/165.

I change the Crystal 32 kHz which solved my problem.

1
  • 1
    At best, this answer is extremely cryptic and hard to understand. Can you explain why changing the crystal solved the issue?
    – MichaelT
    Jan 23, 2019 at 12:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.