I recently made an arduino RC controller using two 500mW NRF24L01 modules, at first it was very disappointing cause it didn't work, then I realized I had to make changes since the original circuit was designed for the original NRF24L01 modules which are 100mW
After connecting everything, I realized the connection only works if I touch some pins on the transmitter side, so I removed the antenna on the transmitter and it worked again, so I read somewhere that the problem is I was getting to close to the receiver, maybe by removing the antenna it's like I'm away from the receiver? I changed the pa level to low, now it works even if it's close to the receiver, but I think it affects range drastically, I'm gonna use it in an rc model so I have to be close to it at take off, so what do you think is the problem here? Could it be the power? Maybe the transmitter is not getting enough power? Or maybe it's the code? What happens if the set pa level command is high on the transmitter side and low on the receiver side?
Here are the codes
Transmitter
// 4 Channel Transmitter | 4 Kanal Verici
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeOut = 0xE9E8F0F0E1LL; //IMPORTANT: The same as in the receiver 0xE9E8F0F0E1LL | Bu adres alıcı ile aynı olmalı
RF24 radio(7, 8); // select CE,CSN pin | CE ve CSN pinlerin seçimi
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
};
Signal data;
void ResetData()
{
data.throttle = 127; // Motor Stop (254/2=127)| Motor Kapalı (Signal lost position | sinyal kesildiğindeki pozisyon)
data.pitch = 127; // Center | Merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
data.roll = 127; // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
data.yaw = 127; // Center | merkez (Signal lost position | sinyal kesildiğindeki pozisyon)
}
void setup()
{
//Start everything up
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW)
radio.stopListening(); //start the radio comunication for Transmitter | Verici olarak sinyal iletişimi başlatılıyor
ResetData();
}
// Joystick center and its borders | Joystick merkez ve sınırları
int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
val = constrain(val, lower, upper);
if ( val < middle )
val = map(val, lower, middle, 0, 128);
else
val = map(val, middle, upper, 128, 255);
return ( reverse ? 255 - val : val );
}
void loop()
{
// Control Stick Calibration | Kumanda Kol Kalibrasyonları
// Setting may be required for the correct values of the control levers. | Kolların doğru değerleri için ayar gerekebilir.
data.throttle = mapJoystickValues( analogRead(A0), 524, 524, 1015, true );
data.roll = mapJoystickValues( analogRead(A1), 12, 524, 1020, true ); // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
data.pitch = mapJoystickValues( analogRead(A2), 12, 524, 1020, true ); // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
data.yaw = mapJoystickValues( analogRead(A3), 12, 524, 1020, true ); // "true" or "false" for servo direction | "true" veya "false" servo yönünü belirler
radio.write(&data, sizeof(Signal));
}
Receiver
// 4 Channel Receiver | 4 Kanal Alıcı
// PWM output on pins D2, D3, D4, D5 (Çıkış pinleri)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
int ch_width_1 = 0;
int ch_width_2 = 0;
int ch_width_3 = 0;
int ch_width_4 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
};
Signal data;
const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(7, 8);
void ResetData()
{
// Define the inicial value of each data input. | Veri girişlerinin başlangıç değerleri
// The middle position for Potenciometers. (254/2=127) | Potansiyometreler için orta konum
data.throttle = 127; // Motor Stop | Motor Kapalı
data.pitch = 127; // Center | Merkez
data.roll = 127; // Center | Merkez
data.yaw = 127; // Center | Merkez
}
void setup()
{
//Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.
ch1.attach(2);
ch2.attach(3);
ch3.attach(4);
ch4.attach(5);
//Configure the NRF24 module
ResetData();
radio.begin();
radio.openReadingPipe(1,pipeIn);
radio.startListening(); //start the radio comunication for receiver | Alıcı olarak sinyal iletişimi başlatılıyor
}
unsigned long lastRecvTime = 0;
void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); // receive the data | data alınıyor
}
}
void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
ResetData(); // Signal lost.. Reset data | Sinyal kayıpsa data resetleniyor
}
ch_width_1 = map(data.throttle, 0, 255, 1000, 2000); // pin D2 (PWM signal)
ch_width_2 = map(data.pitch, 0, 255, 1000, 2000); // pin D3 (PWM signal)
ch_width_3 = map(data.roll, 0, 255, 1000, 2000); // pin D4 (PWM signal)
ch_width_4 = map(data.yaw, 0, 255, 1000, 2000); // pin D5 (PWM signal)
// Write the PWM signal | PWM sinyaller çıkışlara gönderiliyor
ch1.writeMicroseconds(ch_width_1);
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
ch4.writeMicroseconds(ch_width_4);
}
And these are the schematics
The difference I made was use a LM7805 regulator to get the 7.4v from the 2s battery down to 5v and feed it to an Ams1117 3.3v and power the transmitter from there
As for the receiver, I have disabled autoack, so it can't draw more than 27mA according to the datasheet, or maybe it can? And that could be the issue? I'm driving it directly from the 3.3v pins on the nano
Btw, the NRF24L01 clones I'm using are from Ebyte
E01 2g4m27d

