Good Day Every One.....
With Reference to the previous post. I stuck in 2-way communication between Arduino Pro Mini and Nodemcu. I tried a lot but no success. Also One way communication is successful. I try to change everything but did not get two way communication with success and unable to find the problem.
Note: This code is working nicely with Nodemcu to Nodemcu communication and also UNO to Nodemcu communication. And Also I tried many other programs by which One way communication is successful but I stuck when I go for two way communication and then Arduino Pro Mini can not receive data and shows "0" value on serial monitor. Arduino Pro Mini is programming and powering from UNO. Here is the Pin configuration,
Arduino Mini Arduino UNO
Tx Tx
Rx Rx
5v VCC
GND GND
Reset Reset NRF 24L01
9 CE
10 CSN
11 MOSI
12 MISO
13 SCK
VCC 3.3V
GND GND
Code For Arduino Mini
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};
//byte addresses[][6] = {"1Node", "2Node"};
//const byte addresses[] = {"1Node"};
int button_pin = A0;
int led_pin2 = 2;
int led_pin3 = 3;
// int Seat_Value1;
short int seat_status;
struct dataStruct {
int Seat_Value;
// int Seat_Value_1;
// int button_pin = D0;
int Button_State;
} myData;
// struct dataStruct1 {
//int Seat_numb;
// int Seat_Value1;
//int button_pin1 = D0;
//int Button_State;
//} myData1;
void setup() {
Serial.begin(57600);
pinMode(button_pin, INPUT);
pinMode(led_pin2, OUTPUT);
pinMode(led_pin3, OUTPUT);
radio.begin();
radio.setChannel(83);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
//radio.openWritingPipe(addresses[0]);
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1, addresses[0]);
//radio.openWritingPipe(addresses[0]);
// radio.openReadingPipe(pipe, addresses[1]);
//radio.stopListening();
}
void loop() {
radio.stopListening();
int Seat_Value = 2;
myData.Button_State = digitalRead(button_pin);
myData.Seat_Value = Seat_Value;
//myData.Button_State = Button_State;
radio.write( &myData, sizeof(myData));
//radio.startListening();
//if (radio.available()){
//while(!radio.available());
//radio.read( &myData, sizeof(myData));
// if (myData.Seat_Value1 == 2)
// {
// digitalWrite(led_pin3, HIGH);
// digitalWrite(led_pin2, LOW);
//}
// else
// {
// digitalWrite(led_pin3, LOW);
// digitalWrite(led_pin2, HIGH);
// }
// radio.startListening();
delay(5);
radio.startListening();
// if (radio.available()) {
while (!radio.available())
//{
radio.read(&seat_status, sizeof(seat_status));
Serial.println(seat_status);
if (seat_status == 2)
{
digitalWrite(led_pin2, HIGH);
digitalWrite(led_pin3, LOW);
}
else
{
digitalWrite(led_pin2, LOW);
digitalWrite(led_pin3, HIGH);
}
// radio.read( &myData1, sizeof(myData1));
// radio.read(&mydata1, sizeof(mydata1));
/* if (myData1.Seat_Value1 == 2)
{
digitalWrite(led_pin2, LOW);
digitalWrite(led_pin3, HIGH);
}
else
{
digitalWrite(led_pin2, HIGH);
digitalWrite(led_pin3, LOW);
} */
/* if (myData1.Button_State == HIGH)
{
digitalWrite(led_pin2, HIGH);
}
else
{
digitalWrite(led_pin2, LOW);
}
if (myData1.Seat_Value1 == 2)
{
digitalWrite(led_pin3, HIGH);
}
else
{
digitalWrite(led_pin3, LOW);
} */
//}
}
//}
Nodemcu NRF 24L01
D4 CE
D2 CSN
D7 MOSI
D6 MISO
D5 SCK
3.3v 3.3V
GND GND
Code for Nodemcu
#include <SPI.h>
#include <RF24.h>
//#include <Servo.h>
RF24 radio(D4, D2); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};
//byte addresses[][6] = {"1Node", "2Node"};
//const byte addresses[] = "1Node";
//const byte pipe = 1;
int button_pin1 = D0;
int led_pin = D1;
int led_pin1 = D8;
int seat_status;
// boolean button_state1 = 0;
struct dataStruct {
int Seat_Value;
//int Seat_Value1;
// int button_pin = D0;
int Button_State;
// byte led_pin;
// byte led_pin1;
} myData;
// struct dataStruct1 {
// int Seat_numb;
// int Seat_Value1;
// int button_pin = D0;
// int Button_State;
// } myData1;
void setup() {
pinMode(button_pin1, INPUT);
pinMode(led_pin, OUTPUT);
pinMode(led_pin1, OUTPUT);
// led_pin.attach(D1);
// led_pin.attach(D8);
// myServo_1.attach(5);
// myServo_2.attach(6);
radio.begin();
radio.setChannel(83);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
//radio.startListening();
//radio.startListening();
}
void loop() {
radio.startListening();
//int Seat_Value1 = 3;
if (radio.available()) {
while (radio.available()) {
radio.read( &myData, sizeof(myData) );
// led_pin.write(myData.Button_State);
// led_pin.write(myData.Seat_Value);
if (myData.Button_State == HIGH)
{
digitalWrite(led_pin, HIGH);
}
else
{
digitalWrite(led_pin, LOW);
}
if (myData.Seat_Value == 2)
{
digitalWrite(led_pin1, HIGH);
// delay(5);
// radio.stopListening(); //This sets the module as transmitter
// int seat_status = 2;
// radio.write(&seat_status, sizeof(seat_status)); //Sending the data
// delay(5);
//radio.stopListening();
//int Seat_Value1 = 2;
// myData1.Button_State = digitalRead(button_pin1);
// myData1.Seat_Value1 = Seat_Value1;
// radio.write(&myData1, sizeof(myData1));
//myData.Seat_Value1 = Seat_Value1;
//radio.write(&myData, sizeof(myData));
}
else
{
digitalWrite(led_pin1, LOW);
}
// }
// }
}
delay(5);
radio.stopListening(); //This sets the module as transmitter
int seat_status = 2;
radio.write(&seat_status, sizeof(seat_status)); //Sending the data
// delay(5);
}
}
//}