Sunday, December 4, 2011

Star Wars Christmas Tree

In addition to all of the Christmas trees, ornaments, stockings, garlands, and other decorations that fill our house for the Christmas season, my wife lets me have one small tree of Star Wars Ornaments.  For the past few years it has been unlit, and she decided that it needed some lights this year.  She found a battery operated strand of 30 white LEDs on sale at Target last week, but I figured we could do better than just plain lights.....we needed Star Wars lights.  I built a small controller for the light strand that makes it flash in the pattern of the Star Wars theme song.  The basic concept is that the note durations are how long the lights are on, and the pitch translates to light intensity.  The lowest note in the song corresponds to the dimmest light setting, and the highest note to the brightest. 


I first cut the strand and measure that it draws ~70 mA with a new set of 4xAA batteries, which is way more than a mcu gpio can output, so I started with a 2n3904 transistor to turn the strand on and off.  I really only needed 1 pin from an mcu, so I went to my parts box and dug around for small microcontrollers.  The two options I had on hand were an AVR ATTINY85 and a handful of MSP430 microcontrollers.  I had a couple of ez430 thumbsticks that TI was giving away a while ago, along with a pack of the extra target boards, and this project was well suited to the small form factor and ease of use that those provide.  I ended up using one of the MSP430F2012 target boards.  It has a built in LED, which I did my initially firmware testing with to get  the note lengths and song pace working right, and then I used PWM output from the Timer A module to control the intensity of the LEDs on the actual strand.  

I'm not really a musical person, and all of the notes on the piano sheet music I was finding just confused me, so I found a violin arrangement (so only 1 note is being played at a time) and set about transcribing that into code for my microcontroller.  I broke the song down into repeating chunks so that I wouldn't have to code in every single note and could reuse the chunks.  Each note is represented by a single byte, where the lower three bits represent the length of the note, and the upper bits represent the pitch.  I went through and labeled the notes 1-12 from lowest to highest, and store those values, which are mapped to the range of PWM duty.  I recorded the note duration and pitch by hand for the whole song, and then used an Octave script to combine the values into my chosen representation of the information.


In the next picture you can see the circuit board a little closer.  I'm using an LM317 with a couple resistors and capacitors to provide 3.3V for the MSP430, and then the LED strand is switched on my a 2n3904 transistor with a 1k resistor on the gate.  Using the ez430 target board makes it easy to connect to the programmer/debugger, and it's not much more expensive than the bare chip (~$3.30 vs ~$2.70).  One of the value line (MSP430G series) chips would certainly have worked, but I had a few of these target boards lying around and it did the job just fine.


Below you can see a video of the tree in action.  The tree plays the full Star Wars Theme, but this is just the intro.  It looks better in person than on my camera, but you at least can get the idea.  My wife was kind enough to play violin along with the tree for the accompaniment.  You can download the source code here if you want it.

3 comments:

  1. pretty neat project pal

    ReplyDelete
  2. I noticed the multi-port usb adapter you had in one of the pictures. Be careful with that one. It somehow fried all my devices connected to it and the hub itself. Just thought I should give you a head up.

    ReplyDelete
  3. Looks awesome, it's funny that if you wished to undertake a project like this 20 years ago it would have probably come to hundreds of pounds in opposition to tens. Great effect anyway. Keep it up, the harder the projects get the better you become, and the closer you are to being self employed.
    I am also obliged to recommend UK christmas world tree lights for the remainder of your decorations =)

    ReplyDelete