Hello, I am trying to make a rc airplane with arduino and nrf modules. I have a brushless motor with a 30A ESC and i am trying to arm it.
This is the Transmitter code:
#include <SPI.h>// nrf communication
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); //CE CSN
struct channels {//Data to be sent
int ch1 = 0;
int ch2 = 0;
int ch3 = 0;
};
channels ch;
const byte address[6] = "10000";//address to send data
int x = A0;// potentiometer pins
int x2 = A1;
int y = A2;
void setup() {
Serial.begin(9600);
pinMode(x, INPUT);
pinMode(y, INPUT);
pinMode(x2, INPUT);
radio.begin();//Beginning the radio communication
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();//Setting the nrf to transmitter mode
}
void loop() {
ch.ch1 = map(analogRead(x), 0, 1023, 1000, 2000);// mapping the values
ch.ch2 = map(analogRead(x2), 0, 1023, 0, 180);
ch.ch3 = map(analogRead(y), 0, 1023, 0, 180);
radio.write(&ch, sizeof(channels));//Sending the data
Serial.println(ch.ch1);
Serial.println(radio.isChipConnected());//Checking if the nrf module is connected
}
This is the receiver code:
#include <ESC.h>//Include the RC ESC library
#include <Servo.h>// Servo library
#include <SPI.h>//nrf communication libraries
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(8, 7); // CE CSN
Servo s1;//Servo 1
Servo s2;//Servo 2
const byte address[6] = "10000";//address to communicate with the other nrf module
ESC bldc (6,1000,2000,690);// ESC(Pin Number,Maximum value,Minimum value,Arm value)
struct channels{//data to receive
int ch1;
int ch2;
int ch3;
};
channels data;
void setup() {
Serial.begin(9600);
radio.begin();//Beginning the radio communication
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();//Setting the nrf to listen mode
s1.attach(5);
s2.attach(3);
bldc.arm();//Function to arm the ESC
delay(5000);//Delay to wait for the arming
}
void loop() {
if(radio.available()){
radio.read(&data,sizeof(channels));//Reading the data
Serial.println(data.ch1);
if(data.ch1>1010){//setting a speed to start the motor
bldc.speed(data.ch1);//Starting the motor at the instructed speed
}
}
else{//to stop the motor
bldc.stop();
}
}
This worked for some time and while i was about to test the airplane it wouldn't arm at all.
At first I thought it might be the code. So i tested an example code, It didn't work either.
Then I thought it might be the arm value but do arm values change?
Can anyone tell me how to solve this?
Thank you in advance for the help!