Hi everyone!
İt is my first time on Arduino Form so if anything is wrong with my entry please inform me about it.
I'm trying to make a RC controlller for my model plane with 1 arduino uno and 1 arduino nano. I've succesfully communicated with 2 arduinos but arduino nano is broken and now Im trying to communicate between two arduino uno's but I dont know why these two dont communicates. I've checked connections multiple times I'm sure that connections are okey. I've tried simple nrf24 Simple nRF24L01+ 2.4GHz transceiver demo output of the Transmitter was " Data Sent Message 0 Acknowledge received" but Receiver just stuck at Simple Tx starting. Now Im getting "Data Sent Message 8 Tx failed" I dont know why but first ı connected arduino to comport without NRF24L01 the output was
Data Sent Message 0 Acknowledge received
Data Sent Message 1 Acknowledge received
Data Sent Message 2 Acknowledge received
as soon as I connected NRF to arduino the output became "Data Sent Message 3 Tx failed"
I'm using a NRF24 3.3v adaptor and Ive shorted it once but Ive checked the pins voltage with a simple led blink code but Im not sure that is the right way to check if it is working. Can anyone help me?
Now with the same arduinos but different models of nrf24 the model is nr24 ml01dp5 Simple nRF24L01+ 2.4GHz transceiver demo works with no problem but when ı use my code the connection fails. The code that Im using is below
Transmitter
// 8 Channel Transmitter (No Trim) | 8 Kanal Verici (Trim Yok)
// Input pin A5
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte pipeOut[5] = {'R','x','A','A','A'}; // NOTE: The same as in the receiver 000322 | Alıcı kodundaki adres ile aynı olmalı
RF24 radio(9, 10); // select CE,CSN pin | CE ve CSN pinlerin seçimi
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
};
Signal data;
void ResetData()
{
data.throttle = 0;
data.pitch = 127;
data.roll = 127;
data.yaw = 127;
data.aux1 = 0; // Signal lost position | Sinyal kesildiğindeki pozisyon
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup()
{
//Configure the NRF24 module | NRF24 modül konfigürasyonu
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.stopListening(); // Start the radio comunication for Transmitter | Verici için sinyal iletişimini başlatır.
ResetData();
}
// Joystick center and its borders | Joystick merkez ve sınırları
int Border_Map(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 for channels | Her bir kanal için kumanda Kol Kalibrasyonları
data.roll = Border_Map( analogRead(A3), 0, 512, 1050, true ); // "true" or "false" for signal direction | "true" veya "false" sinyal yönünü belirler
data.pitch = Border_Map( analogRead(A2), 0, 512, 1023, true );
data.throttle = Border_Map( analogRead(A1),570, 800, 1023, false ); // For Single side ESC | Tek yönlü ESC için
// data.throttle = Border_Map( analogRead(A1),0, 512, 1023, false ); // For Bidirectional ESC | Çift yönlü ESC için
data.yaw = Border_Map( analogRead(A0), 0, 512, 1023, true );
data.aux1 = Border_Map( analogRead(A4), 0, 512, 1023, true ); // "true" or "false" for change signal direction | "true" veya "false" sinyal yönünü değiştirir.
data.aux2 = Border_Map( analogRead(A5), 0, 512, 1023, true ); // "true" or "false" for change signal direction | "true" veya "false" sinyal yönünü değiştirir.
data.aux3 = digitalRead(7);
data.aux4 = digitalRead(8);
bool rslt;
rslt= radio.write(&data, sizeof(Signal));
if(rslt){
Serial.println("gönderildi");
delay(500);
}
}
receiver
// 8 Channel Receiver | 8 Kanal Alıcı
#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;
int ch_width_5 = 0;
int ch_width_6 = 0;
int ch_width_7 = 0;
int ch_width_8 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;
Servo ch7;
Servo ch8;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
};
Signal data;
const byte pipeIn[5] = {'R','x','A','A','A'};
RF24 radio(9, 10);
void ResetData()
{
data.throttle = 0;
data.roll = 127;
data.pitch = 127;
data.yaw = 127;
data.aux1 = 0; // Define the inicial value of each data input. | Veri girişlerinin başlangıç değerleri
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup()
{
// Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.
Serial.begin(9600);
ch1.attach(0);
ch2.attach(2);
ch3.attach(3);
ch4.attach(4);
ch5.attach(5);
ch6.attach(6);
ch7.attach(7);
ch8.attach(8);
ResetData(); // Configure the NRF24 module | NRF24 Modül konfigürasyonu
radio.begin();
radio.openReadingPipe(1,pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.startListening(); // Start the radio comunication for receiver | Alıcı için sinyal iletişimini başlatır.
}
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
}
if (radio.available() == 1){
Serial.println("BAĞLANTI KURULDU");
delay(500);
}
else {
Serial.println("bağlantı kurulamadı");
delay(500);
}
ch_width_1 = map(data.roll, 0, 255, 1000, 2000);
ch_width_2 = map(data.pitch, 0, 255, 1000, 2000);
ch_width_3 = map(data.throttle, 0, 255, 1000, 2000);
ch_width_4 = map(data.yaw, 0, 255, 1000, 2000);
ch_width_5 = map(data.aux1, 0, 255, 1000, 2000);
ch_width_6 = map(data.aux2, 0, 255, 1000, 2000);
ch_width_7 = map(data.aux3, 0, 1, 1000, 2000);
ch_width_8 = map(data.aux4, 0, 1, 1000, 2000);
ch1.writeMicroseconds(ch_width_1); // Write the PWM signal | PWM sinyaller çıkışlara gönderiliyor
ch2.writeMicroseconds(ch_width_2);
ch3.writeMicroseconds(ch_width_3);
ch4.writeMicroseconds(ch_width_4);
ch5.writeMicroseconds(ch_width_5);
ch6.writeMicroseconds(ch_width_6);
ch7.writeMicroseconds(ch_width_7);
ch8.writeMicroseconds(ch_width_8);
}
/>
// 8 Channel Transmitter (No Trim) | 8 Kanal Verici (Trim Yok)
// Input pin A5
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte pipeOut[5] = {'R', 'x', 'A', 'A', 'A'}; // NOTE: The same as in the receiver 000322 | Alıcı kodundaki adres ile aynı olmalı
RF24 radio(9, 10); // select CE,CSN pin | CE ve CSN pinlerin seçimi
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
} data;
void ResetData(){
data.throttle = 0;
data.pitch = 127;
data.roll = 127;
data.yaw = 127;
data.aux1 = 0; // Signal lost position | Sinyal kesildiğindeki pozisyon
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup() {
//Configure the NRF24 module | NRF24 modül konfigürasyonu
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.stopListening(); // Start the radio comunication for Transmitter | Verici için sinyal iletişimini başlatır.
ResetData();
}
// Joystick center and its borders | Joystick merkez ve sınırları
byte Border_Map(int Pin, int lower, int middle, int upper, bool reverse) {
int val = constrain(analogRead(Pin), 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() {
static uint16_t rslt = 0;
static unsigned long lastTime = 0;
data.roll = Border_Map( A3, 0, 512, 1050, true ); // "true" or "false" for signal direction | "true" veya "false" sinyal yönünü belirler
data.pitch = Border_Map( A2, 0, 512, 1023, true );
data.throttle = Border_Map( A1, 570, 800, 1023, false ); // For Single side ESC | Tek yönlü ESC için
data.yaw = Border_Map( A0, 0, 512, 1023, true );
data.aux1 = Border_Map( A4, 0, 512, 1023, true );
data.aux2 = Border_Map( A5, 0, 512, 1023, true );
data.aux3 = digitalRead(7);
data.aux4 = digitalRead(8);
rslt += radio.write(&data, sizeof(Signal));
if (millis() - lastTime > 1000) {
Serial.print("gönderildi ");
Serial.println(rslt);
lastTime += 1000;
}
}
// 8 Channel Receiver | 8 Kanal Alıcı
#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;
int ch_width_5 = 0;
int ch_width_6 = 0;
int ch_width_7 = 0;
int ch_width_8 = 0;
Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;
Servo ch7;
Servo ch8;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
} data;
const byte pipeIn[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(9, 10);
void ResetData() {
data.throttle = 0;
data.roll = 127;
data.pitch = 127;
data.yaw = 127;
data.aux1 = 0; // Define the inicial value of each data input. | Veri girişlerinin başlangıç değerleri
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup() {
// Set the pins for each PWM signal | Her bir PWM sinyal için pinler belirleniyor.
//Serial.begin(9600);
ch1.attach(0);
ch2.attach(2);
ch3.attach(3);
ch4.attach(4);
ch5.attach(5);
ch6.attach(6);
ch7.attach(7);
ch8.attach(8);
ResetData(); // Configure the NRF24 module | NRF24 Modül konfigürasyonu
radio.begin();
radio.openReadingPipe(1, pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.startListening(); // Start the radio comunication for receiver | Alıcı için sinyal iletişimini başlatır.
}
unsigned long lastRecvTime = 0;
void recvData() {
while (radio.available())radio.read(&data, sizeof(Signal));
lastRecvTime = millis();
}
void loop() {
if ( radio.available() )recvData();
if ( millis() - lastRecvTime > 1000)ResetData();
ch_width_1 = map(data.roll, 0, 255, 1000, 2000);
ch_width_2 = map(data.pitch, 0, 255, 1000, 2000);
ch_width_3 = map(data.throttle, 0, 255, 1000, 2000);
ch_width_4 = map(data.yaw, 0, 255, 1000, 2000);
ch_width_5 = map(data.aux1, 0, 255, 1000, 2000);
ch_width_6 = map(data.aux2, 0, 255, 1000, 2000);
ch_width_7 = map(data.aux3, 0, 1, 1000, 2000);
ch_width_8 = map(data.aux4, 0, 1, 1000, 2000);
// 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);
ch5.writeMicroseconds(ch_width_5);
ch6.writeMicroseconds(ch_width_6);
ch7.writeMicroseconds(ch_width_7);
ch8.writeMicroseconds(ch_width_8);
}
There is an error with Transmitter code the error was "val is not declared" once I declared val as
byte Border_Map(int val, int Pin, int lower, int middle, int upper, bool reverse)
now the error is "Compilation error: too few arguments to function 'byte Border_Map(int, int, int, int, int, bool)"
// 8 Channel Transmitter (No Trim) | 8 Kanal Verici (Trim Yok)
// Input pin A5
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const byte pipeOut[5] = {'R', 'x', 'A', 'A', 'A'}; // NOTE: The same as in the receiver 000322 | Alıcı kodundaki adres ile aynı olmalı
RF24 radio(9, 10); // select CE,CSN pin | CE ve CSN pinlerin seçimi
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
byte aux1;
byte aux2;
byte aux3;
byte aux4;
} data;
void ResetData() {
data.throttle = 0;
data.pitch = 127;
data.roll = 127;
data.yaw = 127;
data.aux1 = 0; // Signal lost position | Sinyal kesildiğindeki pozisyon
data.aux2 = 0;
data.aux3 = 0;
data.aux4 = 0;
}
void setup() {
//Configure the NRF24 module | NRF24 modül konfigürasyonu
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipeOut);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS); // The lowest data rate value for more stable communication | Daha kararlı iletişim için en düşük veri hızı.
radio.setPALevel(RF24_PA_MAX); // Output power is set for maximum | Çıkış gücü maksimum için ayarlanıyor.
radio.stopListening(); // Start the radio comunication for Transmitter | Verici için sinyal iletişimini başlatır.
ResetData();
}
// Joystick center and its borders | Joystick merkez ve sınırları
byte Border_Map(int Pin, int lower, int middle, int upper, bool reverse) {
int val = constrain(analogRead(Pin), lower, upper);
if ( val < middle )val = map(val, lower, middle, 0, 128);
else val = map(val, middle, upper, 128, 255);
return byte(reverse ? 255 - val : val );
}
void loop() {
static uint16_t rslt = 0;
static unsigned long lastTime = 0;
data.roll = Border_Map( A3, 0, 512, 1050, true ); // "true" or "false" for signal direction | "true" veya "false" sinyal yönünü belirler
data.pitch = Border_Map( A2, 0, 512, 1023, true );
data.throttle = Border_Map( A1, 570, 800, 1023, false ); // For Single side ESC | Tek yönlü ESC için
data.yaw = Border_Map( A0, 0, 512, 1023, true );
data.aux1 = Border_Map( A4, 0, 512, 1023, true );
data.aux2 = Border_Map( A5, 0, 512, 1023, true );
data.aux3 = digitalRead(7);
data.aux4 = digitalRead(8);
rslt += radio.write(&data, sizeof(Signal));
if (millis() - lastTime > 1000) {
Serial.print("gönderildi ");
Serial.println(rslt);
lastTime += 1000;
}
}
Can you explain what was wrong with my code?
and what is the purpose of this?
rslt += radio.write(&data, sizeof(Signal));
if (millis() - lastTime > 1000) {
Serial.print("gönderildi ");
Serial.println(rslt);
lastTime += 1000;
is better then this
How can I understand that data is receiven. You deleted if statement that ı used it to understand if data is received. If that was wrong, How can I understand if data is received without connecting all the joysticks and stuff?
joystick on receiver?
Sender hat default value and sending it everytime. his serial show every second how much is sendet after start.
nah just servos and a drone motor on receiver
1 servo is enough to check. of course we can put debugging messages back, but after all it must be disabled to let receiver working without loosing sent data
do you able to connect one switch more to receiver, for example jumper?
what do you mean by one more switch?
or one button, you hold this button pressed and reset receiver and it will boot in dubugging mode, and will show in serial the received data.
without pressing it booting in normal mode and no message will show in serial
i have checked now your original sketch, there is nothin about receiving data, only one line if something is available
No Im not able to do that now
This part receives data
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
}
i know. it remains nearly unchanged
So what was your point saying that there is nothing about receiving data
no data is shown in serial
I thought that if radio.available() is not equals to 1 ı can assume that the communication fails. So I didnt serial print any data. Am I wrong?
.available()
is a function to check how much bytes are ready to be received or in case of radio is it a message awaiting receiving. nothing about data itself.
so it is impossible to use this function to check how good or how bad the data was readout.
but the .read()
function can do this.