Like pretty much everyone who ever pulled apart their Nintendo Game and Watch so they could beef it up with a speaker and AA battery holder scavenged from a transistor radio (that thing was awesome), I was outraged when Ahmed was arrested. Luckily, now I’m an adult with some disposable income and a penchant for collecting cool gadgets, so I was able to go home and start building a movie-bomb-like clock pretty much immediately.
I started with a spare Arduino-compatible board (the lovely little Freetronics Eleven) and a display module I’d just picked up as an experimental addition for my KSP control panel. Had to order in a real-time clock module, but that gave me a couple of days to get the first few components hooked together on a piece of protoboard and the basics up and running. This was the first time I’d tried using thin strips of board with header pins soldered on as ghetto arduino connections, and I like how they work for ad-hoc breakouts. The display is an SPI device with a separate RGB backlight, hence all of the initial orange connections. When the RTC arrived I was able to quickly bung it on the board and add a little bit of extra code to read time from it over an I2C connection. In hindsight I also should have hooked up the timer pin on the module, which generates a pulse every second. But didn’t and am too lazy to go back and redo it now. At any rate, after that I had a clock that was able to show me the time.
Then I needed some way to house it, without hiding all of the gory detail. So I snarfed some 3mm clear perspex from the box of offcuts at the Robots and Dinosaurs maker space, whipped up a quick set of mounting holes in LibreCAD (again, I’m getting good at designing and cutting these sorts of panels thanks to my work on my KSP control board) and used the robodino laser cutter to make a faceplate. Bolted all of the panels in place, then used a couple of small bits of wood clamped on to the bottom of the panel with screws to form a base to hold it upright.
I guess having a clock that shows the date and time is a reasonable place to stop. A reasonable, and very very boring place to stop. So I kept going.
Starting simple — that backlight can be pretty bright and annoying. So I bought a light-dependant resistor, whacked it on in a corner, and added some code to sample the ambient light level and dynamically adjust the LCD backlight. Full brightness during the day, down to almost as low as it can go when the lights are off. Much better.
For power I used a spare 5V wall wart, again left over from a couple of iterations of powering my KSP controller. Poor forethought put the Arduino’s barrel jack too close to the base for use, but I had a spare one kicking around that I was able to screw on to the side of the protoboard, and run power leads back to the Arduino.
I’ve had some ESP8266 modules kicking around in my parts bin waiting for a rainy day for a while now. If you haven’t heard of these things yet, they’re amazing. WiFi, very capable microcontroller, can easily interface with an Arduino or just as easily be reprogrammed with the Arduino IDE, and cost well under $AU10 each. They require 3.3V, and more current than the Arduino’s onboard regulator can supply. Luckily my display also uses 3.3V logic, so I already had a 74HC4050 logic converter with some spare pins on my board. Just had to add a 3.3V linear regulator and associated capacitors, and my clock was now online. While I was doing that, I added a few header pins to the board, so I could easily attach an FTDI cable to reprogram the ESP8266, and it made the whole thing look more complicated.
I run an MQTT service on my home server. It’s a great multipurpose, multidevice message bus. My OpenHAB install integrates with it. My kodi media player publishes now playing info on it. My phone publishes (some) location data to it. I have a handful of other Arduino devices that send and receive information across it using the fantastic pubsubclient library. So I wrote a simple client for the ESP8266 that joins my home network, and subscribes to a list of interesting topics on the MQTT bus. Whenever it receives anything it’s subscribed to, it passes it to main clock controller using a regular serial connection. Suddenly I had a thing on the internet, with nary a buzzword in sight.
One of the aforementioned Other Arduino Devices on my network is a little one-day project I knocked together last year. A remote temperature sensor consisting of an ATTiny84 controller, DHT22 temp and humidity sensor, and nRF24L01 low-power radio transceiver, powered by a couple of AAA batteries. That sits outside and broadcasts current temp and humidity data on MQTT, which mostly just gets used to generate nice graphs. Reading that to show current temperature on my clock was trivial. Then I added a small script on my server that polls local forecast information from the BoM and broadcasts that a few times a day. On the clock side, I started using icons from the free Meteocons weather icon collection, downscaled and hand-tweaked. They take up a fair bit of space, but storing them in PROGMEM on the Arduino means I’ve got room for quite a few. This gave my clock current (ultra)local conditions, and the daily forecast. After running this for a while I’m in the habit of checking it in the mornings instead of, you know, looking outside.
The space in the bottom left started out just showing the text forecast precis (which, incidentally, is wonderfully poetic; I’m having a hard time using it to accurately choose an icon). But there’s so much cool stuff I want to know!
I use public transport all the time — my daily commute to work is by train, and I use the bus stop around the corner to get up to Newtown a fair bit too. I also use Uber for occasional rides. The next logical step for me was radiating next departure times for all of the public transport services I use. The easiest is Uber, which has a super-simple API to poll approximate pickup time for a given location. I wrote a quick shell script that runs on my server, polls the Uber API every minute, and broadcasts pickup times on MQTT. Now my clock knows how long I’ll wait for a ride.
That pretty much brings me to the current status. Every now and then I tweak the code on the controller, adding new icons and trying to improve the way it decides which icon to show. I’m still poking at the code required to translate the Transport Data Exchange info offered by Transport for NSW, but to be honest it was pretty disheartening to learn that they don’t offer real-time updates to plebs like me who’ll never have more than one user for their project. Still thinking about other stuff to toss up in that space, but my recent experiments with CI for Arduino projects may lead to publishing build results in the not too distant future.
This was a really fun project. Building a clock was something I’d wanted to try for ages but never quite got around to. I’ve wound up with a genuinely useful and hopefully interesting-looking object.
Like most of my other Arduino projects, the code for this is online: https://bitbucket.org/pjhardy/smartclock . My local repository is a couple of revisions ahead of that but there’s not much interesting except for me completely rearranging my local network after accidentally publishing the WPA key. :/