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();
}