problem with code

feiji

Member
Hello
i've been trying to control brushless motors with a simple code with arduino, when i run the following code nothing happens, the motors do not start
/////////////////
#include <Servo.h>
Servo m1;
Servo m2;

void setup() {
Serial.begin(9600);
m1.attach(5);
m2.attach(7);
m1.writeMicroseconds(1000);
m2.writeMicroseconds(1000);
delay(1000);
}

void loop() {
m1.writeMicroseconds(1150);
m2.writeMicroseconds(1150);
delay(1000);
m1.writeMicroseconds(1200);
m2.writeMicroseconds(1200);
delay(1000);
m1.writeMicroseconds(1150);
m2.writeMicroseconds(1150);
delay(1000);
m1.writeMicroseconds(1100);
m2.writeMicroseconds(1100);
delay(1000);
/////////////////////////////

but when i run this code by adding the last 3 lines to the code : (m1.writeMicroseconds(1000)..)
it works perfectly.


#include <Servo.h>
Servo m1;
Servo m2;

void setup() {
Serial.begin(9600);
m1.attach(5);
m2.attach(7);
m1.writeMicroseconds(1000);
m2.writeMicroseconds(1000);
delay(1000);
}

void loop() {
m1.writeMicroseconds(1150);
m2.writeMicroseconds(1150);
delay(1000);
m1.writeMicroseconds(1200);
m2.writeMicroseconds(1200);
delay(1000);
m1.writeMicroseconds(1150);
m2.writeMicroseconds(1150);
delay(1000);
m1.writeMicroseconds(1100);
m2.writeMicroseconds(1100);
delay(1000);
m1.writeMicroseconds(1000);
m2.writeMicroseconds(1000);
delay(1000);
}

the problem is that i can not use that line(turn the motor off by sending 1000 ) in an other program which requires the continuous running of the motor, so is there any suggestion to what i might be doing wrong ? or a solution to this problem ?
Thank you
 
Is 1000 supposed to turn the motors off? Have you tried
m1.writeMicroseconds(900);
m2.writeMicroseconds(900);

I have not written any arduino code, but I have thought about it for controlling a slider.
 
Is 1000 supposed to turn the motors off? Have you tried
m1.writeMicroseconds(900);
m2.writeMicroseconds(900);

I have not written any arduino code, but I have thought about it for controlling a slider.


1000 is the minimum value for the motors i'm using, and it's the standard minimum value for brushless motors. when it's 1000, the motors are off.
 
What happens when you call this at the beginning of the loop function or previous to the code that calls the loop function?
m1.writeMicroseconds(1000);
m2.writeMicroseconds(1000);
 
What happens when you call this at the beginning of the loop function or previous to the code that calls the loop function?
m1.writeMicroseconds(1000);
m2.writeMicroseconds(1000);


this works as an initialisation for the motors , it's a must so that they can start rotating, i used it in the setup funtion to initialise them and i used in the end of the loop function because that was the only way i could make the motors rotate, otherwise , if i remove this line from the end of the loop funtion , rhe motors won't even start
 
I think you are using the wrong class for your purpose after digging a little deeper.

The servo class is for servos, which have a start, stop and the speed in-between. I think you are using the wrong classes(Servo.h)

Look for a three phase motor class. (try writing one up if you can't find one)
 
i
I think you are using the wrong class for your purpose after digging a little deeper.

The servo class is for servos, which have a start, stop and the speed in-between. I think you are using the wrong classes(Servo.h)

Look for a three phase motor class. (try writing one up if you can't find one)


i think the class is fine, i just retried the code without turning off the motors and it worked fine.
 
Back
Top