How many servos can be on a BotBoarduino?

Hello

How many servos can be on a BotBoarduino? I am trying to attach seven servos to the BotBoarduino but I can only get six to respond. What I want to do is have six run the arm, which is an AL5A arm, and one to provide a camera mount rotation. The cameras are completely independent of the board.

Thanks

Posting your code is usually a good start for trouble shooting.

In theory if you are using the Servo library, the Botboarduino like other Arduinos that are based on the Atmega328 can handle up to 12 servos. But as Zoomkat mentioned mentioned, probably need more info or code to tell you much.

Kurt

Info:

I am powering the board with the wall-wart. The board is also sending serial output to an Arduino UNO.

Code:

Arm.h

[code]#ifndef ARM_H
#define ARM_H

#include “Arduino.h”
#include <Servo.h>
#include <PS2X_lib.h>

#define DISPLACE 3

class Arm{
private:
void servo1(int);
void servo2(int);
void servo3(int);
void servo4(int);
void servo5(int);
void servo6(int);
void servo7(int);
enum {maxservos = 7};
int pin[maxservos];
int pos[maxservos-1];
Servo servo[maxservos];
PS2X controller;
void calibrate();
void deflt();
public:
Arm();
void prep();
void run();
};

#endif[/code]

Arm.cpp

[code]#include “Arm.h”

Arm::Arm(){}

void Arm::prep(){
Serial.begin(9600);
pin[0] = 2;
pin[1] = 3;
pin[2] = 4;
pin[3] = 5;
pin[4] = 10;
pin[5] = 11;
pin[6] = 13;
servo[0].attach(pin[0]);
servo[1].attach(pin[1]);
servo[2].attach(pin[2]);
servo[3].attach(pin[3]);
servo[4].attach(pin[4]);
servo[5].attach(pin[5]);
servo[6].attach(pin[6]);
controller.config_gamepad(9,7,8,6,false,false);
calibrate();
}

void Arm::run(){
controller.read_gamepad();

if(controller.Analog(PSS_LY) > 129){
	servo1(DISPLACE);
}

if(controller.Analog(PSS_LY) < 125){
	servo1(-DISPLACE);
}

if(controller.Analog(PSS_RY) > 125){
	servo2(DISPLACE);
}

if(controller.Analog(PSS_RY) < 129){
	servo2(-DISPLACE);
}

if(controller.Analog(PSS_LX) > 128){
	servo3(DISPLACE);
}

if(controller.Analog(PSS_LX) < 126){
	servo3(-DISPLACE);
}

if(controller.Button(PSB_PAD_UP)){
	servo4(DISPLACE);
}

if(controller.Button(PSB_PAD_DOWN)){
	servo4(-DISPLACE);
}

if(controller.Button(PSB_L1)){
	servo5(DISPLACE);
}

if(controller.Button(PSB_R1)){
	servo5(-DISPLACE);
}

if(controller.Button(PSB_CROSS)){
	servo6(DISPLACE);
}

if(controller.Button(PSB_TRIANGLE)){
	servo6(-DISPLACE);
}

if(controller.Button(PSB_SQUARE)){
	servo7(DISPLACE);
}

if(controller.Button(PSB_CIRCLE)){
	servo7(-DISPLACE);
}

if(controller.Button(PSB_L2)){
	calibrate();
}

if(controller.Button(PSB_R2)) {
	deflt();
}

}

void Arm::servo1(int a){
servo[0].write(servo[0].read() + a);
}

void Arm::servo2(int a){
servo[1].write(servo[1].read() + a);
}

void Arm::servo3(int a){
servo[2].write(servo[2].read() + a);
}

void Arm::servo4(int a){
servo[3].write(servo[3].read() + a);
}

void Arm::servo5(int a){
servo[4].write(servo[4].read() + a);
}

void Arm::servo6(int a){
servo[5].write(servo[5].read() + a);
}

void Arm::servo7(int a){
servo[6].write(servo[6].read() + a);
}

void Arm::calibrate(){
pos[0] = servo[0].read();
pos[1] = servo[1].read();
pos[2] = servo[2].read();
pos[3] = servo[3].read();
pos[4] = servo[4].read();
pos[6] = servo[6].read();
}

void Arm::deflt(){
if(servo[0].read() != pos[0]) servo[0].write(pos[0]);
if(servo[1].read() != pos[1]) servo[1].write(pos[1]);
if(servo[2].read() != pos[2]) servo[2].write(pos[2]);
if(servo[3].read() != pos[3]) servo[3].write(pos[3]);
if(servo[4].read() != pos[4]) servo[4].write(pos[4]);
if(servo[6].read() != pos[6]) servo[6].write(pos[6]);
}[/code]

CSRIVBB.ino

[code]#include <Drive.h>
#include <PS2X_lib.h>
#include <Servo.h>
#include <Arm.h>

Arm arm;
DriveBB drive;
PS2X controller;
boolean n = false;

void setup(){
arm.prep();
drive.prep();
controller.config_gamepad(9,7,8,6,false,false);
}

void loop(){
controller.read_gamepad();
if(n == true){
drive.run();
}
else{
arm.run();
}
if(controller.ButtonPressed(PSB_SELECT)){
n = !n;
}
delay(50);
}[/code]

From the code it appears you are trying to use some type of psc controller. Does the controller work with the 6 arm servos? which pin did you add to the code for your additional servo? have you connected the extra servo to a pin known to work to verify that servo is not broken? How do you expect the extra servo to be controlled from the psc controller?

I forgot to suggest last night that you might try using a different IO pin than 13 for the 7th servo. Like most Arduinos, I believe there is an LED with other associated hardware on that IO pin, which may be interfering with the servo operations.

Kurt

Yes, when there is no 7th servo. I commented out the 7th motor code to check this.

13

The extra servo works on its respective pin. What happens is that the first servo (servo[0] in the code) of the arm no longer responds. I did check to see if the 1st motor had attached which returned true. What is happening is that the write command does not execute. The 1st servo was originally on pin 12 but was moved to pin 2 and the servo still would no move.

Circle and Square

I should have mentioned that the 7th servo works. What happens is that the 1st servo to attach stops working. Sorry about that.

I think you have bug in your program. When you look at the line:
pos[6] = servo[6].read();

It will overwrite memory as pos was defined as count of servo -1…

Kurt

Some servo test code for use with the arduino IDE you might modify to see if you can get seven servos working independent of the psc controller code.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Yes I did. Everything works now. Thank you.

I want to use a BotBoarduino to control a robot arm that needs 12 (may be more) standard servos.

The user Manual for BotBoarduino says it has 20 I/O pins,6 are analog inputs and 14 are digital pins,
and it can control up to 20 servos.

My questions are:

  1. Can I plug the servos in to any of the 12 digital pins (pin 2-13)?

  2. If I plug in the servos in to any of the 6 analog pins (A0 - A5), will it work?
    Are the A0-A5 pins for input only? Or they can be used for both input (from sensors)
    and output (to control servos and motors)?
    (I’m asking this because it’s possible I need more than 12 servos for my robot arm.)

  3. This is a general question. I know BotBoarduino is Arduino Duemilanove compatible.
    I read the manual for Arduino Duemilanove, which says, among the 14 digital pins,
    only 6 provide PWM outputs.

My understanding is that the control signal for servos are PWM signals. It sounds like
only the 6 digital PWM pins in BotBoarduino can be used to control these servos.
But from all I read, it says any digital channel can be used to control these servos.
Could you pleas explain?

Thank you very much.

Roger

Yes. You can use the servo library which can control servos via the digital pins

You could get them to work, since the analog pins can be made to provide the necessary R/C protocol. However the standard servo library only uses the digital pins.

All digital and analog pins can be used for input and output. You should not control DC motors directly using any of the pins simply because they cannot provide the required current. The BotBoarduino has VS which can provide the servos with external power.

Keep in mind if your arm uses more than 12 servos, the ones at the base need to provide a lot of torque to lift the rest of the arm up. It’s for exactly that reason that most arms which use servos don’t have more than about 6-7 degrees of freedom.

Correct. However, the pins can provide timed 5V pulses, which is what servos need.

No; in order to position a servo motor, the servo needs to be connected to a 4.8V to 6V power supply (red and black wire) and the third wire (usually yellow or white) is connected to a digital pin. This digital pin would sent it a timed 5V pulse of between 500us to 2500us, repeated every ~30ms. Therefore if the digital pin goes HIGH (5V) for 1500us, then goes LOW (0V) for 30ms and repeats, the servo would move to 90 degrees (if you consider a servo’s travel to be 0 to 180 degrees rather than -90 to +90). Knowing that 500us corresponds to a servo’s mininimum angle (usually 0 degrees) and 2500us corresponds to a servo’s maximum position (usually 180), you can calculate the pulse which corresponds to a desired servo angle.

I understand these basics. (Last year, I built a robot arm using BotBoarduino to control an AL5D. We won the 2nd
place medal in Science Olympiad competition. We got a lots of helps here last year. Many thanks!)

My understanding is that PWM (Pulse-width modulation) signals are the “pule width” stuff you mentioned above.
My question is this: There seams to be two kind digital pins (from the manuals for BotBoarduino and Duemilanove):
The regular one (without PWM outputs), and the ones with PWM outputs. What you are saying here
is that both kind pins can be used to control the servos in the same way. Then, what’s difference between the two?
What are the digital pins with PWM outputs used for?

The servo torque is not a concern. My new project is a robot for solving Rubik’s Cube. (I have completed the
program to calculate the moves. Now I need to build robot arms to carry out the moves). It will have four
independent arms, each with three servos (forward/backward; rotation; grabber). Each servo only needs
minimum torque. So I need 4 x 3 = 12 servos already. It is very likely I’ll need a servo to up/down a platform
(that support the Rubik’s cube). I might need more movements for this platform. So I will need more than
12 servos.

Now to the analog pins. I’ll never use BotBoarduino to control regular motors, only servos.
Could you please provide a pointer to sample Arduino code that control servo from A0- A5 pins?
Or where can I learn this?

Last question: I’ll need 4 servos (for arm rotation) that can rotate 360 degrees (or at least 270 degrees).
Last year, our robot arm also needed one 360 degree servo (for the base). Last year I tried, but all servos
sold at Lynxmotion can only rotate 180 degrees. I bought a GWS S125 1T servo
for the base. They can rotate 360 degrees, but the quality is low. (When the servo is supposed
to stay stationary, sometimes it slowly rotates.) For this servo, our robot arm got the 2nd place medal.
The gold medal team refused to tell us what 360 degree servo they used. Can you tell me any other servo
(at Lynxmotion or other place) that can rotate 360 degree (or at least 270 degree).

That’s a lot of questions. Thanks a lot in advance.

PWM can ideally be used to approximate sinusoidal waves or analog (required by some DC motor controllers for example).
en.wikipedia.org/wiki/Pulse-width_modulation
arduino.cc/en/Tutorial/PWM

What are the digital pins with PWM outputs used for?
Mostly DC motor controllers which require PWM input. There are of course other applications which you may come across, but most simply need digital / analog / serial / I2C. Perhaps we can create an article about the differences later and post if on GoRobotics.

You would do it the same way you would with a digital pin (not using the servo library). Analog pins are more “versatile” that digital pins, and can do everything digital pins can.

The 785HB servo is one of a few R/C servos (quarter scale winch servo) which can rotate more than 180 degrees. It’s available from our parent company RobotShop:
robotshop.com/en/hitec-hs785 … motor.html