Need help with nRF24L01 module code

Getting these errors:

D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino:14:11: error: redefinition of 'RF24 radio'
 RF24 radio(7, 8); // CE, CSN
           ^
D:\1. Documents\Arduino\NRF_tx\NRF_tx.ino:14:6: note: 'RF24 radio' previously declared here
 RF24 radio(7, 8); // CE, CSN
      ^~~~~
D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino:16:21: error: redefinition of 'const byte address [6]'
 const byte address[6] = "00001";
                     ^
D:\1. Documents\Arduino\NRF_tx\NRF_tx.ino:16:12: note: 'const byte address [6]' previously defined here
 const byte address[6] = "00001";
            ^~~~~~~
D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino: In function 'void setup()':
D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino:18:6: error: redefinition of 'void setup()'
 void setup()
      ^~~~~
D:\1. Documents\Arduino\NRF_tx\NRF_tx.ino:18:6: note: 'void setup()' previously defined here
 void setup()
      ^~~~~
D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino: In function 'void loop()':
D:\1. Documents\Arduino\NRF_tx\NRD_rx.ino:27:6: error: redefinition of 'void loop()'
 void loop()
      ^~~~
D:\1. Documents\Arduino\NRF_tx\NRF_tx.ino:26:6: note: 'void loop()' previously defined here
 void loop()
      ^~~~

exit status 1

Compilation error: redefinition of 'RF24 radio'

I downloaded the official library from link below as zip and imported it in the official project.

I am using the newest IDE 2.0.3 for arduino.

Here is the code:

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

The error messages tell you exactly what is wrong. You are declaring multiple objects with the same names and scopes. Don't do that. You can't have more than one setup loop loop funions, to start.

Hey,

I just updated the post with the code.. I am following a basic tutorial. This is what the code suggests. What is the correct way to do this instead? Thanks.

Edit: I used example code from official git

And still get the same error!! Any help is welcome ..

I think you have somehow rx and tx sketch in the same folder.

1 Like

You are correct.. a different file was giving issues?! I am used to having all my project files in one folder. What is the proper way to do this?

The Arduino IDE expects each project in its own folder, named like the main project ino,
without the ino extension.
All ino files in that directory will be combind to a single file before compilation.

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