Go Down

Topic: DS1307 Real time clock on breadboard (Read 52357 times) previous topic - next topic

GordonEndersby

Dear all,

Heres my simple real time clock on a breadboard.
Using the DS1307 http://www.glacialwanderer.com/_blog/blog2008/04_April/DS1307.pdf
The breakout boards you can buy seemed a bit expensive so I decided to hook up the cheap components on a breadboard to try out on my Arduino.
The Crystal is 32768kHz.
The battery is a 3v coin cell in a holder.

Heres a pic


Heres a schematic of the breadboard.
The photo doesn't completely  match the schematic but the wiring and pins are correct.

Thanks to http://code.rancidbacon.com/ElectronicBreadboardTemplates for the inkscape template.

I used the code from this forum topic http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191209057
You need to install the DS1307 library from there.
This code was compiled on version 13 of the ide with a 328p but will work with a standard arduino.
Code: [Select]
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

int rtc[7];

void setup()
{
 Serial.begin(9600);
/*
 RTC.stop();
 RTC.set(DS1307_SEC,1);
 RTC.set(DS1307_MIN,57);
 RTC.set(DS1307_HR,17);
 RTC.set(DS1307_DOW,4);
 RTC.set(DS1307_DATE,18);
 RTC.set(DS1307_MTH,2);
 RTC.set(DS1307_YR,9);
 RTC.start();
*/
}

void loop()
{
 RTC.get(rtc,true);

 for(int i=0; i<7; i++)
 {
   Serial.print(rtc[i]);
   Serial.print(" ");
 }
 Serial.println();

 delay(1000);

}



To initialy set the time uncomment the RTC.set lines and change the values.
Once youve done this the clock is set and the 3v battery keeps the time.

Eventually its going to be incorporated in my main project.
A temperature logging device with one wire temp sensors ,web server, serial lcd display, buttons and using the 328p. But its an ever evolving project. Once I get the time tied up with the temp data, Ill be nearly there.


If Ive made a glaring mistake let me know.

Gordon


Nachtwind

nice summary - was quite useful to me (as i had the same in mind ^^)
Maybe two small additions:
1) It seems the chip does not run without a 3V supply on Pin 3 - so you have to either hook up a 3V battery on it or attach it to the 3V Pin of the arduino (of course data is not saved the second way).

2) I very much doubt that you used a crystal that "is 32768kHz." ;0)  Its a 32.768kHz crystal ,0). Its not a big story, but i was wondering as it didnt run (see 1)  if i had used the wrong one ;0)

Thanks again for that post :0)
Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

GordonEndersby


I thought Id put it together as Id found the info from various sources.

1, Yes I missed the decimal point, 32.768kHz

2, Thats why they recomend the button cell.
If you dont mind setting the time on reboot of the arduino then the real time library is easier and doesnt have external  components.
I wanted something that would survive power down so used the 3v button cell and holder.
I hear they can last nearly 9 years?
Some button cell holders have longer leads underneath that make it easier to plug in to the breadboard.

Ive just put an Atmel 168 on a breadboard and got it working. Next im going to put the 168 and DS1307 on stripboard ready to make a binary clock. Always wanted a binary clock.

Gordon

retrolefty

Don't forget that the DS1307 has a programmable clock pulse output pin avalible on it's pin 7. I think it defaults to 1 sec clock output.

If you wire that to a jumper pin and then onto a Arduino I/O pin you have a source for contious clock for your applications. If wire it to pins 2 or 3 you can use it as a freerunning interrupt source.

Lefty

bHogan

Here's a little function that sets the clock pulse output pin on the DS1307 . . .
Code: [Select]
void Set_Square_Wave(int rate){  // set the square wave output on pin 7 of the DS1307 chip
 rate = rate + 144;                         // add 0x90 (dec 144) to rate
 Wire.beginTransmission(0x68);              // write the control register
 Wire.send(0x07);                           // register address 07H)
 Wire.send(rate);                           // 90H=1Hz, 91H=4kHz, 92H=8kHz, 93H=32kHz
 Wire.endTransmission();
}


Pass it 0-3 (maybe 1-4 :)) and get 1 of the 4 outputs. Always thought it could come in handy, but never thought of using it for interrupts - nice idea.

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

peter247

No , the DS1307 will work without the 3v battery .
It just resets after each reboot , so is o.k for the set up tests where the need a clean chip.
http://peter224722.blogspot.com

Nachtwind

Interestering.
I tried yesterday the time i wrote that small paragraph. without three volt on that pin it didnt 'update' the time while running 0o...

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

peter247

All I can say is that my DS1307 does, but will just revert back after every power off.

So far my LED clock which is using the DS1307 for timing looks to be almost working.
4 * 74LS47, and a MCP23016-1/SP , I think I went mad with the chip count over programming complexity .
I could have done the same thing with just 2 * MCP23016-1/SP chips, But looking at other LED shields they don`t even have that.
http://peter224722.blogspot.com

metRo_

GordonEndersby
the code that you posted in the first post work with ds1337?

GordonEndersby


Shiwa

I tried to set the year of DS1307 with #include <DS1307.h>
till 2012 its OK
but e.g.

RTC.set(DS1307_YR,13);
or  RTC.set(DS1307_YR,98);
dont work.
or date 31

what is the problem ?

itsthemedication

Thanks Gordon for the excellent photos.  Here is a link to three code sets tested on the duemilanove and the mega.  The first set allows you to set the arduino time manually using epoch time.  The second set lets you set the arduino clock and the 1307 real time clock using epoch time, and the third set is the basic code to set the arduino using an rtc1307 that has been set to current time.  Hope this helps.

http://sites.google.com/site/measuringstuff/code-examples#TOC-DS1307-Real-Time-Clock-

alm7100

Hi GordonEndersby

Just remember when you are using a webpage to set the time, i'ts a byte and not at char there is used to set the time.

CowJam

Running without a 3v cell...
Quote
I tried yesterday the time i wrote that small paragraph. without three volt on that pin it didnt 'update' the time while running 0o...


You need to link the pin to ground that would otherwise go to the positive terminal on the battery.

Shiwa

nice to see activity here today, who recognized my problem ? #10

Go Up