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