DS1307 RTC library

Im using the DS1307 library that comes with the arduino software, but it doesnt seem to have a "isrunning?" command which is causing problems for me. Is there a better library, or a way to preform this inquiry?

Have you supplied power to the DS1307? If so, it isRunning(). There is no need for a function to tell you that.

I use this one: adafruit's RTClib

Here are a couple of simple sketches that I have used (not particularly efficient use of Arduino processing power, but maybe enough to get people started):

//
// DS1307SetTime.pde
//
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//
// RTClib from https://github.com/adafruit/RTClib
//
// davekwx
//

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup ()
{
    Serial.begin(9600);
    Wire.begin();
    rtc.begin();

    char inbuf[80];
    char outbuf[80];
    int i;
    unsigned year;
    unsigned month;
    unsigned day;
    unsigned minutes;
    unsigned hours;
    unsigned seconds;
    Serial.print("Enter date/time: YYYYMMDDHHMMSS");
    while(Serial.available() < 14)
        ;
    Serial.println();
    for(i = 0; i < 14; i++) {
        inbuf[i] = Serial.read();
    }
    sscanf(inbuf, "%4d %2d %2d %2d %2d %2d ", &year, &month, &day, &hours, &minutes, &seconds);
    sprintf(outbuf, "YYYY = %d, MM = %02d, DD = %02d, HH = %02d, MM = %02d, SS = %02d",
            year, month, day, hours, minutes, seconds);
    Serial.println(outbuf);
    rtc.adjust(DateTime(year, month, day, hours, minutes, seconds));
}

uint8_t oldSeconds = 0;
void loop ()
{
    DateTime now = rtc.now();
    if (now.second() != oldSeconds) {
        char buffer[100];
        oldSeconds = now.second();
        sprintf(buffer, "%s %s %2u %d %02d:%02d:%02d",
        now.weekDay(), now.mon(), now. day(), now.year(), now.hour(), now.minute(), now.second());
        Serial.println(buffer);

    }
    delay(200);
}

and

//
// DS1307ShowTime.pde
//
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//
// RTClib from https://github.com/adafruit/RTClib
//
// davekw7x
//
#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"

const int ledPin = 13;
RTC_DS1307 RTC;

// initialize the lcd with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup ()
{
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
    Wire.begin();
    RTC.begin();
    lcd.begin(20,2);

    if (! RTC.isrunning()) {
        Serial.println("RTC was not running, you will have to run DS1307SetTime.");
        Serial.println("For now, I'll set the RTC to the date and time the program was compiled.");
        Serial.println("For better initialization, run Dave's DS1307SetTime sketch.");
        Serial.println();
        // following line sets the RTC to the date & time this sketch was compiled
        RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

uint8_t old_seconds = 0;
void loop ()
{
    DateTime now = RTC.now();
    if (now.second() != old_seconds) {
        char buffer[40];
        old_seconds = now.second();
        sprintf(buffer, "%s %s %2u %d %02d:%02d:%02d",
        now.weekDay(), now.mon(), now.day(), now.year(), now.hour(), now.minute(), now.second());
        Serial.println(buffer);
        lcd.setCursor(0,0);
        sprintf(buffer, "%s %s %2u %d    ", now.weekDay(), now.mon(), now.day(), now.year());
        lcd.print(buffer);
        lcd.setCursor(0,1);
        sprintf(buffer, "    %02d:%02d:%02d       ", now.hour(), now.minute(), now.second());
        lcd.print(buffer);

    }
    delay(200);
}

Output from DS1307ShowTIme on the serial monitor (See Footnote.)


Fri Mar 11 2011 17:02:35
Fri Mar 11 2011 17:02:36
Fri Mar 11 2011 17:02:37
Fri Mar 11 2011 17:02:38
Fri Mar 11 2011 17:02:39
Fri Mar 11 2011 17:02:40
Fri Mar 11 2011 17:02:41
.
.
.

Regards,

Dave

Footnote:
For a convenient display I added the following two functions to RTClib.cpp to make it easy to display month and day of week as short "strings."

const char *DateTime::weekDay() const
{
    static const char *day [7] = {
        "Sun", "Mon", "Tue", "Wed",
        "Thu", "Fri", "Sat"
    };
    return day[dayOfWeek() % 7];
}
// January = 1, February = 2, ...
const char *DateTime::mon() const
{
    static const char *m[12] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };
    return m[month()-1];
}

And I added the ;public function declarations in RTClib.h

    const char * weekDay() const; // String abbreviation
    const char * mon() const;

The same type of things could be done with external functions, but I decided to make them part of the class.

PaulS:
Have you supplied power to the DS1307? If so, it isRunning(). There is no need for a function to tell you that.

In fact, when the chip is completely powered down and back up again it is not running, and a flag is set in a DS1307 register that indicates that the device is not running.

Testing that flag is a really good way to see if the backup battery is working, and to see whether you need to set the time (and then start it running). The RTClib that I downloaded from adafruit has the function the Original Poster was asking about. I showed a way to use it in the DS1307ShowTime sketch in my previous post.

Regards,

Dave

Hi guys, I'm also having problem with my RTC. I'm using the adafruit lib, but I'm unable to set the time. Running the "ds1307" example always gives me the following output :

2000/0/0 0:0:0
 since midnight 1/1/1970 = 2313941504s = 26781d
 now + 7d + 30s: 2043/5/6 17:32:14

2000/0/0 0:0:0
 since midnight 1/1/1970 = 2313941504s = 26781d
 now + 7d + 30s: 2043/5/6 17:32:14
...

I'm a newcomer in arduino. The DS1307 starts to get hot after a minute or two. Is there something wrong?

The DS1307 starts to get hot after a minute or two. Is there something wrong?

Depends if you want to cook toast on it or tell the time. How do you have it wired up?

It's a small rtc shield that i got from eBay. There are two ways to connect it using A4-A5 directly or with some sda and sdc connection.

el_pablo:
The DS1307 starts to get hot after a minute or two. Is there something wrong?

Yes. It should not be warm to the touch at all.

el_pablo:
It's a small rtc shield that i got from eBay. There are two ways to connect it using A4-A5 directly or with some sda and sdc connection.

Wow I wasn't expect this but I just bought that same one from eBay and mine almost burned me when I touched it. I really hope we didn't get ripped off :disappointed_relieved:
I am also a new and idk what to make of that... Idk el_pablo maybe if we both have the same issue we should demand a refund

I'm not sure these ebay store from China even care for their customers... I will send him the link to this thread.

This overheating problem is probably unrelated to the original post and deserves a new thread.

Right now all we know is that your 'eBay' devices are not operating properly. We have no way of knowing if you are doing something wrong or if the devices are just defective. If you provide us with a link to the eBay source we can:

(1) Possibly come up with some information to help you make your devices function properly.
or
(2) Not order from that source and avoid similar problems ourselves.

Don

This is the RTC shield that I bought.

el_pablo:
This is the RTC shield that I bought.

http://cgi.ebay.ca/DS1307-Based-Real-Time-Clock-Arduino-I2C-/230584918558?pt=LH_DefaultDomain_0&hash=item35afeea21e#ht_753wt_1139

Yup that is the same one i have. I have never worked with a RTC before and because of the complexity of the code and process of using it, it would be difficult for me to be able to tell if 1). I am not using it right 2). I broke it...? 3). or i didn't break it, it came faulty

But because i followed instruction given for a similar RTC and el_pablo has the same issues. I am getting the feeling its not our fault or we are missing some kind of instructions.

Should i email the seller? and what should i say.

PS. if our DS1307 IC got that hot does that mean that they are now fried? Because guessing by normal ebay policy i will have to pay for return shipping and for the same price i can get another new DS1307 IC...?

Well there are loads of DS1307 based RTC modules out there on the internet but I could not find any other places (besides other similar eBay sites in different countries) that sold that particular module. All of the eBay sites with that module display the same information (or lack of information).

The module is unique in that it is designed specifically for the Arduino and it should be idiot proof. Unless of course it was an idiot who designed or assembled the board. When you get an overheating chip it is frequently because the power is connected backwards. I can't tell any of this from the provided picture but it is possible that:
(1) they got the pin spacing wrong so you aren't getting 5V and GND at the left set of pins when the pins at the right are in 4 and 5.
(2) they got the wiring to 5V and GND backwards.
(3) they got the chip in backwards.

What is the labeling on the five pins opposite the Arduino? If the left one is VCC then the chip is in correctly, if it is GND then the chip is in backwards. If you provide some nice clear pictures of both sides of the board I may be able to determine if the other guesses are correct.

if our DS1307 IC got that hot does that mean that they are now fried?

Re-fried chips sometimes still function but they are frequently out of spec.

Don

HOT POTATOES ... i figured it out el_pablo you need to put 2 10k pull of resistors between the A4/A5 pins. So (A4-Arduino) and (A4-10K Resistor- 5vcc) and the same for A5...

Here is a picture

But i thought RTC module already has resistors? I can see them on the board... anyways ... a little of a pain that i have to uses external components

ds3232wiring.png

I'm pretty much a noob and I had no trouble getting my 1307 running on a breadboard without a shield. It's a pretty simple circuit.

But i thought RTC module already has resistors? I can see them on the board...

They typically are on the board but not connected unless you install a jumper. They are configured that way because if you use several I2C devices you must have only one set of pull-up resistors connected. Did your board come with any documentation.

Don

I'm pretty much a noob and I had no trouble getting my 1307 running on a breadboard without a shield. It's a pretty simple circuit.

It will run OK that way but the clock may not be accurate. There are some very specific requirements for the physical configuration of the crystal.

Don

Thanks Eric, I'll give it a try later.

EP