BaneBots PWM Motor controller?

hi, i'm new to the whole arduino (and partially robotics too....) thing.

i currently have two [new] BaneBots PWM motor controllers. I was wondering if i can use them with an arduino controller? i have looked it up, but can't seem to find a solid answer.

if yes, can someone post a demo code/wiring diagram?

thanks, beekman

Yes,

Those motor controllers take a standard PWM signal to control the motor’s speed. The Arduino Duemilanove board has 6 PWM output pins which could be used for this purpose. In essence you treat the motor controller like it was a servo.

Take a look at the Sweep example in the Arudino playground to learn how to control a servo:

Below is a sketch I use to control a Robot Power Scorpion XL. You will need to determine the center position and range of your motor controller.

#include <Servo.h>

// define arduino pins
#define pin_motor_l  9
#define pin_motor_r  10

// sensor objects
Servo motor_l;
Servo motor_r;

// sensor variables
int motor_center = 74;

/**
 * Arduino initialization
 */
void setup()
{
  // initialize motors
  motor_l.attach(pin_motor_l);
  motor_r.attach(pin_motor_r);
}

/**
 * Loop functions
 */
void loop()
{
  int value = 25;
  
  setLeftMotorSpeed(value);
  setRightMotorSpeed(value);
}

/**
 * Sets the left drive motors speed
 *
 * @param speed_l the left motor speed [-50,50]
 */
void setLeftMotorSpeed(int speed_l)
{
  motor_l.write(motor_center+speed_l);
}

/**
 * Sets the right drive motors speed
 *
 * @param speed_r the right motor speed [-50,50]
 */
void setRightMotorSpeed(int speed_r)
{
  motor_r.write(motor_center+speed_r);
}

and the pos and neg off the motor controller go the the 5v+ and ground on the arduino?

I am not sure exactly what motor controller you are using, but here is a link to a banebots manual that explains the connections:
http://www.trossenrobotics.com/store/p/4265-BaneBots-Motor-Controller-9A-peak-.aspx

White (Signal) - Connect this to Arduino digital pin capable of PWM.
Red (+BEC) - Connect this to Arduino 5v pin.
Black (Ground) - Connect this to Arduino Gnd pin.
The two other power connectors go to the battery that will be powering the motor.

Please note that each motor controller will draw current from your Arduino board, so you may not be able to power two of these from the USB connection alone.

I am using a couple BaneBots motor controllers and I emailed them to get the PWM range. 1000ms is full reverse, 1500ms is stopped, and 2000ms is full forward. Here is some code I used to get it working:

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;


int motor1Pin = 9; // the first motor's port number
int motor2Pin = 10; // the second motor's port number


void setup() { //call this once at the beginning
    pinMode(motor1Pin, OUTPUT); 
    pinMode(motor2Pin, OUTPUT);      
    servo1.attach(motor1Pin,1000,2000); 
    servo2.attach(motor2Pin,1000,2000);   
}

void loop() { //main loop
    
             servo1.write(93);
             servo2.write(93);//stop
             delay(1000); //wait 1 second

            servo1.write(120);
             servo2.write(120); // slow
              delay(1000); //wait 1 second
                  
            servo1.write(150);
             servo2.write(150); //medium
           delay(1000); //wait 1 second

             servo1.write(179);
             servo2.write(179); //fast
            delay(1000); //wait 1 second

        
            servo1.write(130);
             servo2.write(50); //right
            delay(1000); //wait 1 second

         

            servo1.write(50);
             servo2.write(130); //left
            delay(1000); //wait 1 second
      }

I used the Servo class which simplifies things a bit. When you write to a servo using this class, you give it degrees. So writing 0 degrees corresponds to sending a PWM signal that is 1000ms. Writing 90 degrees means 1500ms, etc. You’ll notice in my code that I wrote 93 degrees to get it to stop and that is because writing 90 didn’t stop it completely. Sometimes it takes some experimenting to get it exact.