Can't use arduino mega for nrf24l01+

I have tried to make communication with arduino mega and a nano.
even if the transmitter not available arduino mega as a receiver get garbage data like ??????????
I have disconnected the nrf24l01 module but still mega is showing empty data in the serial monitor.
I have debug the code by writing if radio available then show data.
and now it showing data in infinite loop in the serial monitor.

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

RF24 radio(9, 53); // CE, CSN

const byte address[6] = "00001";

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

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

Is there any solution or any way to check this.
I have bought a new mega but still it is same

Which pins did you use on the MEGA2560 for the SPI signals (MOSI, MISO & SCK)?

Have you tried the CheckConnection sketch from post #30 in the nRF24L01 tutorial here:

I have used CE-9, CSN-53
SCK-52
MISO 50
MOSI 51

Those are the correct pins for the SPI interface. How are you powering the nRF24L01+ module?

Did you try the CheckConnection sketch? Post the output of the sketch here if you are unsure about the wiring.

How to use CheckConnectionSketch.
I didn't get that.

// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}

this code showing "Data received" again and again
without connecting the nrf
just uploading the code to mega showing this
how it is getting radio signal I don't know

Go to the tutorial I linked to in post #2. Scroll down that tutorial until you get to post #30. In post #30 there is a sketch called CheckConnection.ino. You will need to modify it for your CE & CSN pins but it should run ok after that. It will print out some information from the nRF24L01 module that will indicate if the sketch is communicating with the module.

From my recollections, that doesn't look right.

I could be wrong here but I think there were some discussions a while back around an update to the nRF24L01 library. I wonder if there is an incompatibility between the demos and the latest library.

Hopefully one of the other form members who has more knowledge than me will jump in and advise you further.

yeah you are right.
nrf is not communicating with mega properly
every time I open the serial monitor is shows different value then previous.
and some address are also 0x00
so there is an issue.
Do you have any idea to solve this.

I have checked the connection and wiring with continuity test.
seems ok to me.
but what is the issue with that I don't know.
and its a new mega

Do you have any details on that little interface board. Presumably it is generating the 3.3V for the nRF24L01+ from the MEGA 5V?

Did you do this in the CheckConnection.ino sketch:

You could try and swap over the CE and CSN pins in case that little interface board has got them the wrong way round.

Those modules give a lot of people problems when powered with an Arduino, the solution most of the time is to use an external power supply. You will find many kludges such as adding capacitors etc, none are 100%.

Doesn't work - you must never call read on more characters than you know are in the buffer. Perhaps you meant:

    if ( radio.available() >= sizeof(dataReceived)) {
        radio.read( &dataReceived, sizeof(dataReceived) );


with ce 9 and csn to 53
after setting ce to 53 and csn to 9 in sketch
then each time I open serial monitor it shows either 0x08 to all
or 0xc5 to all
but not constant..
but with ce 9 and csn 53 it defaults to 0x08.

is this normal?

Ok. It seems that CE and CSN were the correct way round to begin with. Your post above shows that the data rate reported back hasn't changed. Your post #10 at least appears to show the reported data rate has changed.

I've not used nRF24L01 modules for a while now, but as I mentioned earlier, I think there might have been a library update that broke some of the early examples.

There are other forum members that have more recent experience of the nRF24L01 and they may be able to advise you further.

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