header text

a blog of things that I (eventually) make work

Thursday 10 March 2016

Smart Mirror - Software Update

I've now integrated the PIR module I've had kicking around for a while into my Processing sketch:


As you can see, the data displays for a set amount of time after motion is detected, and then hides. 

This was achieved simply by wiring the PIR module to one of the GPIO pins of the Pi, and then reading the state of the pin in Processing (which now has native support for hardware IO built in to the Raspberry Pi distribution).

The next step is to use an optocoupler to get the backlight of the screen to turn on and off using this same method, to allow the screen to be completely hidden from view when the mirror is idle.

Wednesday 9 March 2016

Smart Mirror - Custom composite cable

Yesterday I mentioned that the composite video cable for the Raspberry Pi that I bought was far too long. It serves its purpose well, but at 3m long it would be a bit ridiculous to include it in the final build of the frame.

The newest models of the Pi (including the 3, which I recently bought but have yet to even power up...) do not include a full size RCA jack for composite video like previous models did, but instead use a three-ring 3.5mm jack, providing combined stereo audio and video, similar to some old camcorders or the original iPod video.

To make my own cable, I was going to need to source one of these jacks from somewhere. I didn't want to cut up my iPhone headphones, so went off to Poundworld in the hope they'd have a cheap set that included a microphone (which use the same jack, except the extra connections are for the mic). I didn't find any of these, but as luck would have it, I did find a remote shutter release for smartphones, a bit like this one. This had a three ring jack attached to it, so I bought one and cannibalised it.

Here's the cable I built during testing:


(Yes it's a bodge, but it works!)

I later epoxied the crap out of both ends of the cable to allow for some strain relief.

As ever with projects like this, I've thought of a bunch of other features I want to add (feature creep again...) so the new to do list is even longer than yesterday:
  • Build a custom short composite video cable for the RPi. The one I bought is far too long for this and could be the source of some of the signal problems I've been having with the screen, so a shorter custom one should fix this. DONE
  • Add in a 19V -> 5V converter module. This is already ordered but is shipping directly from China. Because the screen needs 12-24V DC for power, I'm using an old universal laptop power supply for it. I'd like to use the same source to power the Pi, so that only one cable has to enter the frame, so a small DC-DC buck converter module should do the trick.
  • Software updates as necessary. I've not modified the software since the last blog post about this, so I need to add in the PIR module (so that the screen isn't always on) and make a couple of other improvements.
  • Switch out the Raspberry Pi 2 for a Raspberry Pi 3 for a performance boost and to save using dongles for bluetooth and wifi.
  • Figure out a way of turning the LCD backlight on and off (probably a relay or optoisolator?) so that it is completely black and inconspicuous when in "mirror mode".

Tuesday 8 March 2016

Smart mirror - it lives!

I've been quite lazy in updating the blog recently because of reasons, but I finally have something worth publishing:


The smart mirror is (mostly) working!

I got my act together and started plugging things in and taping things together and I'm pretty pleased with the results.



The base of the mirror is an Ikea RIBBA frame which was super cheap and perfect for this purpose, It's a nice simple design and has plenty of depth for the screen and RPi to occupy.

The rear side of the frame glass (and it is actual glass, not perspex etc.) is covered in mirror tint film which I think is designed to keep heat out of buildings. This allows the light of the monitor to pass through from inside the frame, while also reflecting pretty much all light that enters the frame.

If you're going to use this technique to make your own one-way glass, my advice would be follow the manufacturer instructions EXACTLY. The film is a huge pain to apply perfectly with no bubbling, and took me many attempts to get right. Also make sure you have a sharp craft knife (or scalpel, as I did) on hand to trim the film, as you'll need an accuracy you can't get with scissors.

All in all it makes a pretty convincing mirror.

The screen (pictured in earlier blog posts) was de-cased and mounted to the back of a piece of thick black card (cut from an old record sleeve because it's what I had to hand) with bright orange gaffer tape. The bright orange wasn't a design decision, nor was it necessarily the best choice, but I wanted to get this thing done. The cutout for the screen was done using a scalpel and a steel rule. It would be nice to have done this using a laser cutter and a piece of acrylic for added stability - maybe next time.

Note: this isn't a picture of the final reverse side of the mounting card below, this one was hacked together for testing.




I also drilled some holes in the back of the frame for ventilation and a hole for the power cord to pass through.



The next steps before I'm happy with it as a final product are:

  • Build a custom short composite video cable for the RPi. The one I bought is far too long for this and could be the source of some of the signal problems I've been having with the screen, so a shorter custom one should fix this.
  • Add in a 19V -> 5V converter module. This is already ordered but is shipping directly from China. Because the screen needs 12-24V DC for power, I'm using an old universal laptop power supply for it. I'd like to use the same source to power the Pi, so that only one cable has to enter the frame, so a small DC-DC buck converter module should do the trick.
  • Software updates as necessary (feature creep yay!). I've not modified the software since the last blog post about this, so I need to add in the PIR module (so that the screen isn't always on) and make a couple of other improvements.




Sunday 31 January 2016

The Bill Murray GIF Player (BMRGP)

I was bored on a train earlier, so I wrote this Processing sketch that pulls a random GIF of Bill Murray from the internet every time you click the mouse.

I guess it was inspired by an exhibition I went to at the Baltic in Gateshead, called Bill Murray: A Story of Distance, Size and Sincerity by Brian Griffiths. It's as cool as it sounds.

Anyway, the code is on my Github if you want to compile and play with it. You'll need the GifAnimation library and an internet connection, since it uses the Giphy API.

P.S. I didn't screw up and leave my API key in the code, it's a public beta key.


Friday 29 January 2016

Code development - Now with icons!

After surprisingly little work, I've arrived at a version of the smart mirror Processing sketch that includes a limited amount of error checking and also displays icons to represent the weather.

The icons were sourced from an awesome pack called Climacons by Adam Whitcroft (thanks!).


Integrating them into the sketch was surprisingly simple; The Yahoo weather API includes a numeric parameter that indicates the current weather. This saves needing to do string comparisons to determine which icon to use. Instead, I was able to construct a CSV file which has columns for this numeric value, the corresponding weather, and the filename of the icon that most closely matches the weather state. Then it was a simple matter of pulling out the numeric value from the API, looking the value up in a table, and displaying the relevant graphic.

All of this serves to reinforce why Processing is such a great language for fast development of ideas, and makes me realise exactly why a program in Processing is referred to as a "sketch".

Raspberry Pi setup progress

Since the smart mirror project is essentially an embedded system, the easy choice for the hardware was a Raspberry Pi. They're cheap, well documented, and more than powerful enough for my needs (plus I wanted an excuse to buy one).

I also purchased a 5" TFT to use with it (<£15 on Amazon) which has a composite video input.

Having set everything up, I'm thinking of switching out the TFT for something that uses HDMI as an input. The resolution of the screen (800 x 480) is a lot to ask of composite video, and the result is a slightly flickery image.


Wifi was super easy to set up, generic drivers for the dongle I bought got installed straight away. Performance seems to be lacking but that's a problem that can probably be solved with a driver update. The (Poundland) bluetooth dongle I picked up doesn't seem to work OOB, so that will require a bit of work to investigate.

Next steps: installing Processing, Git and SSH to enable me to push code to the Pi and run it.

Sunday 24 January 2016

Fun with the TfL API, Yahoo Weather and Processing

Recently I've been playing around with pulling data from the Transport for London API in Processing. There's a crazy amount of possibilities for what you can do with the data that TfL can serve up, but my idea is relatively simple.

I'm pulling live data on bus arrival times for the stop at the end of my street, as well as the current status of the Northern Line (my nearest tube line) and the current weather. The end idea is to have a small screen set up in my hall with a Processing sketch running on a Raspberry Pi that will constantly provide me with data about when my next bus to work is, if I would be better off taking the tube, and whether I should maybe take an umbrella.

By default, the TfL API returns data in JSON format. Before starting this project I'd never worked with JSON before, so there was a bit of a learning curve involved. Processing can natively import and manipulate JSON objects (since Processing is essentially Java), but some of its abilities are somewhat limited.

Because of this, my sketch takes the useful info from the JSON object (bus number, destination and arrival time) and turns it in to a Table, which Processing is much better at manipulating. This allows me to sort the data by arrival time, so I can display the next bus arrivals.

The result I currently have is something which mimics the electronic arrivals boards seen at some bus stops:


Compared to my version:


Check out that Helvetica.

At the bottom you can see the fruits of my efforts with the Yahoo Weather API. This is slightly easier to work with in Processing as it will directly serve XML to the sketch.

Code snippets will follow when I've properly optimised it and added in error handling. This is important since this sketch is intended to run indefinitely.