I have a few Arduino boards with nRF24L01 transceivers on them. I have 2 boards sending sensor values and one to receive them and putting it in a PLX-DAQ spreadasheet. I am able to get either one to work at a time, but I have not been able to get both to send data and the other one to pick them both up at the same time.
This is what I have for one of my sending (I used the library by TMRh20)
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int id=1;
float moisture;
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(9600);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
myRadio.write(&data, sizeof(data));
Serial.println(analogRead(A0));
data.moisture = analogRead(A0);
delay(1000);
}
and the respective receive:
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int id=0;
float moisture;
};
byte addresses[][6] = {"0"};
typedef struct package Package;
Package data;
int row = 0;
int x = 0;
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,Moisture");
Serial.println("RESETTIMER");
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &data, sizeof(data) );
}
Serial.print("DATA,TIME,");
Serial.println((-10.32 * (log(data.moisture) / log(2.718)) + 72.66));
row++;
x++;
if (row > 60)
{Serial.println("CLEARDATA");
Serial.println("ROW,SET,2");
row = 0;}
}
}
then the other send
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package2
{
int id=1;
float psi;
};
typedef struct package2 Package2;
Package2 datas;
void setup()
{
Serial.begin(9600);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
myRadio.write(&datas, sizeof(datas));
Serial.println(analogRead(A0));
datas.psi = analogRead(A0);
delay(1000);
}
and the receive for that
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package2
{
int id=0;
float psi;
};
byte addresses[][6] = {"0"};
typedef struct package2 Package2;
Package2 datas;
int row = 0;
int x = 0;
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,Moisture");
Serial.println("RESETTIMER");
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &datas, sizeof(datas) );
}
Serial.print("DATA,TIME,");
Serial.println(0.29325513196*datas.psi);
row++;
x++;
if (row > 60)
{Serial.println("CLEARDATA");
Serial.println("ROW,SET,2");
row = 0;}
}
}
this all works fine, but I am having trouble getting both of them. I guess to start off with, is it possible in the first place? I tried something like this:
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int id=0;
float moisture;
};
struct package2
{
int id=0;
float psi;
};
byte addresses[][6] = {"0"};
typedef struct package Package;
Package data;
int row = 0;
int x = 0;
typedef struct package2 Package2;
Package2 datas;
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,Moisture,Air Pressure");
Serial.println("RESETTIMER");
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.setChannel(95);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.setChannel(115);
myRadio.read( &data, sizeof(data) );
Serial.print("DATA,TIME,");
Serial.print((-10.32 * (log(data.moisture) / log(2.718)) + 72.66));
Serial.print(",");
myRadio.setChannel(95);
myRadio.read( &datas, sizeof(datas) );
Serial.println(0.29325513196*datas.psi);
row++;
x++;}
if (row > 60)
{Serial.println("CLEARDATA");
Serial.println("ROW,SET,2");
row = 0;}
}
}
obviously, I changed the channel on the second sender to match. I did this because I figured they would interfere with each other if they were sending on the same channel. Anyway, I don’t 100% get how they work, so any help would be appreciated.