Hello, I started making a project which involved 2 Arduino Unos, 2 nRF24L01+ modules, 2 LCDs, and buttons. The plan was to make bidirectional communication between the Arduinos with sending each other a text message which is displayed on the LCDs using a button on the other side. I made the code and uploaded it on both the Arduinos but it only work one way. The first arduino is sending the message to the second but not vice versa. I think my problem is how I made the code so I am uploading it here with the schematics and I look forward to the answers. (I apologize for the schematic it's kind of messy.
//Code 1: First Arduino
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <LiquidCrystal.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][10] = { "ADDRESS01", "ADDRESS02" }; //addresses define
const int rs = 10, en = 9, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //LCD define
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //LCD
const int B1_Pin = 6; // Pushbutton B1
char txt1[] = "B1", txt3[] = "00";
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
pinMode(B1_Pin, INPUT);
radio.begin();
radio.openWritingPipe(addresses[0]); //ADRESS01
radio.openReadingPipe(1, addresses[1]); //ADRESS02
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
};
void loop() {
delay(10);
radio.startListening();
delay(10);
radio.stopListening();
int B1_State = digitalRead(B1_Pin);
if (B1_State == HIGH) {
radio.write(&txt1, sizeof(txt1));
Serial.println(txt1);
} else {
radio.write(&txt3, sizeof(txt3));
Serial.println(txt3);
};
delay(10);
if (radio.available()) {
char txt[5] = "";
radio.read(&txt, sizeof(txt));
switch (txt[1]) {
case '2':
lcd.print("hello, world!");
delay(3000);
lcd.clear();
break;
default: lcd.clear(); break;
};
Serial.println(txt);
};
};
//Code 2: Second Arduino
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <LiquidCrystal.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][10] = {"ADDRESS01","ADDRESS02"}; //adresses define
const int rs = 10, en = 9, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //LCD define
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //LCD
const int B2_Pin = 6; // Pushbutton B1
char txt7[] = "B2", txt8[] = "00";
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
pinMode(B2_Pin, INPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); //ADDRESS02
radio.openReadingPipe(1, addresses[0]); //ADRESS01
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
};
void loop() {
delay(10);
radio.stopListening();
delay(10);
radio.startListening();
int B2_State = digitalRead(B2_Pin);
if (B2_State == HIGH) {
radio.write(&txt7, sizeof(txt7));
Serial.println(txt7);
} else {
radio.write(&txt8, sizeof(txt8));
Serial.println(txt8);
};
delay(10);
if (radio.available()) {
char txt[6] = "";
radio.read(&txt, sizeof(txt));
switch (txt[1]) {
case '1':
lcd.print("hello, world!");
delay(3000);
lcd.clear();
break;
default: lcd.clear(); break;
};
Serial.println(txt);
};
};