Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

Servo driver problem ....
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Servo driver problem ....

by skatun on Tue Apr 15, 2008 10:19 am

Hi
I am trying to drive 8 servos, unfortunately I cant get the code to work. Does anyone see the mistake? ( Only tested it with 2 servos so far)

Code: Select all | TOGGLE FULL SIZE
 
#include <ServoTimer2.h>    // the servo library



ServoTimer2 servo1;           
ServoTimer2 servo2;

////////////////////Read RC
int servoPin1 = 5;       //PD5
int servoPin2 = 6;        //PD6
int servoPin3 = 7;      //PD7
int servoPin4 = 11;    //PB3
int servoPin5 = 12;    //PB4
int servoPin6 = 13;    //PB5
int servoPin7 = 14;    //PC0 ???
int servoPin8 = 21;    //PC6  ???
        

int pulseWidth1 = 900;
int pulseWidth2 = 2500;

void setup() {
 
  servo1.attach(servoPin1);     // attach a pin to the servos
  servo2.attach(servoPin2);
 
 
}
////////////////////////////////////////////////////////////

void loop()
{

  if(pulseWidth1<2500){
        servo1.write(pulseWidth1++);
        servo2.write(pulseWidth2--);
  }
  else{
    servo1.write(pulseWidth1--);
    servo2.write(pulseWidth2++);
  }
 
       
       
 
   
    delay(2000);
}
Kim Skåtun
NTNU
Norway
skatun ( at ) gmail.com

skatun
 
Posts: 3
Joined: Tue Apr 15, 2008 10:09 am

by mtbf0 on Tue Apr 15, 2008 5:27 pm

what happens when you run the code?

it looks to me like it will move both servos from one extreme to the other, (though you might try using min and max values of 1000 and 2000 to be sure you're operating the servos within spec) and they will pretty much stick at the positions opposite where they started as pulseWidth1 oscillates between 2501 and 2500.

you might, instead, try something like this in your main loop.

Code: Select all | TOGGLE FULL SIZE
int step = 1;

void loop (void) {
  if ((pulseWidth1 >= 2500) || (pulseWidth1 <= 900)) step = -step;
  pulseWidth1 += step;
  pulseWidth2 -= step;
}


i suppose that i should confess to never having actually used the servo libs.

goo luck.
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.