Help with Arduino + ESP8266 + nrf24l01

Hello everyone!

My project is a central with Arduino Mega + ESP + nrf24l01. This central will send informations of type “ON/OFF” and receive confirmations of what was send. This also will receive informations like “Temperature, humidity, ect”, using the nrf24l01 to communicate.
I can connect to the Blynk and I can also send to the three Nodes nrf24l01 that I’m using, but in time of receive the confirmations, looks that have a interence between they, because they are mixing.
I’m using the library “RF24.h” and “nRF24L01.h”, downloaded from the “Library Manager” of Arduino.
I ask the help of the friends of the forum.
Thanks to all.

CODE FOR TX:

// #define BLYNK_PRINT Serial   
   #include <SPI.h>
   #include <ESP8266_HardSer.h>
   #include <BlynkSimpleShieldEsp8266_HardSer.h>
   #define EspSerial Serial
   ESP8266 wifi(EspSerial);
   
   #include <SimpleTimer.h>
   SimpleTimer timer;

//-----------------------------------------------------------

#include <WidgetLED.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";  

WidgetLED led1(V3);
WidgetLED led4(V4);
WidgetTerminal terminal(V1);

//==========================  NRF24L01 CONFIG  ==========================

//#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
//#include "RF24_config.h"
                     //          CE, CS
RF24 radio(9,53);    //RF24 radio(9, 10); 

const uint64_t wAddress_1 = 0xB00B1E50B1LL;
const uint64_t wAddress_2 = 0xB00B1E50A4LL;

//  Receptor
const uint64_t rAddress_1 = 0xB00B1E50D2LL;
const uint64_t rAddress_2 = 0xB00B1E50C3LL;

int Recebe_dados[9];
int Envia_dados[9];

int Recebe_dados_2[9];
int Envia_dados_2[9];

//int dadosRF;

int role = 1;


//-------------------   MUDANÇAS PARA NRF24  -----------------

 
#define led_dimer 5

float tempC;
int reading;

int LED3 = 7;
int LED2 = 4;
int LED1 = 5;

boolean debug;
String response;
String print_info;


int param_led1;

int onn_led1;
int manda_dimer;
int manda_email = 0;
int volta_led;

int pausa_reconect;
int enable_disable;
int pausa_conex;
int pausa_manda_led;
int pausa_dimer;
int pausa_virtual;
int pausa_recone;
int pausa_bota;
int pausa_analg;
int pausa_but;
int pausa_led1;

int pausa_leitura_1;
int pausa_leitura_2;

//==================================================================

boolean transmitido;
int vailed1;
int RX = 0;   // se zero entao recebe dados


void setup() { 
        
       pinMode(LED1, OUTPUT); 
       pinMode(LED2, OUTPUT);
       pinMode(LED3, OUTPUT);
       pinMode(led_dimer, OUTPUT);
   
       Serial.begin(9600);
       delay(10);
       radio.begin();
       delay(10);
       EspSerial.begin(9600);
       delay(10);
       Blynk.begin(auth, wifi,"xxxxxxxxxxxxxxx","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
       
       while (Blynk.connect() == false) {
       Serial.println("RESTART NO SETUP...");
       digitalWrite(LED2, HIGH);
       sei();
       delay (100L);  
       asm volatile ("jmp 0");
       cli();
     }
       Serial.println("Programa Iniciado...");

       terminal.println(F("Blynk & Arduino Mauro. v" BLYNK_VERSION ": Programa iniciado"));
       terminal.println("------------------");
       terminal.println("wiff Conectado");
       terminal.flush();

       radio.setChannel(110);             // Set the channel
       
       radio.setPALevel(RF24_PA_LOW);     // Set PA LOW for this demonstration. We want the radio to be as lossy as possible for this example.
       radio.setDataRate (RF24_2MBPS);    //(RF24_1MBPS);//RF24_250KBPS           // Raise the data rate to reduce transmission distance and increase lossiness

       radio.startListening();               

//     pausa_leitura_1 = timer.setInterval (4000L, leitura_1);//3
       pausa_leitura_2 = timer.setInterval (3000L, leitura_2);//3
}

//=========================   ATUALIZAÇÃO GERAL BLYNK   =============

bool isFirstConnect = true;
BLYNK_CONNECTED() {            //Esta função irá executar cada tempo de conexão é estabelecida Blynk
    if(isFirstConnect) {
       Blynk.syncVirtual(V8);  // GROJE TEMPERATURA
       Blynk.syncVirtual(V9);  // 
       isFirstConnect = false;
   }
}      

//==============================================================

 void loop() {

  Blynk.run();
  timer.run(); 
}

//=====================  SETA ACENDE LED   ====================

BLYNK_WRITE(V8)  { 
 
       radio.stopListening();               //encerrando qualquer modo de recepção,
       radio.openWritingPipe(wAddress_1);
       
       volta_led = param.asInt();
       
       Envia_dados[1] = volta_led;  //onn_led1;
       radio.write(&Envia_dados, sizeof(Envia_dados) );  //radio.write( bufer, 1);
       
       radio.startListening();
}

//-----------------------------------------------------------


BLYNK_WRITE(V9)  { 
 
       radio.stopListening();               //encerrando qualquer modo de recepção,
       //radio.openWritingPipe(Write_add[2]);
      
       radio.openWritingPipe(wAddress_2);
       
       Envia_dados_2[2] = param.asInt();            //onn_led1;
       
       radio.write(&Envia_dados_2, sizeof(Envia_dados_2) );  //radio.write( bufer, 1);
       
       radio.startListening();

}


  
//-------------------     V8   -------------------

void leitura_2(){

       radio.openReadingPipe(2,rAddress_2);
       //radio.openReadingPipe(1,Readi_add[3]);
     if(radio.available()) {
       boolean concluido = false; 
       while (!concluido) {
       radio.read(&Recebe_dados_2[0], sizeof(Recebe_dados_2));
       concluido = true;
       } 
     
       Serial.print("Recebendo PIPE_1 LED... ");
       Serial.println(Recebe_dados_2[3]);
    
       digitalWrite(LED1,Recebe_dados_2[3]);
     }


delay(1000);     
            
    
       radio.openReadingPipe(1,rAddress_1);
       //radio.openReadingPipe(1,Readi_add[1]);
    if(radio.available()) {
       boolean concluido = false; 
       while (!concluido) {
        radio.read(&Recebe_dados[0], sizeof(Recebe_dados));
        concluido = true;
     }
 
       digitalWrite(LED2, Recebe_dados[7]);
     
       Serial.print("Recebendo PIPE_2 LED... ");
       Serial.println(Recebe_dados[7]);
  }     
       
       radio.closeReadingPipe(rAddress_1);
    
}

CODE FOR RX1:

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

#include <SimpleTimer.h>
SimpleTimer timer;

RF24 radio(9, 10); 

const uint64_t rAddress_1 = 0xB00B1E50B1LL;
const uint64_t wAddress_1 = 0xB00B1E50D2LL;

int Recebe_dados[9];
int Envia_dados[9];

int estatus_led1;

char  c;
int lm35_analg = A1;
int potenciometro  = A0;
int estatu_dimer;
int retorna_dimer;

int recebe_dimer;
int manda_dimer;
int unido_dimer; //volatile   

int pausa_recebe_dimer; 
int pausa_analg;
int pausa_but;

 
//====================================================

int load = 6;
volatile int power;  // = 40;
int botao_0 = A5;
int botao_1 = A4;

#define led_dimer 3
#define liga_relay 4

int liga_led;
int estadorele;   
int leitura;
int estado_led1;
int LED1 = 5;

//==========================

int UP = A5;  
int DOWN = A4;
int LAMP = 6;   
int dimming = 128;
int counts = 7;

int dimmer[7] = { 128, 120, 110, 105, 100, 95, 90, };              
int i = 0;


//======================================================== 

 void setup() {

    Serial.begin(9600);
    radio.begin();                           // Setup and configure rf radio
  
    radio.setChannel(110);                     // Set the channel
    radio.setPALevel(RF24_PA_LOW);           // Set PA LOW for this demonstration. We want the radio to be as lossy as possible for this example.
    radio.setDataRate(RF24_2MBPS);  //(RF24_1MBPS); //RF24_250KBPS // Raise the data rate to reduce transmission distance and increase lossiness
    
    radio.startListening();
    
    pinMode(led_dimer, OUTPUT);
    pinMode(potenciometro,INPUT);
    pinMode(lm35_analg, INPUT); 
    pinMode(LED1, OUTPUT);
    pinMode(liga_relay,INPUT_PULLUP);

    pinMode(load, OUTPUT);
    //attachInterrupt(0, zero_cross_int, RISING);
    pinMode(botao_0, INPUT_PULLUP);
    pinMode(botao_1, INPUT_PULLUP);
  
    pausa_but = timer.setInterval(2000L, status_but);

}

//==================    V8     ======================================

void loop() {

timer.run();
       
      radio.openReadingPipe(1,rAddress_1);
       
    if(radio.available()) {
       bool concluido = false;             // Armazenar o payloads até chegar tudo
       while (!concluido) { 
       concluido = radio.read(&Recebe_dados[0], sizeof(Recebe_dados));
       if(concluido == true) {  Rx();  }  //else  {   Tx();    }
    }
 }

}  

       
//===============   RECEBE P ACENDER LED V8  ===================

void Rx() {

   if(Recebe_dados[1] == 1) { 
       estadorele = 1;
       status_but();
       
   }
   if(Recebe_dados[1] == 0){
       estadorele = 0;
       status_but();
   }
     digitalWrite(LED1, estadorele);
       
     Serial.print("RECEBENDO LED......");
     Serial.println(Recebe_dados[1]);
}
//====================   ENVIA  V8  =====================

void status_but() {

    radio.stopListening();          // encerrando qualquer modo de recepção,
    radio.openWritingPipe(wAddress_1);
                
    Envia_dados[3] = estadorele;  //digitalRead(LED1);
    radio.write(&Envia_dados, sizeof(Envia_dados));
    
    Serial.print("ENVIANDO V_8 LED1 ...");
    Serial.println(Envia_dados[3]);
    
    radio.startListening();   
  
}

CODE FOR RX2:

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

#include <SimpleTimer.h>
SimpleTimer timer;

RF24 radio(9, 10); 

const uint64_t rAddress_2 = 0xB00B1E50A4LL;
const uint64_t wAddress_2 = 0xB00B1E50C3LL;

int Recebe_dados_2[9];
int Envia_dados_2[9];

char  c;
int lm35_analg = A1;
int potenciometro  = A0;
int estatu_dimer;
int retorna_dimer;

int recebe_dimer;
int manda_dimer;
int unido_dimer; //volatile   

int pausa_recebe_dimer; 
int pausa_analg;
int pausa_but;

//====================================================

int load = 6;
volatile int power;  // = 40;
int botao_0 = A5;
int botao_1 = A4;

#define led_dimer 3
#define liga_relay 4

int liga_led;
int estadorele;   
int leitura;
int estado_led1;
int LED1 = 5;

//==========================

int UP = A5;  
int DOWN = A4;
int LAMP = 6;   
int dimming = 128;
int counts = 7;

int dimmer[7] = { 128, 120, 110, 105, 100, 95, 90, };              
int i = 0;

//======================================================== 

  
 void setup() {

    Serial.begin(9600);
    radio.begin();                           // Setup and configure rf radio
  
    radio.setChannel(110);                     // Set the channel
    radio.setPALevel(RF24_PA_LOW);           // Set PA LOW for this demonstration. We want the radio to be as lossy as possible for this example.
    radio.setDataRate(RF24_2MBPS);  //(RF24_1MBPS); //RF24_250KBPS // Raise the data rate to reduce transmission distance and increase lossiness

    radio.startListening();
    
    pinMode(led_dimer, OUTPUT);
    pinMode(potenciometro,INPUT);
    pinMode(lm35_analg, INPUT); 
    pinMode(LED1, OUTPUT);
    pinMode(liga_relay,INPUT_PULLUP);

    pinMode(load, OUTPUT);
    //attachInterrupt(0, zero_cross_int, RISING);
    pinMode(botao_0, INPUT_PULLUP);
    pinMode(botao_1, INPUT_PULLUP);
    
    pausa_but = timer.setInterval(2000L, status_but);

}

//===================    V9   =====================================

void loop() {

timer.run();
       
       radio.openReadingPipe(1,rAddress_2);
      
    if(radio.available()) {
       bool concluido = false;             // Armazenar o payloads até chegar tudo
       while (!concluido) { 
       concluido = radio.read(&Recebe_dados_2[0], sizeof(Recebe_dados_2));
       if(concluido == true) {  Rx();  }  //else  {   Tx();    }
    }
 }
}
       
//===============   RECEBE P ACENDER LED  V9   ===================

void Rx() {

   if(Recebe_dados_2[2] == 1) { 
       estadorele = 1;
       status_but();
    }

   if(Recebe_dados_2[2] == 0){
       estadorele = 0;
       status_but();
    }
       digitalWrite(LED1, estadorele);
       Serial.print("RECEBENDO LED......");
       Serial.println(Recebe_dados_2[2]);
}

//============   TEMPO PARA MANDAR ESTATUS LED V9  ===


void status_but(){

    radio.stopListening();          // encerrando qualquer modo de recepção,
    radio.openWritingPipe(wAddress_2);
    
    Envia_dados_2[7] = estadorele; //digitalRead(LED1);    //estadorele; 
    
    radio.write(&Envia_dados_2, sizeof(Envia_dados_2) );

    Serial.print("MANDANDO LED...");
    Serial.println(Envia_dados_2[7]);
    
    radio.startListening();

}
1 Like

@Costas can help you in these modules :wink:

Thank you. All the help is welcome.

Edit: This is a part of what’s happening with me -> https://youtu.be/L6DgTNZdcjU

Personally, I like the RF24Network library the best so far. I did something similar here: http://www.instructables.com/id/Lego-Trains-Blynk/

It’s sending infrared commands to trains, so I guess you can use it to send other stuff. It works very well with Blynk too.

Hello.
Thanks for help. Sorry for delay. I looked at your instructables and I liked, I like of lego.
Well, I tryed adptate your code to mine but I don’t had sucess, because of this I resolved try a example of “Network_Ping, RF24Network” that is what I need, send and receive informations. It’s going be hard to me but I won’t desist. Any results I’ll post here, for now I want to ask:
The adress 00 is only to transit informations of a module to other? Can I use him to both send and receive?
Thanks.

Im on my phone, so long story short, each nrf device needs it own addres :slight_smile:

Hello.
In the library “RF24” I use:

"radio.stopListening(); //to stop of receive
"radio.startListening(); //to start send

And at the library “RF24Network” how I do to stop of receive and start to send and vice-versa?

Thanks

Hello. I’m facing a new problem, I need identificate what position of array I’m receiving the value to send to the correct void to work with the valuer received.

Transmitter:

> int bufer[9];    //Nine positions

> BLYNK_WRITE(V1){

> bufer[1] = param.asInt();  //send to position 1
> bool ok = radio.write(bufer, sizeof(bufer) );   //send
> }

Receptor:

> int bufer[9];    //Nine positions

>  if(radio.available(&pipeNum)){ 
>      radio.read(&bufer[0], sizeof(bufer));
>    }

> if( bufer == position 1){       //If is position 1
>  void 1();
> }

> if( bufer == position 2){       //If is position 2
>  void 2();
> }.....

I’ll be gratefull if someone can help me. Thanks

Hello. I’m facing a new problem, I need identificate what position of array I’m receiving the value to send to the correct void to work with the valuer received.

Arrays work a bit weird. if you want to declare them 9 positions, as you do, the first index of the data is actually 0, so array[0] pointer refers to the first value stored in the array.

Thanks for the answer. I know that the array begin from [0], but supose that I’m receiving a index from [0], so how I do to compare with this index to I can work with your value in a specific void?

I’m not sure I understand what it is you want. What is it you want to achieve? What kind of data do you want to receive and how does your struct look like? Somewhere you must define what message you want to send and receive. If it is just an array, it is just that, an array.

So if I send buffer[0] = 0; to another NRF, you can put that in another array and use it.

I want to read in which index’m getting zero.

Aha, that’s not really difficult. You can achieve this by means of a simple loop to read all the values in the array.

for(int i=0;i<sizeof(nameofArray);i++)
{
  if(nameofArray[i] == 0)
  {
     // do something if index i matches 0
  }
}

Something like that should do the trick.

I’m sorry I do not know where I’m really going wrong, I send another index [3] so get 0

 int bufer[9];

 if(radio.available(&pipeNum)){ 
     radio.read(&bufer[0], sizeof(bufer));
   }


  for(int i=0;i<sizeof(bufer[0]);i++){

  if(bufer[i] == 0)
  {
     Serial.print(" Mostra index do bufer: ");
     Serial.println(bufer[i]);
     Rx();
  }
 }

 void Rx(){
 if ( bufer[0] == 1 ){
 }
 }

Can you show us the whole sketch? It’s pretty hard with just a loose piece of code to do debugging. Also, which library are you using for the NRF? Because I use the RF24 library and there may be difference between different libraries for sending stuff.

My project is send the commands and receive back the states.

Library:
“RF24 by TMRh20 Version 1.1.6”
“RF24Network by TMRh20 Version 1.0.6”

TX - Arduino Mega 2560, ESP 8266, NRF 24l01

 #include <SPI.h>
 #define BLYNK_PRINT Serial  
 #include <ESP8266_HardSer.h>
 #include <BlynkSimpleShieldEsp8266_HardSer.h>
 #define EspSerial Serial
 ESP8266 wifi(EspSerial);
 #include <WidgetLED.h>  
 #include <SimpleTimer.h>
 SimpleTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx"; 


WidgetLED led1(V10);
WidgetTerminal terminal(V17);

//==========================  NRF24L01 CONFIG  ==========================

#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
//#include "RF24_config.h"
                     //          CE, CS
RF24 radio(9,53);    //RF24 radio(9, 10); 

const uint64_t falando_pipes[5] = { 0xABCDABCD06LL, 0xABCDABCD18LL, 0xABCDABCD22LL, 0xABCDABCD35LL, 0xABCDABCD48LL };
const uint64_t ouvindo_pipes[5] = { 0xABCDABCD56LL, 0xABCDABCD64LL, 0xABCDABCD72LL, 0xABCDABCD85LL, 0xABCDABCD92LL };

//------------------------------------

int bufer[9];

uint8_t pipeNum;

float tempC;
int reading;

int LED3 = 7;
int LED2 = 4;
int LED1 = 5;

boolean debug;
String response;
String print_info;

int onn_led1;
int manda_dimer;
int manda_email = 0;
int volta_led;

int pausa_reconect;
int enable_disable;
int pausa_conex;
int pausa_manda_led;
int pausa_dimer;
int pausa_virtual;
int pausa_recone;
int pausa_bota;
int pausa_analg;
int pausa_lendo1;
int pausa_lendo2;

int vem_led;

//==================================================================

void setup() { 
        
       pinMode(LED1, OUTPUT); 
       pinMode(LED2, OUTPUT);
       pinMode(LED3, OUTPUT);
    
       Serial.begin(9600);
       delay(10);
       EspSerial.begin(9600);
       delay(100);
       Blynk.begin(auth, wifi,"******************","***********************************");
       
       while (Blynk.connect() == false) {
       Serial.println("RESTART NO SETUP...");
       digitalWrite(LED3, HIGH);
       sei();
       delay (100L);  
       asm volatile ("jmp 0");
       cli();
     }
       Serial.println("Programa Iniciado...");

       terminal.println(F("Blynk & Arduino Mauro. v" BLYNK_VERSION ": Programa iniciado"));
       terminal.println("------------------");
       terminal.println("wiff Conectado");
       terminal.flush();
       
       delay(10);
       radio.begin();                       
       
       radio.setChannel(100);               // Set the channel
       radio.setPALevel(RF24_PA_HIGH);      // Set PA LOW for this demonstration. We want the radio to be as lossy as possible for this example.
       radio.setDataRate (RF24_250KBPS);    //(RF24_1MBPS);//RF24_250KBPS           // Raise the data rate to reduce transmission distance and increase lossiness

       radio.openReadingPipe(1,ouvindo_pipes[0]);
       radio.openReadingPipe(2,ouvindo_pipes[1]);
       radio.openReadingPipe(3,ouvindo_pipes[2]);
       radio.openReadingPipe(4,ouvindo_pipes[3]);
       radio.openReadingPipe(5,ouvindo_pipes[4]);
                                
       radio.startListening();               
                
       pausa_dimer =  timer.setInterval (4000L, status_dimer);
       pausa_analg =  timer.setInterval (30000L, Uptime_analog);  
       pausa_lendo1 = timer.setInterval (4000L, lendo_pipe1);   
       pausa_lendo2 = timer.setInterval (4500L, lendo_pipe2);
                
       //pausa_reconect = timer.setInterval(4000, reconnectBlynk);
       //timer.setInterval(4000, ledVirtual1);
       //timer.setInterval(40000, pedi_ip);
       //enable_disable = timer.setInterval(5000L,restart_tempos);
       //timer.disable(enable_disable);

}

//=========================   ATUALIZAÇÃO  BLYNK   =============

bool isFirstConnect = true;
BLYNK_CONNECTED() {            //Esta função irá executar cada tempo de conexão é estabelecida Blynk
    if(isFirstConnect) {
       //Solicitar servidor Blynk para re-enviar os valores mais recentes para todos os pinos
       //Blynk.syncAll();      //atualiiza todos os pinos
     
       //Blynk.syncVirtual(V2);  // S1 atualizar só mente um pino Virtual :
       //Blynk.syncVirtual(V7);  // DIMER 
       //Blynk.syncVirtual(V0);  // TEMPERATURA
     
       isFirstConnect = false;
   }
}      

//==============================================================

 void loop() {

   
  if(radio.available(&pipeNum)){ 
    radio.read(&bufer[0], sizeof(bufer));
  
  // trata o pipe 1  
    if(pipeNum == 1){                      
     lendo_pipe1();
   }
  
  // trata o pipe 2
    if(pipeNum == 2){  
     lendo_pipe2();
   }

  else{ Serial.print(" Endereco! ");
        Serial.println(pipeNum);
   }
 }


/*
 *  ouvindo o pipe 2
if(radio.available(&pipeNum)){ 
   radio.read(&bufer[0], sizeof(bufer));
  if(pipeNum == 1){  //ouvindo do rx1 pipe[0]
    lendo_rx1();
    status_dimer();
  }
*/

Blynk.run();
timer.run(); 

}


//=====================  send to turn on the led on pipe 1  ====================

BLYNK_WRITE(V1)  { 

       radio.stopListening();              
       radio.openWritingPipe(falando_pipes[0]);
                                           
       bufer[1] = param.asInt();           
   
  bool ok = radio.write(bufer, sizeof(bufer) );  
    while (!ok){
     ok = radio.write(bufer, sizeof(bufer) );
        
       Serial.print(" MANDANDO LED1...");
       Serial.println( bufer[1]);
        
     }
       radio.startListening();
}

//========  send to turn on the led on pipe 2   =============

BLYNK_WRITE(V2)  { 
 
       radio.stopListening();              
       radio.openWritingPipe(falando_pipes[1]);
                                            
       bufer[3] = param.asInt();            
  
  bool ok = radio.write(bufer, sizeof(bufer) );  
    while (!ok){
     ok = radio.write(bufer, sizeof(bufer) );
        
       Serial.print(" MANDANDO LED2...");
       Serial.println( bufer[3]);
    }
       radio.startListening();
}

//======   Receiving the stats of led1 on pipe 1  =============

void lendo_pipe1(){

     Serial.print(" dados obtidos no tuboA: ");
     Serial.println(pipeNum);
     Serial.print("BUFER: ");
     Serial.println(bufer[2]);   
     Blynk.virtualWrite(V1,bufer[2]);  
     
  if(bufer[2] == 1){
     digitalWrite(LED1,HIGH);
  }
  else{ digitalWrite(LED1,LOW); }
}

//=========   Receiving the stats of led2 of pipe2  ============

void lendo_pipe2(){

     Serial.print(" dados obtidos no tuboB: ");
     Serial.println(pipeNum);
     Serial.print("BUFER: ");
     Serial.println(bufer[3]);
     Blynk.virtualWrite(V2,bufer[4]);
  if(bufer[4] == 1){
     digitalWrite(LED2,HIGH);
  }
  else{ digitalWrite(LED2,LOW); } 
  
}


//==============  Sending dimer to pipe1 ======================

BLYNK_WRITE(V3) {  
      
       //timer.restartTimer(pausa_lendo1);
       //timer.restartTimer(pausa_lendo2);
       //timer.restartTimer(pausa_analg);
       timer.restartTimer(pausa_dimer);         
       //timer.restartTimer(pausa_reconect);

       radio.stopListening();     
       radio.openWritingPipe(falando_pipes[0]);
                                        
       manda_dimer = param.asInt();  
       bufer[5] = manda_dimer;            

       radio.write(bufer, sizeof(bufer) );
        
       Serial.print(" MANDANDO DIMER:...");
       Serial.println(bufer[5]);

       radio.startListening();
}

//========  Receiving stats of dime of pipe 2  ==================

void status_dimer() {
  
       radio.openReadingPipe(1,ouvindo_pipes[0]);
    if(radio.available()) {
       boolean concluido = false; // Armazenar o payloads até chegar tudo
       while (!concluido) {
       concluido = radio.read(&bufer[0], sizeof(bufer));
    }
  } 
       Blynk.virtualWrite(V3,bufer[6]);    // Retorno status do dimer
       
       Serial.print("RECEBENDO DIMER:...");
       Serial.println(bufer[6]);
       // analogWrite(led_dimer, bufer[6] / 1);
}


//================ Receiving temperature =================

 void Uptime_analog() {

       radio.openReadingPipe(1,ouvindo_pipes[0]);
    if(radio.available()) {
       boolean concluido = false;   
       while (!concluido) {
       concluido = radio.read(&bufer[0], sizeof(bufer));
    }
  }

      reading = bufer[0]; 
      tempC = reading / .9 ;  ///.9;  //.931
      //bufer[0] + 9.3;  //  + .000;     
      Blynk.virtualWrite(V0,tempC);
      Serial.print("TEMPERATURA:...");
      Serial.println(tempC);
}

PIPE 2 - Arduino UNO R3, NRF24l01

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "RF24_config.h"
#include <SimpleTimer.h>
SimpleTimer timer;


RF24 radio(9, 10); 

const uint64_t ouvindo_pipes[5] = { 0xABCDABCD06LL, 0xABCDABCD18LL, 0xABCDABCD22LL, 0xABCDABCD35LL, 0xABCDABCD48LL };
const uint64_t falando_pipes[5] = { 0xABCDABCD56LL, 0xABCDABCD64LL, 0xABCDABCD72LL, 0xABCDABCD85LL, 0xABCDABCD92LL };

int bufer[9];   // = {};
//int bufer_compara[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

int lm35_analg = A1;
int potenciometro  = A0;
int estatu_dimer;
int retorna_dimer;

int recebe_dimer;
int manda_dimer;
int unido_dimer; //volatile   

int pausa_recebe_dimer; 
int pausa_analg;
int pausa_but;


int load = 6;
volatile int power;  // = 40;
int botao_0 = A5;
int botao_1 = A4;

#define led_dimer 3
#define liga_relay 7

int liga_led;
int estadorele;   
int leitura;
int estado_led1;
int LED1 = 5;

int UP = A5;  
int DOWN = A4;
int LAMP = 6;   


//======================================================== 

 void setup() {

    Serial.begin(9600);
    radio.begin();                            
  
    radio.setChannel(100);                     
    radio.setPALevel(RF24_PA_HIGH);           
    radio.setDataRate(RF24_250KBPS);       // RF24_1MBPS // RF24_250KBPS  

    radio.openReadingPipe(1,ouvindo_pipes[0]);
    
    radio.startListening();
    
    pinMode(led_dimer, OUTPUT);
    pinMode(potenciometro,INPUT);
    pinMode(lm35_analg, INPUT); 
    pinMode(LED1, OUTPUT);
    pinMode(liga_relay,INPUT_PULLUP);

    pinMode(load, OUTPUT);

    pinMode(botao_0, INPUT_PULLUP);
    pinMode(botao_1, INPUT_PULLUP);
    
    pausa_but = timer.setInterval(3000L, status_Led_1());
    pausa_recebe_dimer = timer.setInterval(3000L, Dimer());
    pausa_analg = timer.setInterval(40000L, Uptime_analog);
}

//========================================================

void loop() {

timer.run();
uint8_t pipeNum;

   if(radio.available(&pipeNum)){
     radio.read(&bufer[0], sizeof(bufer));
   
   if(pipeNum == 1){
     Serial.print(" dados obtidos no tuboA: ");
     Serial.println(pipeNum);


  Is only this my problem
 //------------------------------
 if( bufer[0] ==  bufer[1]){    //  Here is my problem, I need know what is the position of bufer that
     Led_1();                   //  I'm receiving to send to the correct void
 }                              //  If I'm receiving on index bufer[1], works on void Led_1() 
 if( bufer[0] ==  bufer[3]){    //  If I'm receiving on index bufer[3] works void Led_1() 
     Dimer();             
 }                      //  Is only this my problem
//------------------------------  
 
}

//===========    Manual button of dimer   ======================    

     if((digitalRead(botao_1) == LOW) && (bufer[5] < 254)){  
       delay(50);
       //sobe();
     }

else if((digitalRead(botao_0) == LOW) && (bufer[5] > 0)) {
       delay(50);
       //dece();
       }
else { 
    
       bufer[6] =  bufer[5];
       //analogWrite(led_dimer, bufer[6] / 1);
     } 

//=========  Manual button to turn on led    ====================

       leitura = digitalRead(liga_relay);
    if(leitura != 1)  {
    while(digitalRead(liga_relay) != 1)  {
       delay(150);
   }
       estadorele = !estadorele;
       status_but();
   } 
       digitalWrite(LED1, estadorele);
  }

}  // FIM FO LOOP
      
//===============   receiving to turn on led1   ===================

void Led_1() {

   if(bufer[1] == 1) { 
       estadorele = 1;
       status_but();
    }
   
   if(bufer[1] == 0){
       estadorele = 0;
       status_but();
    }

     Serial.print(" RECEBENDO LED...");
     Serial.println(bufer[1]);
}

//============ sending stats of led of pipe 1 ======================

void status_Led_1(){

    radio.stopListening();         
    radio.openWritingPipe(falando_pipes[0]); 
   
    bufer[2] = estadorele; 
    bool ok = radio.write(bufer, sizeof(bufer) );  
    while (!ok){
    ok = radio.write(bufer, sizeof(bufer) );
    }
    
    Serial.print(" MANDANDO LED...");
    Serial.println( bufer[2]);
    
    radio.startListening();   
}

//============   sending temperature  ====================

void Uptime_analog(){
  
    radio.stopListening();              
    radio.openWritingPipe(falando_pipes[0]);      
    // float temp =   
    bufer[0] = analogRead(lm35_analg) *  0.48828125;
    radio.write( bufer, sizeof(bufer) );
   
    Serial.print("TEMPERATURA: "); 
    Serial.println(bufer[0]);
       
    radio.startListening();   
}

//===============  receiving dimer  ====================

void Dimer(){
        
       timer.restartTimer(pausa_but);  
       recebe_dimer = bufer[5];
       analogWrite(led_dimer, bufer[5] / 1);
       Serial.print(" RECEBENDO DIMER:..");
       Serial.println(recebe_dimer);
}

//=========  manual button to send status of dimer  =====================

void sobe() {

       radio.stopListening();                  
       radio.openWritingPipe(falando_pipes[0]);    
       timer.disable(pausa_recebe_dimer); 
       bufer[5] = bufer[5] + 5;
       bufer[6] = bufer[5];
       radio.write(bufer, sizeof(bufer) );
       //analogWrite(led_dimer, bufer[6] / 1);
       Serial.print("MAIS...+....");
       Serial.println(bufer[5]); 
       timer.enable(pausa_recebe_dimer);
       radio.startListening();
}  
void dece() {
  
       radio.stopListening();                  
       radio.openWritingPipe(falando_pipes[0]);     
       timer.disable(pausa_recebe_dimer); 
       bufer[5] = bufer[5] - 5;
       if(bufer[5] <= 5 ){ bufer[5] = 0; }
       bufer[6] = bufer[5];
       radio.write(bufer, sizeof(bufer) );
       //analogWrite(led_dimer, bufer[6] / 1);
       Serial.print("MENOS...-....");
       Serial.println(bufer[5]);
       timer.enable(pausa_recebe_dimer);
       radio.startListening();
}
1 Like

I don’t think it will work that way. The index has no position, it is just filled with data and there is no pointer. I’m still not sure what you want to achieve by this. Isn’t it much easier to forget the NRF and just get a couple of cheap Wemos chips? It’ll save you so much hassle.

You might want to take a look here: http://www.instructables.com/id/Lego-Trains-Blynk/

I’m doing something similar with trains. Sending messages across, but I address each individual NRF. I think you lack that ability, but I’m not sure.

Hello.
Well, I’m a little happy because finaly I can do what I wanted. I want to thanks to @Costas and @Lichtsignaal.
It’s this, in the end, I used the library “RF24Network”, with him I can send to the slavers a character and after the command, at this way I can compare what command I’ll receive and send to be treated at the correct “void”.
I’ll leave the codes here to be helpfull to someone.

TX:

//#include <SPI.h>
//#define BLYNK_PRINT Serial  
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#define EspSerial Serial
ESP8266 wifi(EspSerial);
#include <WidgetLED.h>
  
#include <SimpleTimer.h>
SimpleTimer timer;

char auth[] = "**********************************";

WidgetLED led1(V3);
WidgetLED led4(V4);
//WidgetTerminal terminal(V1);

//--------------------------------------------------------------------

#include <avr/pgmspace.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
//#include "printf.h"

RF24 radio(9,53);                      // nRF24L01(+) radio attached using Getting Started board 
RF24Network network(radio);            // Network uses that radio

const uint16_t esse_node = 00;           // Desse node  Address of our node in Octal format

int dados[9];

unsigned long delay1 = 0;

int led_conex = 7;
int but_led1 = 8;
int on_led1  = 5;
int on_led2  = 4;
int estadorele;
int leitura;

float tempC;
int reading;

int pausa_led1;
int pausa_led2;
int pausa_dimer1;
int pausa_temper;
int pausa_receb_dados;

int role = 1;


//======================================================================================

void setup(void) {
  pinMode(led_conex,OUTPUT);
  pinMode(but_led1,OUTPUT);
  pinMode(on_led1, OUTPUT);
  pinMode(on_led2, OUTPUT);
 
//------------   CONFIG ESP8266    -------------------------------------  

   EspSerial.begin(9600);
   delay(100);
   Blynk.begin(auth, wifi,"********************","*****************************");
       
   while (Blynk.connect() == false) {
   Serial.println("RESTART NO SETUP...");
   digitalWrite(led_conex, HIGH);
   sei();
   delay (100L);  
   asm volatile ("jmp 0");
   cli();
   }
   Serial.println("Programa Iniciado...");
/*
   terminal.println(F("Blynk & Arduino Mauro. v" BLYNK_VERSION ": Programa iniciado"));
   terminal.println("------------------");
   terminal.println("wiff Conectado");
   terminal.flush();
*/
//---------------------------------------------------------------------------  
   
   Serial.begin(9600);
   radio.begin();
   SPI.begin();
   radio.setPALevel(RF24_PA_MAX);   ///  RF24_PA_LOW or RF24_PA_MIN via radio.setPALevel(RF24_PA_MIN) ;
   network.begin(/*channel*/ 110, /*node address*/ esse_node);
 
//   pausa_temper = timer.setInterval (10000L, lendo_temper);
   pausa_receb_dados = timer.setInterval (1000L, recebe_tudo);

}
//=========================   Atualiza todos os Comandos   =============

bool isFirstConnect = true;
BLYNK_CONNECTED() {            //Esta função irá executar cada tempo de conexão é estabelecida Blynk
    if(isFirstConnect) {
       //Solicitar servidor Blynk para re-enviar os valores mais recentes para todos os pinos
       //Blynk.syncAll();      //atualiiza todos os pinos
       Blynk.syncVirtual(V1);  // S1 atualizar só mente um pino Virtual :
       Blynk.syncVirtual(V2);  // DIMER 
       Blynk.syncVirtual(V3);  // GROJE TEMPERATURA
       isFirstConnect = false;
   }
}      

//==============================================================


void loop() {

network.update();
Blynk.run();
timer.run();  

/*  
    unsigned long startTimer = millis();                //start timer, we will wait 200ms 
    bool timeout = false; 
    while ( !wirelessSPI.available() && !timeout ) {          //run while no recieve data and not timed out
    if (millis() - startTimer > 200 ) timeout = true;       //timed out
   }

/*    wirelessSPI.startListening();                       //switch to recieve mode to see if the guess was right
    unsigned long startTimer = millis();                //start timer, we will wait 200ms 
    bool timeout = false; 
    while ( !wirelessSPI.available() && !timeout ) {          //run while no recieve data and not timed out
   if (millis() - startTimer > 200 ) timeout = true;       //timed out
   }
*/

}

//===================   envia led1 RX 1   ====================

BLYNK_WRITE(V1)  { 
uint16_t to = 01; 
    
      dados[1] = param.asInt();                           

      RF24NetworkHeader header(to,'V');
      bool ok = network.write(header,dados,sizeof(dados));

     Serial.print(" Enviando led1...");
     Serial.println( dados[1]);
     Serial.println(to);  // Envia p Node1
}
//==================     envia led2 RX 2   ================

BLYNK_WRITE(V2)  { 
uint16_t to = 02;                           // Send to master
   
   dados[3] = param.asInt();                           

   RF24NetworkHeader header(to,'F');       // Send header type 'T'
   bool ok = network.write(header,dados,sizeof(dados));
 
   Serial.print(" Mandando led2...");
   Serial.println( dados[3]);
   Serial.println(to);  // Envia p Node2
}
//============    lendo led1 RX 1    =================

void lendo_led1(){

    Blynk.virtualWrite(V1,dados[2]);
    digitalWrite(on_led1,dados[2]);
    Serial.print(" Recebendo led1: ");
    Serial.println(dados[2]);
}
//==============   Lendo led2 RX 2   ===============

void lendo_led2(){

    Blynk.virtualWrite(V2,dados[4]);
    digitalWrite(on_led2,dados[4]);
    Serial.print(" Recebendo led2: ");
    Serial.println(dados[4]);
}
//============    enviando Dimer1 RX 1   ================

BLYNK_WRITE(V3) { 
uint16_t to = 01; 
 
  timer.restartTimer(pausa_receb_dados);  
 
   RF24NetworkHeader header(to, 'D');
   dados[5] = param.asInt();                           
   bool ok = network.write(header,dados,sizeof(dados));
  
   Serial.print(" Enviando Dimer1...");
   Serial.println( dados[5]);

}
//============    lendo dimer1 RX 1  =================

void lendo_dimer1() {

    Serial.print(" Recebendo Dimer: ");
    Serial.println(dados[6]);
    Blynk.virtualWrite(V3,dados[6]);
 }
//=============  lendo temperatura1 RX 1  =========

void lendo_temper(){
/*      
   if( network.available() )  {
      RF24NetworkHeader header;
      network.peek(header);
  
  if( header.from_node == 01 ){  
  if( header.type == 'A'){
      network.read(header,&dados[0],sizeof(dados));
      Serial.print(" Recebendo A node: ");
      Serial.println(header.from_node);
*/      
      reading = dados[7]; 
      tempC = reading / .9 ;  ///.9;  //.931
      //bufer[0] + 9.3;  //  + .000;     
      Serial.print(" Temperatura:...");
      Serial.println(tempC);
      Blynk.virtualWrite(V0,tempC);
//    }
//   }   
//  }

}
//=======  tentativa de receber os dados por timer======

void recebe_tudo(){

  if( network.available() )  {
      RF24NetworkHeader header;
      network.peek(header);

  if( header.from_node == 01 ){  // recebe led1 RX 1
  if( header.type == 'R'){
      network.read(header,&dados[0],sizeof(dados));
      Serial.print(" Recebendo R node: ");
      Serial.println(header.from_node);
      lendo_led1();
    }
   }

  if( header.from_node == 01 ){  // receb dimer RX 1
  if( header.type == 'P'){
      network.read(header,&dados[0],sizeof(dados));
      Serial.print(" Recebendo P node: ");
      Serial.println(header.from_node);
      lendo_dimer1();
   }
  }


  if( header.from_node == 01 ){  
  if( header.type == 'A'){
      network.read(header,&dados[0],sizeof(dados));
      Serial.print(" Recebendo A node: ");
      Serial.println(header.from_node);
  lendo_temper();
  }
 }
  

delay(20);

  if( header.from_node == 02 ){  
  if( header.type == 'M'){
      network.read(header,&dados[0],sizeof(dados));
      Serial.print(" Recebendo M node: ");
      Serial.println(header.from_node);
      lendo_led2();
    }
   }

}

}

RX 1:

#include <avr/pgmspace.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include "printf.h"

#include <SimpleTimer.h>
SimpleTimer timer;

RF24 radio(9,10);                  // nRF24L01(+) radio attached using Getting Started board 
RF24Network network(radio);        // Network uses that radio

const uint16_t esse_node = 01;       // Esse node    Address of our node in Octal format ( 04,031, etc)

int dados[9];


uint16_t from_node;               // ler node recebido

int lm35_analg = A1;
int botao_0 = A5;
int botao_1 = A4;

int but_led1 = 7;
int on_led1  = 5;
int on_led2  = 4;
int estadorele;
int leitura;
#define led_dimer 6

int pausa_but;
int pausa_dimer;
int pausa_rdimer;
int pausa_status_led;
int pausa_Dim1;
int pausa_tempe;

int vai_dimer;

//=======================   SETUP   ===========================

void setup(void)
{
  pinMode(but_led1,INPUT_PULLUP);
  pinMode(on_led1, OUTPUT);
  pinMode(on_led2, OUTPUT);  
  pinMode(led_dimer, OUTPUT);

  pinMode(botao_0, INPUT_PULLUP);
  pinMode(botao_1, INPUT_PULLUP);
  
  Serial.begin(9600);
  Serial.println("RF24Network/examples/helloworld_rx/");
 
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_LOW or RF24_PA_MIN via radio.setPALevel(RF24_PA_MIN) ;
  network.begin(/*channel*/ 110, /*node address*/ esse_node);

  pausa_status_led = timer.setInterval (60000L, status_led1);  
  pausa_Dim1 = timer.setInterval (10000L, envia_Dim1);
  pausa_tempe = timer.setInterval (60000L, Uptime_analog);   

//  pausa_dimer = timer.setInterval (3000L, status_dimer);
//  pausa_rdimer = timer.setInterval (2000L, recebe_dimer1);      

status_led1();

}

//=======================    LOOP   =========================


void loop(void){

timer.run(); 
  network.update();                              // Check the network regularly
   
  if( network.available() )  {
     RF24NetworkHeader header;
  
     network.peek(header);
  if(header.type == 'V'){
    network.read(header,&dados[0],sizeof(dados));
    recebe_led1();
  
    Serial.print(" Recebendo V node: ");
    Serial.println(header.from_node);
  } 
        
     network.peek(header);
  if(header.type == 'D'){
    network.read(header,&dados[0],sizeof(dados));
    recebe_dimer1();
    
    Serial.print(" Recebendo D node: ");
    Serial.println(header.from_node);
  }
  
}   

//===============    BUT PARA DIMER   ======================    

     if((digitalRead(botao_1) == LOW) && (vai_dimer < 300)){ //254 
       delay(50);
       sobe();
     }
else if((digitalRead(botao_0) == LOW) && (vai_dimer > 0)) {
       delay(50);
       dece();
       }
else {   
       dados[6] =  vai_dimer;
       analogWrite(led_dimer, dados[6] / 2);
     } 

//==================     BUTÃO LIGAR   ==============================

       leitura = digitalRead(but_led1);
    if(leitura != 1)  {
    while(digitalRead(but_led1) != 1)  {
       delay(200);
   }
       estadorele = !estadorele;
       status_led1();
   } 
      //digitalWrite(on_led1, estadorele);
   
}  // FIM FO LOOP

//===============    RECEBE LED 1   ===================

void recebe_led1(){

    estadorele = dados[1];
        
    Serial.print(" Recebendo led1    ");
    Serial.println(dados[1]);
    status_led1();
}
//=================   ENVIA LED 1   ============================================

void status_led1(){

uint16_t to = 00;
     
     dados[2] = estadorele;
    
     RF24NetworkHeader header(to, 'R');
     bool ok = network.write(header,dados,sizeof(dados));
  if (ok == true){
     Serial.print(" Enviando led1: ");
     Serial.println(dados[2]);
     Serial.println("ok.");
  }  else
     Serial.println("failed.");
     digitalWrite(on_led1, estadorele);
}


//============   TEMPO PARA MANDAR TEMPERATURA   ====================================

void Uptime_analog(){
   
 uint16_t to = 00;
     
     dados[7] = analogRead(lm35_analg) *  0.48828125;
        
     RF24NetworkHeader header(to, 'A');
     bool ok = network.write(header,dados,sizeof(dados));
  if (ok == true){
     Serial.print(" Enviando Temper: ");
     Serial.println(dados[7]);
     Serial.println("ok.");
  }  else
     Serial.println("failed.");

}   

//===============    RECEBE DIMER 1     ==============

void recebe_dimer1(){
  
    pausa_status();

    vai_dimer = dados[5];   //int invet_dim = dados[5];
                            //vai_dimer = ~invet_dim + 1;
    //analogWrite(led_dimer, vai_dimer / 1);
    
    Serial.print(" Recebendo Dimer1 ");
    Serial.println(dados[5]);
 
}

//===============    ENVIA DIMER 1     =============

void envia_Dim1(){

uint16_t to = 00;
     
     dados[6] = vai_dimer;
    
     RF24NetworkHeader header(to, 'P');
     bool ok = network.write(header,dados,sizeof(dados));
  if (ok == true){
     Serial.print(" Enviando Dimer: ");
     Serial.println(dados[6]);
     Serial.println("ok.");
  }  else
     Serial.println("failed.");

}     
     
//==========  TRATA BUT PARA MANDAR DIMER  =====================

void sobe() {

       pausa_status();

       vai_dimer = vai_dimer + 2;   // 5
       dados[6] = vai_dimer;

       analogWrite(led_dimer, dados[6] / 2);  // 1
       Serial.print("MAIS...+....");
       Serial.println(dados[5]); 

envia_Dim1();

}  

void dece() {
       pausa_status();

       vai_dimer = vai_dimer - 2;   // 5
       if(vai_dimer <= 5 ){ vai_dimer = 0; }
       dados[6] = vai_dimer;

       analogWrite(led_dimer, dados[6] / 2);
       Serial.print("MENOS...-....");
       Serial.println(dados[5]);

envia_Dim1();

} 

//====================   pausa status   ============

void pausa_status(){

    timer.restartTimer(pausa_status_led);  
    timer.restartTimer(pausa_Dim1);
    timer.restartTimer(pausa_tempe);
  
}

RX 2:

#include <avr/pgmspace.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include "printf.h"

#include <SimpleTimer.h>
SimpleTimer timer;

RF24 radio(9,10);                  // nRF24L01(+) radio attached using Getting Started board 
RF24Network network(radio);        // Network uses that radio

const uint16_t esse_node = 02;       // Esse node    Address of our node in Octal format ( 04,031, etc)

int dados[9];


uint16_t from_node;               // ler node recebido


int botao_0 = A5;
int botao_1 = A4;

int but_led1 = 7;
int on_led1  = 5;
int on_led2  = 4;
int estadorele;
int leitura;
#define led_dimer 3

int pausa_but;
int pausa_dimer;
int pausa_rdimer;
int pausa_status_led;
int  pausa_Dim1;

//=======================   SETUP   ===========================

void setup(void)
{
  pinMode(but_led1,INPUT_PULLUP);
  pinMode(on_led1, OUTPUT);
  pinMode(on_led2, OUTPUT);  
  pinMode(led_dimer, OUTPUT);

  pinMode(botao_0, INPUT_PULLUP);
  pinMode(botao_1, INPUT_PULLUP);
  
  Serial.begin(9600);
  Serial.println("RF24Network/examples/helloworld_rx/");
 
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_LOW or RF24_PA_MIN via radio.setPALevel(RF24_PA_MIN) ;
  network.begin(/*channel*/ 110, /*node address*/ esse_node);

  pausa_status_led = timer.setInterval (60000L, status_led1);  
//  pausa_Dim1 = timer.setInterval (4100L, envia_Dim1);

//  pausa_but = timer.setInterval (1000L, status_led1);   
//  pausa_dimer = timer.setInterval (3000L, status_dimer);
//  pausa_rdimer = timer.setInterval (2000L, recebe_dimer1);      

status_led1();
}

//=======================    LOOP   =========================


void loop(void){

timer.run(); 
  network.update();                              // Check the network regularly
   
  if( network.available() )  {
     RF24NetworkHeader header;
  
     network.peek(header);
  if(header.type == 'F'){
    network.read(header,&dados[0],sizeof(dados));
    recebe_led1();
  
    Serial.print(" Recebendo F node: ");
    Serial.println(header.from_node);
  } 

/*       
     network.peek(header);
  if(header.type == 'D'){
    network.read(header,&dados[0],sizeof(dados));
    recebe_dimer1();
    
    Serial.print(" Recebendo D node: ");
    Serial.println(header.from_node);
    Serial.print("");

  }
*/
  
}   

//===============    BUT PARA DIMER   ======================    
/*
     if((digitalRead(botao_1) == LOW) && (dados[5] < 254)){  
       delay(50);
       sobe();
     }

else if((digitalRead(botao_0) == LOW) && (dados[5] > 0)) {
       delay(50);
       dece();
       }
else {   
       dados[6] =  dados[5];
       analogWrite(led_dimer, dados[6] / 1);
       //Serial.println("ENTROU NO ELSE.....");
     } 
*/
//==================     BUTÃO LIGAR   ==============================


       leitura = digitalRead(but_led1);
    if(leitura != 1)  {
    while(digitalRead(but_led1) != 1)  {
       delay(200);
   }
       estadorele = !estadorele;
       status_led1();
   } 
      //digitalWrite(on_led1, estadorele);
   
}  // FIM FO LOOP


//===============    RECEBE LED 1   ===================

void recebe_led1(){

    estadorele = dados[3];
        
    Serial.print(" Recebendo led2    ");
    Serial.println(dados[3]);
    status_led1();
}

//=================   ENVIA LED 1   ============================================

void status_led1(){

uint16_t to = 00;
     
     dados[4] = estadorele;
    
     RF24NetworkHeader header(to, 'M');
     bool ok = network.write(header,dados,sizeof(dados));
  if (ok == true){
     Serial.print(" Enviando led1: ");
     Serial.println(dados[4]);
     Serial.println("ok.");
  }  else
     Serial.println("failed.");
     digitalWrite(on_led1, estadorele);
}
/*
//===============    RECEBE DIMER 1     ==============

void recebe_dimer1(){

    timer.restartTimer(pausa_status_led);  
    timer.restartTimer(pausa_Dim1);
    
    dados[5];
    analogWrite(led_dimer, dados[5] / 1);
    
    Serial.print(" Recebendo Dimer1 ");
    Serial.println(dados[5]);
 
}

//===============    ENVIA DIMER 1     =============

void envia_Dim1(){

uint16_t to = 00;
     
     dados[6] = dados[5];
    
     RF24NetworkHeader header(to, 'P');
     bool ok = network.write(header,dados,sizeof(dados));
  if (ok == true){
     Serial.print(" Enviando Dimer: ");
     Serial.println(dados[6]);
     Serial.println("ok.");
  }  else
     Serial.println("failed.");

}     
     
     
//==========  TRATA BUT PARA MANDAR DIMER  =====================

void sobe() {
       timer.restartTimer(pausa_status_led);  
       timer.restartTimer(pausa_Dim1);  

       dados[5] = dados[5] + 5;
       dados[6] = dados[5];

       analogWrite(led_dimer, dados[6] / 1);
       Serial.print("MAIS...+....");
       Serial.println(dados[5]); 

envia_Dim1();

}  

void dece() {
       timer.restartTimer(pausa_status_led);  
       timer.restartTimer(pausa_Dim1);

       dados[5] = dados[5] - 5;
       if(dados[5] <= 5 ){ dados[5] = 0; }
       dados[6] = dados[5];

       analogWrite(led_dimer, dados[6] / 1);
       Serial.print("MENOS...-....");
       Serial.println(dados[5]);

envia_Dim1();

} 

*/

Here is the example of how is the project: Arduino + nrf24l01 + ESP8266 + Blynk

“Não há ninguém tão sábio que não possa aprender e ninguém tão ignorante que não possa ensinar”

2 Likes

Hey @mauroviana I interested with your project, can you provided the wiring diangram?