nRF24L01 delay problem

Hello everyone ,

i’m building a radio command for my drone using nrf24l01 and an Atmega8 standalone.
When i open arduino serial monitor to check the data from the receiver i notice a delay of 2 secondes .
i don’t know why this delay happen , because i used the same code before on another RC and it works correct

transmitter code

 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
  
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(A0, 10); 

struct MyData {
  byte throttle;
  byte yaw;
  byte pitch;
  byte roll;
};

MyData data;

void resetData() 
{    
  data.throttle = 0;
  data.yaw = 127;
  data.pitch = 127;
  data.roll = 127;
}

void setup()
{
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  resetData();
 
}


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 );  //variable = (condition) ? optionA : optionB;
}

void loop()
{
  data.throttle = mapJoystickValues( analogRead(A5), 0, 511, 1023, false );
  data.yaw      = mapJoystickValues( analogRead(A4),  0, 510, 1023, false );
  data.pitch    = mapJoystickValues( analogRead(A3), 0, 507, 1023, false );
  data.roll     = mapJoystickValues( analogRead(A2), 0, 512, 1023, false );

radio.write(&data, sizeof(MyData));

  
}

receiver code (using serial monitor to verify data)

 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeIn = 0xE8E8F0F0E1LL; 
RF24 radio(A0, 10); 


struct MyData {
byte throttle;
byte yaw;
byte pitch;
byte roll;

};

MyData data;

void resetData()
{

data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;


}



void setup()
{
Serial.begin(9600); 
resetData();
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);

radio.openReadingPipe(1,pipeIn);
radio.startListening();

}



unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis(); 
}
}

void loop()
{
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
resetData();
}

Serial.print("Throttle: "); Serial.print(data.throttle);  Serial.print("    ");
Serial.print("Yaw: ");      Serial.print(data.yaw);       Serial.print("    ");
Serial.print("Pitch: ");    Serial.print(data.pitch);     Serial.print("    ");
Serial.print("Roll: ");     Serial.print(data.roll);      Serial.print("\n");



}

aladeen97:
When i open arduino serial monitor to check the data from the receiver i notice a delay of 2 secondes .
i don't know why this delay happen , because i used the same code before on another RC and it works correct.

The most likely explanation is that the problem code is not exactly the same as the working code.

Apart from that you are not giving us much to help you with. An nRF24 message takes a few millisecs so a delay of 2000 millisecs implies a huge problem.

My wild guess is that your Rx code is sending data to Serial much too often and the Serial Output Buffer is filling up causing the Arduino to block. You should only print when a message arrives.

...R
Simple nRF24L01+ Tutorial