Hello Guys,
I have been trying this for weeks. My goal is to set up 3 transmitters and 1 receiver. Basically each transmitter will read and send one set of data (pressure, temperature and status) to the receiver. I have one transmitter to one receiver setup. It works like charm, and setup second transmitter to the receiver, it also worked. When I tried to use on e receiver to receive the data from both transmitters, it only received one. The other one are reading all zeros.
I suspected the address(pipe #) wasn't setup right but tried different ways, it still only read one set of data.
Please help!
/*
* this is a working transmitting program that will send digital data out
*/
#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);
the second transmitter is the same besides the pipe change to pipe2, parameters are p2, t2, and s2.
The receiver code look like this:
#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[0]);
radio.openReadingPipe(2,pipes[1]);
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);
}
else
{
Serial.println("it failed to read");
}
delay(2500);
}
Output look like this:
Pressure Temperature Status
Pipe1
0.02
24.17
0.00
Pipe2
0.00
0.00
0.00
Pressure Temperature Status
Pipe1
0.02
24.17
0.00
Pipe2
0.02
24.17
0.00
Pressure Temperature Status
Pipe1
0.02
24.27
0.00
Pipe2
0.00
0.00
0.00
Pressure Temperature Status
Pipe1
0.03
24.27
0.00
Pipe2
0.00
0.00
0.00