In my spare time I've been teaching myself some electronics. Although I've written code all my life, I've always had a real fascination with making little eletronic gadgets that through simple automatic actions make your life better, or at least more interesting. The state of microprocessors is now to the point where you can get whole little computers on cheap chips, and one such example of an open system built on such a microprocessor is the Arduino platform. Basically the Arduino provides an easy to program base for litttle projects, all using open source hardware and software, and on a standard board that can be had for ~$25, cheaper if you are willing to solder a bit.
My big failings in school have always been that I can't learn something without a practical purpose, so I decided to try to build a way of controlling my Squeezebox using some kind of RFID tags. My original goal was to have a tray of some sort, where you would plop tags representing artists, and a playlist would be built using that mix of artists. Sadly, the current generation of hobbiest RFID readers don't support multiple tags, so I had to change things a bit and settle for a single tag representing a playlist, but it still turned out pretty neat.
I'm not the first to think of controlling music with RFID, somebody made a pretty neat player called PlayStand way back in 2002. But its RFID reader was plugged directly into the PC. I didn't want a PC in my living room, I wanted the player to be totally self contained, which seemed possible since the Squeezebox was already responsible for playing the MP3s. All I needed to do was trigger a song to start playing once it saw the tag. Problem was that my server is in another room and I don't have an ethernet drop in my living room. There are ways of making Arduinos work with Wifi, but they are all really expensive, so after a bit of looking around I remembered that the Squeezebox itself could act as a bridge. So the arduino actually connects via ethernet to the Squeezebox, sending commands to a little PHP script I have running on the same server as the SqueezeCenter. That script provides a management interface to map RFID tags to particular URLs, so after configuring it, when it gets a message that new RFID is in place it triggers a playlist to start. You could use this same system to perform other actions that can be performed via a script, such as having a coaster both stop the music and post a tweet that you are off to work or somesuch. But I'm just using it for music.
The RFID reader is the Parralax Serial Reader, which is both expensive and slow. (don't know why I said cheap in the video, it is far from it for $40) It works reasonably well but has some annoying shortcomings. As I said, one is that it can only read one tag a time, another is that it tends to queue up the tags in the serial bus, always outputting the current tag in its field at 2400 baud. Thankfully it also sports an enable pin, so you can just shut the thing down and back up to clear things out reasonably well. It also seems to sometimes return a garbled tag id, which can cause a bit of havoc because the Arduino will want to treat this as a new tag and post the change to the server. I currently have it verifying the tag once before going off to the server and that is pretty reliable, but I might up it to three times to be fool proof.
The tags are also from Parallax, 50mm round tags. This was my original choice as I figured they would have a good range, and they did, but then disaster struck and they just barely didn't fit into the coasters. I tried switching to the smaller adhesive tags Parallax sells, but they didn't have quite have the range. I did notice that having the tag butted up against the metal plate in the coasters really cut down on their range, as I did test the 35mm tags first and had them working, but once I stuck them on the coasters they couldn't reach through the wood in the cabinet. In a fit of desperation I ended up ever so slightly trimming the casing of the original 50mm tags and that did the trick. RFID tags aren't as cheap as I thought.. I know Parallax tends to charge a ton for their items, but over $2 each was pretty shocking.. oh well, all in the name of science.
When I first started I wasn't sure how the tags and reader were all going to look. I was originally thinking of building some kind of wooden case for the reader, I wanted it to be something I would use and be attractive. But after reflecting on how awful looking every little thing I make like that is, I decide maybe it would be cooler to hide it entirely. I thought that photo coasters would be neat because you could have them printed up custom from any number of sites and have real solid artwork. But once I looked at the prices for the custom coasters I quickly decided that was a flawed plan, plus I wanted it to be pretty easy to change up the coasters and add new ones so I could keep them up to date with what I was listening to. So a little bit of browsing later I came across these glass photo coasters from Amazon. They were cheap, about $2 each, and looked decent, plus I could just print out photos and insert them myself, changing them easily as I wished. They turned out perfect, although they are a bit delicate when inserting the pictures and the tags needed some trimming. They really do look sharp once the artwork is in. (shout out to my bro Marc for throwing together the art for me)
The project would have been done in an evening if not for being a bit on the bleeding edge with ethernet support on the Arduino. I first went with the official Arduino ethernet shield. Shields are just an awesome idea on the Arduino, they are a way of literally plugging in functionality, all while still maintaining the standard digital inputs and outputs. When I first started playing with the shield I was ecastatic, it worked on the first try and everything was chugging along nicely. But joy soon turned to frustration when I found that when powered off a wall wart the ethernet shield wouldn't get a link without a hard reset. Turns out this is a hardware bug in the current revision of the ethernet shield, and I couldn't get any of the workarounds working. Arr!
Thankfully, the Arduino being the open platform it is, someone else had designed an ethernet shield. LadyAda at AdaFruit industries, had designed her own ethernet shield which used the same chipset as the official one, so the same libraries would work for it. Plus it had the added bonus that you got to solder it together. That let me add my own headers for the RFID reader and pull out the reset pin on the WizNet module so I could restart it from the Arduino. After putting it together I had a pretty reliable system and put it aside waiting to have the coasters made.
Sadly, when I picked up the project a few weeks later, I found that I couldn't make multiple requests to the server. The first one would work fine, but on the second request the call to connect to the server wold just hang, never to return. I went a bit nuts trying different things, building simple example and having the same thing happen.. this worked a couple weeks ago, why was it broken now? Turns out I had upgraded my version of the Arduino libraries in those two weeks, and a new bug had been introduced making multiple connections hang. Double arr! Once I patched up the library and put in a few fail safes and incantations I got a completely reliable system.
The last piece of the puzzle is the server side script itself. I opted to just throw something together using the web hacking language de riguer, PHP. The script basically just has three commands: 1) I see a tag, do something 2) Stop the music and 3) Here's what to do when you see this tag. The script just writes out the URLs you map to the tags to simple text files, and keeps track of the last tag it has seen in order to make it a bit easier to set up. All in all it is ugly, but gets the job done, and since you have a server running PHP if you have a squeezebox, it sure seemed like the logical choice.
So if you want to do something like this yourself, it is all pretty easy. Get yourself an Arduino, the RFID reader and ethernet shield. You'll need to do a tiny bit of wiring from the ethernet shield to the RFID reader, but apart from that, you are set. The server side script can be found here and the arduino script right here. You can contact me at nicpottier at the gmail if you have any questions.