Hi,
im new here and new with Arduino stuff so I need help.
I planned to build my one drone. I have an receiver and an transmitter and 4 brushless motors with ecs and i want the motors to move depending on a joystick value the transmitters transmitts.
My problem is, any of the motors move as they should after i calibrated the esc's. Sometimes they start moveing and when the joystick is in the (comeing from 0 going to full throttle) middleposition they stop and go in calibration mode again. Also i have to calibrate them new everytime i attach the battery. They all "beep" correctly in the calibration (100% then 0% throttle) but then just one or none moves for 5 sec or so then they start calibration again.
I guess i have some code problems why this doesnt work at least with one of the motors. It's the same with every motor. The transmitter is fine and gives the right values (from 0 - 180).
Also is it correct that i can only use certain Pins on my Arduino nano to control the ESC's?
I read that only certain Pins can create a PWM signal i need to control those so I cant just use PINs 2-5? Is there a way around that because the other Pins are in use for the radiotransmittion/receiving.
Hope someone can help me. Thanks.
// btw. i copied this code from a Youtube tutorial so i dont understand everything that is going on here
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h> // my 4 Motors
Servo chanel_1;
Servo chanel_2;
Servo chanel_3;
Servo chanel_4;
int ch1_value = 0;
int ch2_value = 0;
int ch3_value = 0;
int ch4_value = 0;
const uint64_t pipeIn = 0xE8E8F0F0E1LL; //Remember that this code is the same as in the transmitter
RF24 radio(9, 10); //CSN and CE pins
// The sizeof this struct should not exceed 32 bytes
struct Received_data {
byte ch1;
byte ch2;
byte ch3;
byte ch4;
};
Received_data received_data;
/**************************************************/
void setup()
{
Serial.begin(9600);
//We reset the received values
received_data.ch1 = 127;
received_data.ch2 = 127;
received_data.ch3 = 127;
received_data.ch4 = 127;
//Once again, begin and radio configuration
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
//We start the radio comunication
radio.startListening();
chanel_1.attach(4,1000,2000); // attaching my Motors
chanel_2.attach(3,900,1900);
chanel_3.attach(5,1000,2000);
chanel_4.attach(2,1000,2000);
}
/**************************************************/
unsigned long last_Time = 0;
//We create the function that will read the data each certain time
void receive_the_data()
{
while ( radio.available() ) {
radio.read(&received_data, sizeof(Received_data));
last_Time = millis(); //Here we receive the data
}
}
/**************************************************/
void loop()
{
//Receive the radio data
receive_the_data();
// ch1_value = map(received_data.ch1,0,255,0,180);
//ch2_value = map(received_data.ch2,0,255,5,175);
ch3_value = map(received_data.ch3,0,255,0,180); // I only need ch3_value for now (It represents the Joystick value on the Transmitter)
//ch4_value = map(received_data.ch4,0,255,5,175);
Serial.print(ch3_value);
chanel_1.write(ch3_value); // making the motors move depending on the value (Joystick-position)
chanel_2.write(ch3_value);
chanel_3.write(ch3_value);
chanel_4.write(ch3_value);
}//Loop end