Error in program for Nrf24L01

Hi everyone,
I recently want to test the function of my Nrf24L01 board
However, it does not work as expected
if I write the program like this, it will shows"error: void value not ignored as it ought to be(at the "done = radio.read( data, sizeof(data) );" part)"
Program(Receiving):

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

char data[50] = "";

void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();;
}

void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( data, sizeof(data) );
Serial.print("Received!");
Serial.println(data);
}
}
else
{
Serial.println("No radio available");
}
}

I did try fixing this problem. However, when I change the code like this, it cannot receive any data:
Program:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

char data[50] = "";

void setup()
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();;
}

void loop()
{
  bool done = false;
  while (radio.available() && !done)
  {
    radio.read(data, sizeof(data));
    Serial.print("Received!");
    Serial.println(data);
    done = true;
  }

  if (!done)
  {
    Serial.println("No radio available");
  }
  delay(1000);
}

Program(Transmit):

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t abc = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);
char data[] = "Hello World, KinCony";

void setup()
{
   Serial.begin(9600);
   radio.begin();
   radio.openWritingPipe(abc);
}

void loop()
{
   Serial.print("Sent!")
   radio.write( data, sizeof(data) );
   
}

I just don't know how to fix, I have been debugging for 6 hours already
Hope you guys can help me!
Love you guys so much <3

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

      done = radio.read( data, sizeof(data) );

The read() function does not return a value, hence the error

The prototype of the read method is void read(void* buf, uint8_t len);. So it does not return a value. You however assign the non-existing return value to the variable done

It is caused by using old sample code for the new library.

So there is also a missing radio.stopListening(); call
in the setup of the transmitter sketch, which the new library needs.

:o
I will try it later
If there is error again, I will call for help again
Thanks <3

But I did include it in the void setup already
is there any other solution?

I did know it already
so I did change something
However, it cannot receive anything but spamming "No radio available", which I was set to print if there is no signal received

With invisible ink?

Still, there is a error
Error message:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

C:\Users\20191432\Desktop\IDK\IDK.ino: In function 'void loop()':

IDK:33:45: error: void value not ignored as it ought to be

       done = radio.read( data, sizeof(data) );

                                             ^

exit status 1

void value not ignored as it ought to be



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

New version of code:

#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

char data[50] = "";

void setup()
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  radio.stopListening();
}

void loop()
{
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
      done = radio.read( data, sizeof(data) );
      Serial.print("Received!");
      Serial.println(data);
    }
  }
  else
  {
    Serial.println("No radio available");
  }
}
      done = radio.read( data, sizeof(data) );

As previous noted

I know; I was typing mine while you posted yours. As mine had a tiny more detail, I left it :wink:

No problem, but even with more details @hkg-kingley has not heeded the advice

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