Cant get NRF24L01+ to work with Arduino Mega

I've tried to get the NRF24 Module to work with my Arduino mega by looking through a bunch of YouTube tutorials and websites on how to get 2 Arduino boards to communicate with each other wirelessly but have not had any success for about a year of trying. I've tried buying a new batch of NRF24 modules, using different jumper cables and using a 10uF capacitor to see if it was a power issue but had no success at all. I've even tried various boards such as Arduino Uno and Arduino Due but neither of them worked. I've also tried different NRF24 libraries such as ones matching the same versions in the videos and website but still wasn't able to get them to communicate to each other.

Pin Wiring from NRF24 to Arduino Mega pins:
VCC: 3.3V
GND: GND
MISO: 50
MOSI: 51
SCK: 52
CE: 9
CSN: 10

Transmitter Code:

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

RF24 radio(9, 10);
const byte address[6] = "00002";

int state = 5;

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

void loop(){
  radio.write(&state, sizeof(state));
  delay(1000);
}

Reciever Code:

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

RF24 radio(9, 10);

const byte address[6] = "00002";

int state = 0;

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

void loop(){
  
  radio.startListening();
  while(!radio.available());
  radio.read(&state, sizeof(state));
  Serial.print(state);
}

What comes out on the Serial Log of the receiver is just zeros when the transmitter should be sending an integer to the receiver and should be outputting 5 instead.

I've run into a similar issue using an ESP32-WROOM-32D and Arduino Pro Micro (8Mhz), here are the settings I found that work for me.

Libraries: nRF24L01.h & RF24.h

Transmit Settings:

// Put these inside "Setup"
 radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.
  radio.setDataRate(RF24_1MBPS);
  radio.setPayloadSize(sizeof(Payload));
  radio.setChannel(1);
  radio.enableDynamicPayloads();

Receive Settings:

// Put these inside "Setup"
  radio.setPALevel(RF24_PA_LOW);
  radio.setDataRate(RF24_1MBPS);
  radio.setPayloadSize(sizeof(payload));
  radio.setChannel(1);
  radio.enableDynamicPayloads();
  radio.openReadingPipe(1, address);
  radio.startListening();

One other thing to note, unless you are using an adapter board with the RF module, the signals going to it need to be 3.3v logic instead of 5v logic. You may want to get a Logic Level Shifter.

You will want to start with the basics using the gettingstarted sketch included with the radio library:

  1. Verify the radio can communicate with the MCU:
  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }

If you get the message "radio hardware is not responding" it means you have an issue with SPI communication to the radio. This is 99% due to incorrect wiring or bad wiring.

  1. If radio.begin() returns true, but the devices are not communicating, users can uncomment the lines printf_begin() & radio.printDetails() and view the settings. They should appear as the following:
SPI Speedz	= 10 Mhz
STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	= 0x65646f4e31 0x65646f4e32
RX_ADDR_P2-5	= 0x33 0xce 0x3e 0xe3
TX_ADDR		= 0x65646f4e31
RX_PW_P0-6	= 0x04 0x04 0x04 0x04 0x04 0x04
EN_AA		= 0x3f
EN_RXADDR	= 0x02
RF_CH		= 0x4c
RF_SETUP	= 0x03
CONFIG		= 0x0f
DYNPD/FEATURE	= 0x00 0x00
Data Rate	= 1 MBPS
Model		= nRF24L01+
CRC Length	= 16 bits
PA Power	= PA_LOW
ARC		= 5

If the settings do not appear as above, troubleshoot wiring, pin connections, etc.

See RF24/COMMON_ISSUES.md at master · nRF24/RF24 · GitHub

1 Like

robin2 nrf24 tutorial

I've tried using the code to verify if the radio can communicate and it only works on the Arduino mega board that was the transmitter but doesn't work on the other one that's listening. So, I've tried rewiring and swapping out the NRFl01 module, but it didn't fix the problem. What I did find out was when switching which board will transmit and which one receives one of the boards whether transmitting or receiving, is printing out the error: "radio hardware not responding." Not sure how this happens but it could just be a defective board. I will try using an Arduino uno just to see if it was really just a bad board.

Can you take a picture of your setup?

Problem solved, I was able to get NRF communication to work between an Arduino Uno and Mega. Turns out one of my Arduino Mega boards was not working correctly even though it was powered and able to receive code. The first Arduino Mega board that works came from the Sunfounder company while the faulty second one came from Elegoo. Both boards seem to be identical but on top of the board the Sunfounder chip has the print, Atmel Atmega2560 16u-TW 355E3F 1819V47 while the Elegoo chip has, Atmel Atmega2560 16U-TH 355E3F 2303Z1X. My guess is that the MISO MOSI and SCK pins are different on the Elegoo Arduino Mega Board.

1 Like

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