Sunday, January 23, 2011

DS1307 Tinkering

A couple of weeks ago I finally had a chance to assemble the Adafruit DS1307 Breakout Board I bought awhile back.  The DS1307 is a popular real-time clock that communicates with an I2C interface.  The Adafruit board is a really simple kit - the DS1307 itself, a timing crystal, a bypass capacitor, a couple of pull-up resistors for the I2C bus, and backup coin cell.



Once I got the board assembled, I started to interrogate the DS1307 with my Bus Pirate (another recent purchase).  The Bus Pirate is a great tool for testing and experimenting with new hardware.  In a nutshell, it's a device that connects your computer's USB to a variety of common interfaces like I2C, SPI, 1-Wire, etc.  Using the Bus Pirate's command-line interface, one can quickly evaluate a device by sending the appropriate bit patterns and monitoring the response.  There's a bunch of tutorials for the the Bus Pirate at the Dangerous Prototypes web site, including one for the DS1307.  Loosely following that tutorial I quickly verified that my DS1307 was working.




Once I verified the device worked, I wrote a quick and dirty Arduino program to display the time.  My plan was to use the Arduino to directly drive a four-digit seven-segment display I had in my junk box.  I used seven digital outputs for the segments and four additional digitals for each digits common cathode.  Using a timer interrupt routine, the display digits are scanned by setting segment bits high and one of the digit CC lines low every time the timer overflow interrupt fires.  (The source code is over here at github.)



While the display worked, I was disappointed by how dim it appeared.  I slowed down the scan rate by putting a counter dividing variable in the timer ISR, but that didn't help.  It looked dim even when I slowed down the scan rate to 1 second per digit.  (Obviously the scan flicker at that rate is exaggerated, but I wanted to see what effect the scan rate had on the dimness.)   So thinking dimness might be due to the Arduino's inability to source or sink enough current to light the display brightly, I added some driver transistors to the circuit to drive the LEDs from an external power supply.  (Schematic below.) That didn't help either, so for now I'll chalk it up to the display itself and its lack of contrast under my shop light and lack of red filter.  However, the LED segments do seem to glow a little brighter when tested with a power supply, so the transistor approach probably could be made to drive the LED brighter.  But that's for another day...

No comments: