Failed to sent data by multiple nodes using module nrf24l01

Hello guys,My problem is failed to sent data when using multiple pipes and in the RX serial monitor displayed No Radio Available,while when I'm using one pipe (point to point) that is worked with the same devices (arduino and nrf24l01)

Here is the Transmitter Code

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

#define DHT2TYPE DHT11   
#define DHT2PIN A1    

RF24 radio(9,10);                    
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0A3LL };       
DHT dht2(DHT2PIN, DHT2TYPE);

float t2; 

struct payload{
  float temp;
};


void setup(void) {
  Serial.begin(9600);
  dht2.begin(); 
  SPI.begin();
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipes[1]);
  radio.startListening();
}

void loop(void) { 
  
Serial.println("Sending...");

float t2 = dht2.readTemperature();

Serial.print("Temp2: ");
Serial.println(t2);
delay(500);

payload data = {t2};
radio.write(&t2, sizeof(data));
delay(600);

  
}

Here is the Receiver code

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

RF24 radio(9,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0A3LL };    

float t2;
struct payload{
  float temp;
};


void setup(void) {
  Serial.begin(9600);
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1, pipes[1]);
  radio.openReadingPipe(2, pipes[2]);
  radio.startListening();
  delay(50);
}

void loop(void)
{
if ( radio.available() ) {
  delay(50);
  payload dataREV;
  radio.read(&t2, sizeof(dataREV));

t2 = dataREV.temp;
Serial.print("Temp: ");
Serial.println(t2);
delay(50);
}

else 
{
Serial.println("No radio available");
}
delay(500);  
}

any body can help me to solve this problem?

thanks

asepsukandar:
Hello guys,My problem is failed to sent data when using multiple pipes and in the RX serial monitor displayed No Radio Available,while when I'm using one pipe (point to point) that is worked with the same devices (arduino and nrf24l01)

  • Can you provide a simple diagram showing how all your Arduinos are intended to communicate with each other?
  • What is the distance between them?
  • How often must messages be sent (how many times per second)?
  • Do you need 2-way communication?
  • Are all of the Arduinos powered-up all of the time or are some of the sleeping to save energy?
  • What is the purpose of the project?

...R
Simple nRF24L01+ Tutorial

Robin2:

  • Can you provide a simple diagram showing how all your Arduinos are intended to communicate with each other?
  • What is the distance between them?
  • How often must messages be sent (how many times per second)?
  • Do you need 2-way communication?
  • Are all of the Arduinos powered-up all of the time or are some of the sleeping to save energy?
  • What is the purpose of the project?

...R
Simple nRF24L01+ Tutorial

I want to try our simple tutorial using two way communication (Swap Roles) by multinodes
and the data that sending is from sensor DHT11
And I still failed,can u help me?

asepsukandar:
I want to try our simple tutorial using two way communication (Swap Roles) by multinodes
and the data that sending is from sensor DHT11
And I still failed,can u help me?

Do you mean that you tried one of my examples and it did not work?

If so, please post the programs that YOU uploaded to your Arduinos and also post some examples of the output from the programs.

...R

@asepsukandar

I had had a problem with multiple pipes. Maybe it is related to your problem. Removing all "AckPayload" related lines solved my issue.

Best

Robin2:
Do you mean that you tried one of my examples and it did not work?

If so, please post the programs that YOU uploaded to your Arduinos and also post some examples of the output from the programs.

...R

This one is master code

// MasterSwapRoles

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

#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};
const byte masterAddress[5] = {'T','X','a','a','a'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[6] = "Message ";
char txNum = '0';
float t1,t2,t3,t4,t5,t6;  // the two values to be sent to the master

  struct payload{
  float t1;
  float t2;
  float t3;
  float t4;
  float t5;
  float t6;   
  };

bool newData = false;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second

//============

void setup() {

    Serial.begin(9600);
    Serial.println("MasterSwapRoles Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.openWritingPipe(slaveAddress);
    radio.openReadingPipe(1, masterAddress);

    radio.setRetries(3,5); // delay, count
    send(); // to get things started
    prevMillis = millis(); // set clock
}

//=============

void loop() {

    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
    getData();
    showData();
}

//====================

void send() {

payload data = {t1,t2,t3,t4,t5,t6};

        radio.stopListening();
            bool rslt;
            rslt = radio.write( &data, sizeof(data) );
        radio.startListening();
        Serial.print("Temperature1: ");
        Serial.print(t1);
        Serial.print("Temperature2: ");
        Serial.print(t2);
        Serial.print("Temperature3: ");
        Serial.print(t3);
        Serial.print("Temperature4: ");
        Serial.print(t4);
        
        if (rslt) {
            Serial.println("  Acknowledge received");
            updateMessage();
        }
        else {
            Serial.println("  Tx failed");
        }
}

//================

void getData() {
  
 payload data = {t1,t2,t3,t4,t5,t6};
   
   t1 = data.t1;
   t2 = data.t2;
   t3 = data.t3;
   t4 = data.t4;

    if ( radio.available() ) {
        radio.read( &data, sizeof(data) );
        newData = true;
    }
}

//================

void showData() {

   payload data = {t1,t2,t3,t4,t5,t6};
    if (newData == true) {
        Serial.print("Data received ");
         
   t1 = data.t1;
   t2 = data.t2;
   t3 = data.t3;
   t4 = data.t4;
        Serial.print("Temperature1: ");
        Serial.print(t1);
        Serial.print("Temperature2: ");
        Serial.print(t2);
        Serial.print("Temperature3: ");
        Serial.print(t3);
        Serial.print("Temperature4: ");
        Serial.print(t4);
        newData = false;
        delay(1000);
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '5') {
        txNum = '0';
    }
    dataToSend[6] = txNum;
}

This one is slave code

// SlaveSwapRoles

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

#define DHT1TYPE DHT11   
#define DHT1PIN A0
#define DHT2TYPE DHT11   
#define DHT2PIN A1
#define DHT3TYPE DHT11   
#define DHT3PIN A2
#define DHT4TYPE DHT11   
#define DHT4PIN A3
#define DHT5TYPE DHT11   
#define DHT5PIN A4
#define DHT6TYPE DHT11   
#define DHT6PIN A5      

#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};
const byte masterAddress[5] = {'T','X','a','a','a'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataReceived[6]; // must match dataToSend in master
float t1,t2,t3,t4,t5,t6;  // the two values to be sent to the master

  struct payload{
  float t1;
  float t2;
  float t3;
  float t4;
  float t5;
  float t6;   
  };


bool newData = false;
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
DHT dht3(DHT3PIN, DHT3TYPE);
DHT dht4(DHT4PIN, DHT4TYPE);
DHT dht5(DHT5PIN, DHT5TYPE);
DHT dht6(DHT6PIN, DHT6TYPE);

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);
    Serial.println("SlaveSwapRoles Starting");
    dht1.begin();
    dht2.begin();
    dht3.begin();
    
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    
    radio.openWritingPipe(masterAddress); // NB these are swapped compared to the master
    radio.openReadingPipe(1, slaveAddress);

    radio.setRetries(3,5); // delay, count
    radio.startListening();

}

//====================
void loop() {

  float t1 = dht1.readTemperature();
  float t2 = dht2.readTemperature();
  float t3 = dht3.readTemperature();
  float t4 = dht4.readTemperature();
  float t5 = dht5.readTemperature();
  float t6 = dht6.readTemperature();
   
    getData();
    showData();
    send();
}
//====================

void send() {
  payload data = {t1,t2,t3,t4,t5,t6};
  
    if (newData == true) {
        radio.stopListening();
            bool rslt;
            rslt = radio.write( &data, sizeof(data) );
        radio.startListening();

        Serial.print("Temperature1: ");
        Serial.print(t1);
        Serial.print("Temperature2: ");
        Serial.print(t2);
        Serial.print("Temperature3: ");
        Serial.print(t3);
        Serial.print("Temperature4: ");
        Serial.print(t4);
       
        if (rslt) {
            Serial.println("Acknowledge Received");
            
        }
        else {
            Serial.println("Tx failed");
        }
        Serial.println();
        newData = false;
    }
}

//================

void getData() {

   payload data = {t1,t2,t3,t4,t5,t6};
   
 
   
  
    if ( radio.available() ) {
        radio.read( &data, sizeof(data) );
        newData = true;
    } 
}

//================

void showData() {
    if (newData == true) {
        Serial.print("Data received ");

     payload data = {t1,t2,t3,t4,t5,t6};
          
   t1 = data.t1;
   t2 = data.t2;
   t3 = data.t3;
   t4 = data.t4;
        Serial.println(t1);
        Serial.println(t2);
        Serial.println(t3);
        Serial.println(t4);
    }
}

The display of serial monitor just data t1 till t6 without real value or just 00,

When I'm using 1 sensor is worked with the same code but without using struct payload

Any advice sir,thanks before..

I don't have time to study your code now (and maybe not today, at all). I will bookmark it so I can find it again when I have time.

In the meantime, if you have not already done so, make sure you can get my example working without any changes or additions to my code.

Is there any particular reason why you are using the swap roles example rather than either of the others?

...R

Both sketches are way to convoluted and hide the flow of control

Look at these variants
'Master' (watch out, non-standard pin settings)

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

#define CE_PIN   8
#define CSN_PIN 7

//#define CE_PIN   9
//#define CSN_PIN 10

const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
const byte masterAddress[5] = {'T', 'X', 'a', 'a', 'a'};

RF24 radio(CE_PIN, CSN_PIN);

struct payload {
  float temp[6];
  byte count;
  void update() {
    count++;
  }
  void print() {
    Serial.print(F("cnt "));
    Serial.print(count);
    for (byte i = 0; i < sizeof(temp)/sizeof(temp[0]); i++) {
      Serial.print(F(", t"));
      Serial.print(i);
      Serial.print(F(" = "));
      Serial.print(temp[i]);
    }
  }
} txData, rxData;

unsigned long lastSend;
const unsigned long txInterval = 1000;

void setup() {
  printf_begin();
  Serial.begin(250000);
  Serial.println(F("Master Starting"));

  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);
  radio.openWritingPipe(slaveAddress);
  radio.openReadingPipe(1, masterAddress);
  radio.enableDynamicPayloads();
  radio.setRetries(3, 15);
  radio.startListening();
  radio.printDetails();
}

void loop() {
  unsigned long topLoop = millis();
  if (topLoop - lastSend >= txInterval) {
    lastSend = topLoop;
    radio.stopListening();
    bool rslt = radio.write(&txData, sizeof(txData));
    radio.startListening();
    Serial.print(F("TX "));
    txData.print();
    if (rslt) {
      Serial.println(F("  OK"));
      txData.update();
    } else {
      Serial.println(F("  failed"));
    }
  }
  if (radio.available()) {
    radio.read( &rxData, sizeof(rxData) );
    Serial.print(F("RX "));
    rxData.print();
    Serial.println();
  }
}

'Slave' (no DHTs, it just echos the received packet after modifying the count field)

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

#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
const byte masterAddress[5] = {'T', 'X', 'a', 'a', 'a'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio


struct payload {
  float temp[6];
  byte count;
  void update() {
    count++;
  }
  void print() {
    Serial.print(F("cnt "));
    Serial.print(count);
    for (byte i = 0; i < sizeof(temp) / sizeof(temp[0]); i++) {
      Serial.print(F(", t"));
      Serial.print(i);
      Serial.print(F(" = "));
      Serial.print(temp[i]);
    }
  }
} txData, rxData;

void setup() {
  printf_begin();
  Serial.begin(250000);
  Serial.println(F("Slave Starting"));

  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);
  radio.openWritingPipe(masterAddress);
  radio.openReadingPipe(1, slaveAddress);
  radio.enableDynamicPayloads();
  radio.setRetries(3, 15);
  radio.startListening();
  radio.printDetails();
}

void loop() {
  if (radio.available()) {
    radio.read(&rxData, sizeof(rxData) );
    Serial.print(F("RX "));
    rxData.print();
    Serial.println();
    rxData.update();  // advance count
    radio.stopListening();
    bool rslt = radio.write(&rxData, sizeof(rxData) );
    Serial.print(F("TX "));
    rxData.print();
    radio.startListening();
    if (rslt) {
      Serial.println(F(" OK"));
    }  else {
      Serial.println(F(" failed"));
    }
  }
}

Why is the junk packet from the master used to trigger a non-polled answer?
Why don't your measuring nodes simply send their data when it is time to?

i just want to use our MultiTXPaylad example with sensor DHT11 and using 3 Tx and 3 sensor,just like that sir

Robin2:
I don't have time to study your code now (and maybe not today, at all). I will bookmark it so I can find it again when I have time.

In the meantime, if you have not already done so, make sure you can get my example working without any changes or additions to my code.

Is there any particular reason why you are using the swap roles example rather than either of the others?

...R

asepsukandar:
i just want to use our MultiTXPaylad example with sensor DHT11 and using 3 Tx and 3 sensor,just like that sir

You quoted my comment but you did not answer either of my questions that are in it.

And you have not said whether you have taken account of the Advice in Reply #7

...R

sorry for that sir,actually i'm decide to use swap roles method because for me that simply than ack payload

Robin2:
You quoted my comment but you did not answer either of my questions that are in it.

And you have not said whether you have taken account of the Advice in Reply #7

...R

asepsukandar:
sorry for that sir,actually i'm decide to use swap roles method because for me that simply than ack payload

As you seem unwilling to answer my questions I don't know how to help.

...R