# Error in program for Nrf24L01

**URL:** <https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741>\
**Category:** Programming\
**Created:** [April 11, 2023, 9:32am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741 "2023-04-11T09:32:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 11, 2023, 9:32am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/1 "2023-04-11T09:32:15Z")

</div>

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):

```cpp
#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:

```cpp
#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):

```cpp
#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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 11, 2023, 9:40am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/2 "2023-04-11T09:40:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 11, 2023, 9:46am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/3 "2023-04-11T09:46:11Z")

</div>

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

```

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

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 11, 2023, 9:48am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/4 "2023-04-11T09:48:09Z")

</div>

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`_

---

<div class="post-metadata">

**Author:** ![Whandall](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/whandall/32/222457_2.png) [@Whandall](https://forum.arduino.cc/u/Whandall)\
**Post date:** [April 11, 2023, 10:05am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/5 "2023-04-11T10:05:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 11, 2023, 10:54am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/6 "2023-04-11T10:54:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 11, 2023, 2:38pm UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/7 "2023-04-11T14:38:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 11, 2023, 2:39pm UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/8 "2023-04-11T14:39:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Whandall](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/whandall/32/222457_2.png) [@Whandall](https://forum.arduino.cc/u/Whandall)\
**Post date:** [April 11, 2023, 3:30pm UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/9 "2023-04-11T15:30:13Z")

</div>

> [@hkg-kingley](#):
>
> But I did include it in the void setup already

> [@hkg-kingley](#):
>
> ```arduino
> void setup()
> {
> Serial.begin(9600);
> radio.begin();
> radio.openWritingPipe(abc);
> }
> 
> ```

With invisible ink?

---

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 13, 2023, 2:01am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/10 "2023-04-13T02:01:41Z")

</div>

Still, there is a error  
Error message:

```cpp
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.

```

---

<div class="post-metadata">

**Author:** ![hkg-kingley](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hkg-kingley/32/947020_2.png) [@hkg-kingley](https://forum.arduino.cc/u/hkg-kingley)\
**Post date:** [April 13, 2023, 2:03am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/11 "2023-04-13T02:03:30Z")

</div>

New version of code:

```cpp
#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");
  }
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 13, 2023, 6:31am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/12 "2023-04-13T06:31:58Z")

</div>

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

```

As previous noted

> [@UKHeliBob](#):
>
> The read() function does not return a value, hence the error

> [@sterretje](#):
>
> 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`_

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 13, 2023, 7:52am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/13 "2023-04-13T07:52:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 13, 2023, 8:00am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/14 "2023-04-13T08:00:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 10, 2023, 8:01am UTC](https://forum.arduino.cc/t/error-in-program-for-nrf24l01/1113741/15 "2023-10-10T08:01:17Z")

</div>

Closed on October 10, 2023, 8:01am UTC

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