Go Down

Topic: help me figuring out where i went wrong.. trying to run 2dcbl esc (Read 730 times) previous topic - next topic

Justinmrose

Hello my name is Justin and I am new to the arduino world and I am hopelessly lost trying to write code to control my two brushless motors. I hope that you can help!? The servo library won't work for my need. The code I need is kind of complicated. By the way I have a arduino micro that's brand new. I need code that first sends a full pwm signal's (2000-2200 microseconds) to both the esc's for two seconds followed by lowest pwm signal (750-1000 microseconds or so) for five seconds. Here is where it gets complicated for me, I need one of the bldc/esc to go to between 40-45% throttle and stay there. I need the second bldc motor to be controlled 0-100% throttle by only a potentiometer. Here is where it gets even trickier (for me atleast...) I need the first motor/ESC that's set at 40-45% to also be controlled by the potentiometer. So that for example when the potentiometer is turned 15% the first motor will be at 55-60% throttle and the second is at only 15% throttle. I know this is a large request but I really need help I've been trying for a week now after work trying different code combinations. Thanks for your help

Justinmrose

Code: [Select]
#include <Servo.h>
 
Servo smmEDF;  // create servo object to control a servo
Servo mmEDF;  // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position
int potpin = 0;
int potpins = 1;
int val;
 
void setup()
{
  smmEDF.attach(9);  // attaches the servo on pin 9 to the servo object
  mmEDF.attach(10);
}
 
void loop()
{
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    smmEDF.write(pos);              // tell servo to go to position in variable 'pos'
    delay(200);                       // waits 15ms for the servo to reach the position
    mmEDF.write(pos);
    delay(200);
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    smmEDF.write(pos);              // tell servo to go to position in variable 'pos'
    delay(200);                       // waits 15ms for the servo to reach the position
    mmEDF.write(pos);
    delay(200);
  }

  {
    val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
    val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
    mmEDF.write(val);                  // sets the servo position according to the scaled value
    delay(15);
  }
  {
    val = analogRead(potpins);
    val = map(val, 0, 1023, 0, 180);
    smmEDF.write(val);
    delay(15);
  }
}
 

Riva

Do you need to calibrate ESC's every MCU restart?

Try the untested (but compiling) code below. You may need to adjust the max/min throttle values from the default 2000/1000 to arm the ESC's.

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

Servo smmEDF;  // create servo object to control a servo
Servo mmEDF;  // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int val;

void setup()
{
  smmEDF.attach(9);  // attaches the servo on pin 9 to the servo object
  mmEDF.attach(10);
 
  // Do ESC's need calibrating every reboot?
  smmEDF.writeMicroseconds(2000);     // Full throttle (2300 max)
  mmEDF.writeMicroseconds(2000);      // Full throttle
  delay(2000);                        // Wait 2 seconds
  smmEDF.writeMicroseconds(1000);     // Min throttle (700 min)
  mmEDF.writeMicroseconds(1000);      // Min throttle
  delay(5000);                        // Wait 5 seconds
}

void loop()
{
  int val = analogRead(potpin);       // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 1000, 2000);// scale it to use it with the servo (value between 1000 and 2000)
  mmEDF.writeMicroseconds(val);       // sets the ESC speed according to the scaled value
  val += 420;                         // Add 42% throttle constant
  val = constrain(val, 1000, 2000);   // Legalize result
  smmEDF.writeMicroseconds(val);      // sets the servo position according to the scaled value
  delay(15);
}
Don't PM me for help as I will ignore it.

Justinmrose

that was it thanks for your help i really appreciate it.

Go Up