Electronic – arduino – Broadcast in nRF24L01+

arduinonrf24l01

I'm able to establish a communication channel between two nRF24L01+. But once I kick in a second listener, only one of them gets the message. Funny enough, it's always the same that "wins" in the situation where two are listening. Is there any way of having multiple receivers (like a broadcast?)

Here's the receiving code I'm using for the Arduino:

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

#define channel        0x4c                  // nrf24 communication channel
#define writingPipe    0xF0F0F0F0E1LL        // nrf24 communication address
#define dataRate       RF24_250KBPS          // nrf24 data rate (lower == more distance)
#define paLevel        RF24_PA_HIGH          // nrf24 power level (black ebay models have some problems with PA_MAX)

RF24 radio(8,7);

char receive_payload[33]; // +1 to allow room for a terminating NULL char

void setup(void) {
  Serial.begin(57600);
  printf_begin();

  radio.begin();
  radio.setPALevel(paLevel);
  radio.setChannel(channel);
  radio.openReadingPipe(0, writingPipe);
  radio.enableDynamicPayloads();
  radio.setDataRate(dataRate);
  radio.setAutoAck(false);
  radio.startListening();

  radio.printDetails();
}

void loop(void) {   
  // if there is data ready
  if (radio.available()) {
    uint8_t len;
    bool done = false;
    while (!done) {
      // Fetch the payload, and see if this was the last one.
      len = radio.getDynamicPayloadSize();
      done = radio.read(receive_payload, len);

      // Put a zero at the end for easy printing
      receive_payload[len] = 0;

      // Spew it
      printf("Got payload size=%i value=%s\n\r", len, receive_payload);
    }
  }

  delay(1000);
}

Best Answer

Yes, you can have multiple units receive the same broadcast (or multicast) message, if they are each configured to use the same receive address that the transmitters is sending to. (And in range of course).

Remember that each can have up to 6 configured receive addresses, so one of the ways to use the device is to configure one receive address which is unique to a given device, and one receive address which is shared with other devices (eg: all receivers, so some subset of them). The transmitter can send to a single receiver by using its unique address, or to all of the receivers in the group by using the shared address. ("Multicast" may be a somewhat better description in that it goes to multiple receivers in this scenario, but it need not go to all receivers - you can control the subset of receivers using a given shared address).

Of course, if you are sending a multicast message, it must not use ACK - because multiple receivers would try to send their ACK packets at about the same time, which would collide. (Also: since the hardware defined packet structure does not have a "source" address, the way that Enhanced ShockBurst ACK works is that the receiver sends the ACK packet to its own address, and the transmitter must be configured to receive at the address it's sending to. Thus in multicast, a given receiver's address - to which it will send an ACK - is also the shared receive address for the other receivers). So ACK must be off for multicast (as your code says).


There is not quite enough information to answer why your particular setup causes only one receiver to accept the packet. Suppose you have one transmitter T, and two receivers R1 and R2 (both using the same address). R1 is the one which "always wins". Is this the situation: (R2 not operating): R1 reliably receives from T (R1 not operating): R2 reliably receives from T (both R1, R2 operating): only R1 receives from T, R2 does not

That is, adding a R1 to the second situation causes R2 to stop receiving from T. Can you verify this by starting the T to R2 test in a loop and then after a while also powering up R1, at which point R2 stops receiving; then power down R1 and see if R2 starts receiving again?

If so I'd suspect that some kind of ACK problem is involved, or there is some problem with R1 and R2 being too close with some kind of RF or antenna intererence, or they are on the same power supply and there is some interference between them through the power line.

The nRF24 family is a bit sensitive about power; sometimes you need to put a filter cap across the power input to the module; eg: a 10 uF electrolitic (observing + and -). I've had what I thought were software or config problems clear right up when I improved the nRF24L01+'s power supply.