Problem: Bidirectional communication between NRF24L01s (1 master + 2 slaves)

Hi everyone! I’d appreciate any insights, corrections, or observations regarding this issue:

Project: Bidirectional communication using NRF24L01 (PA+LNA) between a MASTER (Arduino Mega) and two independent Slaves (Arduino UNO and MEGA).

Problem: The MASTER successfully sends messages to both Slaves, and both receive them correctly. However, while Slave UNO replies successfully, Slave MEGA fails to send a reply back to the Master.

I suspect the issue might lie in the Channel and Pipe configuration. To rule out overlapping issues, I disconnected Slave UNO (which works fine), but Slave MEGA still couldn’t send a reply back to the Master.

Thanks in advance!

SCHEMATIC (Mega + NRF24L01):

SCHEMATIC (UNO + NRF24L01):

SERIAL PORT DISPLAY

Master Serial display:

4.1 Serial MASTER

Slave Mega Serial display:

Slave UNO Serial display:

Only Master and Slave Mega (no Slave UNO) Serial display:

4.4 Serial MASTER (SLAVE UNO disconnected)

MASTER CODE:

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

RF24 radio(7, 8); // CE, CSN

const byte addresses[4][6] = {"00001", "00002", "00003", "00004"};
// addresses[0] = "00001"; MASTER -> SLAVE UNO
// addresses[1] = "00002"; MASTER -> SLAVE MEGA
// addresses[2] = "00003"; SLAVE UNO -> MEGA
// addresses[3] = "00004"; SLAVE MEGA -> MEGA

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);

  radio.openWritingPipe(addresses[0]);  // To send message to SLAVE UNO (channel 00001)
  radio.openWritingPipe(addresses[1]);  // To send message to SLAVE MEGA (channel 00002)
  radio.openReadingPipe(1, addresses[2]);  // To receive reply from SLAVE UNO (channel 00003)
  radio.openReadingPipe(2, addresses[3]);  // To receive reply from SLAVE MEGA (channel 00004)
}

void loop() {
  const char message[] = "Message from MASTER";

  //SEND MESSAGE TO SLAVE UNO------------------------------------------------------------
  radio.stopListening(); 
  radio.openWritingPipe(addresses[0]); // To send message to SLAVE UNO (channel 00001)
  if (radio.write(&message, sizeof(message))) { //Confirm if message was sent
    Serial.println("Message sent to SLAVE UNO");
  } else {
    Serial.println("Failed messaging to SLAVE UNO");
  }

  //RECEIVE REPLY FROM SLAVE UNO---------------------------------------------------------
  radio.startListening();
  
  //Verify if a reply has been received
  unsigned long startTime = millis(); 
  bool receivedReply = false; 

  while (millis() - startTime < 1000) {  //Wait 1sec to receive reply
    if (radio.available()) {
      char replyFromSlaveUNO[32] = "";
      radio.read(&replyFromSlaveUNO, sizeof(replyFromSlaveUNO));
      Serial.println(replyFromSlaveUNO);
      receivedReply = true;
      break;
    }
  }

  if (!receivedReply) {
    Serial.println("No reply from SLAVE UNO");
  }
  
  //SEND MESSAGE TO SLAVE MEGA-----------------------------------------------------------
  radio.stopListening();  
  radio.openWritingPipe(addresses[1]); // To send message to SLAVE MEGA (channel 00002)
  if (radio.write(&message, sizeof(message))) { //Confirm if message was sent
    Serial.println("Message sent to SLAVE MEGA");
  } else {
    Serial.println("Failed messaging to SLAVE MEGA");
  }

    //RECEIVE REPLY FROM SLAVE MEGA--------------------------------------------------------
  radio.startListening();
  
  //Verify if a reply has been received
  startTime = millis(); 
  receivedReply = false; 

  while (millis() - startTime < 1000) { //Wait 1sec to receive reply
    if (radio.available()) {
      char replyFromSlaveMEGA[32] = "";
      radio.read(&replyFromSlaveMEGA, sizeof(replyFromSlaveMEGA));
      Serial.println(replyFromSlaveMEGA);
      receivedReply = true;
      break;
    }
  }

  if (!receivedReply) {
    Serial.println("No reply from SLAVE MEGA.");
  }
  
  delay(1000); 
}

SLAVE MEGA:

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

RF24 radio(7, 8); // CE, CSN
const byte addresses[4][6] = {"00001", "00002", "00003", "00004"};

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);

  radio.openReadingPipe(1, addresses[1]); // Receive from MASTER (channel 00002)
  radio.openWritingPipe(addresses[3]); // Send to MASTER (channel 00004)
}

void loop() {
  radio.startListening(); 

  //RECEIVE FROM MASTER
  if (radio.available()) {
    char receivedMessage[32] = "";
    radio.read(&receivedMessage, sizeof(receivedMessage));
    Serial.println(receivedMessage); //Confirm message received from MASTER

    //REPLY TO MASTER
    radio.stopListening(); 
    const char reply[] = "Reply from SLAVE MEGA";
    if (radio.write(&reply, sizeof(reply))) { //Confirm if reply was sent to MASTER
      Serial.println("Reply sent to MASTER");
    } else {
      Serial.println("No reply sent to MASTER");
    }
  }
}

SLAVE UNO:

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

RF24 radio(7, 8); // CE, CSN
const byte addresses[4][6] = {"00001", "00002", "00003", "00004"};

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);

  // Configurar lectura y escritura
  radio.openReadingPipe(1, addresses[0]);  // Receive from MASTER (channel 00001)
  radio.openWritingPipe(addresses[2]);  // Send to MASTER (channel 00003)
}

void loop() {
  radio.startListening(); 

  //RECEIVE FROM MASTER
  if (radio.available()) {
    char receivedMessage[32] = "";
    radio.read(&receivedMessage, sizeof(receivedMessage));
    Serial.println(receivedMessage); //Confirm message received from MASTER

    //REPLY TO MASTER
    radio.stopListening();  
    const char reply[] = "Reply from SLAVE UNO";
    if (radio.write(&reply, sizeof(reply))) { //Confirm if reply was sent to MASTER
      Serial.println("Reply sent to MASTER");
    } else {
      Serial.println("No reply sent to MASTER");
    }
  }
}

This is your likely problem.

const byte addresses[4][6] = {"10000", "20000", "30000", "40000"};

I shake my fist at whoever wrote these examples that use backwards addressing. Its confusing because pipes 1 or higher need to use the same addresses except for 1 byte, and its the left-most byte in your address array not the right-most.

1 Like

Thank you so much @TMRh20

I changed the addressing code line as you said, and removed the delays. There might be the occasional message that is not received after several successful transmissions, but in general, it runs smoothly now. :grinning:

I have to go deeper into this RF communication thing.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.