Step 3The time keeper
So I moved on to the Real Time Clock piece of the puzzle. At this point it is worth discussing why there is a RTC in the circuit. One approach to solving my problem would be to simply send a raw counter from the Arduino and then do all of the heavy lifting at the receiving end. However, on reflection I liked the idea that I could use the battery backed RAM on the DS1307 as a store for my counter and that my "packet" of data would be able to broadcast the time that the count was accurate. This may seem like an odd decision but I think in the long term its going to serve me well.
The DS1307 is an i2c device and there are a number of articles on the device on the internet (as well as interfacing to an Arduino), so I am not going to concentrate on the ins and outs of the device. Instead I shall illustrate a pitfall I came across and the eventual design I went for.
My initial idea was to have the DS1307 RAM be the store for the counter and that during the interrupt handling routine I would read and then update the counter. However, I discovered that whilst the Wire library in Arduino is really useful it won't work in an interrupt routine (which is fair enough).
My second approach, which worked, was to maintain a counter in the Arduino RAM and then, after a configured delay in the main loop, write the value out to the DS1307 RAM.
The circuit diagram shows the connections for the DS1307 and how I hooked it up to the Arduino (note that the Futurlec mini-board I used already has the required pull-up resistors and therefore they aren't shown on the diagram).
So now I had the second building block in place. I had a means of capturing a date and time and a counter value updated by an interrupt routine.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
















































