Electronic – arduino – DS1307 RTC not working with rweather library

arduinortc

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.begin(9600);
    Serial.print("Setting output\n");
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    Serial.print("output Set\n");
    delay(2000);
    Serial.print("delay over\n");

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

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

    RTCTime theTime;
    controller.readTime(&theTime);

    Serial.print("startup time");
    Serial.println();
    Serial.print(theTime.hour);
    Serial.print(":");
    Serial.print(theTime.minute);
    Serial.print(":");
    Serial.print(theTime.second);
}

void loop() 
{

}

Best Answer

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.