I'm using the DS1307 RTC together with arduino and this library http://rweather.github.com/arduinolibs/classDS1307RTC.html

When i power the chip directly from the 5V and GND outputs from my arduino UNO all works well.

When i power the chip using a digital pin with output set to HIGH for voltage input and/or a digital pin with output set to LOW for GND the library is unable to read the time from the RTC.

This exact same configuration does work with library provided by adafruit http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/understanding-the-code

But i would like to use the rweather library because it provides more features ( like easier access to the RAM and an alarm convenience function ), it's also much better written and well documented.

The following code works with both libraries but only fails with the rweather library when not using 5V and GND directly. When starting with 5V and then switching to an output pin the library can read the time, so it seems that this is related to a start up issue of some sort.

#include <Wire.h>
#include <RTC.h>
#include <SoftI2C.h>
#include <DS1307RTC.h>

void setup() 
    pinMode(7, OUTPUT);
    pinMode(6, OUTPUT);
    // provide power for the RTC module
    Serial.print("Setting output\n");
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    Serial.print("output Set\n");
    Serial.print("delay over\n");

    SoftI2C bus(5, 4);
    DS1307RTC controller(bus, 3);

    Serial.print(controller.isRealTime() ? "controller is realtime" : "controller is simulating");

    RTCTime theTime;

    Serial.print("startup time");

void loop() 

  • \$\begingroup\$ Are you setting the right pins? If you are plugging in the board right in the arduino headers, you need Pins 3 and 2, not 6 and 7. If you set analog pin 3 (digital 17) to an OUTPUT and HIGH and analog pin 2 (digital 16) to an OUTPUT and LOW you can power the RTC directly from the pins! \$\endgroup\$ – Passerby Feb 22 '13 at 21:28
  • 1
    \$\begingroup\$ @Passerby: But "Low" is not 0V reference in this case. The ground for the device can be 0.3V or higher than the board ground, and this might cause issues. \$\endgroup\$ – Gustavo Litovsky Feb 22 '13 at 21:44
  • \$\begingroup\$ @GustavoLitovsky that is why i have also tested the setup with the GND of the RTC connected directly to GND of the arduino, the library only works when connecting both RTC 5V and GND to the arduino 5V and GND directly \$\endgroup\$ – Willem D'Haeseleer Feb 22 '13 at 21:46
  • \$\begingroup\$ @WillemD'haeseleer: Try several I/O pins together for more current, and perhaps my test that I outlined below to see whether it's just a startup issue. Did you add any decoupling capacitors? \$\endgroup\$ – Gustavo Litovsky Feb 22 '13 at 21:48
  • 1
    \$\begingroup\$ @WillemD'haeseleer based on the edits, your question isn't why it doesn't work at all, but "Why does it work with Library A, and not Library B", correct? With Ada's library, you can use the digital outputs to power the rtc, but not with Rweather's? You should edit the question to reflect that more boldly. \$\endgroup\$ – Passerby Feb 22 '13 at 22:54

I guess the arduino pin cannot source enough current for the RTC. Try use a transistor to command the power for the RTC. Use npn one, connect emitor to +5V of the arduino, base to arduino pin and collector to +5V of the RTC.

  • 1
    \$\begingroup\$ The RTC uses very very low current, and can be powered by the digital pins, unless they have a lot of current draw on other pins. You can even power some lcds (nokia ones for example) directly from a microcontroller. The RTC only needs 1.5mA, during active reads, less when simply keeping time. \$\endgroup\$ – Passerby Feb 22 '13 at 21:31
  • \$\begingroup\$ @Passerby i have edited my question with more info \$\endgroup\$ – Willem D'Haeseleer Feb 22 '13 at 21:39

My suspicion is that the device is drawing a higher peak current, perhaps at startup, and this is the reason for the failure. There is a way to test this. Simply connect the device to VCC and start it up. Then connect it to the I/O pin providing power, without allowing the power rail to crater. See if that works.

Another thing you should try is to connect multiple I/Os together to try and see if that can enable you the extra current it needs. Some decoupling capacitors might be needed to stabilize the device.

[Edit:] I hadn't originally noticed that you were also running the ground from an I/O pin. This isn't necessary and as I said, it will make ground reference higher than the microcontroller's, and perhaps cause marginal digital signaling that will cause issues.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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