(Header?)-Problem with 3 NRF24L01 -network

Dear Arduino Forum,

now the time has come, that I am unable to move on with my coding, as all my searches etc. won't lead me go any further.

The project I am desperately looking for help is simply explained and half of the project ist perfectly working. But I cannot figure out the coding mistake that keeps me from screaming (I MADE IT :slight_smile: )


What I am trying to do is building a network with 3 Arduino Nanos with NRF24L01.

One of these is working as a master (called master00) and has a potentiometer attached , the second Nano/NRF24L01 (called node01) has 4 LEDs (green, yellow, red and blue) and the third nano/NRF24L01 (called node012) has a button.

The potentiometer of the master00 regulates depending on the potentiometer value which one of the green, yellow or red LED (node01) will light up.
The fourth LED (blue) should light up, when the user presses the button on the third arduino nano (node012).

Fortunately the sketch with the potentiometer regulating the 3 LEDs (green, yellow and red) works perfectly well and so I know coding and the assembly of the nano/NRF24L01 system worked.
But i cannot get node012 working that pressing the button lights up the fourth, blue LED on node 01! :confused:


Code of master00

#include <RF24_config.h>

#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

#include <SPI.h>
RF24 radio(7, 8);                // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 00;   // Address of this node in Octal format ( 04,031, etc)
const uint16_t node01 = 01; 
const uint16_t node012 = 012;    // Button-Sensor      
void setup() {
  SPI.begin();
  radio.begin();
  network.begin(90, this_node);  //(channel, node address)
  radio.setDataRate(RF24_2MBPS);
}
void loop() {
  network.update();
  unsigned long potValue = analogRead(A0);  // Read the potentiometer value
  RF24NetworkHeader header(node01);     // (Address where the data is going)
  bool ok = network.write(header, &potValue, sizeof(potValue)); // Send the data

 
}

Code of node01

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

#include <SPI.h>
RF24 radio(7, 8);                // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 01;   // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00;    // Address of the master node in Octal format
const uint16_t node012 = 012; 

#define led1 6 //green
#define led2 5 //yellow
#define led3 4 //red
#define led4 3 //blue

void setup() {
  SPI.begin();
  radio.begin();
  network.begin(90, this_node);  //(channel, node address)
  radio.setDataRate(RF24_2MBPS);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
}
void loop() {
  network.update();
  //===== Receiving =====//
  while ( network.available() ) {     // Is there any incoming data?
    RF24NetworkHeader header;
    unsigned long incomingData;
    network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data
    // Turn on the LEDs as depending on the incoming value from the potentiometer
    if (header.from_node == 0){
      if (incomingData > 100) {
          digitalWrite(led1, HIGH);
    } else {
      digitalWrite(led1, LOW);
    }
      if (incomingData > 300) {
      digitalWrite(led2, HIGH);
    } else {
      digitalWrite(led2, LOW);
    }
      if (incomingData > 500) {
      digitalWrite(led3, HIGH);
    } else {
      digitalWrite(led3, LOW);
    }
   }

/*      if (header.from_node == 10) {
      digitalWrite(led4, !incomingData);
    } 
*/

    RF24NetworkHeader header2;
    unsigned long buttonState;
    network.read(header2, &buttonState, sizeof(buttonState)); // Read the incoming data
    // Turn on the LED as depending on the incoming value from the potentiometer
    //if (header.from_node == 10){
     digitalWrite(led4, !buttonState);
    //} //else {
      //digitalWrite(led1, LOW);
    //}
      

  }
}

Code of node012

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

#include <SPI.h>
RF24 radio(7, 8);
RF24Network network(radio);

// Constants that identify this node and the node to send data to
const uint16_t this_node = 012;
const uint16_t master00 = 00;
const uint16_t node01 = 01;

#define button 6

// The network header initialized for this node
//RF24NetworkHeader header2(this_node);

void setup(void){
  pinMode(button, INPUT);

  SPI.begin();
  radio.begin();
  delay(5);
  network.begin(90, this_node);
  radio.setDataRate(RF24_2MBPS); 
}

void loop() {
  network.update();

  while (network.available()) {
    unsigned long buttonState = digitalRead(button);  // Read the button value
    RF24NetworkHeader header2(node01);     // (Address where the data is going)
    bool ok = network.write(header2, &buttonState, sizeof(buttonState)); // Send the data
  }
}

I have tried out so many versions, but I am really not able to do it. Please give me a hand.

Joe

If the 2 slaves are within range of the master you can probably achieve what you want in a much simpler way. Have a look at this Simple nRF24L01+ Tutorial. There is an example of a master and 2 slaves in Reply #17. The idea could be extended to several slaves.

...R

Hi Robin2

thank you very much for answering to my problem. I will definitely check on the link you have sent me.
I will send a message to you if I could get it done, ok?!

See you

Joe

arduino_helpseeker:
I will send a message to you if I could get it done, ok?!

Just post a Reply here. No personal messages, thank you.

...R

Oh ok, sorry! Will leave a message here in the post. Thx for the hint!