Go Down

Topic: Controlling A Brushless Motor (Read 65906 times) previous topic - next topic

Lazer57

I bought a brushless motor, a brushless motor controller and a li-po battery.

The motor controller has 3 wires (white, red and black), can these be connected to the arduino deicimila to control the motor?

If so, what pins and how do I control it? I don't see an applicable library/example for it.

Mine has a white wire instead of the yellow shown in the image.

mem

#1
Nov 10, 2008, 06:20 am Last Edit: Nov 10, 2008, 06:23 am by mem Reason: 1
The three thin wires with the servo connecter should be connected to the arduino as if it was a servo. The white wire is the signal that connects to the Arduino output pin. The blck wire should be connected to ground. The center wire has +5 volts and should not be connected to the arduino (unless you want to use this to provide the +5 volts to power the arduino)

The three thick wires are connected to the motor.  (you can reverse any two of these wires if the motor turns in the wrong direction). The two thick wires connect to the battery.

Use one of the Arduino servo libraries to drive the controller. Most need arming by sending a minimum throttle signal.  Check the instructions that came with the controller to find out what pulse width this is.

weirdo557

pretty sure those controllers use a servo signal to controll them. try using the hardware servo library and treating them like a servo. looks like the white is the signal (connect to digital pin) the black is ground, and the red is +5 volts.

(be carefull, i've never personally used one of those controllers)

Lazer57

thnx for the responses but i still have questions (i will solder everything tomorrow and then try to control the motor).

unfortunatelyi don't have instructions for the controller, the only info i have for it is at the bottom of this post.

where does pulse width come into play in the servo examples? (i.e. does myservo.write work like analogWrite except that it is pre-tweaked for degrees?)

will this code work (assuming i don't have a problem with arming)?: is a delay necessary (if no delay is used, will it just automatically delay the 2ms period of the PWM signal?)? is a minimum throttle signal necessary previous to this code or will the fact that this code ramps up make that unecessary?
Code: [Select]
int ESCpin = 11;    // ESC signal wire connected to pin 11 on arduino
int val = 0;        //variable to store PWM value

void setup()
{
 
}


void loop()
{
 for(val = 0; val <= 255; val += 5)
 {
   analogWrite(ESCpin, val);
   delay(100);
 }
}


Manufacturer's descriptions:
.
·Input Volt: 6V-12V
·Constant Current: 30A
·Max Current: 40A
·Low-Voltage Cutoff: Auto detect and set
·Size: 55*24.5*5.3mm
·Weight:22g(Net Weight)
·Hight rate PWM
·Low resistence
·Sisteen cells Max (with BEC disabled)
·User programmable brake
·Low voltage auto setting based on battery
·Throttle range self-adjusting
·Soft start ramp up
·Auto motor cutoff with reset
·Runs motor in forward or reverse
·Safe power arming program ensures motor will not run accidentally after turn on
·Low torque start
·Auto shut down when signal is lost

mem

#4
Nov 11, 2008, 09:50 am Last Edit: Nov 12, 2008, 09:13 am by mem Reason: 1
you should not try to use your speed controller with that sketch!

Servo signals are not the same as PWM.  Although they are sometimes confusingly called PWM, servo signals are actually PPM (pulse position modulation). In the servo code, altering the degrees varies the width of the HIGH pulse from approx 1ms to 2ms. But unlike PWM, the LOW pulse is always around 20ms long.

If you are using Arduino version 0012, there is a servo library that comes with that. You could try it with the  example knob.pde sketch that uses a potentiometer to adjust the pulse width. But any library and sketch that is intended for a servo should work. You will need to expirement to see if the speed controller arms at 0 degrees or 180 degrees. Once armed (you should hear some beeps if the controller is connected to the motor) , varying the number of degrees should change the speed of the motor.

Good luck!

Lazer57

here's an update as i mess around with it more and maybe i'll get some more tips/info as i am in the process of trying stuff out.

i ran the servo sweep sketch and it took a while but then the motor kicked in and sped up (wow its fast, was holding it in my hand), then it slowed down to a stop (was too busy trying to turn it off to know for sure if its speed tapered to a stop) and i turned it off after it repeated the process a second time.

i then tried just going at "int pos = 0" and i got 3 beeps and a few jiggles but nothing happened. i did the same with "int pos = 180" with the same results, same with 90. which i guess means it doesn't arm at any of those values.

thnx for the responses so far mem, it has helped a lot, makes me happy that i bought the arduino due to the help i get on the forum and website.

i just finished making a motor mount with a 25pack cd storage container. filled it with golf balls, mounted the motor with a couple rubber dampeners and i have some rubber feet on the bottom. not gunna hold that thing in my hand ever again, it wanted to rip free... it was pretty awesome. :)

Lazer57

#6
Nov 12, 2008, 04:32 am Last Edit: Nov 12, 2008, 06:07 am by Lazer57 Reason: 1
ok i think i got this figured out. here's my sketch to keep the motor running continously and at the lowest speed possible.

Code: [Select]
#include <Servo.h>

Servo myservo;

int pos = 0;

void setup()
{
 myservo.attach(9);
}


void loop()
{
 if(pos <= 30)
 {
   for(pos = 0; pos < 40; pos += 5)
   {
     myservo.write(pos);
     delay(1000);
   }
 }
 else
 {
   int pos = 31;
 }
}


here's what i figured out (i think):
1) it arms at position 0 (well apparently anything under 30, but i'll have to see if it takes less than 5 seconds if i set position to 0 for a period of time)
2) the minimum position is 30, having pos = 25 rarely worked and less than that never worked
3)it takes 5 seconds to arm (it won't run at all if given less than 5 seconds to reach position 30)

i am interested in making a library for brushless motors. got lots to learn about brushless motors, ESCs and the best way to interact with them though. will save others time and confusion though.

vahakn

#7
Nov 26, 2008, 09:43 pm Last Edit: Nov 26, 2008, 09:46 pm by vahakn Reason: 1
Hi there

im also trying to controll a motor, but Im using a Digital Speed Controll made by Hitec, it is an SP 1801n:
http://www.hitecrcd.com/Manuals/SpeedControls/Sp1801.pdf

I have adapted a version of the servo sweep program with pretty crappy results but i got it turning. (too fast for my liking)

I tried your program but i got nothing out of it.
Do you know what I can change in your parameters to get something happening, What numbers do what in your program?

thanks

Vahakn

here is my post:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227728415

here is my prog:


int servoPin = 7;            // R/C  Servo connected to digital pin
int mySpeed;                 // angle of the servo (roughly in degrees) 0-180
int pulseWidth;              // function variable

void servoPulse(int servoPin, int myAngle) {
 pulseWidth = (mySpeed * 11) + 500;  // converts angle to microseconds
 digitalWrite(servoPin, HIGH);       // set servo high
 delayMicroseconds(pulseWidth);      // wait a very small amount
 digitalWrite(servoPin, LOW);        // set servo low
 delay(20);                          // refresh cycle of typical servos (20 ms)
}

void setup() {
 pinMode(servoPin, OUTPUT);          // set servoPin pin as output
}

void loop() {
 // cycle through every angle (rotate the servo 180 slowly)
for (mySpeed=110; mySpeed<=118; mySpeed++) {  
  servoPulse(servoPin, mySpeed);
 }
 delay(1000);
}
-=------------------------

retrolefty

I've used several models of brushless speed controllers in R/C electric planes over the last few years. They are very reliable and powerful controllers, avalible in all kinds of maximum current & voltage ratings. They can run a little hot and normally one mounts them in a plane such that they can receive a little air flow for cooling.

You can treat them just like a servo, however most do have a few safety features, such as disabled at power up and wait until servo command is moved to 'zero poition', this prevents the motor starting at first turn off. Also it senses battery voltage and when low either cuts off the motor or pulses the motor on and off to allow time for a safe landing.  

Here is a great site with a section on R/C electronics
http://www.rcgroups.com/aircraft-electric-general-357/

mem

#9
Nov 27, 2008, 11:46 am Last Edit: Nov 27, 2008, 11:48 am by mem Reason: 1
The ESC needs to arm before it will drive the motor. Typically an ESC will arm when it gets minimum throttle setting for a second or so. But some controllers are programmable or self adapt to the transmitter so you need to read the instructions for your ESC.

Lazer's code arms his ESC  because it starts by sending a minimum pulse width for 1 second.

I would recommend that code to drive an ESC had a specific function for arming. Here is an example, this may need to be modified for ESC that need longer arm times or different pulse widths. And its not tested so let me know if it works for you ;)

Code: [Select]
// this uses the Arduino servo library included with version 0012

// caution, this code sweeps the motor up to maximum speed !
// make sure the motor is mounted securily before running.

#include <Servo.h>

Servo myservo;

void arm(){
 // arm the speed controller, modify as necessary for your ESC  
 setSpeed(0);
 delay(1000); //delay 1 second,  some speed controllers may need longer
}

void setSpeed(int speed){
 // speed is from 0 to 100 where 0 is off and 100 is maximum speed
 //the following maps speed values of 0-100 to angles from 0-180,
 // some speed controllers may need different values, see the ESC instructions
 int angle = map(speed, 0, 100, 0, 180);
 myservo.write(angle);    
}

void setup()
{
 myservo.attach(9);
 arm();  
}


void loop()
{
 int speed;

 // sweep up from 0 to to maximum speed in 20 seconds
 for(speed = 0; speed <= 100; speed += 5) {
   setSpeed(speed);
   delay(1000);
 }
 // sweep back down to 0 speed.
 for(speed = 95; speed > 0; speed -= 5) {
   setSpeed(speed);
   delay(1000);
 }
 setSpeed(0);  
 delay(5000); // stop the motor for 5 seconds
}

Tobias

Hi,

I wanted to control a Brushless Motor with my arduino. So I connected my ESC to the motor (3 cable from motor to 3 output cable from the ESC), the ESC ground to arduinos ground (black), the signal line (white) to an arduino output pin. I didn't connect the red 5+ from ESC.

When connected the the ESC to a LIPO (red on red, balck on black), the ESC beeped, the motor didn't move.

To far so good, as my pules were at 900mycros, which should be the base (motor off) value.
As I increased the pulse signal slightly (with a pot.) the motor began to move. But after a few seconds my (borrowed) esc started to burn.

My friend told me that he had used this esc with this motor, so i guess the esc should been strong enough.

Has anyone an idea what went wrong?
Did I connect the esc correctly to the arduino?
Can you burn the esc by sending weird pulses?
thanx,
tobias

jezuz

i might be way off, or i might be on topic, but:

i have seen lots of references to using the h bridge setup to control dc motors...

is using an ESC essentially like replacing the whole h bridge setup?

mem

Electronic Speed Controllers for brushed DC motors are implemented using an internal H-bridge. Radio Control ESC usually have additional features like arming protection and of course they are controlled by PPM signal from an RC receiver rather than the analogWrite form of PWM.

Using an ESC can be an easy way to control a DC motor but make sure you use the correct ESC for your motor.

SiN

hello everyone, i came across this post as i also wanted to power my brushless motors. using the code which mem posted i have managed to do this.

one thing i am having trouble whit is powering 4 at once? as i am building a quad helicopter so i need to power all 4.

any help with this will be most appreciated  :)

mem

The servo library distributed with Arduino only drives two servos. The code in this thread drives up to 8: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230479947


Go Up