Control ESC-BLDC Motor Via Serial Monitor
hi, need program controlling esc-bldc motor via serial monitor of arduino ide. far, have done controlling motor move forward (from min max speed) or move backward, mean ccw (from min max speed).
the problem is: can barely understand annoying esc. have seen several codes saying controls speed of esc-bldc motor via serial monitor, , when upload arduino, doesn't f move. lol. when upload codes below, works. have noticed codes not working either uses analogwrite
or object.write(value_here). while code working (see below), uses object.writemicroseconds
i'm pretty confused here.
anyway, main objective why i'm asking sample program to: make esc-bldc motor controlled via serial monitor, in way press w , s (w cw, , s ccw or reverse). normal rc-cars. when press w continuously, motor min. speed max speed. please help. if can provide sample code sample code similar objective, big me. lot. hope reply.
g
the problem is: can barely understand annoying esc. have seen several codes saying controls speed of esc-bldc motor via serial monitor, , when upload arduino, doesn't f move. lol. when upload codes below, works. have noticed codes not working either uses analogwrite
or object.write(value_here). while code working (see below), uses object.writemicroseconds
i'm pretty confused here.
anyway, main objective why i'm asking sample program to: make esc-bldc motor controlled via serial monitor, in way press w , s (w cw, , s ccw or reverse). normal rc-cars. when press w continuously, motor min. speed max speed. please help. if can provide sample code sample code similar objective, big me. lot. hope reply.
g
code: [select]
#include <servo.h>
servo bldc_motor; //creates "servo" object (the esc , motor)
void setup()
{
bldc_motor.attach (9); //attach motor pin 9
serial.begin(9600);
}
void loop()
{
bldc_motor.writemicroseconds(1500); //provides "neutral" pulse. esc won't start without this.
serial.println("bldc motor test..");
serial.println("starting in...");
serial.println("");
for (int = 4; >= 0; --) //countdown timer
{
serial.print(i+1);
serial.println("");
delay (1000);
}
while(1)
{
serial.println("forward.");
for (int = 1500; <= 2000; i++)
{
int speed_value = map (i, 1500, 2000, 0, 100); //maps signal pulse percentage
serial.println(speed_value);
serial.print('%');
bldc_motor.writemicroseconds (i); //actually write value motor
delay(10);// small delay can see what's happening
}
bldc_motor.writemicroseconds (1000); //full reverse. esc automatically brake motor.
delay (500); //small delay let things happen
bldc_motor.writemicroseconds (1500); //give neutral signal
serial.print("motor stopped");
delay (3000); //keep way while
serial.print("backward");
for (int = 1500; >= 1000; --)
{
int speed_value = map (i, 1500, 1000, 0, 100); //maps signal pulse percentage
serial.print (speed_value); //prints percentage lcd
serial.print ('%'); //notice single quotation marks. i've sent char value, not string because it's 1 character
serial.println("");
bldc_motor.writemicroseconds (i); //actually write value motor
delay(10);// small delay can see what's happening
}
bldc_motor.writemicroseconds (1500);
serial.print ("motor stopped");
delay (3000);
}
}
quote
anyway, main objective why i'm asking sample program to: make esc-bldc motor controlled via serial monitor, in way press w , s (w cw, , s ccw or reverse).what want not supported serial monitor (the serial monitor requires each individual command entered , sent). need write program computer has keyboard interface actions want. below serial monitor test code may similar desire keyboard control.
code: [select]
// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type character (s increase or
// decrease) , enter change servo position
// (two hands required, 1 letter entry , 1 enter key)
// use strings 90x or 1500x new servo position
// ide 1.0.5 , later
// powering servo arduino *does not work*.
#include<servo.h>
string readstring;
servo myservo;
int pos=1500; //~neutral value continous rotation servo
//int pos=90;
void setup()
{
myservo.attach(7, 400, 2600); //servo control pin, , range if desired
serial.begin(9600);
serial.println("serial servo incremental test code");
serial.println("type character (s increase or decrease)");
serial.println("and enter change servo position");
serial.println("use strings 90x or 1500x new servo position");
serial.println();
}
void loop()
{
while (serial.available()) {
char c = serial.read(); //gets 1 byte serial buffer
readstring += c; //makes string readstring
delay(2); //slow looping allow buffer fill next character
}
if (readstring.length() >0) {
if(readstring.indexof('x') >0) {
pos = readstring.toint();
}
if(readstring =="a"){
(pos=pos-1); //use larger numbers larger increments
if(pos<0) (pos=0); //prevent negative number
}
if (readstring =="s"){
(pos=pos+1);
}
if(pos >= 400) //determine servo write method
{
serial.println(pos);
myservo.writemicroseconds(pos);
}
else
{
serial.println(pos);
myservo.write(pos);
}
}
readstring=""; //empty next input
}
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Control ESC-BLDC Motor Via Serial Monitor
arduino
Comments
Post a Comment