Hello all,
I have been scouring this form for a solution and there are a few other threads similar, but I could not get their given solutions to work with my code / libraries. I am trying to have 2 different NRF transmitters send data to a single receiver. I can get each transmitter to send data separately, but when I have the two sending data simultaneously, using different address and reading pipes, I can only read data from one of the transmitters. To complicate the matter further, when i have the code print out which pipe is is receiving data from, it lists the wrong pipe. I posted the code for the two transmitters and receiver.
Transmitter 1:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening();
}
void loop() {
float data[2]={2.22,3.33};
radio.write(&data,sizeof(data));
delay(5000);
}
Transmitter 2:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening();
}
void loop() {
float data[2]={8.88,9.99};
radio.write(&data,sizeof(data));
delay(1000);
}
Receiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const int ledpin = 6;
RF24 radio(7, 8); // CE, CSN
const byte address[][6] = {"00001","00002"};
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, address[0]);
radio.openReadingPipe(2, address[1]);
radio.setPALevel(RF24_PA_HIGH);
radio.startListening();
pinMode(ledpin,OUTPUT);
digitalWrite(ledpin,LOW);
}
void loop() {
byte pipe;
if (radio.available(&pipe)){
digitalWrite(ledpin,HIGH);
float data[2]={0,0};
radio.read(&data,sizeof(data));
Serial.println(pipe);
Serial.println(data[0]);
Serial.println(data[1]);
Serial.println();
delay(100);
}
else{
digitalWrite(ledpin,LOW);
}
}
The serial output is:
2
2.22
3.33
and it repeats every 5 seconds.
Any tips, suggestions, or help is much appreciated. I am very new to all this, so please bare with me if what I ask seems simple.
As a reference, i tried to model my code off of this. You can find which library i am using from the same site too.
Thanks in advance!
Sami