NRF2401+ Mixed messages/three transmitters,one receiver

I have three transmitters, each a different address transmitting different information. I am attempting to scan for new data from each transmitter. I am receiving the messages from the wrong receivers most of the time. It works fine if I only listen to one transmitter for a while, but to check each address one right after the other results in reading the wrong data.

#include <nRF24L01.h>
#include <RF24.h>
bool newData = false;//used to indicate that new data has arrived from the radio
char data[12];//data recieved from radio goes here
byte radioAddress[5] = {'A', 'S', 'C', 'i', 'i'};
RF24 radio(7, 8);

void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate( RF24_250KBPS );
  radio.printDetails();
  delay(1000);
}

void loop() {
  radioAddress[0] = 'A';
  getData();
  if (newData == true) {
    Serial.print("Outside data = ");
    Serial.println(data);
  }

  radioAddress[0] = 'B';
  getData();
  if (newData == true) {
    Serial.print("Crawlspace data = ");
    Serial.println(data);
  }

  radioAddress[0] = 'C';
  getData();
  if (newData == true) {
    Serial.print("Timestamp = ");
    Serial.println(data);
  }
}


void getData() {
  radio.openReadingPipe(1, radioAddress);
  radio.startListening();
  if ( radio.available() ) {
    radio.read( &data, sizeof(data) );
    newData = true;
  } else newData = false;
}

I wonder why I can’t switch addresses on the fly like this? I have a different project where I do switch addresses that does work, but the only difference is that I switch and stay switched until I see the data I was looking for.

I am probably going to modify the transmitters to all use the same address but add a identifier byte to the data. Probably the best way to go, as I may have more than six transmitters eventually. I considered using pipes, but I have not found a good explanation that shows me how to do it, and six transmitters might not be enough.

Any ideas on why the radio would receive the data from the wrong address in my code above? I’d like to make it work, even if I do switch to an identification byte/single address system.

I think it is astonishing that you receive anything with this approach,
you listen at most some milliseconds on each channel.

Why don't you just receive on three different addresses?

An alternative would be to let the all data stations send their data onto the same address,
but that needs some id inside the packet.

I'm guessing that the radio is buffering received data, despite the address. It is scanning very rapidly and does not seem to miss any messages. One of the transmitters is transmitting every 4 seconds, another is every eight, and the last one transmits once a minute. It fills my screen up with messages and I can tell which one is which based on the data.

My transmitters are mostly running on battery power, so that rules out the ack payload method. I'm working now on including ID information in the packet. I think that is the more sane approach.

I'm still confused how it can pick up a message that it was not addressed to.

I can program the chip to receive 6/256 of all packets.

You are messing with the pipe registers without need,
don't worry about the outcome, change the strategy. :wink:

For rarely awake nodes, a transmission to a well known address is the best way to go IMHO.
You still have the option to enforce ACKs on that pipe, but that is less flexible than a multicast send
(only one station may and has to ACK).

Remember that any station can listen to that pipe if it is interested in the information of the other modules.

And there are other ways to receive from three stations.

Whandall:
Why don't you just receive on three different addresses?

amdkt7:
I have three transmitters, each a different address transmitting different information. I am attempting to scan for new data from each transmitter.

Your second sentence suggests that the listener is changing the addresses it is listening for and that is a guaranteed way to be listening for the wrong address at the wrong time.

My suggestion is to get all the TX's to send to the same address so the listener does not have to change. Then just include in the message a byte or char that identifies the sender. The nRF24 has only one receiver so it can only receive one message at a time.

An even better strategy IMHO is for the master to initiate communication with each slave in turn as that way there is no risk of two slaves sending data at the same time and causing data corruption. There is an example of this in my Tutorial

...R
Simple nRF24L01+ Tutorial

Thanks Robin. I am going to use the same address for all the transmitters with an ID code. I like the idea of the master requesting data, but my sensors are all battery operated and will be sleeping most of the time.

I read the datasheet and it sounded like I could switch addresses, and in fact a previous project worked for some reason, but this project is a little more complicated. I thought that I would get no data, not data from the wrong transmitters.

It's a fun project, but a bit of learning

You still did not answer: Why don't you receive on all three addresses at the same time?

If you choose to ignore my questions, I will do so with yours.

Whandall:
You still did not answer: Why don't you receive on all three addresses at the same time?

If you choose to ignore my questions, I will do so with yours.

Quite frankly, I don't understand your question.

Why didn't you use

  radioAddress[0] = 'A';
  radio.openReadingPipe(1, radioAddress);
  radioAddress[0] = 'B';
  radio.openReadingPipe(2, radioAddress);
  radioAddress[0] = 'C';
  radio.openReadingPipe(3, radioAddress);

in setup?

Which would receive on all three addresses at the same time.

Whandall, I did not understand using pipes like that. Would it work the way that I was changing the address in the first byte?

I had little understanding of how to use pipes, and I was not trying to do so. I have learned a little more about it, but I have been pretty confused. I once found a pretty good description of how it works, but I can't seem to find that resource anymore.

I appreciate the help!

Whandall:
Which would receive on all three addresses at the same time.

I think it would be slightly more accurate to say it would "listen" for all three addresses at the same time. It can only receive one at a time and then direct the message to the appropriate pipe.

Speaking personally, I can't see any benefit from listening for 3 separate addresses.

...R

Yes, I am now working on using a single address for all transmitters and will use a code in the packet to identify which one I am reading. I think that might make it less likely that I would miss a packet, and possibly a bit less resources.

Robin2:
Speaking personally, I can't see any benefit from listening for 3 separate addresses.

Easy separation of data streams, or in this case,
easy separation of the node data without changing the packet format.

OP: it could be done like this

 byte pipe;
    if (radio.available(&pipe)) {
      if (pipe == 1) {
        // example selection
      }
    }