Sunday, July 31, 2011

monkeying around

Here's a simple animatronic monkey I've put together, as my first foray into fun with servos.

The baby monkey's head is mounted on a servo, so the head can turn left and right.  A Wii nunchuk hooked up to an Arduino controls the servo, using the analog joystick.  The red board is an mp3trigger, which plays monkey noises in response to button presses on the nunchuk. 

Here's a video of the thing in action:

The center for the servo seems to be off, and there's some jitter, but I was happy enough with this for a demo.  To secure the servo and baby monkey, I've sewed both to the belly of the big monkey, which serves as a sort of base.

For reading from the nunchuk, I used code from here:

Before putting together this version with the nunchuk, I first controlled the servo with a gamepad connected to a PC that was communicating with the Arduino using serial commands.  For that, I used the excellent Python scripts from Principialabs:

These use pyserial and pygame.  I added some bits to use pygame on the PC for audio.  I had the idea of maybe using a ladyada Wave shield for the audio, but found its library has a timer conflict with the servo library, which is why I decided to use an mp3trigger board instead.

To use the mp3trigger board by triggering on the track pins (rather than using serial control), I've set the track pins as input pins in the Arduino setup.  Then when a button is pressed, I set the appropriate track's pin as an output, write it low, then set it back as an input.  Without leaving the pins as inputs, they'll trigger constantly, I suppose because they need to be allowed to float.

The purpose of this project was to get started with animatronics.  Next I will set up a larger doll or stuffed toy with a pan-and-tilt bracket, to play with a larger range of motion.