The serial print not completed

Hi,
The sketch didn't print out what asked, why?
also it doesn't receive at all, what can be?
Thanks
Adam

/* https://create.arduino.cc/projecthub/lightthedreams/nrf24l01-for-communication-1-way-and-2-way-80e65c




*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};    //Setting the two addresses. One for transmitting and one for receiving
int button_pin = 2;

boolean button_state = 0;
boolean button_state1 = 0;
int led_pin = 3;

 char dataReceived[32]; // this must match dataToSend in the TX
int ackData[2] = {109, -4000}; // the two values to be sent to the master
bool newData = false;

const char  *cmdOn = "StationCmdA1";
const char  *cmdOff = "StationCmdA2";
const char  *cmdBlink = "StationCmdAx";

//const char *msg = "hello";

void setup() {

  Serial.begin(9600);
  Serial.println("xxx_setup!");

  Serial.print("File   : "), Serial.println(__FILE__);
  const char compile_date[] = __DATE__ " " __TIME__;
  Serial.print("Compile timestamp: ");
    Serial.println(compile_date);

  pinMode(led_pin, OUTPUT);
  Serial.begin(9600);
  radio.begin();                            //Starting the radio communication
  radio.openWritingPipe(addresses[0]);      //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[1]);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MIN);            //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}

void loop()
{
  delay(5);
  radio.startListening();                    //This sets the module as receiver
  if (radio.available())                     //Looking for incoming data
  {
    // radio.read(&button_state, sizeof(button_state));

    radio.read( &dataReceived, sizeof(dataReceived) );

    Serial.println("dataReceived =");
    Serial.println(dataReceived);

    if (dataReceived == cmdOn)
    {
      digitalWrite(led_pin, HIGH);
    }
    else if (dataReceived == cmdOff)
    {
      digitalWrite(led_pin, LOW);
    }
    else
    {
      delay(2);
    }
    delay(5);

    radio.stopListening();                           //This sets the module as transmitter
    button_state1 = digitalRead(button_pin);
    radio.write(&button_state1, sizeof(button_state1));   //Sending the data
  }
}

I’m sure there’s a reason you used Serial.begin twice.

I can’t think of a reason, but go ahead, and there is always the assumption that radio.available goes true sometime.

1 Like

Great!
Thank you lastchancename.
it was a mistake.
The sketch still doesn't receive, any clue?

Is radio.available() ever true ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.