getting a more stable conection with nrf24l01 (with anthena)

I am working on a car and transmitter that wirelessly communicate with 2 nrf24l01 with antene, it is quite good but sometimes an error value is passed (every 8 times or so). I have seen this on the serial monitor, if nothing is done with the joystick the number remains 0 and then every 8 times suddenly a 127, which leads to a short sudden movement. I could write a piece of code that he filters it out but maybe it's better if I get a more stable conection. anyone have an idea? everything is welcome!

*** receiver ***

void receiveData() {
  if (radio.available()) {
    
    radio.read(&receivedData, sizeof(receivedData));
    pot_L_VAL = atoi(&receivedData[0]);
    delay(5);

    radio.read(&receivedData, sizeof(receivedData));
    pot_R_VAL = atoi(&receivedData[0]);
    delay(5);
    
    radio.read(&receivedData, sizeof(receivedData));
    xAxis_L_VAL = atoi(&receivedData[0]);
    delay(5);

    radio.read(&receivedData, sizeof(receivedData));
    xAxis_R_VAL = atoi(&receivedData[0]);
    delay(5);
  }
}

*** transmitter***

void send_Package() {
  Read_Controller();
  pot_L_VAL.toCharArray(xyData, 5);
  radio.write(&xyData, sizeof(xyData));

  pot_R_VAL.toCharArray(xyData, 5);
  radio.write(&xyData, sizeof(xyData));

  xAxis_L_VAL.toCharArray(xyData, 5);
  radio.write(&xyData, sizeof(xyData));

  xAxis_R_VAL.toCharArray(xyData, 5);
  radio.write(&xyData, sizeof(xyData));

  delay(20);

}

(I use a lot of tabs so if you want to see the full code you have to download the zip file, sorry)
and the _PCM3 files are the files for the reveiver, the _PCT files are for the transmitter...

Isaak

code.zip (3.86 KB)

idv7:
sometimes an error value is passed (every 8 times or so). I have seen this on the serial monitor, if nothing is done with the joystick the number remains 0 and then every 8 times suddenly a 127, which leads to a short sudden movement. I could write a piece of code that he filters it out but maybe it's better if I

...maybe it's better if you find the source of the bug. It would be a better use of time than trying to modify the code to cover up the effects. If you post the entire sketch, in code tags as the forum guidelines suggest, then someone may be able to see the cause of the problem.

Very consistent behavior as you have described is, as has already been said, due to a software bug and not simply a random glitch in radio transmission .

Don't send the data in four separate messages. Put all the four values into an int array and send the array.

Don't have delay()s in the receiver. Do the timing in the transmitter - I suspect sending 5 updates per second will be plenty, certainly not more than 10 would be needed.

For example

int dataToSend[4];
dataToSend[0] = pot_L_VAL;
dataToSend[1] = pot_R_VAL;
dataToSend[2] = xAxis_L_VAL;
dataToSend[3] = xAxis_R_VAL;
radio.write(&dataToSend, sizeof(dataToSend));
delay(200);

On the RX side save the incoming data to an identical array

...R
Simple nRF24L01+ Tutorial

thank you Robin,
i will apply these things and let you know if it works!

Isaak