Updated DS1307 simple library for arduino 1.0 and older

Hi all

I just corrected a few bugs in the DS1307.h library found on this forum, and added 1.0 compatibility.

I added a new example sketch with detailled comments, in french and in english
(DS1307_demo_en or _fr)

You can find the archive here :
http://bricofoy.free.fr/forums/arduino/DS1307.zip

Please report bugs to bricofoy (at) free.fr

Enjoy

Hello,

I'm relatively new to the Arduino platform and am trying to use the DS1307 for
a timestamp source. I've downloaded the DS1307.h library and have tried to run
some of the examples. The sketches compile and load without error
but the output is not a valid date (for example the DS1307_demo_en sketch
produces the following timestamp: "Actual time : 45:85:85 7 165/45/2165")

What pins should I be using for SDA and SDC on the Arduino UNO?

Thank you,

sda is A4 and sdc is A5. You must have pullups resistors somewhere on the I2C bus, only on one device.

Regarding the program output, did you set time in the ds1307 first ?
When entering for exemple h00m00s00 R , and then some spaces, what is the next output ?

bricofoy,

I just pulled out my DS1307 this morning and finally decided to hook it up. It's good to see the community already active with support. But, I, too, get the same results as miker. To answer your question, when I enter 'h00m00s00 R ' I get the following output:

Actual time : 45:85:85 7 165/45/2165
hours set to 0

Actual time : 45:85:85 7 165/45/2165
minutes set to 0

Actual time : 45:85:85 7 165/45/2165
seconds set to 0
Actual time : 45:85:85 7 165/45/2165

Actual time : 45:85:85 7 165/45/2165

Actual time : 45:85:85 7 165/45/2165

And here's what I get when I enter 'h08m59s00M03D25Y12':

Actual time : 45:85:85 7 165/45/2165
hours set to 8

Actual time : 45:85:85 7 165/45/2165
minutes set to 59

Actual time : 45:85:85 7 165/45/2165
seconds set to 0

Actual time : 45:85:85 7 165/45/2165
month set to 3

Actual time : 45:85:85 7 165/45/2165
day of month set to 25

Actual time : 45:85:85 7 165/45/2165
year set to 12

Actual time : 45:85:85 7 165/45/2165

Any idea what the problem might be?

Gene

i am getting errors like error wconstants.h: no such file or directory what is my problem pls help me

gdahilig:
Any idea what the problem might be?

Gene

I'm afraid not :frowning: Seems the communication with the ds1307 is wrong. Are you sure about your I2C bus ? Do you have another I2C device to connect on the bus and try to see if it works ? Make sure you did not reverse SDA ans SDC pins between arduino board and DS1307.

I'm quite puzzled you got the exact same output Miker got... Looks like a software bug (or you both have the exact same hardware issue, but this sound strange). It should be interesting to know wich arduino version you and miker are using ? So you should also try with another library for the DS1307, maybe there is a large bug lurking around in the one I updated :confused:

santoshaxl:
i am getting errors like error wconstants.h: no such file or directory what is my problem pls help me

What arduino IDE version are you using ? I tested with both 1.0 (wich I use) and 0.22 and it worked fine.

Please include the complete error message and tell us what program are you trying to compile, one of yours or one of the examples provided with the library ?

I'm running Arduino v.1.0 software and the board is an Arduino Uno rev 3 board. I checked the SDA and SDC pins the were correct. I tried switching them anyways just in case and that didn't work. I'll see if I can dig up another I2C device to see how that works.

Nick Gammon has a I2C scanner on his (very good) website - Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino - that might be of help...

I just tried to reproduce the error you got, and the only way to produce something like that (but not with the exact same output) was to short-circuit sda and sdc, or to use wrong pullup resistor value.

can you try the i2c scanner robtillaart mentionned ?

okay, miker and gdahilig, I eventually got your exact same output :

Heure actuelle : 45:85:85 7 165/45/2165

I achieved this... when unpluging the DS1307 !

So this is exactly what I suspected : there is a problem in your I2C bus, perhaps wrong pullup resistors values, or more basically your ds1307 chip is just dead.

In the next release of the lib, I will include a communication test to verify DS1307 respond before any further operation, and output a warning in such case.

bicofoy,

Sorry it took so long for me to reply. Pull up resistors did the TRICK. I had none (doh!), but once those were put in, it all seems to work great!

Thanks for the much appreciated help!

gene

bricofoy:
Hi all

I just corrected a few bugs in the DS1307.h library found on this forum, and added 1.0 compatibility.

I added a new example sketch with detailled comments, in french and in english
(DS1307_demo_en or _fr)

You can find the archive here :
http://bricofoy.free.fr/forums/arduino/DS1307.zip

Please report bugs to bricofoy (at) free.fr

Enjoy

I tried to show the time and date in arduino with RTC 1307, but after I turn off the power and turn it on again the next day, hour and date don't update,, confused why

Do you have a backup battery on the RTC?

robtillaart:
Do you have a backup battery on the RTC?

yes I put 3.3 volt battery also in DS1307, but date not updating, the time updating but late from time actually...

why? i'm confused...

Maybe your RTC is "broken".

I have a couple of tiny RTC bought on ebay and one of them works fine and the other one, when I poweroff external battery, loses the hour. So, external battery doesn't work. I tried with the other one's battery and same happends.

But the other one, works fine with and without external power.

3.3 volt battery also in DS1307

did you check with a voltmeter, ( I cannot count the number of dead batteries I tried in my life)

On my Arduino Uno Rev3, I had the exact same problem:

Actual time : 45:85:85 7 165/45/2165

But I use a prefab RTC board which already has pull up resistors and a rechargeable backup battery included.

Whatever I tried, it was just not working.

Double checking the wiring did not reveal any mistake made by me, so I decided to check the A4 en A5 ports. Guess what? I was using the SDA & SCL contacts that are positioned next to the Aref pin. Measuring those pin to A4 and A5, gave me the solution: SDA was connected to A4, but SCL is not connected to A5. BTW: SCL seems to be connected to nothing on my Arduino Uno R3.

Maybe it is coincidence, and am I in possesion of the only board with that fault, but it wouldn't do any harm to check your board if you're having troubles with I2C communication.

And many thanks for the library, it seems to work perfect, with very understandable commands.