nRF24 Multiple transmitters for a single receiver

I'm testing three nRF24 modules, they are two transmitters and a single receiver.
The code works perfectly when there is only one transmitter sending the signal to the receiver, but I am not getting how to make two transmitters to send the signal to the receiver.

I've been using these codes. I created two codes for the transmitters, and the difference between them is the adress:

Transmitter 1
const byte address[6] = "00001";
Transmitter 2
const byte address[6] = "00002";

In the receiver code, i made these changes:

  radio.begin();
  radio.openReadingPipe(1, addresses[1]);
  radio.openReadingPipe(2, addresses[2]);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

and

void loop() {

  //-------------


  if (radio.available(1)) {
    char text[32] = "";
    radio.read(&text, sizeof(text));

    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("---------------------");
    display.println("-         1         -");
    display.println("---------------------");
    display.println();
    display.println(text);
    display.display();

    Serial.print("Msg. ");
    Serial.println(text);
  }
  delay(2000);  

  if (radio.available(2)){
          char text[32] = "";
    radio.read(&text, sizeof(text));

    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("---------------------");
    display.println("-         2         -");
    display.println("---------------------");
    display.println();
    display.println(text);
    display.display();

    Serial.print("Msg. ");
    Serial.println(text);
  }
  delay(2000);  
  }

But i dont't know how to use "(radio.available())" and It is not correct in my code.

What strategy, what protocol are You trying to use? It's all about protocol. Having the wrong idea no code on earth will do what You want.
An example: Both transmitters sends all or parts of the message at the same time as the other transmitter. You need to find a strategy how to avoid that. Study the ethernet concept! That communication calls for the transmitter side receiving an acknowledge telling the message is properly received. If no acknowledge arrives..... Higher levels of strategy is needed.

They MUST send a message at different times. How you arrange for that to take place is part of the communication protocol. That is up to you to create!

Just as you turn on two radios in a room and turn the volumes up high. Can you properly listen to both at the same time?

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