Trouble with Servo Breakout & Wave Shield.
Moderators: adafruit_support_bill, adafruit

Re: Trouble with Servo Breakout & Wave Shield.

by unorthodoxarts on Wed Jan 16, 2013 9:54 pm

Oh. Hahah. I see. The 'pulselen' in the pwm.setPWM() thing is a placeholder. Ahhah!

The only thing now, is that the 'delay' after the pwm.setPWM() doesn't control the speed at which the servo moves, but the gap in between them moving. Is there any way to slow down the rate it moves?

Thank you again.
unorthodoxarts
 
Posts: 11
Joined: Fri Dec 28, 2012 2:13 pm

Re: Trouble with Servo Breakout & Wave Shield.

by adafruit_support_bill on Thu Jan 17, 2013 6:45 am

The servo will always move at 'full speed' to the position you set. If you want it to move slowly, you need to give it incremental moves as in the example code:

Code: Select all | TOGGLE FULL SIZE
  for (uint16_t pulselen = map (120,0,180,SERVOMIN,SERVOMAX); pulselen < map (180,0,180,SERVOMIN,SERVOMAX); pulselen++)
  {
    pwm.setPWM(servonum, 0, pulselen);
  }


If you want to change the speed of the move, you can add a delay inside the loop:

Code: Select all | TOGGLE FULL SIZE
  for (uint16_t pulselen = map (120,0,180,SERVOMIN,SERVOMAX); pulselen < map (180,0,180,SERVOMIN,SERVOMAX); pulselen++)
  {
    pwm.setPWM(servonum, 0, pulselen);
    delay(2);
  }


To move in the other direction:

Code: Select all | TOGGLE FULL SIZE
  for (uint16_t pulselen =  map (180,0,180,SERVOMIN,SERVOMAX); pulselen >  map (120,0,180,SERVOMIN,SERVOMAX); --pulselen)
  {
    pwm.setPWM(servonum, 0, pulselen);
    delay(2);
  }


There are ways to clean that up and make it easier to use. But it's best if you understand this part first.
User avatar
adafruit_support_bill
 
Posts: 35784
Joined: Sat Feb 07, 2009 10:11 am

Re: Trouble with Servo Breakout & Wave Shield.

by SolangeB on Wed Mar 25, 2015 3:05 am

Is it possible to get servos rotating in opposite directions. I used the code above and was able to get 2 servos to rotate simultaneously in the same direction (code below). How do I get them to rotate simultaneously in opposite directions now? I'm new to this as well.

for (uint16_t pulselen = map (0,0,180,SERVOMIN,SERVOMAX); pulselen < map (120,0,180,SERVOMIN,SERVOMAX); pulselen++)
{
pwm.setPWM(2, 0, pulselen);
delay(10);
pwm.setPWM(4, 0, pulselen);
delay(10);
}

SolangeB
 
Posts: 2
Joined: Wed Mar 25, 2015 3:00 am

Re: Trouble with Servo Breakout & Wave Shield.

by adafruit_support_bill on Wed Mar 25, 2015 5:57 am

Something like this should work:
Code: Select all | TOGGLE FULL SIZE
for (int i = 0; i < 180; i++)
{
    uint16_t pulselen1 = map (i,0,180,SERVOMIN,SERVOMAX);
    uint16_t pulselen2 = map (i,0,180,SERVOMAX,SERVOMIN);

    pwm.setPWM(2, 0, pulselen1);
    pwm.setPWM(4, 0, pulselen2);
    delay(20);
}
User avatar
adafruit_support_bill
 
Posts: 35784
Joined: Sat Feb 07, 2009 10:11 am

Re: Trouble with Servo Breakout & Wave Shield.

by SolangeB on Wed Mar 25, 2015 4:42 pm

Thanks you so much. It worked. Only thing is now one servo stops about half a second before the other when they both rotate. Do you have any idea what could be the issue?

SolangeB
 
Posts: 2
Joined: Wed Mar 25, 2015 3:00 am

Re: Trouble with Servo Breakout & Wave Shield.

by adafruit_support_bill on Wed Mar 25, 2015 4:46 pm

One servo may have a slightly different response than the other. Some variability between servos is typical and for critical applications you may need to tune the pulse widths a bit.
User avatar
adafruit_support_bill
 
Posts: 35784
Joined: Sat Feb 07, 2009 10:11 am