Showing posts with label MSP430. Show all posts
Showing posts with label MSP430. Show all posts

Saturday, February 18, 2012

Baby Star Lights

My daughter just turned 3 months old, and she is completely fascinated by lights and things that move.  I got the idea to make a star projector from seeing one of these stuffed animals that puts a star pattern on the ceiling, although mine is a little different.  My project uses an MSP430 to control an LED inside of a ping pong ball that's mounted on the end of a servo to rotate it.


I started out by taking a ping pong ball and drilling holes all over it with a 1/16" bit, the smallest in my set.  I used a 3/16" bit to make hole for an LED and I spray painted the ball black to avoid having the ball glow.  To test it out, I wired up a quick LED circuit and when I went into a dark closet it was clear that 1/16" was too big of holes--the light was not near focused enough on the ceiling, and  it'd look even worse in the baby's room.  I started over with a new ping pong ball and used a hot sewing needle to poke tiny holes and got closer to the look I wanted.




 Switching over to the electronics, I used an MSP430G2211, which is one of the chips that comes with the MSP430 Launchpad.  Any of the small MSP430's would work just as well...the firmware's really simple.  Basically when you switch it on, the LED turns on, and then the servo rotates slowly one way to the max and then goes back the other way, and repeats.  It runs for a set amount of time (15 minutes right now...it can be varied based on how long it takes for my daughter to calm down and go to sleep), and then shuts everything down and goes to sleep (LPM3).  The servo control is on P1.1, and the LED is on P1.2.  I got a servo for $2.50 that works great.  I tried to use a red-yellow two color LED, but the one I had was too dim, so I used a bright bluish-white LED instead.  I might use an RGB LED in the future if I come back to this and clean it up.  It's powered by a 4xAA holder from Radio Shack with a power switch built in, and an L78L33 provides 3.3V for the MSP430.  The PCB I used is a spare from a stalled project (a Wii Nunchuk controlled RC car...the same board is used as the controller/transmitter and receiver/motor driver and also serves as a simple breakout board for 14 pin MSP430F/Gs) that I had made at Seeed Studio.


The most frustrating part of this project was when I tried to package it up.  I used a small Sparkfun box as a case, and once I put everything inside the box I realized that the wires I was using from the PCB to the LED at the end of the servo arm were way too thick and there wasn't enough give.  The servo was straining really hard and not moving much, so I reduced the swing range to only a few degrees, but that still didn't fix it.  I had to cut out that wire and use the thinnest I could find, which was some wire I snipped off of a spare battery holder.  It works...but I may decide to start over with the whole enclosure (maybe use this as a chance to try out a laser cutting service) and use thinner wire yet so that it works more like I'd initially planned.


The picture here is a longer exposure, so its fuzzy because of the movement, but you get the idea of how it looks on the ceiling.  The source code is very simple, but it's available at https://sourceforge.net/projects/babystarlights/.  The project didn't turn out quite like I'd planned, but it's tons of fun to see my daughter staring at the lights and following them as they move around the room, and my wife even asked to help me solder it.  My camera wouldn't pick up the light on the ceiling, but here's a quick clip of the light in action.

Wednesday, December 7, 2011

Star Wars Christmas Tree...Now with Sound

A few days ago I posted a set of Christmas tree lights that flashes to the Star Wars theme song.  I initially did not include a sound output intentionally because the tree sits in our dining room and it'd be annoying to have a song playing whenever we had the tree lit.  I decided later that as long as I could turn the sound off, it'd be a fun addition to the project, so I added a small piezo buzzer between pins 8 & 9 of the MSP430 and made the software changes necessary to output the song on the buzzer as well as on the lights.  I soldered a couple female headers onto my protoboard so that I can plug the buzzer in (to have sound) or take it out (for lights only).


In order to add the sound, I had to go back to the music and re-transcribe it with the actual note values (I ignored flats/sharps before because you couldn't really distinguish them on the lights...but it matters more with the sound).  I looked up the frequencies of those notes here.  The notes in the song range in frequency from ~294 Hz to 880 Hz.  I tried to keep the structure of my code as similar to the first version as possible, so the audio PWM is handled in software in the interrupt routine that fires when Timer A reaches the end of its period for the LED PWM.  I bumped up the DCO frequency from 1Mhz to 8Mhz to provide finer resolution for the musical notes, but the rest of the changes are pretty minor.  An updated version of the source code is available at https://sourceforge.net/projects/starwarsxmasled/.

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.