So i need to control a 270kv 2.4kw brushless motor with a 100a esc.
However, i want my arduino to output either the 1000ms signal or 2000ms signal based on if a push button also linked to the board has been pressed.
I know this has been asked before but having tried other guides i can't even get past the esc programming feature as i had assumed max throttle range would be set when i output a 2000ms signal but instead i get the disconnect beep sequence.
Using an Arduino Genuino Uno but would like to transfer code to a Arduino ATMEGA32U4 Beetle.
Code i am using currently:
include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(8); //Specify the esc signal pin,Here as 8
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop() {https://forum.arduino.cc/
// put your main code here, to run repeatedly:
int val; //Creating a variable val
val= digitalRead(7); //Read input from analog pin a0 and store in val
if (digitalRead(7) == HIGH > LOW) { //Opens the door when the 'open' button is pressed
esc.attach(11); //Gives the servo power
esc.write(90); //Tells servo to move to 0 degree mark
delay(1); // waits 1000ms for the servo to reach the position
} else {
esc.write(40);
delay(1);
}
}
I've also linked the ESC programming sheet for additional info, In place of a push button that is yet to arrive i was tripping the button input pin (d7) directly with the orange wire from the 5v output.
Any help is greatly appreciated and apologies for my incompetence, i'm far more hands on with DIY i generally leave the programming to the smart people.
esc.attach(8); //Specify the esc signal pin,Here as 8
......
esc.attach(11); //Gives the servo power
You need to make your mind up. Is the ESC connected to pin 8 or pin11? I'm pretty sure it isn't connected to both. And the attach should in setup() to run once not in loop() where it will try reattaching every millisecond or two.
Write(90) and write(40) have nothing to do with the 1000 or 2000 that you say you want and delay(1) is nowhere near long enough for a servo to get anywhere useful.
Also your if statement is very odd.
BTW pulse lengths are microseconds not milliseconds (ms)
Yeah my bad on the pins, converting them from someone elses code i made a mistake, adjusting that got it working on the genuino board but when i upload the sketch onto the atmega board the motor just spins continually... thoughts?
include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(9); //Specify the esc signal pin,Here as 9
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop() {https://forum.arduino.cc/
// put your main code here, to run repeatedly:
int val; //Creating a variable val
val= digitalRead(11); //Read input from analog pin a0 and store in val
if (digitalRead(11) == HIGH > LOW) { //Opens the door when the 'open' button is pressed
esc.attach(9); //Gives the servo power
esc.write(90); //Tells servo to move to 0 degree mark
delay(1); // waits 1000ms for the servo to reach the position
} else {
esc.write(40);
delay(1);
}
}
Update:
Tried this instead with same results, am i getting closer??
include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(9); //Specify the esc signal pin,Here as 9
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop() {https://forum.arduino.cc/
// put your main code here, to run repeatedly:
int val; //Creating a variable val
val= digitalRead(11); //Read input from analog pin a0 and store in val
if (digitalRead(11) == HIGH > LOW) { //Opens the door when the 'open' button is pressed
esc.writeMicroseconds(2000); //Tells servo to move to 0 degree mark
// waits 1000ms for the servo to reach the position
} else {
esc.writeMicroseconds(1000);
val= digitalRead(11); //Read input from analog pin a0 and store in val
What is connected to pin 11 and how is it wired?
if (digitalRead(11) == HIGH > LOW)
What do you expect that to do ( HIGH is always greater than LOW)?
//Opens the door when the 'open' button is pressed
Opens the door while the button is pressed.
esc.writeMicroseconds(2000); //Tells servo to move to 0 degree mark
For a servo, 2000 microseconds is 180(ish) degrees. And 1000 is 0 degrees. 1500 is 90 degrees.
Pin 11 is my button input
Not sure, i borrowed this code from someone else but it seems to work? when i disconnect pin 11 (button closed) the motor stops. When connected, the motor spins.
Just having issues porting this code onto the micro
Yeah. some other guys code, i'll send you a link to his page if you wanna correct his grammar <3
Well how does that translate for an ESC? is 2000 full speed and 1000 is stationary, or is 1500 stationary and 1000 is full reverse...?
Jango955:
3. Yeah. some other guys code, i'll send you a link to his page if you wanna correct his grammar <3
It's not about grammar. "When" means at the instant it becomes pressed; "while" means for the duration of a press. In logic terms, those are different things.
"When" means a thing will happen only once; "while" means a thing could happen a gazillion times due to the loopy nature of loop().
Okay, enlightening, in that case i need the motor to be active whilst pressed...
so i need while?
New problem, new code.
Thought i may need to use analogue for the PWM output, but now the motor spins while pin 11 is connected, but when disconnected, there is a huge delay before the motor deactivates
include <Servo.h>
Servo esc;
void setup() {
// put your setup code here, to run once:
esc.attach(A0); //Specify the esc signal pin,Here as 0
esc.writeMicroseconds(1000); //initialize the signal to 1000
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop() {https://forum.arduino.cc/
// put your main code here, to run repeatedly:
int val; //Creating a variable val
val= digitalRead(11); //Read input from analog pin a0 and store in val
if (digitalRead(11) == HIGH) { //Opens the door when the 'open' button is pressed
esc.writeMicroseconds(2000); //Tells servo to move to 0 degree mark
// waits 1000ms for the servo to reach the position
} else {
esc.writeMicroseconds(1000);
You only answered half the question. Does the switch pin have a pulldown resistor connected to ground? If not the pin will "float" when open and not work right.
If you want the motor to turn while the switch is pressed you have it right.
val= digitalRead(11); //Read input from analog pin a0 and store in val
Pin 11 is not A0. Comments that are incorrect are worse than no comments.
Well how does that translate for an ESC? is 2000 full speed and 1000 is stationary, or is 1500 stationary and 1000 is full reverse...?
You have the data sheet for the ESC, right? That should tell you how it operates.
Jango955:
4. Well how does that translate for an ESC? is 2000 full speed and 1000 is stationary, or is 1500 stationary and 1000 is full reverse...?
Yes. Depends on the ESC design. Airplane and most multicopter ESCs use 1000 for stop and 2000 for full throttle. Car (and boat?) ESC's use 1000 for full reverse and 2000 for full forward (1500 for stop). A few multicopter ESCs have forward and reverse so you can fly inverted.
Okay, thankyou all for your contributions, especially regarding the input_pullup feature. i now have it working on the micro board with no input delay, cheers all (posting finalized code below hopefully in the correct format)
# include <Servo.h>
Servo esc;
void setup() {
esc.attach(A0); //My output ESC signal
esc.writeMicroseconds(1000); //initialize the signal to 1000 for ESC startup
pinMode(11, INPUT_PULLUP);
Serial.begin(50000);
delay(4000);
}
void loop() {
delay(1);
if (digitalRead(11) == LOW) { //
esc.writeMicroseconds(2000);
} else {
esc.writeMicroseconds(1000);
delay(1);
}
}