I'm new here ...
I have a small project in which I need control up to 30 servos using
an application, through the serial port (USB).
I have a Mega Arduino, I know that you can control up to 48 servos, but do not know
how to make an optimal code for that .. can control up to 6 servos (by PWM) without
problem using the instruction "case" to get the handle of the servo
and then the value of the position servo ..
But he liked to take it more simply, get a string with 30
identifiers over the respective values ??of position ..
can control up to 6 servos (by PWM) without problem
No, you can't. Servos are not controlled using PWM. They are controlled using PPM.
I have a Mega Arduino, I know that you can control up to 48 servos, but do not know
how to make an optimal code for that
Optimal code depends on what you want to do. Arrays will almost certainly come into play.
But he liked to take it more simply, get a string with 30
identifiers over the respective values ??of position
He who? If you want speed, you almost certainly don't want a string of anything. An array of bytes, now, that's a different story.
What kind of servos are you using? The standard 0 to 180 type? If so, you can send a start of data marker (a byte whose value is greater than 180, and less than 255), the 30 serial positions, and and end of data marker (a byte whose value is greater than 180, and less than 255, and different from the start marker).
On the Arduino, read the data from the serial port, discarding data until the start marker arrives. Keep reading, storing and counting the values until the end marker arrives. If you received 30 values, use them. If not, the packet was corrupt, and should be discarded.
I'm using standards servos, 0 to 180. I just need to control 30 servos, by USB. The speed is not to important...
I have this code working with 6 servos, "a" to "f" is the identifier servo and "0" to "180" is the position value.
But I don't know how to "scale" this to up 30 servos..
if (Serial.available())
{
char ch = Serial.read();
switch(ch)
{
case '0'...'9':
val = val * 10 + ch - '0';
break;
case 'a':
g_servo2.write(val);
val = 0;
break;
case 'b':
g_servo3.write(val);
val = 0;
break;
case 'c':
g_servo4.write(val);
val = 0;
break;
case 'd':
g_servo5.write(val);
val = 0;
break;
case 'e':
g_servo6.write(val);
val = 0;
break;
case 'f':
g_servo7.write(val);
val = 0;
break;
}
}
//Servo::refresh(); // Should try to call this every 20 ms to insure servo stays set
}
If you are going to purchase 30 servos, you might want to consider getting a seperate servo controller to be controlled by your arduino. An ssc-32 ($40) can control 32 servos.
I bought the Lynxmotion SSC-32 board. How should I connect the SSC-32 board to the Arduino board? Should I use Arduino Mega board instead of Arduino Uno board?
At 136 posts, you should know that taking a question onto an unrelated post is not a good idea. You should also know that posting questions about hardware without posting a link to the hardware wastes everybody's time.
jeffmorris:
I bought the Lynxmotion SSC-32 board. How should I connect the SSC-32 board to the Arduino board? Should I use Arduino Mega board instead of Arduino Uno board?
I'd go ahead and get the mega as the price difference between the mega and uno is now only a couple of $. You connect the arduino tx and rx to the ssc-32 TTL rx and tx, and connect the grounds between the two boards. make sure both are set for the same baud rate.