3 Tx to 1 Rx NRF24L01+

Hai guys, i wanna make a simple WSN in my house use three sensor node, each sensor node have one DHT22 and one Light Intensity Sensor to one receiver

nah i dont get it when the data receive on receiver is not sequential at all and sometime data from other node cant be received.

The receiver code look like this:

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


#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

const uint64_t pipe[4] = {0x0,0xF0F0F0F0ABLL,0xF0F0F0F0BCLL,0xF0F0F0F0CDLL};

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 2000;

bool newData = false;

typedef struct{
  float A;
  float B;
  uint16_t C;
  int D;
}A_t;

A_t data;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Master Node Starting...");
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  //radio.setDataRate(RF24_1MBPS);
  //radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_MAX); 
  radio.setChannel(0);
  radio.setCRCLength(RF24_CRC_16);
}

void loop() {
  // put your main code here, to run repeatedly:
  for (int n=1;n<4;n++){
    radio.openReadingPipe(n, pipe[n]);
    radio.startListening();
    getData();
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
      showData();
      prevMillis = millis();
    }
    radio.closeReadingPipe(n);
  }
}

void getData() {
  if (radio.available()){
      radio.read(&data,sizeof(data));
      newData = true;
    }
}

void showData() {
  Serial.print("Time = ");
  Serial.print(round(millis()/1000));
  Serial.println(" second, Node from " + String(data.D));
  Serial.print("Temp = ");
  Serial.print(data.A);
  Serial.print(" C, Hum = ");
  Serial.print(data.B);
  Serial.print(" %, Intensity = ");
  Serial.print(data.C);
  Serial.println(" lux");
  newData = false;
}

The transmitter code look like this:

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <BH1750FVI.h> // BH1750 Sensor Library
#include <Wire.h> // I2C Library
#include <DHT.h> // DHT22 Sensor Library


#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

#define DHTPIN 2  // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino

const uint64_t pipe = 0xF0F0F0F0ABLL; //other pipe 0xF0F0F0F0BCLL and 0xF0F0F0F0CDLL

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
uint16_t lux; //Stores intesity value

BH1750FVI LightSensor;

struct dataStruct{
  float A;
  float B;
  uint16_t C;
  int D;
}data0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Slave Node 0 Starting...");
  
  LightSensor.begin();
  LightSensor.SetAddress(Device_Address_H);//Address 0x5C
  LightSensor.SetMode(Continuous_H_resolution_Mode);

  dht.begin();
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  //radio.setDataRate(RF24_1MBPS);
  //radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_MAX); 
  radio.setChannel(0);
  radio.setCRCLength(RF24_CRC_16);
  radio.openWritingPipe(pipe);
}

void loop() {
  // put your main code here, to run repeatedly:
  getData();
  send();
}

void getData() {
  lux = LightSensor.GetLightIntensity();// Get Lux value
  hum = dht.readHumidity();
  temp= dht.readTemperature();
  data0.A = temp;
  data0.B = hum;
  data0.C = lux;
  data0.D = 0;
}

void send() {
  radio.stopListening();
  bool ok = radio.write(&data0, sizeof(data0));
}

If it is practical to arrange your system so that the receiver is the "master" and calls to each of the "slaves" in turn it will make the whole thing much simpler. It will mean that there is no doubt which slave sends the data and no risk of two slaves sending at the same time and interfering with each other. The second example in this Simple nRF24L01+ Tutorial can be extended to deal with several slaves.

...R

nah,I want make algorithm like that. but I do not understand how to make it. if I had to make a command sequence that is sent simultaneously to the slave then the slave who has the same status with the command received from the master, the slave will transmit the data to the master. like this program

The following program that I have made, but the received data still did not sequentially

Transmitter

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <BH1750FVI.h> // BH1750 Sensor Library
#include <Wire.h> // I2C Library
#include <DHT.h> // DHT22 Sensor Library


#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

#define DHTPIN 2  // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino

const uint64_t pipe = 0xF0F0F0F0ABLL;

int a;
float hum;  //Stores humidity value
float temp; //Stores temperature value
uint16_t lux; //Stores intesity value

BH1750FVI LightSensor;

typedef struct{
  float A;
  float B;
  uint16_t C;
  int D;
}A_t;

A_t data;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Slave Node 0 Starting...");
  
  LightSensor.begin();
  LightSensor.SetAddress(Device_Address_H);//Address 0x5C
  LightSensor.SetMode(Continuous_H_resolution_Mode);

  dht.begin();
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  //radio.setDataRate(RF24_1MBPS);
  //radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_MAX); 
  radio.setChannel(0);
  radio.setCRCLength(RF24_CRC_16);
  radio.openReadingPipe(1, pipe);
}

void loop() {
  // put your main code here, to run repeatedly:
  getData();
  radio.startListening(); 
  if (radio.available()) {
    radio.read(&a,sizeof(a));
    Serial.println(a);
    if ( a == 1 ) {
      send();
      a = 0; 
    }
  }
}

void getData() {
  lux = LightSensor.GetLightIntensity();// Get Lux value
  hum = dht.readHumidity();
  temp= dht.readTemperature();
  data.A = temp;
  data.B = hum;
  data.C = lux;
  data.D = 0;
}

void send() {
  radio.stopListening();
  radio.openWritingPipe(pipe);
  bool ok = radio.write(&data, sizeof(data));
  Serial.println("Status " + String(ok));
}

Receiver

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


#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

const uint64_t pipe[4] = {0x0,0xF0F0F0F0ABLL,0xF0F0F0F0BCLL,0xF0F0F0F0CDLL};

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;

bool newData = false;
int a;

typedef struct{
  float A;
  float B;
  uint16_t C;
  int D;
}A_t;

A_t data;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Master Node Starting...");
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  //radio.setDataRate(RF24_1MBPS);
  //radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_MAX); 
  radio.setChannel(0);
  radio.setCRCLength(RF24_CRC_16);
  radio.openReadingPipe(1, pipe[1]);
  radio.openReadingPipe(2, pipe[2]);
  //radio.openReadingPipe(3, pipe[3]);
}

void loop() {
  // put your main code here, to run repeatedly:
  for (a = 1; a < 3; a++) {
    send();
//    currentMillis = millis();
//    if (currentMillis - prevMillis >= txIntervalMillis) {
      getData();
//      prevMillis = millis();
//    }
  }
}

void getData() {
  if (radio.available()) {
    radio.read(&data,sizeof(data));
    showData();
    newData = true;
  }
  else {
    Serial.println("RTO");
  }
}

void showData() {
  Serial.print("Time = ");
  Serial.print(round(millis()/1000));
  Serial.println(" second, Data from node " + String(data.D));
  Serial.print("Temp = ");
  Serial.print(data.A);
  Serial.print(" C, Hum = ");
  Serial.print(data.B);
  Serial.print(" %, Lux = ");
  Serial.print(data.C);
  Serial.println(" lux");
  newData = false;
}

void send() {
  for (byte n = 1; n < 3; n++) {
    radio.stopListening();
    radio.openWritingPipe(pipe[n]);
    bool rslt;
    rslt = radio.write( &a, sizeof(a) );
    delay(1000);
    radio.startListening();
//    Serial.print("Node ");
//    Serial.print(n);
//    if (rslt) {
//      if (n < 3) {
//        Serial.print("  Done || ");
//      }
//      else {
//        Serial.println("  Done || ");
//      }
//    }
//    else {
//      if (n < 3) {
//        Serial.print("  Failed || ");
//      }
//      else {
//        Serial.println("  Failed || ");
//      }
//    }
  }
}

m3r4h100:
nah,I want make algorithm like that. but I do not understand how to make it

Does that mean "No, I do not want to make an algorithm like that"
OR does it mean "Yes, I want to make an algorithm like that"

If you do want to use the master-slave system that I suggested then the basic code is in the second example in my tutorial.

...R