Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I am trying to connect the ds1307 to Arduino to get the the time on the LCD and I used this circuit in my project and I tried the example code in the library but it didn't work. What could the problem be?

the code:

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

============================

fritzing breadboard image

share|improve this question
the first one #include <Wire.h> – alone Sep 18 '12 at 20:17
Are you seeing anything at the serial port on the computer? – justing Sep 18 '12 at 20:29

1 Answer

up vote 1 down vote accepted

It won't work if there are no pullups on the lines, because I2C uses an open drain bus.

Add a 2.2kΩ resistor (can be anything between this and 10kΩ, a lower value is better for long lines and higher clock speed) from SCL to +5V and also another one from SDA to +5V (so one between DS1307 pins 5 and 8, another one between pins 6 and 8) .

The resistors (marked Rp) are shown below:

I2C Pullups

If you need the square wave out, you will also need a pullup on this too, details are in the datasheet.

share|improve this answer
oh thanks.... i wiil try this and i hope it work – alone Sep 19 '12 at 6:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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