Arduino nrf24l01 AckPayload problem

I am trying to do 2 way communication with nrf24l01using acknowledge payload. My normal Rx Tx communication is working properly but ı can't get any ackpayload data from my receiver. Here is my Rx Tx codes:

TX
verici.ino (2.0 KB)



#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = {"00001"};
int AllValues[5];
int JoyLeft[2];
int JoyRight[2];

int voltageRead;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;

int potans;

void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(1);
  radio.enableAckPayload();
  radio.openWritingPipe(address);
  //radio.openReadingPipe(1, addresses[1]);
  
  //radio.stopListening();

  delay(100);
}


void loop() {
  
  potans = analogRead(A4);
  potans = map(potans, 425, 20, 1023, 0);
  potans = constrain(potans, 0,1023);
  
  JoyLeft[0] = analogRead(A0);
  JoyLeft[1] = analogRead(A1);
  
  JoyRight[0] = analogRead(A2);
  JoyRight[1] = analogRead(A3);

  AllValues[0] = JoyLeft[0];
  AllValues[1] = JoyLeft[1];
  AllValues[2] = JoyRight[0];
  AllValues[3] = JoyRight[1];
  AllValues[4] = potans;

  //Serial.println(joy1[1]);
  //Serial.println(AllValues[1]);
  
  //Serial.println(AllValues[2]);

  // radio.write(&AllValues,sizeof(AllValues ));
  //  delay(5);
  // radio.stopListening();
  // while ( radio.available()) {
  // radio.read(&voltage,sizeof(float));
  // }

  while(radio.isAckPayloadAvailable() ) {
    radio.read(&voltageRead, sizeof(voltageRead));

    Serial.print("var");
    Serial.print("\t");
  }
    
  // Always use sizeof() as it gives the size as the number of bytes.
  // For example if AllValues was an int sizeof() would correctly return 2
    
  radio.write(&AllValues, sizeof(AllValues));
           
  Serial.print(JoyLeft[0]);
  Serial.print("\t");
  Serial.print(JoyLeft[1]);
  Serial.print("\t");
  Serial.print(JoyRight[0]);
  Serial.print("\t");
  Serial.print(JoyRight[1]);
  Serial.print("\t"); 
  Serial.print(potans);
  Serial.print("\t"); 
  Serial.println(voltageRead);      
  }

RX
alici.ino (3.3 KB)


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#include <Smoothed.h>


Servo throtles;
Servo elevators;
Servo rudders;
Servo aileronlefts;
Servo aileronrights;

bool sinyal;

int throtle;
int elevator;
int rudder;
int aileronleft;
int aileronright;

int AllValues[5];

int voltageRead = 0;
float voltage;
Smoothed <float> voltages;
float R1 = 46400.0;
float R2 = 54700.0;

unsigned long soniletim = 0;
unsigned long now = 1;


RF24 radio(7, 8); // CE, CSN
const byte address[6] = {"00001"};

void setup() { 
  Serial.begin(9600);
  

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(0, address);
  
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(1);
  radio.enableAckPayload();
  radio.startListening();
  radio.writeAckPayload(1, &voltage, sizeof(float));

  throtles.attach(3, 1000, 2000);
  elevators.attach(5);
  rudders.attach(6);
  aileronlefts.attach(10);
  aileronrights.attach(9);

  rudder = map(AllValues[0], 0, 1023, 135, 35);
  aileronright = map(AllValues[0], 0, 1023, 40, 140);
  aileronleft = map(AllValues[0], 0, 1023, 140, 40);
  elevator = map(AllValues[0], 0, 1023, 140, 40);
  throtle = map(AllValues[4], 0, 1023, 180, 0);

  elevator = 90;
  rudder = 85;
  aileronleft = 83;
  aileronright = 76;

  voltages.begin(SMOOTHED_AVERAGE, 10);

 
  delay(100);
 
  
}
void loop() {
  sinyal = 0;
  if ( radio.available()) {
      
      radio.read(AllValues, sizeof(AllValues));
      radio.writeAckPayload(1, &voltageRead, sizeof(voltageRead));
      soniletim = millis();

      rudder = map(AllValues[0], 0, 1023, 35, 135);
      aileronright = map(AllValues[2], 0, 1023, 116, 36);
      aileronleft = map(AllValues[2], 0, 1023, 123, 43);
      elevator = map(AllValues[3], 0, 1023, 140, 40);
      throtle = map(AllValues[4], 0, 1023, 1000, 2000);

      sinyal = 1;
      } 
    
    Serial.print(sinyal);
    Serial.print("\t");
    if(sinyal ==1 ){
      Serial.print("sinyal var");
      Serial.print("\t");
    }
    else {
      Serial.print("sinyal yok");
      Serial.print("\t");
    }
  
    now = millis();

    if ( now - soniletim > 200 ){
     elevator = 90;
     rudder = 85;
     aileronleft = 83;
     aileronright = 76;
     throtle = 0;
     //Serial.print("SİNYAL YOK");
     //Serial.print("\t");
     radio.startListening();
     delay(100);
      
    }

    
    throtles.writeMicroseconds(throtle);
    elevators.write(constrain(elevator, 40, 140));
    rudders.write(constrain(rudder, 35, 135));
    aileronlefts.write(constrain(aileronleft, 43, 123));
    aileronrights.write(constrain(aileronright, 36, 116));

    //7.65d 7.68t,
    voltageRead = analogRead(A0); 
    voltage = voltageRead * (5.0/1024)*((R1 + R2)/R2);
    voltages.add(voltage);
    voltage = voltages.get();
    

    Serial.print(rudder);
    Serial.print("\t");
    Serial.print(aileronleft);
    Serial.print("\t");
    Serial.print(aileronright);
    Serial.print("\t");
    Serial.print(elevator);
    Serial.print("\t"); 
    Serial.print(throtle);
    Serial.print("\t");
    Serial.print(now - soniletim);
    Serial.print("\t");
    Serial.println(voltage);
   
    
  }

People do not like to have to download code. Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Have you seen Robin2's excellent simple rf24 tutorial? It has an ack payload example.

Actually i used this tutorial with many others.

AckPayload is payload attached to the Ack.

So you should send, and then try to receive something, not the other way around.

Did I misunderstand you?

I also want to say "radio.isAckPayloadAvailable()" giving zero in TX code.

  radio.write(&AllValues, sizeof(AllValues));
  while(radio.isAckPayloadAvailable() ) {
    radio.read(&voltageRead, sizeof(voltageRead));

    Serial.print("var");
    Serial.print("\t");
  }

I edited some parts of the code but the result is the same

tx



#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = {"00001"};
int AllValues[5];
int JoyLeft[2];
int JoyRight[2];

int voltageRead;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;

int potans;

void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(1);
  radio.enableAckPayload();
  radio.openWritingPipe(address);
  //radio.openReadingPipe(1, addresses[1]);
  
  //radio.stopListening();

  delay(100);
}


void loop() {
  
  potans = analogRead(A4);
  potans = map(potans, 425, 20, 1023, 0);
  potans = constrain(potans, 0,1023);
  
  JoyLeft[0] = analogRead(A0);
  JoyLeft[1] = analogRead(A1);
  
  JoyRight[0] = analogRead(A2);
  JoyRight[1] = analogRead(A3);

  AllValues[0] = JoyLeft[0];
  AllValues[1] = JoyLeft[1];
  AllValues[2] = JoyRight[0];
  AllValues[3] = JoyRight[1];
  AllValues[4] = potans;

  //Serial.println(joy1[1]);
  //Serial.println(AllValues[1]);
  
  //Serial.println(AllValues[2]);

  // radio.write(&AllValues,sizeof(AllValues ));
  //  delay(5);
  // radio.stopListening();
  // while ( radio.available()) {
  // radio.read(&voltage,sizeof(float));
  // }

  radio.write(&AllValues, sizeof(AllValues));
  while(radio.isAckPayloadAvailable() ) {
    radio.read(&voltageRead, sizeof(voltageRead));

    Serial.print("var");
    Serial.print("\t");
  }
    
  // Always use sizeof() as it gives the size as the number of bytes.
  // For example if AllValues was an int sizeof() would correctly return 2
    
  
           
  Serial.print(JoyLeft[0]);
  Serial.print("\t");
  Serial.print(JoyLeft[1]);
  Serial.print("\t");
  Serial.print(JoyRight[0]);
  Serial.print("\t");
  Serial.print(JoyRight[1]);
  Serial.print("\t"); 
  Serial.print(potans);
  Serial.print("\t"); 
  Serial.println(voltageRead);      
  }

rx


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#include <Smoothed.h>


Servo throtles;
Servo elevators;
Servo rudders;
Servo aileronlefts;
Servo aileronrights;

bool sinyal;

int throtle;
int elevator;
int rudder;
int aileronleft;
int aileronright;

int AllValues[5];

int voltageRead = 0;
float voltage;
Smoothed <float> voltages;
float R1 = 46400.0;
float R2 = 54700.0;

unsigned long soniletim = 0;
unsigned long now = 1;


RF24 radio(7, 8); // CE, CSN
const byte address[6] = {"00001"};

void setup() { 
  Serial.begin(9600);
  

  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(0, address);
  
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(1);
  radio.enableAckPayload();
  radio.startListening();
  radio.writeAckPayload(1, &voltageRead, sizeof(voltageRead));

  throtles.attach(3, 1000, 2000);
  elevators.attach(5);
  rudders.attach(6);
  aileronlefts.attach(10);
  aileronrights.attach(9);

  rudder = map(AllValues[0], 0, 1023, 135, 35);
  aileronright = map(AllValues[0], 0, 1023, 40, 140);
  aileronleft = map(AllValues[0], 0, 1023, 140, 40);
  elevator = map(AllValues[0], 0, 1023, 140, 40);
  throtle = map(AllValues[4], 0, 1023, 180, 0);

  elevator = 90;
  rudder = 85;
  aileronleft = 83;
  aileronright = 76;

  voltages.begin(SMOOTHED_AVERAGE, 10);

 
  delay(100);
 
  
}
void loop() {
  sinyal = 0;
  if ( radio.available()) {
      
      radio.read(AllValues, sizeof(AllValues));
      voltageRead = analogRead(A0);
      radio.writeAckPayload(1, &voltageRead, sizeof(voltageRead));
      soniletim = millis();

      rudder = map(AllValues[0], 0, 1023, 35, 135);
      aileronright = map(AllValues[2], 0, 1023, 116, 36);
      aileronleft = map(AllValues[2], 0, 1023, 123, 43);
      elevator = map(AllValues[3], 0, 1023, 140, 40);
      throtle = map(AllValues[4], 0, 1023, 1000, 2000);

      sinyal = 1;
      } 
    
    Serial.print(sinyal);
    Serial.print("\t");
    if(sinyal ==1 ){
      Serial.print("sinyal var");
      Serial.print("\t");
    }
    else {
      Serial.print("sinyal yok");
      Serial.print("\t");
    }
  
    now = millis();

    if ( now - soniletim > 200 ){
     elevator = 90;
     rudder = 85;
     aileronleft = 83;
     aileronright = 76;
     throtle = 0;
     //Serial.print("SİNYAL YOK");
     //Serial.print("\t");
     radio.startListening();
     delay(100);
      
    }

    
    throtles.writeMicroseconds(throtle);
    elevators.write(constrain(elevator, 40, 140));
    rudders.write(constrain(rudder, 35, 135));
    aileronlefts.write(constrain(aileronleft, 43, 123));
    aileronrights.write(constrain(aileronright, 36, 116));

    //7.65d 7.68t,
    voltageRead = analogRead(A0); 
    voltage = voltageRead * (5.0/1024)*((R1 + R2)/R2);
    voltages.add(voltage);
    voltage = voltages.get();
    

    Serial.print(rudder);
    Serial.print("\t");
    Serial.print(aileronleft);
    Serial.print("\t");
    Serial.print(aileronright);
    Serial.print("\t");
    Serial.print(elevator);
    Serial.print("\t"); 
    Serial.print(throtle);
    Serial.print("\t");
    Serial.print(now - soniletim);
    Serial.print("\t");
    Serial.println(voltage);
   
    
  }

better would be

  if (radio.write(&AllValues, sizeof(AllValues))) {
    if (radio.isAckPayloadAvailable() ) {
    }
  }

Writing the AckPayload to the closed pipe 1 will not help to transmit it on a reception on pipe 0.

thank you so much. I will try and give feedback. I lost the only cable i used for my Nano :slight_smile: .

It worked. Thanks for your answers. I didn't notice this line. I tried the swapping roles way before. That's why 1 is there i think.

radio.writeAckPayload(1, &voltageRead, sizeof(voltageRead));

You could now mark the solution and post the working code.