Hello, I am building an RC plane, and I am using an Arduino Nano to control a 30A ESC with a 2200kv motor. I have never used a brushless motor before, so I have no experience with this. I tried using several code examples I found on the internet, but none have worked.
This is my current code, which is supposed to receive an integer for the motor power through an NRF24L01 radio transceiver, and set the speed of the motor (pin D3) to this value.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
Servo esc;
int joyArray[1];
int mPower;
RF24 wirelessSPI(7, 8);
const uint64_t Address = 0xB00B1E5000LL;
void setup(){
esc.attach(3);
arm();
Serial.begin(9600);
wirelessSPI.begin();
wirelessSPI.setAutoAck(1);
wirelessSPI.enableAckPayload();
wirelessSPI.setRetries(5,15);
wirelessSPI.openReadingPipe(1,Address);
wirelessSPI.startListening();
wirelessSPI.printDetails();
}
void loop(){
if(wirelessSPI.available()){
while(wirelessSPI.available()){
wirelessSPI.read(&joyArray, sizeof(joyArray));
mPower = joyArray[0];
setSpeed(mPower);
delay(15);
}
}
}
void arm(){
setSpeed(100);
delay(1000);
setSpeed(0);
delay(2000);
}
void setSpeed(int speed){
int angle = map(speed, 0, 100, 0, 180);
esc.write(angle);
}
I know the radio transceiver is not the problem, because I can control the servo motors for the elevons with no problem (I deleted the code for the elevons for testing purposes, though). When I plug in the battery, the motor makes beeping sounds, and when I run the code it makes different beeping sounds when I change the throttle to 100 or 0, but it does not turn at all. I think the problem is in the code because based on youtube videos it sounds like the code for arming it and setting the speed should be different for different ESCs, but mine came with no instructions. This is the product I bought from Amazon:
https://www.amazon.com/gp/product/B07D546LXK/ref=oh_aui_detailpage_o08_s00?ie=UTF8&psc=1
Thanks for any help!