NRF24 Bi directional Analog value transmission

Hi all,

I have a project using wireless communication with nrf24, the "master" sends some analog data to the "slave" which in return
sends 4 analog values from A2 to A5, but i'm getting so strange reading, here is a sample of the code bellow. I really can't figure out why I get strange readings! Thanks in advance for your help.

// Slave //


#include <RF24.h>


// Setting up radio, CE, CS
RF24 radio(7, 8);
const byte addresses[][6] = {"EMTR1", "RCVR1"};

const int A2Pin = A2;
const int A3Pin = A3;
const int A4Pin = A4;
const int A5Pin = A5;

void setup() {

Serial.begin(9600);

  // Pin modes
  pinMode (A2Pin, INPUT);
  pinMode (A3Pin, INPUT);
  pinMode (A4Pin, INPUT);
  pinMode (A5Pin, INPUT);

  // Let's turn on the radio
  radio.begin();
  radio.setCRCLength(RF24_CRC_8);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_2MBPS);
  radio.setAutoAck(1);
  radio.openWritingPipe(addresses[0]); // RCVR
  radio.openReadingPipe(1, addresses[1]); // EMETR
  radio.startListening();

}


void loop() {



  //////////////Rf Communication/////////////////////////
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {

      int potVal;

      radio.read(&potVal, sizeof(potVal));

      Serial.print(potVal);


      delay(10);
    }


    radio.stopListening();
    digitalWrite(RfLockLedPin, LOW);

    int A2Val = analogRead(A2Pin);
    int A3Val = analogRead(A3Pin);
    int A4Val = analogRead(A4Pin);
    int A5Val = analogRead(A5Pin);

    radio.write(&A2Val, sizeof(A2Val));
    radio.write(&A3Val, sizeof(A3Val));
    radio.write(&A4Val, sizeof(A4Val));
    radio.write(&A5Val, sizeof(A5Val));

    delay(20);

  }
}
// Master //

#include <RF24.h>

const int potPin = A0;

int A2Val;
int A3Val;
int A4Val;
int A5Val;


// Setting up radio, CE, CS
RF24 radio(7, 8);
const byte addresses[][6] = {"EMTR1", "RCVR1"};

void setup() {

  Serial.begin(9600);
  

  pinMode (potPin, INPUT);
 
  

  // Let's turn on the radio
  radio.begin();
  radio.setCRCLength(RF24_CRC_8);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_2MBPS);
  radio.setAutoAck(1);
  radio.openWritingPipe(addresses[1]); // EMETR
  radio.openReadingPipe(1, addresses[0]); // RECVR

}

void loop() {


  radio.stopListening();
  
  int potPinVal = analogRead(potPin);
  
  radio.write(&potPinVal, sizeof(potPinVal));
  
  delay(10);

  radio.startListening();
  while (!radio.available());
  
    radio.read(&A2Val, sizeof(A2Val));
    radio.read(&A3Val, sizeof(A3Val));
    radio.read(&A4Val, sizeof(A4Val));
    radio.read(&A5Val, sizeof(A5Val));
 
    Serial.print(A2Val);
    Serial.print("\t");
    Serial.print(A3Val);
    Serial.print("\t");
    Serial.print(A4Val);
    Serial.print("\t");
    Serial.println(A4Val);

    

  delay(10);

}

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

For 2-way communication the ackPayload system (in the 2nd example) is probably the simplest.

...R

Robin2:
Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

For 2-way communication the ackPayload system (in the 2nd example) is probably the simplest.

...R

Thanks for your answer, the wireless communication is already working fine, I get the correct analog reading from the master but the slave doesn't seem to send the values correctly

BenzDuino:
Thanks for your answer, the wireless communication is already working fine, I get the correct analog reading from the master but the slave doesn't seem to send the values correctly

I find it hard to reconcile those statements.

...R

Robin2:
Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

For 2-way communication the ackPayload system (in the 2nd example) is probably the simplest.

...R

But I'm gonna read this to troubleshoot my issue, I'll keep you posted!

You should have a look at Robin2s samplecode, there is a bidirectonal example too.

Your code is very unsensible (reading packets without checking availability no preload, delays, blocking behavior, ...).

Whandall:
You should have a look at Robin2s samplecode, there is a bidirectonal example too.

Your code is very unsensible (reading packets without checking availability no preload, delays, blocking behavior, ...).

Thank you, will do!

Some updates,

First of, I 've managed to debug a couple of issues on the slave side, when "radio.writing" names should not be too long,
I was able to send back 1 analogRead pin value but can't send all 4!