Step 1: The Idea
Step 2: Collecting the Components
I had a couple Arduino Mega 2560's that I had been working with and I decided to use one for this project. I needed a lot of PWM pins for the LEDs, the motor control, the sound, and many other pins for the touch buttons and all of the other controls I wanted to use. I also had a shield kit for the Mega which I thought would be handy to solder everything to.
I also had a pretty sweet golden door handle that I found. I thought it would make a great carrying handle. I attached it to a volume pedal and told my friend that it was my steampunk volume pedal.
In addition to that, I had a slew of switches, buttons and knobs.
Step 3: Getting Started
So using some ½” metal caps which were to be the keys, I laid out enough to fit across the length of the top comfortably. It ended up being 12, which is a perfect number, matching the Chromatic scale of a piano. Using graph paper, I found equal spacing, taped my template in place and punched 12 pilot holes with an awl. I then used a ½” drill bit and drilled the 12 holes out.
That’s when I realized that the ⅛” inset board, which I thought was wood, was actually some kind of paper board. Every hole was very rough, with a lot of loose paper coming off it. I popped in one of the metal caps, each of which had 6 “legs” to hold it in place. It was loose. It basically fell right out. So I had to find another real piece of wood to be the top lid/control panel.
After searching various hardware and hobby stores, and apparently it is very difficult to find an ⅛” piece of “real” wood, I found one right where I wasn’t looking. I work at an architecture office and we often have a lot of sample materials laying around. Many of them are wood. I found a perfect stack of several different types of wood, all 12” square and ⅛” thick.
I sawed one down to the dimensions of the box, attached it using wood glue, clamped it and let it cure for 24 hours. It worked out very well. Solid and sturdy. I sanded down the sharp and rough edges. Found a good color, a pearlescent blue Martha Stewart craft paint and applied 3 coats with a brush, letting it dry in between. Now, having the box I would move forward with, it was really time to get down to business.
Step 4: Amp and Speakers
These speakers have some really nice bass, and they get LOUD with the Sparkfun amp. Almost too loud, and I worried about my 2 year old’s discretion with the volume knob. I needed 3” holes for the speakers. At this point the basic layout of the top of the box was becoming apparent. The speakers would go on either side, as far into the back corners as possible. The controls and keys would be towards the front. That left the back middle for the animatronic element.
Step 5: The Layout
It was a good size to fit in between the speakers and seemed like a good form to build on. I had experimented with powering the motor using an H-Bridge and felt that I could make it work. So that was decided.
I used ⅛” graph paper to roughly lay out my 3” holes for the speakers, the rectangular hole that the animatronic would mount in, and the 12 keys. Everything fit well. Rather than go buy a $17 3” hole saw, I decided to use a jigsaw. I poked some pilot holes through the graph paper with the awl, removed the graph paper, drilled pilot holes and began sawing. It was a fairly easy saw job, except when the 3” holes overlapped the edges of the box and the saw had to do a bit more work. But I finally had my first holes cut.
Step 6: Cat, Birds and Monkeys
The bird cages needed minimal prepping to make them work. There was a flat metal bottom that was welded/soldered on. I pried it until I could get my wire cutters at the connection points, snipped them and worked it off. Some of the paint came off the bottom, but that’s OK. I did a test fit and they fit well over the top of the speakers.
The cat was also fairly easy to prep. There was a seam down the middle of the belly. I cut along that with a razor knife and removed most of the padding inside the torso. I removed enough of the padding from the arms to be able to fit the monkey arms inside. The feet and hands were full of little plastic beads, so I tried not to spill any of them.
I slipped the cat suit over the monkey body and did a test fit. I found that the arms went inside the cages at a good height, with no snagging. The feet were sticking out a bit further than I would have liked, but I would deal with that later.
Step 7: Buttons and Wires
Step 8: LEDs
Because of having the key nails tapped in, my graph paper was now useless. So I just eyed the spacing and alignment (EM) and punched 2 little holes vertically about ¼” above each key. I used a 1/16” drill bit to drill them out. These would be the holes that the cathode/anode of each LED would go through. I put a dab of general purpose adhesive on the bottom of each one and fitted them, then let it dry overnight. Once the glue was dry, I bent each cathode (-) over in the same direction so that they were touching each other and soldered them. At the end I attached a ground wire. I attached another wire to each anode, soldered them and cleaned it up. Then I started putting together the main project board that everything would be connected to.
I originally used pins 2-13 for the LEDs (as shown in the pic of the underside of the lid), which are all PWM on the Mega. After I did that lack of planning (EM), I realized that pin 3 is required for the audio. Something that is not extremely easy to switch having to do with timers. I had to disconnect and find another set of PWMs on the Mega, the obscure and unlabeled as such pins 44-46. There is still some debate over whether 46 is actually a PWM pin. I wanted to also use a PWM for analog control of the motors so I could adjust the speed of the cat arms based on tempo. I had just enough.
I found a little project board at Radio Shack that seemed like it would fit everything well. I had an H-Bridge IC, 12 LEDs, 12 capacitive touch buttons, 12 of everything it felt like. It gave me just about enough room for all of it.
I used 220ohm resistors for the LEDs. I didn’t do any calculations, I just used them. (EM)
Step 9: The First Sounds
This was mostly due to my laziness. I probably could've dialed in a good sound if I hooked up some pots and tweaked around trying to find a good combo. Instead I assigned some arbitrary values to the parameters. It wasn't all bad, I got it to be a little melodic. Here I am butchering the theme from TRON:
I was looking for a different sound anyway, something more instrumental or shaped. I was still wondering if I could find some code to do polyphony. After Googling for a bit, I found it in a very nice project called Pisanomatic. Pisanomatic is a wheel that when pushed along generates musical sequences called Pisanos. It was derived from a couple other projects, including Auduino. The great part is that it not only did polyphony, but also had different voices and envelopes which could be selected. I started to hack it into place with my code and made some progress, and finally had a decent arpeggiated sound to build on. The voices of the Pisanomatic had a very 8 bit feel to them, which went well with the arpeggios that were so common in Nintendo music.
I was only able to make my Pisanomatic-derived code do 2 note polyphony. If I turned on 3 voices, I got zero output. Still not sure why that is. But two was enough for a bass and melody track. I started experimenting with playing different bass notes derived from the keys that were held down. It sounded good!
Now to build a control panel and really start controlling the sound.
Step 10: Control Panel
I had some arcade style buttons, and I installed them one on each side of the box, pinball style. Installing the first one was a struggle, as I drilled the hole with a 1" drill bit, and it turns out the button was 1 1/8". I had some difficulty scraping the hole until I found an old steak knife I had laying around for opening boxes. That gouged it right out and it was in. I added a black one on the other side. The green one would become a toggle that allows you to select voices and envelopes from the 12 cap keys. The black one is a toggle that allows you to select what scale you're mapped to. (6 voices, 6 envelopes,12 scales) Holding both buttons at once allows you to modify the scale that is currently selected by toggling LEDs on and off.
I still had the problem of those cat's paws. Especially with the cages in place, they were huge. Looking at the placement of the cat's feet, I started to picture knobs on top of them. A tempo knob was a given, and I figured if I had another identical knob I could find a function for it. You can never have too many knobs. All I would need are a couple of long shafted pots that could go through the cat's feet and come out on top. I got them at Radio Shack and installed them, cutting a hole in the cat's feet with a razor knife. They popped through and I used the hacksaw to lob them off. Then I popped some red control knobs on top.
I tweaked the upper and lower range of tempo in the code and found a good balance. The second knob I assigned to shift the "base note" that your keys would start at. At this point, the synth could only play a straight 12 notes, there was no scale mapping or selection.
Also on the left of the control panel is a red 3-way toggle switch. This changes the arpeggio that the keys play to go up (12345), down (54321) or random (34251, etc) - the random toggle is almost like instant improvisation, and the transition between up or down to random and back flows really well and almost creates a song in itself.
It was starting to sound very good, but something was still missing...
Step 11: Drums
I found a piece of Arduino code called BeatVox, which played PCM drum sounds using a similar sound generation method to Auduino. I tried pretty hard to get it working on the same Arduino Mega that I was already using. That would have been great. But ultimately I just couldn't do it, there was too much going on already, or I wasn't good enough. I started to consider alternatives. Enter: The Arduino Pro Mini.
The Pro Mini is an amazing piece of technology. I ordered a quantity from Sparkfun during their 4th of July sale, so I had several to experiment with. I got the BeatVox code working on one and started figuring out how it worked. I was able to make it listen on the serial line to trigger the different drum sounds. I was also able to power it via the 5V from the Mega. It was very simple to wire in to the mix. I did a bit of research on passive mixers using resistors and was able to mix the sound from the Pro Mini with the Mega going into the amp.
Mixing the drum and synth sounds, it really started to shine. Instead of making it produce a straight ahead drum beat as discussed earlier, I decided to make it play drums algorithmically based on what beat you were currently on. So the way it works is, if you are holding down:
0 keys: a hi-hat plays randomly on every beat (50%)
1 keys: a bass drum is played on the 1st beat randomly (50%) thumpthumpthumpthumpthump
2 keys: the second beat is left silent. thump-rest-thump-rest
3 keys: a snare starts to come in on the 3rd beat. holding 3 keys does a rolling triad beat of bass-hihat-snare-bass-hihat-snare.
4 keys: follows the same pattern as before, but a rest on the 4th beat. this creates the typical 4/4 beat.
This makes a very interesting time signature result when you alternate between 3 and 4 keys being held down. (or any combination of keys really) The effect is that when you "play" the keys you are also "playing" the drums automatically. And they are synced perfectly with every note.
There are some other accent notes thrown in at various points. hand claps, etc. I added in a second toggle switch on the left of the control panel to turn the drums off by cutting the PWM line coming from the Mini. This allows you to play just the notes by themselves if you don't want a drum sound. It does result in a shift in volume because of the voltage drop, so I will eventually rewire it so that the toggle switch is cutting the serial line rather than the PWM/PCM signal. That should even it out.
The control panel was complete except for one item. A large LED tipped toggle switch that I found on Skycraft's Facebook, which would trigger a mode known as....
Step 12: Song Mode (The Music Box)
Since I already had about 6 songs defined, I decided to up the array resolution to 96 steps, which allowed me to "double" the current songs by putting rests in between each note, and then replacing the rests with other accent notes as needed. This worked out well, but I don't think was worth the effort in sound. Each song also had separate bass and drum tracks, so that was 36 long arrays (melody, bass, drums). At some point I ran out of memory, which just caused the box to do weird things. I dropped the bass track and made the bass play algorithmically. A bass note equivalent to the melody note will play any time there's a kick drum sound. It works good enough. The melodies were pulled from many different places as I said (sometimes figured out on a piano keyboard by hand), but the drum tracks were all created from scratch. I got to the point where I could follow the numbers of each melody and put together a kick/snare/clap pattern that served the song. Maybe.
What I found interesting is that almost every kids song seems to be played on whole notes (the white keys). One exception to this was on Three Little Kittens (known as DEM KITTENS in my code) - I had to put a little kludge code in the song routine that said "if it's this song, and this note, play this note instead" to play a sharp note.
In song mode, pressing any of the 12 keys selects one of the 12 songs. It doesn't start over at the beginning of the song either. It picks up at the point where the previous song was. This allows you to create some interesting mixes and "play" song mode by choosing different songs in real time.
There is also a random "light show" of LEDs that goes along with the beat and changes as you go to a different song. Currently there are 5 different shows. I will expand it at a later time to include more.
Step 13: A Quick Walk Through the Code
In the setup routine, the 12 capacitive keys are read as a baseline. For some reason 1 of the capacitive pins always reads a little higher than others, so I had to create a baseline to start with, which is likely the proper thing to do anyway.
The 12 cap keys are read and compared to the baseline. If they exceed the baseline (which means they are being touched) their states are stored in an array. This array is then copied to another, which is compared the next time through the loop to determine if the pattern has changed.
Each of the 12 keys has a note value that can be updated any time. It is updated at various points like when you turn the knob controlling the base note or when you select a different scale. It is filled from arrays of scales which are 1's (whole tone) and 0's (semi tone).
From the number of keys held down, a number of beats is assigned. The tempo is derived from a formula using the tempo knob. The tempo ranges from 60bpm up to 180bpm. A millisecond timer is compared to see if we've passed the "interval", the amount of time a beat takes. If it has, the interval is reset and we run through triggering the appropriate drum sounds based on what beat we are on, and play the appropriate note and bass note that is being held down. LEDs are updated. The loop constantly fades the LEDs by a certain amount every run through. This allows you to increase their brightness by small amounts as their key is being touched and the loop takes care of fading them back out in the background.
Inside of the beat loop is also the conditional which says that if we're in song mode, play the right note from the array of the current song we are on. The cat's arms are triggered to go back and forth in the beat loop as well.
Step 14: Things That Didn't Work
Other things that didn't make it in.. some custom drum sounds of either cats meowing or ducks quacking. Real polyphony. This will not be my last synth project. I am hoping to make something special with the next big one.
Step 15: Longer Demonstrations
And here is a bit of song mode: