Skip to content

Overengineering a clock

Like pretty much every­one who ever pulled apart their Nin­tendo Game and Watch so they could beef it up with a speak­er and AA bat­tery hold­er scav­enged from a tran­sist­or radio (that thing was awe­some), I was out­raged when Ahmed was arres­ted. Luck­ily, now I’m an adult with some dis­pos­able income and a pen­chant for col­lect­ing cool gad­gets, so I was able to go home and start build­ing a movie-bomb-like clock pretty much imme­di­ately.

I star­ted with a spare Ardu­ino-com­pat­ible board (the lovely little Freet­ron­ics Elev­en) and a dis­play mod­ule I’d just picked up as an exper­i­ment­al addi­tion for my KSP con­trol pan­el. Had to order in a real-time clock mod­ule, but that gave me a couple of days to get the first few com­pon­ents hooked togeth­er on a piece of pro­to­board and the basics up and run­ning. This was the first time I’d tried using thin strips of board with head­er pins soldered on as ghetto ardu­ino con­nec­tions, and I like how they work for ad-hoc break­outs. The dis­play is an SPI device with a sep­ar­ate RGB back­light, hence all of the ini­tial orange con­nec­tions. 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 con­nec­tion. In hind­sight I also should have hooked up the timer pin on the mod­ule, which gen­er­ates 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.

Basic time-telling device. Not a bomb.

Then I needed some way to house it, without hid­ing all of the gory detail. So I snarfed some 3mm clear per­spex from the box of offcuts at the Robots and Dino­saurs maker space, whipped up a quick set of mount­ing holes in Lib­reCAD (again, I’m get­ting good at design­ing and cut­ting these sorts of pan­els thanks to my work on my KSP con­trol board) and used the robod­ino laser cut­ter to make a face­plate. Bolted all of the pan­els in place, then used a couple of small bits of wood clamped on to the bot­tom of the pan­el with screws to form a base to hold it upright.

Argu­ably a clock now. It sits on a shelf, and time can be determ­ined from some dis­tance. Hasn’t exploded yet.

I guess hav­ing a clock that shows the date and time is a reas­on­able place to stop. A reas­on­able, and very very bor­ing place to stop. So I kept going.

Start­ing simple — that back­light can be pretty bright and annoy­ing. So I bought a light-depend­ant res­ist­or, whacked it on in a corner, and added some code to sample the ambi­ent light level and dynam­ic­ally adjust the LCD back­light. Full bright­ness dur­ing the day, down to almost as low as it can go when the lights are off. Much bet­ter.

For power I used a spare 5V wall wart, again left over from a couple of iter­a­tions of power­ing my KSP con­trol­ler. Poor fore­thought put the Arduino’s bar­rel jack too close to the base for use, but I had a spare one kick­ing around that I was able to screw on to the side of the pro­to­board, and run power leads back to the Ardu­ino.

I’ve had some ESP8266 mod­ules kick­ing around in my parts bin wait­ing for a rainy day for a while now. If you haven’t heard of these things yet, they’re amaz­ing. WiFi, very cap­able micro­con­trol­ler, can eas­ily inter­face with an Ardu­ino or just as eas­ily be repro­grammed with the Ardu­ino IDE, and cost well under $AU10 each. They require 3.3V, and more cur­rent than the Arduino’s onboard reg­u­lat­or can sup­ply. Luck­ily my dis­play also uses 3.3V logic, so I already had a 74HC4050 logic con­vert­er with some spare pins on my board. Just had to add a 3.3V lin­ear reg­u­lat­or and asso­ci­ated capa­cit­ors, and my clock was now online. While I was doing that, I added a few head­er pins to the board, so I could eas­ily attach an FTDI cable to repro­gram the ESP8266, and it made the whole thing look more com­plic­ated.

The pro­to­type board, clock­wise from top middle: 4050 logic con­vert­er, LCD rib­bon con­nect­or, RTC mod­ule, FTDI head­er, LDR, 3.3V reg­u­lat­or, ESP8266. Not shown: explos­ives.

I run an MQTT ser­vice on my home serv­er. It’s a great mul­tipur­pose, mul­tidevice mes­sage bus. My Open­HAB install integ­rates with it. My kodi media play­er pub­lishes now play­ing info on it. My phone pub­lishes (some) loc­a­tion data to it. I have a hand­ful of oth­er Ardu­ino devices that send and receive inform­a­tion across it using the fant­ast­ic pub­sub­cli­ent lib­rary. So I wrote a simple cli­ent for the ESP8266 that joins my home net­work, and sub­scribes to a list of inter­est­ing top­ics on the MQTT bus. Whenev­er it receives any­thing it’s sub­scribed to, it passes it to main clock con­trol­ler using a reg­u­lar seri­al con­nec­tion. Sud­denly I had a thing on the inter­net, with nary a buzzword in sight.

One of the afore­men­tioned Oth­er Ardu­ino Devices on my net­work is a little one-day pro­ject I knocked togeth­er last year. A remote tem­per­at­ure sensor con­sist­ing of an ATTiny84 con­trol­ler, DHT22 temp and humid­ity sensor, and nRF24L01 low-power radio trans­ceiv­er, powered by a couple of AAA bat­ter­ies. That sits out­side and broad­casts cur­rent temp and humid­ity data on MQTT, which mostly just gets used to gen­er­ate nice graphs. Read­ing that to show cur­rent tem­per­at­ure on my clock was trivi­al. Then I added a small script on my serv­er that polls loc­al fore­cast inform­a­tion from the BoM and broad­casts that a few times a day. On the clock side, I star­ted using icons from the free Met­eo­cons weath­er icon col­lec­tion, down­scaled and hand-tweaked. They take up a fair bit of space, but stor­ing them in PROGMEM on the Ardu­ino means I’ve got room for quite a few. This gave my clock cur­rent (ultra)local con­di­tions, and the daily fore­cast. After run­ning this for a while I’m in the habit of check­ing it in the morn­ings instead of, you know, look­ing out­side.

Today’s fore­cast: no kaboom.

The space in the bot­tom left star­ted out just show­ing the text fore­cast pre­cis (which, incid­ent­ally, is won­der­fully poet­ic; I’m hav­ing a hard time using it to accur­ately choose an icon). But there’s so much cool stuff I want to know!

I use pub­lic trans­port all the time — my daily com­mute to work is by train, and I use the bus stop around the corner to get up to New­town a fair bit too. I also use Uber for occa­sion­al rides. The next logic­al step for me was radi­at­ing next depar­ture times for all of the pub­lic trans­port ser­vices I use. The easi­est is Uber, which has a super-simple API to poll approx­im­ate pickup time for a giv­en loc­a­tion. I wrote a quick shell script that runs on my serv­er, polls the Uber API every minute, and broad­casts pickup times on MQTT. Now my clock knows how long I’ll wait for a ride.

I’ve run out of bomb-related cap­tions.

That pretty much brings me to the cur­rent status. Every now and then I tweak the code on the con­trol­ler, adding new icons and try­ing to improve the way it decides which icon to show. I’m still pok­ing at the code required to trans­late the Trans­port Data Exchange info offered by Trans­port for NSW, but to be hon­est it was pretty dis­heart­en­ing to learn that they don’t offer real-time updates to plebs like me who’ll nev­er have more than one user for their pro­ject. Still think­ing about oth­er stuff to toss up in that space, but my recent exper­i­ments with CI for Ardu­ino pro­jects may lead to pub­lish­ing build res­ults in the not too dis­tant future.

This was a really fun pro­ject. Build­ing a clock was some­thing I’d wanted to try for ages but nev­er quite got around to. I’ve wound up with a genu­inely use­ful and hope­fully inter­est­ing-look­ing object.

Like most of my oth­er Ardu­ino pro­jects, the code for this is online: https://bitbucket.org/pjhardy/smartclock . My loc­al repos­it­ory is a couple of revi­sions ahead of that but there’s not much inter­est­ing except for me com­pletely rearran­ging my loc­al net­work after acci­dent­ally pub­lish­ing the WPA key. :/

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*