This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RF24L01with mutiple transmitters

Hello, I am new to all this RF stuff. I am trying to set up multiple transmitters (2 for now) and one receiver. Basically, each of two transmitters read one set of data (pressure, temperature, and status) and send them out to receiver. I tried each one of two transmitter with one receiver, it worked fine. Then when I tried to receive two set of data, it only receive one. The second set of data either show all 0s, or something not real. I am tends to think either pipe address not set up right or there is problem with my receiver code.

T1 code:

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

#include <Wire.h>

int address = 0x28; // 28 is the address
byte byte1, byte2, byte3, byte4;

RF24 radio (8, 10);

float p1 [10];
float t1 [10];
float s1 [10];


const uint64_t pipes[3] = {0xF0F0F0F0E1LL,0xB3B4B5B6CD,0xB3B4B5B6A3};

void setup()

{
  Wire.begin();
  radio.begin();
  Serial.begin(9600);
  
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipes[1]);
 
  radio.stopListening();

}

void loop()
{
   Wire.requestFrom(address, 4); // byte is 4;

  if (Wire.available()<=4 <=4) {//
    byte1 = Wire.read();
    byte2 = Wire.read();
    byte3 = Wire.read();
    byte4 = Wire.read();
  }

  long unsigned p_counts = (long unsigned)byte1 << 8
                           | (long unsigned)byte2;
  long unsigned t_counts = (long unsigned)byte3 << 8
                           | (long unsigned)byte4;
                            
   p1[0] = ((p_counts%16384-1638.0)/13107.0*20.0)-10.0;
   t1[0] = ((t_counts/32.0*200.0)/2047.0-50.0);
   s1[0] = (p_counts/16384);
   




bool ok=radio.write(&p1, sizeof(p1));
    ok=radio.write(&t1, sizeof(t1));
    ok=radio.write(&s1, sizeof(s1));
   
     if(ok)
       {
 
          Serial.println("Pipe 1");
          Serial.println(p1[0]);
          Serial.println(t1[0]);
          Serial.println(s1[0]);
          
       }
      else
       {
          Serial.println("it failed to send");
       }
   delay(500);
}

TX2: code is exactly same as TX1 but change pipe1 to pipe 2;

Receiver code:

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

RF24 radio (8, 10);

float p1[10],p2[10],p3[10];
float t1[10],t2[10],t3[10];
float s1[10],s2[10],s3[10];

const uint64_t pipes[3] = {0xF0F0F0F0E1LL,0xB3B4B5B6CD,0xB3B4B5B6A3};

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

void loop()
{
    if (radio.available()) 
    { 
       delay(100);
       radio.read(p1, sizeof(p1));
       radio.read(t1, sizeof(t1));
       radio.read(s1, sizeof(s1));

       delay(100);
       radio.read(p2, sizeof(p2));
       radio.read(t2, sizeof(t2));
       radio.read(s2, sizeof(s2));
       
       Serial.print ("Pressure   ");
       Serial.print ("Temperature   ");
       Serial.println ("Status");
       
       Serial.println("Pipe1");  
       Serial.println(p1[0]);
       Serial.println(t1[0]);  
       Serial.println(s1[0]);

       delay(100);
       Serial.println("Pipe2");
       radio.read(p2, sizeof(p2));
       radio.read(t2, sizeof(t2));
       radio.read(s2, sizeof(s2));
       
  /*       
       Serial.print ("Pressure    ");
       Serial.print ("Temperature=    ");
       Serial.println ("Status=    ");*/
             
       Serial.println(p2[0]);
       Serial.println(t2[0] );  
       Serial.println(s2[0] );
     
  /*     delay(100);
       radio.read(p3, sizeof(p3));
       radio.read(t3, sizeof(t3));
       radio.read(s3, sizeof(s3));
       
       Serial.println("Pipe3");  
       Serial.print ("Pressure=    ");
       Serial.print ("Temperature=    ");
       Serial.println ("Status=    ");
             
       Serial.println(     p3[0]);
       Serial.println(     t3[0] );  
       Serial.println(     s3[0] );*/
     
      }
  else
  {
    Serial.println("it failed to read");
  }
  delay(2500);
}

Can you please help me? I read the data sheet tried to change to different address, tried different timing. It just not working.

Output: Pressure Temperature Status Pine1 0.02 24.17 0.00 Pine2 0.00 0.00 0.00 Pressure Temperature Status Pine1 0.02 24.17 0.00 Pine2 0.02 24.17 0.00

and repeat the pattern. Thank you very much! Lina

Related