February 5, 2012

Retro Space Invaders Gmail Notifier

Filed under: gmail,technology,weekend projects — Grant @ 9:49 am

A couple of weeks ago I was in our local Boots chemist. They were clearing out all the Christmas gifts at 75% off.  I saw this Space Invaders alarm clock reduced to around £3 ($5) and had to have it, even though I had no use for another alarm clock.  (Btw, even though Boots are now sold out, the same clock is available from Play, IWOOT, Menkind and others.)

The challenge was… what to do with it?

In the end I decided to turn it into an ambient device, connected to the internet and capable of alerting me when things happen. Right now I’ve got it firing up with a new message arrives in my Gmail inbox, but really it could do anything – flag up Twitter replies, indicate the chance of rain or even, paired with one of my previous projects, act as an additional ringer for the doorbell.  I’ve added a row of LEDs (three red, three yellow) to give it some more feedback options.

Every time I get a new email the clock moves from side to side and does the classic Space Invaders sound, then lights one of the LEDs to give me an idea of how many unread messages there are.  There’s loads more that could be done with it, but I was happy just turning it into something more useful without destroying it in the process.

If you want to make one yourself, here’s what I did…

I used an Arduino to give the clock some more logic. I didn’t want to alter the external appearance of the clock and space was incredibly tight inside, so I used an Arduino Nano clone that I had lying around.

First step was to get the components working on a breadboard. I ran 6 LEDs off the Arduino’s digital pins and added an opto-isolator to another digital pin to act as a switch. I knew the Arduino wouldn’t be able to drive the clock’s motor straight off an IO pin, so my plan was to simply trigger the clock’s handy ‘demo’ button from the pin and deliver the main clock/motor power from the direct 5V pin on Arduino.

Here’s the wiring layout that I ended up with…

The original power source for the clock was 3 AA batteries producing around 4.5v. I was planning to power the clock directly over USB – I figured 5V was close enough – so the battery compartment provided the perfect space to house the additional components. Unfortunately the battery box wasn’t quite deep enough for the Nano, so my first job was to cut out the battery recess with a craft knife. I left a small lip on the bottom edge to support the additional components and to retain the original motor mounting point.

With a bit of breadboard trimming (with a hacksaw… quick and nasty!) I was able to fit it into the clock…

Next step, the Arduino sketch. The code is currently dead simple: listen to the serial input and if it’s a number, light that many LEDs; if the new number is higher than the old number (i.e. you’ve got new emails, not just cleared out old ones) then also close the ‘demo’ switch to activate the sound and movement. Here’s the finished code.

int ser = 0; // for incoming serial data
int prevCount = 0;
int timer = 100;
void setup() {
 for (int thisPin = 2; thisPin <= 13; thisPin++) {
 pinMode(thisPin, OUTPUT);
 }
 Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {

 if (Serial.available() > 0) {
 // read the incoming byte:
 ser = Serial.read();
if (ser >= 48 && ser <= 58) {
 int newCount = ser - 48;
 if (newCount > 0 && newCount > prevCount) {
 digitalWrite(12, HIGH);
 delay(100);
 digitalWrite(12, LOW);
 delay(1500);
 digitalWrite(12, HIGH);
 delay(500);
 digitalWrite(12, LOW);
 }
 prevCount = newCount;
 } else {
 digitalWrite(13, HIGH);
 delay(100);
 digitalWrite(13,LOW);
 }
 }
for (int thisPin = 3; thisPin <= 11; thisPin++) {
 digitalWrite(thisPin, LOW);
 }
int topPin = prevCount + 2;
for (int thisPin = 3; thisPin <= topPin; thisPin++) {
 if(thisPin <= 5) {
 digitalWrite(thisPin, HIGH);
 } else {
 digitalWrite(thisPin+3, HIGH); // Because I left a gap in the digital pins
 }
 }
}

The last step was to write a quick script to poll Gmail and get the number of unread messages.  I’ve tried lots of different languages for Arduino serial control in the past – Perl, PHP and DOS shell scripts – but every time it’s been a little bit flakey, at least under Windows. Flash Actionscript is pretty reliable using Serproxy, but that was overkill for this project. So in the end I decided to give Python a go. It was a good choice – reliable and really quick to implement.  Here’s the code…

import serial
import time
import imaplib
ser = serial.Serial('COM6', 9600)
time.sleep(2)
while True:
 obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
 obj.login('GMAIL_USER_HERE','PASSWORD_HERE')
 obj.select()
 obj.search(None,'UnSeen')
 count = len(obj.search(None, 'UnSeen')[1][0].split())
if(count > 9):
 ser.write(':')
 else:
 ser.write(count)
time.sleep(120)
ser.close()

The only bit that had me scratching my head was Arduino’s trick of resetting every time the serial line is opened.  The Nano takes around 1.5 seconds to restart, meaning it would always miss the first mail notification. A wee sleep command fixed that.

And that’s about it. Three hours and around £12 of components (including the Nano clone) to turn an alarm clock into a Gmail notifier.

Future scope

There are still lots of free pins on the Nano, so plenty of scope for expansion. A light sensor could be a useful addition so it doesn’t trigger when the room lights are off, and maybe a knock sensor so it could be set to ‘snooze’ with a quick tap. Apart from that, most other mods would be software-based. I might make the three red LEDs linked to Gmail and the yellow ones linked to Twitter.

If you decide to make one of your own please let me know.  And if you make any improvements to the software, please share!

November 18, 2011

My Christmas e-card for the Herald & Times Group

Filed under: technology,work — Grant @ 7:00 pm

For the past couple of years I’ve had the dubious honour of being asked to produce the Christmas e-card for the Herald & Times Group.  It’s always a tricky brief – produce a seasonal e-card without dragging myself or others away from a busy schedule.

In previous years I’ve just pulled together a picture, some clip art and a Christmas-y tune in Flash to make something like this: http://www.heraldandtimeslabs.com/christmas2010/

…which is OK, but not very exciting.  So this year, I decided to try something different.

Over the space of a week I took around 3,500 still photos around our Glasgow office and Cambuslang print plant.   I then stitched these photos together using a free Mac app called Time Lapse Assembler to produce a pretty smooth 30 frames/sec timelapse video.  In turn, this was edited to match an appropriate Christmas tune in iMovie.  Here’s the result…



Two cameras were used on the shoot.  Most of the pics came from my Nikon D3100 using both an 18-55mm zoom and an 8mm fish eye for the really wide angle shots.  Interval timing was handled by a great little remote shutter release I got off eBay for about £15.  It does everything the official Nikon one does for about a tenth of the price.

My backup camera was a Ricoh CX1 which I used to capture a second angle while the D3100 was in use (like when the drivers were loading their trucks and while everyone gathered for the final “Merry Christmas” shot).

In total I reckon I spent approx four hours shooting the pics (elapsed time was more like 18 hours, but most of the time I could leave the camera and get on with other work) and then about another three hours assembling the footage and editing in iMovie.  So, for less than a day’s work — or about the same as I’d have spent creating another cheesy Santa animation — I reckon we got a much better result.

Producing this video has really given me the timelapse bug, so for Christmas I’m getting a custom-built robotic tripod head which will allow me to combine real tilts and pans with my timelapse photography.  Exciting stuff!

September 5, 2011

Great Scottish Run + Facebook: An experiment in crowdsourcing metadata

Filed under: technology,Uncategorized,work — Grant @ 4:47 pm

The Great Scottish Run took place on Sunday.  Two races – a 10K and a half-marathon – happened under this banner and as always the Herald & Times photographers where there to capture the action.

As in previous years, we ended up with thousands of photographs.  And, as in previous years, we made hundreds of those photos available to buy via our photo sales site.  But the problem we’re always left with is one of discovery: without having the names and email addresses of those pictured, how could we let people know their photo is available to buy?

So, this year we’re trying a new experiment.  As well as putting the pics up on our photo sales site we’re also uploading them all to Facebook.  Users are able to ‘tag’ themselves and their friends in our photos with prizes available to act as an incentive.  All the pics going up on Facebook have a unique reference number which allows them to be found quickly and easily on our photo sales site.

Adding this reference number was actually the trickiest part of the whole process – standard Photoshop actions, even combined with the new Photoshop Variables feature, don’t offer the flexibility needed for this.   Instead, the solution was to script a Photoshop extension in Javascript that would extract the reference number, overlay it on the image and resize the output to a Facebook-friendly res.  What… you can script Photoshop in Javascript?  Who knew?  Not me, until last week.

Anyway, it’s early days but it seems to be working quite well so far.  The technology part was a breeze and should be reusable in future with mimimal effort.

Unfortuantely the Evening Times Facebook page was only five days old at the time of the Great Scottish Run, so we were a bit short of friends to give this a big kickstart.  Hopefully we’ll be able to use this technique again in future to aid discoverability of our photo sales service.

If you took part in the run, go here to see  if you can find yourself or your friends!

August 26, 2011

How to access the Kingston Wi-Drive from *any* web-enabled device

Filed under: technology — Grant @ 5:49 pm

The Kingston Wi-Drive is a new kid on the storage block.   Aimed at providing extra storage to iOS devices, it pairs a wireless SSD storage gadget with a free iPhone app to double the capacity of your Apple handheld.  I’m currently writing up my review of it for The Herald.

What they don’t tell you anywhere on the packaging or instructions (and by implication deny) is that the Wi-Drive works with ANY web and Wi-Fi enabled gadget.

Want to use the Wi-Drive with an Android phone or tablet, Windows or Mac laptop?

Here’s how… Simply connect to the Wi-Drive’s Wi-Fi AP then point your browser to http://kingston.  As if by magic, the main window of the iOS app appears within your browser.  You can browse folders and open files just like in the app…. or perhaps more accurately, just like the internet.

I’ve tested it on a few different devices – phone, tablet and laptop – and it works nicely on all of them.  It’ll even stream movies quite happily from the web interface.

Personally, I think this transforms the Wi-Drive from a super-niche proposition (iPhone users who are stuck for space and aren’t due an upgrade) to something far more mainstream and interesting.

August 24, 2011

First thoughts on Google’s Page Speed Service

Filed under: google,technology — Grant @ 11:28 am

I’m currently Beta testing Google’s new Page Speed Service on my site.  It’s basically a transparent page content optimiser and CDN which aims to speed up delivery of sites to end users. This could be a huge deal for anyone who, like me, hosts their site from home.

Hosting a personal site from home is a great idea, and something I’d strongly recommend to anyone.  As well as learning the basics of server configuration and maintenance you also get several unique benfits, like:

The one problem with hosting from home is bandwidth.  A basic DSL or Cable line is fine for handling modest everyday traffic (this site gets between 300 and 1,000 visits per day), but isn’t suited to handling large spikes.  Hopefully, Google’s Page Speed Service (PSS) will be able to smooth out those spikes and give me the best of both worlds.  So far it’s looking good. (more…)

August 19, 2011

9bulb: a Twitter client in nine lamps

Filed under: technology,weekend projects — Grant @ 12:02 am

What is it?!

I was in B&Q a few weeks ago and this LED panel caught my eye.  It’s not the type of thing I’d normally buy but I fancied its hacking potential as an ambient device of some sort.

Taking the back off revealed a set of nine mini circuit boards, each with a red, green and blue LED plus a simple circuit to cycle through those colours.  The wiring couldn’t have been simpler – the 5V DC power supply ran to a switch with each of the LED boards wired in parallel from that.

(more…)

Next Page »

Powered by WordPress