To calibrate most esc’s you need to power the ESC with a HIGH signal then wait a bit and send a LOW signal.
In theory this is done once and not needed in the actual program of your application.
This Library is the first one I have had any success with, Thanks! However, I am having issues where it seems my esc is receiving a “pulse” in between commands? I will start it up, it will go through its beeps, arm, and start running. But when it is stopped, during a delay command, it will “beep” about every second. Any idea why, or how to get rid of this?
The only “delay” in the library is for “Calib” so first make sure you do not use this all the time.
Should only be used once to calibrate the board.
So what I having trouble with is I am getting spurts of rotation from my motor for no apparent reason. I am attaching a 5 second video link. You can see the motor spins briefly, very slow speed. I got out a stop watch to see if there was any regularity to when it would happen. Over a period of about 2 minutes it did this at these time intervals;
6s
9s
13s
34s
1:00
1:11
1:14
1:46
2:01
This was the code on my board for that experiment;
#include "ESC.h"
#define SPEED_MIN (1000) // Set the Minimum Speed in microseconds
#define SPEED_MAX (2000) // Set the Minimum Speed in microseconds
int arming=1400;
ESC myESC (9, SPEED_MIN, SPEED_MAX, arming); // ESC_Name (ESC PIN, Minimum Value, Maximum Value, Default Speed, Arm Value)
int oESC;
void setup() {
myESC.arm();
delay(8000);
}
void loop() {
myESC.speed(arming);
}
The ESC is set to bi-directional, with 1400 as the neutral.
You should try with a “1500” value for arming and for the test, add the command to the setup so it only sent it once.
This to eliminate any “glitches” that could make you ESC fail.
#include "ESC.h"
#define SPEED_MIN (1000) // Set the Minimum Speed in microseconds
#define SPEED_MAX (2000) // Set the Minimum Speed in microseconds
int arming=1500;
ESC myESC (9, SPEED_MIN, SPEED_MAX, arming); // ESC_Name (ESC PIN, Minimum Value, Maximum Value, Default Speed, Arm Value)
int oESC;
void setup() {
myESC.arm();
delay(8000);
myESC.speed(arming);
}
void loop() {
}
hi, i have a BLDC controller i want to control a hoverboard brushless DC motor i tried to use Servo library and fail to run it since i get only 0.5 as maximum volt output from arduino and its not enough to run the motor when i connect a pot 10k i can run the motor with no problems but its start run when the volt arrive to 1.5 volt … i tried many changes with the values of servo library … but it didnt work couldnt get at least the 1.5 volt … any help ? and what should i change in values to get output between 0 - 5 volts
Hi Muthana,
I am not sure what you are trying to probe in “voltage” as the signal sent to the ESC with this library is a RC servo PWM.
This type of control will only change the length of “HIGH” signal and cannot be verified in Voltage.
Connecting a 10K pot to the ESC might just blow it.
Can you explain in more detail the equipment you are trying to control ? Maybe attach some pictures as well and we will try to guide you.
All the best,
Dear dialfonzo,
i want to use BLDC controller with arduino to control the hoverboard motor , i could run this motor by the BLDC controller using 10k ohm Potentiometer connected on the throttle wires , but i fail to run it using arduino , i could control this motor before with another esc using same code of driving servo motor but with this BLDC controller i couldnt , i hope i can find some help here
This controller is not a “ESC” and do not that the same signal for the speed.
You have to dig into your actual controller and find ways to use it but it will not be with this library.
If you can make it work with a potentiometer, it mean the signal is more than likely an Analog input but the voltage is unknown.
hello dialfonzo;
first of all i am sorry for late reply because i was travel past few days …
about the conreoller they called it BLDC controller( i dont know what is the different between BLDC and ESC ) but what i am sure of it that the motor of hoverboard is a brushless motor, i have successful control it with another type of controller using the same code for driving servo motor …
i tried another way by usng PWM signal its start run with variables speeds as i change the Value of PWM but the problem its not smooth turning and unstable …
i.e. for just once i successed to make it run with servo library when i changed some values inside the library file … but i do not remember the values since i was do many testes
An ESC is usually a controller made for the Radio Control (RC) and take a very specific signal. (Electronic Speed Controller)
It’s a PWM but the length of the pulse is the signal.
An ESC can be either Brushed or Brushless but always use RC standard as the input.
Your BLDC is a Brushless DC controller and might take something else as an input like an analog signal (potentiometer).
thank you very much dialfonzo
@dialfonzo Looks like this would help control my hobbyking 80A SBEC using an Adafruit Trinket M0
I’m getting an error on compile – running the ESC on pin 0 and led on pin 1. Is this compatible with 32bit samd arduino?
WARNING: library RC_ESC-1.1.0 claims to run on (avr) architecture(s) and may be incompatible with your current board which runs on (samd) architecture(s).
Sketch uses 11036 bytes (4%) of program storage space. Maximum is 262144 bytes.
Atmel SMART device 0x1001000a found
Device : ATSAMD21E18A
Hey @Christopher72!
Welcome to the RobotShop community!
I tried a compilation using Arduino IDE 1.8.10 with the latest RC_ESC library, version 1.1. I targeted the Arduino M0 board (since I don’t have the Adafruit files required to target the Trinket M0) and I did get the same warning.
Please note this is not an error but simply a warning. This is to inform you that the library does not officially (at least right now) state support for anything other than AVR architectures (which a Cortex-M0 is not). That being said, the only dependency of the RC_ESC library (currently) is the Arduino Servo library which itself supports the following architectures: avr, megaavr, sam, samd, nrf52, stm32f4, mbed. Therefore, this indicates that RC_ESC should work on all of these platforms without issue (warning or not).
So, please let us know if it runs well on your board (samd architecture) and we’ll tentatively add this to the supported architecture list (therefore removing the warning).
Sincerely,
Hello,
Firstly thanks for this excellent library.
I am using this library to start automatically when ESC and Arduino is powered together (after a switch) … the motor starts, i hold the speed in 2000 and its works fine with the below code:
#include <ESC.h>
#define MOTOR_PWR (4)
ESC myESC (3, 1000, 2000, 1000); // ESC_Name (PIN, Minimum Value, Maximum Value, Arm Value)
int val = 1000; // variable to read the value from the analog pin
int atraso = 0;
int MP;
int low = 0;
int oESC = 1000;
void setup() {
Serial.begin(9600);
pinMode(MOTOR_PWR, INPUT);
myESC.arm();
}
void loop() {
MP = 0;
Serial.print("Start Motor");
for (oESC = 1000; oESC <= 2000; oESC += 1) { // goes from 1000 microseconds to 2000 microseconds
myESC.speed(oESC); // tell ESC to go to the oESC speed value
delay(10); // waits 10ms for the ESC to reach speed
}
while (MP == 0){
oESC = 2000;
Serial.print("WHILE HIGH-----------------------");
myESC.speed(oESC);
delay(10);
}
delay(15); // Wait for a while
}
But i need use a input pin (button) to reduce the speed and its is pushed. How can i coding it? I tried the code below but it s not works…
#include <ESC.h>
#define MOTOR_PWR (4)
#define B1 (5)
ESC myESC (3, 1000, 2000, 1000); // ESC_Name (PIN, Minimum Value, Maximum Value, Arm Value)
int val = 1000; // variable to read the value from the analog pin
int atraso = 0;
int MP;
int low = 0;
int oESC = 1000;
void setup() {
Serial.begin(9600);
pinMode(MOTOR_PWR, INPUT);
pinMode(B1, INPUT);
myESC.arm();
}
void loop() {
MP = digitalRead(B1);
Serial.print(“Start Motor”);
for (oESC = 1000; oESC <= 2000; oESC += 1) { // goes from 1000 microseconds to 2000 microseconds
myESC.speed(oESC); // tell ESC to go to the oESC speed value
delay(10); // waits 10ms for the ESC to reach speed
}
while (MP == HIGH){
MP = digitalRead(B1);
oESC = 1800;
Serial.print(“WHILE HIGH-----------------------”);
myESC.speed(oESC);
delay(10);
}
while (MP == LOW){
MP = digitalRead(B1);
oESC = 2000;
Serial.print(“WHILE LOW-----------------------”);
myESC.speed(oESC);
delay(10);
}
THANKS
Hey @Vitor_Tavares_Rio_Brasil! Welcome to the RobotShop community!
I’ve edited your post to include code boxes (ex: [ code ] and [ /code ] ) to make the post easier to read. In the future, I highly recommend you either use code tags (for short code examples, such as 5-10 lines) or attach files for larger examples (such as the ones you posted).
Concerning your question, there seems to be code in the loop function (both examples) that seems to include a for-loop that will take at least 10000 ms (or ~10s). That would definitely make using the button pretty difficult.
Also, both while cases may cause you problems since you would read the first state about 10 seconds before it is processed by the while loops. Also, your readings do not include any debouncing (hopefully you added some electrically in your circuit for that switch/button). Here are some basic details about debouncing digital inputs.
You should probably move the “start motor” section with the for-loop to the setup function unless you meant to have it run every time there is a state change in the button.
I recommend that you check online for some tutorials on debouncing digital inputs and basic state machine / main loop programming techniques to help get you started with this kind of stuff. You can find many examples of such discussions online such as (in no particular order):
- https://forum.arduino.cc/index.php?topic=212137.0
- https://forum.arduino.cc/index.php?topic=541531.0
- https://forum.arduino.cc/index.php?topic=194009.0
Sincerely,
hey! @dialfonzo i have read you article. So glad someone can finally help me out
I am making an ESC of my own we have been using Mosfets,created our power supply and driver circuits using opto couplers, and using H-brigde for switching the mosfets in perfect order to run the motor
everything is going fine except the programming part. I have been doing it for quite long. I have tried many combinations but the motor is not rotating. It gives a beep. once it moved for 7 turns. but it didnt completed the whole 12 turns.
We are using a BLDC motor of rating
Model: A2212/6T
RPM/V: 2200 kV
Current: 12 A/60 s
The arduino code is as follows please guide me what am I doing wrong
int a=1000;
int pin1=3;
int pin2=5;
int pin3=6;
int pin4=9;
int pin5=10;
int pin6=11;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
///////////////////////////a-1-6///////////
Serial.println("1-6");
analogWrite(pin1, 127);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
analogWrite(pin6, 127);
delay(a);
//////////// b- 1-4/////////////
Serial.println("1-4");
analogWrite(pin1, 127);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
analogWrite(pin4, 127);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
delay(a);
///////////e- 5-2//////////////////////////
Serial.println("5-2");
digitalWrite(pin1,LOW);
analogWrite(pin2, 127);
digitalWrite(pin3,LOW);
digitalWrite(pin4,LOW);
analogWrite(pin5, 127);
digitalWrite(pin6,LOW);
delay(a);
////////////////d- 3-6////////////////////
Serial.println("3-6");
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
analogWrite(pin3, 127);
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
analogWrite(pin6, 127);
delay(a);
//////////////////f- 5-4////////////////////
Serial.println("5-4");
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW);
analogWrite(pin4, 127);
analogWrite(pin5,127);
digitalWrite(pin6,LOW);
delay(5);
/////////////////////c- 3-2/////////////////////
Serial.println("3-2");
digitalWrite(pin1,LOW);
analogWrite(pin2, 127);
analogWrite(pin3, 127);
digitalWrite(pin4,LOW);
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
delay(a);
}
You are trying to build your own ESC code which is not a small task.
What i would suggest is to look at some open-source code for ESC’s and learn out of it.
Hey! @dialfonzo, first of all thank you for the ESC lib and articles.
I am trying to use an arduino to control a TrackStar 120A ESC, which will be used in a car brushless motor. I have tried many different things to arm or calibrate the ESC, but without success. I found your library and tried the same with it. Tried the calibration .ino file, and tried many arm values (500 to 1000), but sound or led appeard in the ESC. I tried the ramp, no success also.
I already used this ESC a couple days ago with an arduino, and it was working. It stopped and now I can’t arm or calibrate it. Sometimes I see 4 red light flashes, 6 or 7 seconds after turning the ESC on.
I’m starting to think this ESC might have some problem, but wanted to know your opinion or hear any suggestions.
Thank you!
Hi AlexVR,
This library take advantage of the Arduino Servo library.
One can achieve the same result directly with the mentioned library alone.
If you got it working with a specific code, it should still be working.
One thing to look into is battery as most ESC will have a battery saving mode for LiPo and will not operate under a certain voltage.
Hope this help