I have a project that uses multiple nRf24l01 to connect two ways together to send sensor signals to one master. This is the master's code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9,10);
const byte addresses[][6] = {"00001", "00002","00003","00004","00005","00006"};
struct but1{
int a = 3;
int b = 4;
}set1;
struct but2{
int c;
int d;
}get1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1, addresses[0]);
radio.openWritingPipe(addresses[3]);
radio.openReadingPipe(2, addresses[2]);
radio.openWritingPipe(addresses[5]);
radio.openReadingPipe(3, addresses[4]);
}
void loop() {
// put your main code here, to run repeatedly:
delay(5);
radio.stopListening();
radio.write(&set1,sizeof(set1));
delay(10);
radio.startListening();
radio.read(&get1,sizeof(get1));
Serial.print(get1.c);
Serial.println(get1.d);
}
and here is the code of salves:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9,10); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
String data;
struct dataStruct{
int a;
int b;
}get1;
struct node{
int c;
int d;
}set1;
void setup()
{
Serial.begin(9600);
radio.openWritingPipe(addresses[0]); // 00001
radio.openReadingPipe(1, addresses[1]); // 00002
radio.setPALevel(RF24_PA_MAX);
}
void loop()
{
delay(5);
radio.startListening();
radio.read(&get1,sizeof(get1));
Serial.print(get1.a);
Serial.println(get1.b);
delay(10);
radio.stopListening();
set1.c = 10;
set1.d = 9;
radio.write(&set1,sizeof(set1));
}
And
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9,10); // CE, CSN
const byte addresses[][6] = {"00003", "00004"};
String data;
struct dataStruct{
int a;
int b;
}get1;
struct node{
int c;
int d;
}set1;
void setup()
{
Serial.begin(9600);
radio.openWritingPipe(addresses[0]); // 00003
radio.openReadingPipe(2, addresses[1]); // 00004
radio.setPALevel(RF24_PA_MAX);
}
void loop()
{
delay(5);
radio.startListening();
radio.read(&get1,sizeof(get1));
Serial.print(get1.a);
Serial.println(get1.b);
delay(10);
radio.stopListening();
set1.c = 8;
set1.d = 7;
radio.write(&set1,sizeof(set1));
}
The first slave is very stable. But the second slave is very unstable in the receiving and sending directions, the output signal is 00. Looking forward to everyone's help.