When I send "a" from the Serial Monitor of the slave, on the master slave window it will show "car1_place_2_go = a" then it should show on the slave Serial Monitor "a" but it doesn't show up in the slave serial window until I send another new characters. So there is a 1 delay shift in the messages showed on the slave Serial Monitor.
Master:
#include <SPI.h>
#include <SoftwareSerial.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
char car1_place_2_go;
char car2_place_2_go;
char temp_place = 0 ;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(addresses[1]); // mastr
radio.openReadingPipe(1, addresses[0]); // carwl
radio.setPALevel(RF24_PA_MIN);
}
void loop()
{
delay(5);
radio.startListening();
if (radio.available())
{
radio.read(&car1_place_2_go, sizeof(car1_place_2_go));
Serial.print("car1_place_2_go = ");
Serial.println(car1_place_2_go);
delay(5);
radio.stopListening();
radio.write(&car1_place_2_go, sizeof(car1_place_2_go));
}
}
Slave:
#include <SPI.h>
#include <SoftwareSerial.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
char car1_place_2_go;
char car2_place_2_go;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00003
radio.openReadingPipe(1, addresses[1]); // 00002
radio.setPALevel(RF24_PA_MIN);
}
void loop()
{
if (Serial.available() > 0)
{
car2_place_2_go = Serial.read();
delay(5);
radio.stopListening();
radio.write(&car2_place_2_go, sizeof(car2_place_2_go));
radio.startListening();
if ( radio.available())
{
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
}
Library I use: https://github.com/nRF24/RF24