0

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

  • Probably you are waiting too long between sending the message and listening for data, so you're only getting the data on the next radio transmission. See my answer to your other nRF24 question. It looks like you can use ACK payload to send and receive data in the same radio transaction. Please remember to upvote or accept the answer if correct. – MichaelT Jun 2 '18 at 10:00
  • From the code it looks like the slave keeps repeatedly sending the serial data. Shouldn’t it only sent it once? – Gerben Jun 2 '18 at 12:21
0

i found the problem is that the receiver in the slave doesn't see what send to it until the next loop and that mean it need a delay so it can see what transmit to it so i add this while loop in the slave so the slave doesn't exit the "void loop" function until it get the message from the master

slave

 radio.startListening();

    while(! radio.available())
    {

    }
    if ( radio.available()) 
    {
        char text[32] = "";
        radio.read(&text, sizeof(text));
        Serial.println(text);
     }
  • you should accept your own answer. – esoterik Aug 2 '18 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.