I mentioned last time that I wasn’t happy about the way I was using the DS32KHz timer – I had it connected to INT0 (digital pin 2) to count the 32768 interrupts per second. There had to be a better way and, as often, Nick Gammon had the answer. Using Nick’s excellent write up and TimerHelpers code, it was easy enough to connect the DS32KHz’s clock to digital pin 5 (T1 input) and have Timer1 count the 32768 pulses before generating an interrupt.
In the first attempt I directly connected the two boards and soldered the buttons and CdS sensor to the processor board – using long wires to make the soldering easy. That was a disaster, it made it extremely hard to get everything in the case and virtually impossible to get the clock display straight.
I’ve done this before, it’s always a bad idea. Especially when you’ve already bought Pololu crimp connectors and housings to avoid making this mistake again – I got mine from Proto-Pic, here are the female connectors. They are tricky to use but well worth persevering with. So, the re-built setup looked like this:
The boards are connected with a ribbon cable (Data In, Load and Clock for the MAX7219 and +5V and Gnd). There’s a ribbon cable with a 6 pin male header on it for connecting to a SparkFun FTDI Basic Breakout (excellent devices for programming custom boards and much cheaper than an FTDI cable) – it’s 6 pins for compatibility with the FTDI breakout, only Reset, Rx, Tx and Gnd are wired up.
There are 2 pin connectors for the buttons and CdS sensor too making it easy to take apart and easy to get the bits into the “case”.
Battery backup turned out to be a waste of time. I figured out the chips actual internal reference voltage (guess who had a great write up on power saving, reference voltages, etc). Using a resistive divider (two resistors and a blue link wire towards the top right in the image above) I could easily measure what the voltage was. The idea was to detect if on battery and put the MAX7219 to sleep, then power off as much of the ATmega328 as well before putting it to sleep. It would wake up once per second when the timer interrupt occurred so could periodically test the voltage before going to sleep again.
I was looking forward to that but I didn’t realise at the time that it would (of course it would, Duh!) cock up the measurement of the photo-resistor unless I ran that through an identical voltage divider. Pillock!
To add insult to injury, there was only one logical place to put the clock in the living room…
It powered by yet another random 5V 1A power supply (don’t even know what it was originally used for). When I plugged that into an extension bar behind the telly, guess what? Yup, the extension is plugged into a beefy UPS! All that faffing about trying to put a backup battery in and it’s not really needed. It’ll lose it’s time when it gets moved but it really is easy to set the time with just two buttons:
- Press “Button 1” for more than 0.5s and release – hours flash
- Press “Button 2” to set hours
- Press “Button 1” – minutes flash
- Press “Button 2” to set minutes
- Press “Button 1” when you want that time to “start” (seconds = 0)
Overall, it was enjoyable to build and it’s easy to get at the programming connector. Haven’t done anything about securing the components into the case permanently. Given what we use it for it might not be necessary (and there are plenty of other things I want to play with…)
I’ve updated the github repo with the software that’s on there. I really should clean it up and fix an annoying bug during setting the clock (Timer1 should be disabled when programming the clock otherwise the minutes can change on you just as you are about to set the time). May get around to it, may not.