After continued failure with the Sparkfun breakout board that was to control multiple servos, I decided to go into effective troubleshooting mode. When trying to identify a problem with anything electric, you start downstream and move upstream with all of the components.
I tested all of the pins on the Sparkfun board and could not find any problem, yet the board got hot when powered up and there was that pesky smoke rising from various pin clusters on the board.
No matter what I did, the board (and code) would not work. I find this terribly odd, as when I first hooked it all up - it worked flawlessly. 2 minutes later - nothing, then smoke.... and more nothing. At times the servos would twitch, and then the smoke would come, other times, no movement, no smoke.... You get the picture. It was just a bad deal all around. I have to believe that I somehow fried the Sparkfun board, yet I have no idea exactly how I accomplished that.
Admittedly, the Sparkfun breakout board was a little beyond my pay grade, so I decided to go back to the basics of programming via the Arduino sketches.
I found a sketch that was written to control a single servo, and modified it to control 3 servos. Ultimately, the Arduino community seems to be full of this methodology. Hence the term "Hacker" that is used lovingly to describe the process and those who partake in it.
Here is the lovely mess that I created to power the three servos.
The Arduino Board which runs the code to move the servos is connected (and powered) to my computer via the USB cable.
In the lower left, a AA battery pack to power the servos independently from the USB power feeding the Arduino board. Depending on how many servos you are controlling, the lack of power from the USB can cause the Arduino to reset. It is suggested to power servos independently from the Arduino board.
The solderless prototyping breadboard in the center is the device that feeds the power and signals from the Arduino to the individual servos.
Them things on the right are the Servos.....
Here is a little video of the setup in action :
Yah, I know.... relatively uneventful, but this code will be scaled to move all of the servos in R2's dome and eventually control the opening and closing of the doors and pie panels on his head. Right now the code is written to run when the unit is powered up. I will have to find out how to make the code run on some kind of input from a remote source (either the RC controller or a wireless RF signal).
I am really pleased with my first attempt at coding the Arduino board, as I took some base code found on the interwebs, modified it, and made it my own. Most important : it did what I wanted it to do.
For those of you that want to see it / use it - here is the code I used. Please be gentle, as I had no idea what I was doing, so there are probably 1000 different ways of writing this code more efficiently. For those who don't know the first thing about code (like e about 3 hours ago), there is some logic in the programming language explained with the comments preceded by the " // " below.
// Sweep
// by BARRAGAN <http://barraganstudio.com> (Hacked to pieces by ScottyK)
// This example code is in the public domain.
#include <Servo.h>
Servo myservo;
Servo myservo2;
Servo myservo3; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo object
myservo3.attach(8); // attaches the servo on pin 8 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo3.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo3.write(pos); // tell servo to go to position in variable 'pos'
delay(3); // waits 3ms for the servo to reach the position
}
}
No comments:
Post a Comment