using a motor speed controller

I am trying to use a BaneBots BB-3-9 speed controller to control some larger motors. I am new to Arduino, and have not been able to get this to work. From what I have read (and please correct me if I am wrong), it is expecting to be talked to like a servo, with pulses. I have been able to get my motors turning a little, but I think it was probably a fluke. I would really appreciate any help at all, and any push in the right direction (maybe some sample code or something?). I can post the code I am using now if that would be helpful. Basically I have been using the servo library, with some results, and I also tried the analogWrite() function, which didn't work at all. I saw this post on these forums, and was wondering if these suggestions would also work for me:

The Arduino should be able to communicate with the controller via any of the supported modes. Mode 1: analog Use the analogWrite() command. They say you'll need a resistor/capacitor filter on the output pin. You'll have to use one of the pins labeled with "PWM". Mode 2: R/C Use the Servo library. Treat it like a continuous-rotation servo. You'll have to use either pin 9 or pin 10. Mode 3: simplified serial Connect the Rx/Tx lines (pins 0 and 1, they're labeled) to the controller as per the spec. Use code like the following: Code:

Serial.begin(9600); Serial.print(127); // idle Serial.print(255); // full forward Serial.print(0); // full reverse

Note that you'll have to set the baud rate using DIP switches on the motor controller. Mode 4: Packeted serial Physical connections will be exactly the same as the serial. You'll just need to send slightly more complex packets over the serial interface.

Any help would be much appreciated!

The quote doesn't appear to relate to the controller you're using, which does appear to emulate a servo.

One thing to watch out for is the loss-of-signal shut-down. It doesn't say how this resets - it may be important to start supplying servo pulses asap after powering on the ESC.

Can you post your code, please?

OK had a look at the datasheet http://banebots.com/mm5/support/manual/BB-0309.pdf

It has a safety feature that requires the throttle stick to be centred, so your first servo.write should be for 90 degrees, I guess.

What do the ESC LEDs report?

Here is the code I am using:

int servoPin = 9;
void setup()
{
pinMode(servoPin,OUTPUT);
}
void loop()
{
int temp;
for (temp = 0; temp <= 200; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1500); // 1.5ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
}
for (temp = 0; temp <= 200; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(2000); // 1.8ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
}
for (temp = 0; temp <= 200; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1000); // 1.2ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
}
}

The lights on the speed controller are actually responding the way I want them to. First only the ready light is on, then DIR1, then DIR2. My problem now is that the voltage that it is putting out is really small: it is always below 1 volt and I am expecting around 12 volts. The other question I have is about the length of the pulses. I know that somewhere near 1.5ms is neutral, but what is the total range of the pulse width that I can use?

You'd probably find it easier to use one of the servo libraries.

the voltage that it is putting out is really small: it is always below 1 volt and I am expecting around 12 volts

How did you check the output voltage? You probably ought to be using an oscilloscope. Have you connected a motor?

Unfortunately, I don't have an oscilloscope (but I really want one). I was just using a multimeter. We did try to connect the motor, but it didn't move. The motor I am using is a little Johnson 3-12v. I tried using the servo library earlier, and it didn't work, but I'll try again. The only thing with that was that servo.write() only lets you give the number of degrees to turn, and I didn't know how to use it for a continuous rotation servo.

You're not using a continuous rotation servo.

An ESC is designed to replace earlier R/C speed controllers that were rheostats, or two or three-stage mechanical switches with large power resistors. These devices were controlled by standard servos; imagine a servo driving the shaft of an external potentiometer (I think early ESCs may even have used this method).

Push the stick forward (180 degrees), and the servo would turn the potentiometer/rheostat/switch to maximum forward. Put the stick (90 degrees) to neutral, and the servo would move the wiper to the mid-position of the rheostat/pot/switch.

Take the servo out of the picture, and you have an ESC.

Ok, so if I use the servo library, then just setting it to 180 degrees is forward continuous, 90 is stopped, and then below that is reverse? And do you have any idea why my speed controller is putting out such small voltages?

Mode 1: analog
Use the analogWrite() command. They say you’ll need a resistor/capacitor filter on the output pin. You’ll have to use one of the pins labeled with “PWM”.

Why not use PWM? Here is the tutorial I used to get my pololu motors running. It uses PWM:

https://custer.lcsr.jhu.edu/wiki/images/8/83/530.421_Lab2.pdf

You have to modify the code to get it working for your project. I think this will work better the treating the motor as a servo.

BTW: Will your driver (BB-3-9) allow the motor the rotate forward and reverse?
And how do you power the motor? External power supply?

Cheers.

Ok, so if I use the servo library, then just setting it to 180 degrees is forward continuous, 90 is stopped, and then below that is reverse?

Yes, pretty much (though it may be reversed).

And do you have any idea why my speed controller is putting out such small voltages?

That's why I asked you how you were measuring the voltage - your meter may not (most probably won't) be able to accurately measure PWM.

Yes, my motor controller allows for reverse and I am using an external 12v battery. I will try the servo library again and see if that fixes the low voltage problem.

@OpenSource:

Why not use PWM?

Because it won't work. An ESC is designed to emulate an R/C servo, with a PPM signal with a pulse repetition rate of around 50Hz.

This is my attempt at replicating my earlier posted code by using the servo library:

#include <Servo.h>
Servo servo1;

void setup()
{
pinMode(9,OUTPUT);
servo1.attach(9);
}
void loop()
{
servo1.write(91);
delay(4000);

servo1.write(160);
delay(4000); 

servo1.write(30);
delay(4000); 
}

The lights on the motor controller are responding correctly, but I can’t seem to give it an angle that is below 30 degree or above 160 degrees. And, I am still having the low voltage problem. I made sure to try it with the motors and I still got nothing. I know that my multimeter can’t measure PWM or anything, but I checked the voltage that was going to the motor and it was changing when it was supposed to, but only in very small amounts. Any ideas?

but I can't seem to give it an angle that is below 30 degree or above 160 degrees

You could try modifying the servo pulse width, using the "attach"

http://arduino.cc/en/Reference/ServoAttach

I emailed the company to find out what the range of pulse widths it can handle is to make sure it is the controller, not something with the arduino. I also asked them about the low voltage thing, so hopefully they can help.

Although I have never used this kind of speed controller, I have coded for the IFI Victor speed controllers before. If you want to use analogWrite, you just use between 5 and 10 % and make sure it's a 20ms duty cycle on a PWM pin. I also had problems with the SoftwareServo library - wouldn't compile. I wrote this function to write servos:

void DoServo(int pin, int val) { val = map(val,500,2500,0,255); digitalWrite(pin,HIGH); delayMicroseconds(val); digitalWrite(pin,LOW); }

Usually, they don't care how fast you update them as long its between 20ms and 50ms. The Victors I used could handle up to 10ms updates with no problem. Also - the code above will disable interrupts (Because of delayMicroseconds). If you have a problem sending it pulses near the end of the limits, note this: RC radios are usually designed to output between +- 45 degrees, while the servo lib can go from +- 90. If you have a problem past 45, the BaneBots controllers probably can't go past 45.

Apalrd

The company said that the range is 1.0ms to 2.0 ms with 1.5ms for neutral. They said they weren't familiar with the Arduino, and suggested I make sure it is sending the right pulses.

edit: Thanks apalrd, I'll try that and see if it helps.

So we had bought 2 motor controllers and had only been testing with one of them. On the off chance that the one we were using might be faulty, we tried the other one and it worked! So the majority of the problem is solved, it was just a broken part. However, we did encounter a new problem. My multimeter is reading 12v from the motor controller, but when I hook it up to the motor, it only turns a few times and then stops (my multimeter confirmed that it was just a lower voltage coming from the controller). The controller's specs are here: http://banebots.com/pc/ELECTRONICS/BB-0309

The motors are here: http://www.allelectronics.com/make-a-store/item/DCM-229/3-12-VDC-MOTOR/-/1.html

And the battery is a 12v 18 amp-hour sealed lead-acid.

Is the motor just pulling too much voltage?

Is the motor just pulling too much voltage?

You can't "pull too much voltage". Voltage is fixed by the power source, and can only drop.

You may be drawing too much current though.

Do you know what the exact motor ratings are, particularly stall current?

I am still looking for the exact specs on the motor, but it is rated for 1.2 amps at 6 volts and we are running it at 12v. The controller is rated for 3 amps continuous and 9 max. When we were testing the motors on it, I noticed that the controller got pretty hot after only a short time. I thought that the controller we got would be able to handle that, but can it?