Servo speed sheild

Hi, Im currently programing a robot wiith 12 sevos, and usually 4 servos should run at the same time to different angels.

I thought about buying the sparkfun pwm sheild (https://www.sparkfun.com/products/10615).
My question is, is theres a way to control the servo speed using this sheild?

this is my current code

#include <VarSpeedServo.h>
VarSpeedServo myservo1;
VarSpeedServo myservo2;

VarSpeedServo myservo3;
VarSpeedServo myservo4;

VarSpeedServo myservo5;
VarSpeedServo myservo6;

VarSpeedServo myservo7;
VarSpeedServo myservo8;
VarSpeedServo myservo9;
VarSpeedServo myservo10;
VarSpeedServo myservo11;
VarSpeedServo myservo12;
void setup() {
   
  myservo1.attach(22);
  myservo2.attach(23);
  myservo3.attach(26);
  myservo4.attach(27);
  myservo5.attach(34);
  myservo6.attach(35);
  myservo7.attach(38);
  myservo8.attach(39);
  myservo9.attach(42);
  myservo10.attach(43);
  myservo11.attach(46);
  myservo12.attach(47);
       
while (millis() <= 1668) {}
    myservo1.write(180,120);             
    myservo5.write(90,120); 
    myservo2.write(170,120);
    myservo6.write(130,120);
    myservo3.write(170,120);             
    myservo7.write(0,120);    
    myservo4.write(30,120);        
    myservo8.write(100,120);
    myservo9.write(40,120);              
    myservo10.write(0,120);             
    myservo11.write(82,120);              
    myservo12.write(160,120);  
    delay(4000);

    while (millis() <= 2268) {}           
    myservo5.write(0,120); 
    myservo6.write(25,120);                       
    myservo8.write(160,120);     
    delay(2300);

while (millis() <= 6882) {} 
   myservo3.write(100, 80);  
   myservo7.write(90, 80);
   delay(500);

//****
myservo2.write(80, 80);
myservo4.write(120, 80);     
myservo6.write(120, 80);
myservo8.write(80, 80);
delay (700);
 }
void loop() {
  // put your main code here, to run repeatedly:
}

As you can see, I’m using the servo speed libary, and in each line I have another servo with different angle and a different speed.

So, Is there a way to control the servo speed with the sparkfun sheild, in a simple way as this?

I’m aware that I can use sweep, but It’s just a lot of coding and far less easy to code, I need an easy option as speed from 1-255.

Thanks

4 servos should run at the same time to different angels.

I don’t think a servo can turn to an angel. An angle, maybe…

Servos are driven by PPM (pulse position modulation), not PWM (pulse width modulation). That shield is not for driving servos.

You change the speed of a servo by taking larger or smaller steps and twiddling your thumbs between steps. Of course, the VarSpeedServo library takes care of that, IF you use the appropriate function to set the speed.

while (millis() <= 6882) {}

So, 6.882 seconds after resetting the Arduino, you never want to do this again. Fine by me, but you should put a comment that explains why.

void loop() {
  // put your main code here, to run repeatedly:

}

Or, a stupid comment if you don’t have any code.

PaulS:
I don’t think a servo can turn to an angel. An angle, maybe…

Servos are driven by PPM (pulse position modulation), not PWM (pulse width modulation). That shield is not for driving servos.

You change the speed of a servo by taking larger or smaller steps and twiddling your thumbs between steps. Of course, the VarSpeedServo library takes care of that, IF you use the appropriate function to set the speed.

while (millis() <= 6882) {}

So, 6.882 seconds after resetting the Arduino, you never want to do this again. Fine by me, but you should put a comment that explains why.

void loop() {

// put your main code here, to run repeatedly:

}



Or, a stupid comment if you don't have any code.

Hi, thanks for your help. First of all, English is not my main langauge, but I usually do my best, unlike most of teenager in american that can’t tell the difference between your and you’re, but that is another topic.

I’ve attached my code just to example how I’m changing the servo speed, to be more spesific:
Yes, I only need to run my code once.
I could add comments but my current code is working fine, and It’s not my problem. This was only an example, this code doesn’t need to get analysed.

According to sprakfun github libary - PWM_Shield/Servos.pde at master · sparkfun/PWM_Shield · GitHub
There is a way to control servo using their product. I only mention this sheild since it’s the only sheild that supposed to have servo support in my retailer store (In my country we don’t have a wide slection of arduino parts like you have in Amazon, eBay etc, and I really need to get this product fast).

I've attached my code just to example how I'm changing the servo speed

I must have missed that part. You are using a library that lets you move servos at variable speeds, but I don't see where you are setting the speed of any of the servos.

PaulS:
I must have missed that part. You are using a library that lets you move servos at variable speeds, but I don't see where you are setting the speed of any of the servos.

Yes that may be unclear, I will add comments when the 5 minuted post delat will end,
but for the current time:
myservo4.write(30,120);
in every line like this the first number is the angle and the second one is the speed.
thats meen, 30 degress rotation for 120 speed value (out of 255). I really don't understand how thats works, I'm just using the varspeedServo libary. I would like to know if there a simple way as this to control the servos using the sparkfun pwm sheild (As I mentioned above, this is the only sheild I could get in the near future)

would like to know if there a simple way as this to control the servos using the sparkfun pwm sheild

I still don't see why you need a shield to control 6 servos. What problem is the shield an attempt to solve?

Not that I think it will, since you do not need to use PWM pins to control servos. While doing so is possible, it is NOT done by analogWrite()ing to the pin.

PaulS:
I still don't see why you need a shield to control 6 servos. What problem is the shield an attempt to solve?

Not that I think it will, since you do not need to use PWM pins to control servos. While doing so is possible, it is NOT done by analogWrite()ing to the pin.

It's 16 servos, and im facing an issue with powering them all. I thought that using an extra sheild or card, with it's own power supply would be more efficient. And I get a lot of twiching with my servos, they just go crazy, usually in the start of the program and espically if I'm running a part of the program with no spesific movement for those servos.

the servos are currently connected to the digital pins.

It's 16 servos

Ah, OK. That shield won't help.

im facing an issue with powering them all.

That shield won't help.

the servos are currently connected to the digital pins.

So, increasing the number of PWM pins won't help.

There ARE servo shields that might help. But, a Mega can easily control 16 servos that have their own power source.

How are the servos powered now? Not be the Arduino, I hope. If they are, you are doing grave harm to your Arduino.

PaulS:
Ah, OK. That shield won't help.
That shield won't help.
So, increasing the number of PWM pins won't help.

There ARE servo shields that might help. But, a Mega can easily control 16 servos that have their own power source.

How are the servos powered now? Not be the Arduino, I hope. If they are, you are doing grave harm to your Arduino.

I'm currently not in front of my robot (it's in the school lab) but in general, ther's a 8v battery, while the (+) is connected to a digital port (not arduino specified, just a connector) and the (-) is connected both to this card and the arduino ground.

The last time we've launched the robto, 5 servos got fried. I'm aware that servo should be getting 6v, but this connection was made by my robotics teacher so I trusted him. Before we've done that we're tried a 8v battery connected to voltage card (I don't know how to translate it to english, it's just a small componomet that turn 8v to 6v) but it's dont a lot of problem and massively heated.

it's just a small componomet that turn 8v to 6v

A voltage regulator. And, yes, they will get hot. They regulate the voltage by turning the excess into heat. How much heat depends on the amount of current. With servos, there will be a lot of current.

You could use one voltage regulator per servo, to minimize the amount of current that each one needs to deal with.

PaulS:
A voltage regulator. And, yes, they will get hot. They regulate the voltage by turning the excess into heat. How much heat depends on the amount of current. With servos, there will be a lot of current.

You could use one voltage regulator per servo, to minimize the amount of current that each one needs to deal with.

Thats a lot of regulator, do you have another solution in mind?

And just to be clear, you don't recomend me to buy a servo sheild? It doesn't have any advantages in powering the servos or get less twiching?

another reason I wanted to buy an external servo card is that I want to add compass and ultrasonic sensor to my system. I don't have any code for them right now, but I've understand that the arduino mega has limited amount of timers, and I need to run things simultaneously (for example, tell the robot to rotate 90 degress with the compass while moving the servos)

And just to be clear, you don’t recomend me to buy a servo sheild?

Buying a servo shield is fine. But, the one you are asking about is not a servo shield.

PaulS:
Buying a servo shield is fine. But, the one you are asking about is not a servo shield.

Whats the difference? According to sparkfun site this sheild is also good for servos, and there's a code in github for that.
can you suggest a better servo sheild? (I saw that there adfruit one, but there's no such a thing in my conutry)

I have a PWM/servo breakout board from Adafruit, and it works great for servos and ESCs. Yours should be about the same. The big difference is the Adafruit unit doesn't need the Arduino's attention. It is a "set it and forget it" operation.

You can use PWM to drive servos, if you can adjust the frequency to the needed ~50Hz. But only a small fraction (5%) of the available duty cycles are useful to control the servo, because only high-pulses between 1ms (aka 5% duty cycle) and 2ms (aka 10% duty cycle) are valid.

So the usable resolution is only 5% of the pwm resolution as well. If you use 12 bit pwm, which has 4096 steps, you end up having 204 steps resolution to drive the servo. Probably enough, but you should know it.

If I'm wrong about what I said, I'm sorry, it's 2AM here :wink:

lg, couka

Actually, I have 250 step resolution, but who's counting? :wink: That is 4us resolution.

can you suggest a better servo sheild?

Since you seem dead-set on buying that one, even though it won’t help, no, I can’t. Go ahead and waste your money.

couka:
You can use PWM to drive servos, if you can adjust the frequency to the needed ~50Hz. But only a small fraction (5%) of the available duty cycles are useful to control the servo, because only high-pulses between 1ms (aka 5% duty cycle) and 2ms (aka 10% duty cycle) are valid.

So the usable resolution is only 5% of the pwm resolution as well. If you use 12 bit pwm, which has 4096 steps, you end up having 204 steps resolution to drive the servo. Probably enough, but you should know it.

If I'm wrong about what I said, I'm sorry, it's 2AM here :wink:

lg, couka

SurferTim:
I have a PWM/servo breakout board from Adafruit, and it works great for servos and ESCs. Yours should be about the same. The big difference is the Adafruit unit doesn't need the Arduino's attention. It is a "set it and forget it" operation.

Hi, I didn't quite get what you've said. I did understand there's no problem to control the servo using this pwm sheild. But can I use the pwm to control the speed?
If you have an example to such a control that's would be great. :slight_smile:

Does anybody knows?