chipKIT Uno32- animatronic puppet style

The Learn.DigilentInc site was launched two weeks ago with several microcontroller projects on it.
After doing all of the projects loaded on the site, I was inspired to test out the skills on a more complex project: seeing if I can use my chipKIT Uno32 with a Starbot Animatronic Puppet. Check out how it turned out and let me know what you think!

 

Materials in the video:

  1. Starbot Animatronic Puppet (assembled with 3- HXT900 Hobby Servos installed)
    www.animatronicshop.com
  2. Breadboard + Breadboard wires (at least 9 for Servos + 4 to connect to CHIPKit)
  3. External power supply to run the servos (it’s always a good idea to isolate your motors/servos from your data)– I have a HY1803D variable power supply that I set at 5V.
  4. Input devices, I used the awesome SparkFun JoyStick Shield that had a joystick for x & y axis + a button to click. Joysticks, potentiometers, buttons… anything would have worked, but I liked getting to use the Shield to cut down on wiring.
  5. A chipKIT Uno32 from Digilent with MPIDE to program.

Why the puppet?

The puppet was a good project to test out the chipKIT Uno32 because it covers a broad range of skills.

Here are few that I thought of:

  • get to know servos- how to power a servo, how to communicate to it and importing the servo library into MPIDE.
  • naming, keeping track and assigning variables in the code.
  • the chipKIT was Arduino Shield compatible– exploring what that means with the SparkFun shield.
  • how to use analogRead with the joystick
  • how does a joystick work
  • capturing information from an input and assigning it to an output

Notes:

I had already assembled the puppet previous to wanting to try out the Uno32. Luckily, Pat Starace, the Starbot Puppet creator made assembly instruction videos that were easy to follow along. Once the servos were put in place… the bot was complete and ready to add electronics.

watching the videos + assembling on my couch
watching the videos + assembling on my couch

Code for the program:

 


#include <Servo.h>

/*written for the SparkFun JoyStick shield and attached to 
Pat Starace's animatronic bot. 
Larissa Swanland- Digilent Inc- 2014*/

/*name each of the servos*/
Servo hor_eyes; 
Servo vert_eyes;
Servo open_mouth;

/*joystick operation*/
const int joystick_x =0; //pin for the x axis 
const int joystick_y =1; //pin for the y axis 
const int joystick_sel=2; //button press of joystick

int valx; //variable for x
int valy; //variable for y
int sel; // variable for select

void setup(){

  /*attach servos*/
  hor_eyes.attach(8); //attaches the hor eyes to pin 8
  vert_eyes.attach(9); //attaches the vert eyes to pin 9
  open_mouth.attach(10); //attaches the mouth to pin 10
  //check on the chipkit UNO that jumper 4 is moved to the PWM output position

  /*declare inputs*/
  pinMode(joystick_sel, INPUT);
  digitalWrite(joystick_sel, HIGH);

}

void loop (){

  /*read the value of the joystick pot and write the position to servo*/
  valx= analogRead(joystick_x);
  valx=map(valx, 0, 1023, 35, 160);
  hor_eyes.write(valx);
  delay(15); //give servo time to get to position

  /*read the value of the joystick pot and write the position to servo*/
  valy= analogRead(joystick_y);
  valy=map(valy, 45, 1023, 35, 160);
  vert_eyes.write(valy);
  delay(15); //give servo time to get to position

  /*read state of select on joystick*/
  sel= digitalRead(joystick_sel);
  //read if the joystick has been clicked
  if(sel==LOW){
    //if the button is clicked then open mouth to 70 degrees
    open_mouth.write(70);
    delay(5);
  }
  else{
    open_mouth.write(5);
    //close mouth at 5 degrees
    delay(5);

  }
}

Some notes about the code–

  • Since I was using servos, I needed to import the servo library from MPIDE’s files.
    Using Sketch>>Import Library>> Servo , a #include <servo.h> came in.
  • The bot has 3 servos controlling each of it’s movements and each movement needed a name and a controlling input (from the JoyStick Shield)
    • 1 servo for the side to side motion of it’s eyes– I named hor_eyes to correspond with the X axis of the joystick.
    • 1 servo for the up and down motion of it’s eyes — vert_eyes to correspond with the Y axis of the joystick.
    • 1 servo for the mouth opening and closing — open_mouth with I decided to make correspond with the select button click of the joystick (press it down and it clicks a button).
  • Servo data lines were attached to the output pins 8, 9 & 10. Since I’m using Pin10 on the chipKIT, I had to make sure that the jumper was put in place to enable PWM instead of SPI Slave (Page 5 of the Uno32 User’s Guide) Pin10 on the chipKIT Uno32 needs to be enabled
  • The joystick is basically two potentiometers and a button. Potentiometers are generally used with an analogRead and a button is a digitalRead.

Wiring up the servos and the bot:

Somewhere in my training I learned it is more effective to separate your data lines from any power lines. You’ll find that if you connect more than two servos to any microcontroller board, the board itself has a hard time sourcing all of the current needed to run the servos. So, to avoid any issues, I just connected them to an external power supply.

Wiring the bot up- servo power comes from external power source
make sure to connect ground from the joystick shield and the Uno32 to the ground of the breadboard (not shown in the graphic)

 

 

 

Be the 1st to vote.

About Larissa Swanland

I'm a bit of an electronics-education evangelist. After all, Education is how we learn about the world. Electronics make the world better. Engineers change the world. So more engineers that know how to design and create electronics? That's the kind of world I want to help create.

View all posts by Larissa Swanland →

Leave a Reply

Your email address will not be published. Required fields are marked *