Computer Controlled Christmas Lights

Brought to you by Jason Malinowski, Justin Beck, and Chris Meyer

Exploring the Software Side

Well, all good hardware (or in our case, not so good hardware) needs some good software to drive it. So, we started to write a basic interface point that lets us work with the relay board. We chose to use .NET 2.0 for this, since it offers a very handy serial port interface that makes programming it very easy. So, in just a few lines of code, we were able to control the board in our own software. We decided early on to implement our own network interface into this control program, which allows us to easily hook in other applications (even on other computers). For the technical people out there: we can just send UDP packets to the software telling which light to turn on and off, and the software will queue the commands and send them out properly. Early versions just sent out the text commands directly across the COM port, but we soon realized we needed to parse the prompts as sometimes we sent out commands faster than the hardware could process it, which would result in wierd commands that would counfuse the board, requiring us to manually sit down and figure out how to fix the board (in many cases we just reset it.)

The Website

One of the early things we got going was a basic website. The first iteration was simply a page hacked together in ASP.NET 2.0. We aquired a D-Link DCS-900W webcam that actually has a built in webserver that serves a Java applet for streamimg video. So, by the end of the first day, we had a website going!

However, we have some bigger aspirations, most notably getting posted on Slashdot. This requires a bit of extra work, as the system we threw together won't scale. So, we built a new system. Here's the technical details: the new site is running on an "old" computer of Justin's: it's a Pentium 4 2.4 Ghz running Apache 2.2 on Slackware Linux 10.1. Most pages are static, except for the CGI script that sends off the UDP packets to Justin's computer to actually control the lights. The webcam is driven by a shell script that is constantly using wget to pull images from the webcam, and saves them to a path where Apache can serve them out. Javascript runs locally on the browser to pull the images down. This scales much better than the webcam streaming videos directly!

A Word of Warning: when you have the basic website up, be careful who you give links to. As we were debugging code the first night, we couldn't explain why lights were randomly turning on and off. Our neighbors across the floor were randomly messing with them and were keeping quiet. Thanks guys...that wasted several minutes of Jason's life.

Putting Lights to Music

Well, obviously we have to sync up some lights to music! So the software here was pretty straightforward, but we quickly realized a big problem that would make our display not quite as cool as Carson William's. Since the relay board was designed to lock and unlock doors, it wasn't designed to handle commands quickly. We can only process several commands per second. The second problem we hit was lag, as there is also a bit of a delay between the time we send a command to the relay board and time the relay board actually processes it.

Visualizations

Despite some of the problems listed above, Jason also tried to write a Windows Media Player visualization that would flash the lights to the music in real time. See, Windows Media Player automatically gives us the frequency data for the current part of the music, which I can intercept and then send messages off to the server on Justin's computer. If you check out the video, you'll notice that for some places of music, it works rather well. However, the harder problem really becomes determining when the lights should be on and when they should be off. The code we demoed in the video simply looks at when the base, midrange, or treble volumes are above a certain level. This degrades quickly when the music is rather chaotic, as the lights quickly degrade into what seems to be random flashing. This is partly because of the limited rate of commands we can do to the relay board, but in general, this algorithm is still rather difficult.

View some of the source code Source Code