Real Time Clock
I didn’t like my first design as the batteries would only last about ten days, so I wanted a design that would last longer. Technobabble:
The reason batteries didn’t last long is that I had to keep power on the AtMega328 (Arduino) continuously to keep the software real time clock running. So I need to be able to put the AtMega328 to sleep or turn it off.
My friend sent me some of these RTC (Real Time Clock) modules: http://www.ebay.co.uk/itm/Arduino-I2C-Tiny-RTC-DS1307-Real-Time-Clock-Module-AT24C32-Board-AVR-MCU-PIC-/221176522620?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item337f25e77c http://www.ebay.com/itm/I2C-Tiny-RTC-DS1307-Real-Time-Clock-Module-AT24C32-Board-for-AVR-MCU-PIC-DIY-/231037403500?pt=LH_DefaultDomain_0&hash=item35cae7016c
These come with an RTC with battery backup and an EEPROM which is also helpful. Problem:
So I have a concern about these modules. Note that the battery is an LIR2032 which is a rechargeable battery. I suspect that it has a charging circuit. Well, I found a schematic and decided to draw my own (see picture). It does have a charging circuit and it would put an additional load on the 18650 battery. Solution:
So for this module, if you remove R5, D1, R4 and R6 and put a jumper across R6 and replace the battery with a CR2032, this will eliminate the battery charging. So that is what I did (see picture).
In this application, the CR2032 is supposed to last about ten years so I have no problem with that. Warning:
I was using an old library from AdaFruit for their datalogger called RTCLib. There was a sketch called DS1307.pde that would set the time. Now this worked fine the first time it was run but then it wouldn’t set the time. There is an updated version with an example that works better: https://github.com/jcw/rtclib
Download the zip, unzip it, rename it from rtclib-master to rtclib and copy it to your Arduino libraries directory. TechnoSpeak I2C:
Technically it should be I(squared) C or IIC which stands for Inter-Integrated Circuit. Basically it is a ‘standard’ serial interface requiring two signals SCL, SDA and ground. SDA is the data signal switching from 0V to 5V with the data going across in sequence (serially). Since there are only two levels and the speed isn’t determined, there is no way to determine where one bit of data ends and the next begins. That is where the SCL (clock) signal comes in. This tells the receiving device where one bit ends and the next begins.
One advantage to I2C is that several devices can be attached to the same two signals. In this case the DS1307 (RTC) and the 24C32 (EEPROM) are both attached to the SCL and SDA lines. In order to tell which device you are talking to each device type has a unique address.
The DS1307 address is 0x68. The 24C32 address is 0x50.
Arduino supports I2C with the ‘wire’ library.
By the way, what this means is that you can’t have more than one of the same device type on the same two lines. E.g., you can’t have two 24C32s.