Arduino Mega 2560 Receiving Issue with nRF24L01

Hello,

I have been using a Mega as a transmitter and an ESP32 as a receiver using the nRF24L01 modules. This has been working fine. Yesterday, I wanted to follow @Robin2's tutorials for bidirectional communication and I just couldn't get the Mega to receive anything. I've seen people mention power issues and wiring and I've double checked everything but I still can't seem to get this to work. I'm trying out simple 1-way communication now where the ESP32 is the transmitter and the Mega is the receiver (the opposite works just fine). Attached below is my code.

// Transmitter (ESP32)

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

RF24 radio(4, 5); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  Serial.println(text);
  delay(1000);
}
// Receiver (Mega)

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

RF24 radio(7, 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.startListening();
}

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

I've tried changing the CE and CSN pins on the Mega but still nothing. I also have a 10uF cap soldered between VCC and GND on both modules (this is what had solved my initial nRF issues). For the RF module attached to the Mega, I am powering it from the 3.3 V pin and connecting the other pins directly to the Mega since I read online that those pins could tolerate 5 V. I'd really appreciate any and all advice. Thank you!

You don't check the return status of radio.begin(), nor do you call radio.isChipConnected().

radio.printDetails() would be full of great debugging info. But you don't call it.

You don't check the return status of radio.write().

You never look at radio.failureDetected to see if the library has detected a fault.

The library gives you all kinds of great tools to assist in debugging communication problems.

You don't appear to be using any of them.

You might want to rethink that approach.

Just to dismiss the obvious, but which pins on the MEGA2560 board are you connecting to for your MOSI, MISO & SCK signals?

On the Mega2560, I'm using the following:

MOSI > pin 51
MISO > pin 50
SCK > pin 52

I've tried radio.printDetails() - just don't have it in the attached code.

I'm still relatively new to these modules so I'm still learning as I go. I will test out the other ones you've mentioned.

So I've run into a bit of a strange situation. Initially radio.printDetails worked for the Mega and everything looked good. The radio.write returned 0 for the ESP32. Now, radio.printDetails shows me only 0s for both devices. Tried a simple 1-way communication sketch with Mega as the transmitter and the ESP32 as the receiver and things are still working. Not sure what's causing this.

I have it in my notes here that the nRF24 boards I have crap out with anything above a 15MHz SPI clock. And since 99.99% of all these modules have been... let's say "free enterprise" versions and not the real thing for well over a decade now, I wouldn't be surprised in the least if some of them were even less able to operate at higher speeds.

TL,DR: try dropping your SPI clock frequency on the nRF24 transactions.

That's good to know. The radio.printDetails for both show SPI frequency as 10 MHz so that should be fine I'd think. Attaching what I'm seeing below.

// ESP32

SPI Speedz	= 10 Mhz
STATUS		= 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1	= 0x0000000000 0x0000000000
RX_ADDR_P2-5	= 0x00 0x00 0x00 0x00
TX_ADDR		= 0x0000000000
RX_PW_P0-6	= 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA		= 0x00
EN_RXADDR	= 0x00
RF_CH		= 0x00
RF_SETUP	= 0x00
CONFIG		= 0x00
DYNPD/FEATURE	= 0x00 0x00
Data Rate	= 1 MBPS
Model		= nRF24L01
CRC Length	= Disabled
PA Power	= PA_MIN
ARC		= 0
// Mega

SPI Speedz	= 10 Mhz
STATUS		= 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1	= 0x0000000000 0x0000000000
RX_ADDR_P2-5	= 0x00 0x00 0x00 0x00
TX_ADDR		= 0x0000000000
RX_PW_P0-6	= 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA		= 0x00
EN_RXADDR	= 0x00
RF_CH		= 0x00
RF_SETUP	= 0x00
CONFIG		= 0x00
DYNPD/FEATURE	= 0x00 0x00
Data Rate	= 1 MBPS
Model		= nRF24L01
CRC Length	= Disabled
PA Power	= PA_MIN
ARC		= 0

Also, radio.isChipConnected is 0 for both...

And that explains why printDetails is showing all 0s. No communication.

Yes, which is baffling. I don't get how a basic 1 way sketch is still working...

Go back to the library examples. Got one of those to work? Add in all the error checks you can. Still works? Add bits from your program that fails one at a time until the modified example fails too. Then the real head scratching begins.

But don't discount the possibility of a failing breadboard, bad hookup wires, or just plain iffy nRF24s.

That's what I'm doing, running through every possibility here hoping it'll be something small that I've missed.

Looking at power issues as well. I have the nRF24 adapters - I'll give those a try and try switching to independent power supply. Thanks for your assistance. I will update if and when I find a solution.

I've never used the power adapters. I've always gone with a dedicated LP2950 or L4931 (that I've bought from Digikey) with appropriate caps on input and output.

1 Like

I'll look into those. I haven't so far because the 10 uF cap I soldered on made them work and I was happy with things. Hoping I'm able to resolve this soon.

Update: SOLVED!

It was a power issue. Many others have recommended using independent power supplies for these antennas. I powered up both antenna modules through an external power supply and that did it for me. While following @Robin2's tutorials on bidirectional comms, an issue I faced was that the Mega would initially start receiving but after 2 or 3 messages, it would fail - not sure what was causing that. I then went ahead and set up even more basic sketches and things finally worked. In case anyone's interested, I've attached my working code below.

// Transmitter (Mega)

#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.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.enableAckPayload();
}

void loop() {
  const char text[] = "Hello ESP32";
  radio.write(&text, sizeof(text));

  if (radio.isAckPayloadAvailable()) {
    char ackData[32] = "";
     radio.read(&ackData, sizeof(ackData));
     Serial.println(ackData);
  }
  // delay(1000);
}

// Receiver (ESP32)

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

RF24 radio(4, 5); // CE, CSN

const byte address[6] = "00001";

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

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

    const char ackData[] = "Hello Mega";
    radio.writeAckPayload(0, &ackData, sizeof(ackData));
  }
}

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