problems with a stable connection - nrf24l01

I am working on a project with a remote control car i am using 2 nrf24l01 modules with anthena, the code has worked but once i started sending more values it went wrong …

in the serial montor I get this values:

received
125
0
0
127
122
133
125
0
0
1

received
1
0
0
1
1
0
1
0
127
122

received
133
125
0
0
127
122
133
125
1
1

received
1
1
0
125
1
1
1
1
0
0

as you can see it is not correct
the values are mixed up …
if anyone knows a solution I would be very happy :slight_smile:

  • receiver code -
void receiveData() {
  if (radio.available()) {
    
    Serial.println("");
    Serial.println("received");
    
    radio.read(&receivedData, sizeof(receivedData));
    pot_L_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(pot_L_VAL);

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

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

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

    radio.read(&receivedData, sizeof(receivedData));
    yAxis_L_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(yAxis_L_VAL);

    radio.read(&receivedData, sizeof(receivedData));
    yAxis_R_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(yAxis_R_VAL);

    radio.read(&receivedData, sizeof(receivedData));
    sw_U_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(pot_L_VAL);

    radio.read(&receivedData, sizeof(receivedData));
    sw_D_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(sw_D_VAL);

    radio.read(&receivedData, sizeof(receivedData));
    sw_L_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(sw_L_VAL);

    radio.read(&receivedData, sizeof(receivedData));
    sw_R_VAL = atoi(&receivedData[0]);
    delay(5);
    Serial.println(sw_R_VAL);


  }
}
  • transceiver code -
void send_Package() {
  Read_Controller();
  delay(10);
  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));

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

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

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

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

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

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

  delay(10);
}

the full program can be found in attachment…

Isaak

Code.zip (4.96 KB)

You should put all the values into an array and send them in a single message. The way you are doing it you are sending messages at much too frequent intervals and if a message gets lost the receiver will not know which value was lost.

Have a look at this Simple nRF24L01+ Tutorial

And if you need more help please post complete programs.

...R