Hi, I want to make bi-directional communication between my Boat(UNO) and my Remote Control(MEGA 2560) with two NRF24L01+.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(48, 53); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
void setup() {
Serial.begin(9600);
pinMode(53, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00002
radio.openReadingPipe(1, addresses[1]); // 00001
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
delay(5);
radio.startListening();
if ( radio.available()) {
while (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text)); // Recieve "text" from Boat.
Serial.println(text);
}
delay(5);
radio.stopListening();
const char texted[] = "Hello from Remote Control"; // Sends "texted" to Boat.
radio.write(&texted, sizeof(texted));
}
}
The code above is for my Remote Control (with MEGA 2560 board). I want my Remote Control to send "Hello from Remote Control" and also receive another text from the Boat.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
delay(5);
radio.stopListening();
const char text[] = "Hello from Boat";
radio.write(&text, sizeof(text)); //Sends "text" to Remote Control
delay(5);
radio.startListening();
while (!radio.available());
char texted[32] = "";
radio.read(&texted, sizeof(texted)); //Recieve "texted" from Remote Control
Serial.println(texted);
}
The code above is for my Boat (with UNO board). I want to send "Hello from Boat" to my Remote Control and also receive another text from the Remote Control.
However, only my Remote Control receive a text from Boat when I plug the Remote Control USB to my laptop for serial monitor (meaning that my Boat is powered via battery and its USB is not connected to anything).
So, can anyone help me check if my codes are correct for what I want my Boat and RemoteControl to do. Which is to send a text to each other and receive a text from each other.