Real Time Clock – DS1307

For my Topsy Turvy clock project I’ve purchased an I2C clock module based on the DS1307 Real-Time Clock chip. As mentioned this came without a battery to keep the post office happy. Although looking at the current wording of the postage restrictions there should have been no issue sending a single battery with the module.

Not actually knowing what battery to get I purchased a CR2016 as that was what my supermarket had in stock. I realised that the code numbers refer to the size so a CR2016 is 20mm diameter x 1.6mm and a CR2032 vs is 20mm diameter x 3.2mm but apparently the thinner ones work ok with most sockets.

Luckily before I actually got around to wiring this up I spotted this thread about exploding batteries on the Arduino forum.

IMPORTANT: Rather than a CR2032 battery, this board requires a rechargable LIR2032 battery.

I’ll have to source one of these batteries or make the modifications mentioned in the above forum link.

My board came without instructions but as it was an I2C device I did not expect any issues (particularly now I’ve got some code for checking I2C addresses). I did a bit of googling and found a few extra bonus features of the board. Firstly, it also contains a AT24C32 I2C EEPROM for storage, I’m not sure I’ll need this but it could come in handy. Some versions of this board also contain a single wire temperature sensor, I’m not sure if this is supposed to be used to check for clock drift or again it’s just a useful feature. However, mine just has empty pads where that component would be mounted.

The board has 2 sets of pins one on each side. I was initially worried that one of these was for the EEProm and one for the clock but it turns out they are just mirrored connections that can be used for connecting through to another device.

I can envisage that if you wanted to do data logging of temperature then this would be an ideal little board to use (assuming you had a temperature IC installed).

I ran the I2C scanner code and it detected two distinct devices at different addresses, I did not actually need to use these but the fact it detected them means that the board was operational and I’d wired it up ok.

I tried various versions of the DS1307 library, the first I tried from NZ did not compile but this one from DFRobot compiled ok for the Uno. DFRobot also had the schematic for the board and I notice that the SDA and SCL already have pullup resistors on them. I had to tweek the code slightly so that it always wrote the initial value on start-up but once I did that it ran ok and periodically displayed the time via the serial port. The code appeared to allow you to set the time but I did not work out what format it was expecting. Once I’ve sorted the battery out I’ll integrate this RTC code with the code for the steppers and put together a suitable serial “UI” for setting the clock.

Example code

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available

Notify me of followup comments via e-mail. You can also subscribe without commenting.