Arduino NRF24

Greetings,
I am currently working on a project that involves two Arduino Mega 2560 boards that communicate wirelessly. I purchased a set of 3 Longrunner 2.4GHz NRF24L01+Pa+LNA modules online, and have tried following numerous tutorials to get any indication of communication between the two boards. Both of the boards are set up identically with regards to wiring:

3.3v from Mega to V+ on RF24
GND to GND
CSN on RF24 to Mega pin 8
CE on RF24 to Mega pin 7
MOSI on RF24 to Mega pin 52
SCK on RF24 to Mega pin 51
MISO on RF24 to Mega pin 50

So far I have not been able to get anything to work, and am wondering if the sample code I am using is not formatted correctly, or if I have incorrectly wired the RF24 modules. I am using the TMRh20 RF24 library version 1.3.9, and have included pictures of the transmit and receive sample codes as well as pictures of the wiring. Any help would be appreciated.

Thanks,

Mike

Edit: There were inconsistencies in what I typed and what was wired, the wiring is now identical to what was typed, and still no results.

Board.jpg

Recieve.png

Send.png

Board.jpg

Recieve.png

Send.png

Here's the problem:

3.3v from Mega to V+ on RF24

That only sources ~ 150mA. nrf24L01+ transmitter needs more.
Adding 10uF cap from 3.3V to Gnd on the nrf board may allow bursts of transmissions to be sent out.

Like CrossRoads says, lack of power is about the number one problem with the RF24 radios.

Having the high power modules close together can be a problem, too. Once you get the power problem sorted, move them at least a couple meters apart and try.

I found Robin2's simple rf24 tutorial very helpful.

Please read the forum guidelines to see how to properly post code. Images of code are hardly useful.

Thank you both for the input, I did manage to get the circuit to send some signals to the other board but would only register about 2/10 to 6/10 of the signals sent depending on the antenna placement. I am not extremely familiar with RF but I was wondering if it was possible that the router and NRF modules have some interference as they are both 2.4GHz, or is the problem most likely a power issue?

The most likely problem is power to the modules. I have been using rf24 modules for years and never have I had trouble if they are powered properly. I always provide 3.3V power with a 3.3V regulator dedicated to the radio module. You can buy adapters that have a regulator on them.

I have never seen any evidence of interference with or from my WiFi router.

Transmit

// SimpleTx - the master or the transmitter

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


#define CE_PIN   7
#define CSN_PIN 8

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


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

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

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

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

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

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

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

Recieve

// SimpleRx - the slave or the receiver

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

#define CE_PIN   7
#define CSN_PIN 8

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;
    }

}

I added the 3.3V regulators that groundFungus recommended, and I am using the two sample codes from above to transmit and receive, same as before. Originally I was only getting the occasional "Acknowledge Received" in the transmit serial monitor, with the corresponding number in the receive serial monitor. This is what I am currently getting and I am extremely confused. I have triple checked all wire connections and they are the same as before, and I have recompiled and restarted each Arduino board countless times now.

Any suggestions?

Rx.jpg

Tx.jpg

Rx.jpg

Tx.jpg

Mscampbell7:
Any suggestions?

If the Data received is repeating quickly (more than once per second) it usually means that the Arduino is not communicating with the nRF24 it is attached to. This is usually due to a wiring error or loose connection.

Try the connection test program in my Tutorial.

...R

After you upload code to the Arduino, power the Arduino (and attached radio) down and back up. The radio does not reset with the Arduino reset, but a power cycle will reset the radio.

Did you move the radio modules apart? How far?

I have rewired it multiple time and confirmed that all of the wirings is correct. The receive arduino serial monitor, no matter what I do, says that data is received but it is not recording any information.

Did you try the reset? Did you move them apart?

Did you try the connection test program from page 2 of Robin2's tutorial? Can you post the results?

It would work better if you would let us know if you try our suggestions and tell us what happened.

This is the results from the test program:

23:46:34.637 -> CheckConnection Starting
23:46:34.637 -> 
23:46:34.637 -> FIRST WITH THE DEFAULT ADDRESSES after power on
23:46:34.683 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
23:46:34.777 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
23:46:34.871 ->      communicating with the nRF24
23:46:34.917 -> 
23:46:34.917 -> SPI Speedz	 = 10 Mhz
23:46:34.917 -> STATUS		 = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
23:46:34.964 -> RX_ADDR_P0-1	 = 0x0000000000 0x0000000000
23:46:35.011 -> RX_ADDR_P2-5	 = 0x00 0x00 0x00 0x00
23:46:35.059 -> TX_ADDR		 = 0x0000000000
23:46:35.105 -> RX_PW_P0-6	 = 0x00 0x00 0x00 0x00 0x00 0x00
23:46:35.151 -> EN_AA		 = 0x00
23:46:35.151 -> EN_RXADDR	 = 0x00
23:46:35.198 -> RF_CH		 = 0x00
23:46:35.198 -> RF_SETUP	 = 0x00
23:46:35.198 -> CONFIG		 = 0x00
23:46:35.244 -> DYNPD/FEATURE	 = 0x00 0x00
23:46:35.244 -> Data Rate	 = 1MBPS
23:46:35.290 -> Model		 = nRF24L01
23:46:35.290 -> CRC Length	 = Disabled
23:46:35.336 -> PA Power	 = PA_MIN
23:46:35.336 -> 
23:46:35.336 -> 
23:46:35.336 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
23:46:35.428 ->  and 250KBPS data rate
23:46:35.428 -> 
23:46:35.428 -> SPI Speedz	 = 10 Mhz
23:46:35.474 -> STATUS		 = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
23:46:35.521 -> RX_ADDR_P0-1	 = 0x0000000000 0x0000000000
23:46:35.566 -> RX_ADDR_P2-5	 = 0x00 0x00 0x00 0x00
23:46:35.614 -> TX_ADDR		 = 0x0000000000
23:46:35.614 -> RX_PW_P0-6	 = 0x00 0x00 0x00 0x00 0x00 0x00
23:46:35.660 -> EN_AA		 = 0x00
23:46:35.705 -> EN_RXADDR	 = 0x00
23:46:35.705 -> RF_CH		 = 0x00
23:46:35.751 -> RF_SETUP	 = 0x00
23:46:35.751 -> CONFIG		 = 0x00
23:46:35.751 -> DYNPD/FEATURE	 = 0x00 0x00
23:46:35.796 -> Data Rate	 = 1MBPS
23:46:35.796 -> Model		 = nRF24L01
23:46:35.843 -> CRC Length	 = Disabled
23:46:35.843 -> PA Power	 = PA_MIN
23:46:35.890 -> 
23:46:35.890 ->

I do apologize that I have been a little spotty with my posts and consistency, I'm in the middle of finals week right now.

I understand that the connection is not working properly (as interpreted by the amount of 0x00 messages) , could this be a USB problem or an Arduino board problem. I have tried this test code with multiple NRF24 chips (including the one I can confirm is working correctly) and it does not work with any of them. I also tried multiple combinations of the nrf24 chips and the 3.3v regulators.

With regards to the other post I made earlier, I tried the reset and moving them closer/further apart with no luck.

Mscampbell7:
This is the results from the test program:

You can see that the data rate has not changed which suggests that the Arduino is not communicating with its nRF24.

When that has happened to me it has always been because I got the connections mixed up.

Of course it is possible that the nRF24 is faulty.

Until the connection test program works there is no point trying anything else.

...R

Some days I wonder if I can actually read. All of the pins were wired correctly, except the V+ pin for the 3.3v regulator was connected to the 3.3v output, rather than the 5v. I am mildly amused and embarrassed at the same time, so I do apologize for asking a bunch of questions without confirming that what I had wired was entirely correct.

This is the test result from the first board:

16:54:35.383 -> CheckConnection Starting
16:54:35.429 -> 
16:54:35.429 -> FIRST WITH THE DEFAULT ADDRESSES after power on
16:54:35.476 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
16:54:35.570 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
16:54:35.617 ->      communicating with the nRF24
16:54:35.664 -> 
16:54:35.664 -> SPI Speedz	= 10 Mhz
16:54:35.709 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
16:54:35.756 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
16:54:35.803 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
16:54:35.850 -> TX_ADDR		= 0xe7e7e7e7e7
16:54:35.897 -> RX_PW_P0-6	= 0x00 0x20 0x00 0x00 0x00 0x00
16:54:35.897 -> EN_AA		= 0x3f
16:54:35.944 -> EN_RXADDR	= 0x03
16:54:35.944 -> RF_CH		= 0x4c
16:54:35.989 -> RF_SETUP	= 0x07
16:54:35.989 -> CONFIG		= 0x0e
16:54:35.989 -> DYNPD/FEATURE	= 0x00 0x00
16:54:36.036 -> Data Rate	= 1MBPS
16:54:36.036 -> Model		= nRF24L01+
16:54:36.083 -> CRC Length	= 16 bits
16:54:36.083 -> PA Power	= PA_MAX
16:54:36.130 -> 
16:54:36.130 -> 
16:54:36.130 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
16:54:36.177 ->  and 250KBPS data rate
16:54:36.224 -> 
16:54:36.224 -> SPI Speedz	= 10 Mhz
16:54:36.224 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
16:54:36.317 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
16:54:36.317 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
16:54:36.364 -> TX_ADDR		= 0xe7e7e7e7e7
16:54:36.410 -> RX_PW_P0-6	= 0x00 0x20 0x00 0x00 0x00 0x00
16:54:36.457 -> EN_AA		= 0x3f
16:54:36.457 -> EN_RXADDR	= 0x03
16:54:36.504 -> RF_CH		= 0x4c
16:54:36.504 -> RF_SETUP	= 0x27
16:54:36.504 -> CONFIG		= 0x0e
16:54:36.549 -> DYNPD/FEATURE	= 0x00 0x00
16:54:36.594 -> Data Rate	= 250KBPS
16:54:36.594 -> Model		= nRF24L01+
16:54:36.641 -> CRC Length	= 16 bits
16:54:36.641 -> PA Power	= PA_MAX
16:54:36.641 -> 
16:54:36.641 ->

This is the test result from the second board:

16:53:02.735 -> CheckConnection Starting
16:53:02.735 -> 
16:53:02.735 -> FIRST WITH THE DEFAULT ADDRESSES after power on
16:53:02.782 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
16:53:02.875 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
16:53:02.969 ->      communicating with the nRF24
16:53:03.014 -> 
16:53:03.014 -> SPI Speedz	= 10 Mhz
16:53:03.014 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
16:53:03.060 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
16:53:03.107 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
16:53:03.154 -> TX_ADDR		= 0xe7e7e7e7e7
16:53:03.201 -> RX_PW_P0-6	= 0x00 0x20 0x00 0x00 0x00 0x00
16:53:03.248 -> EN_AA		= 0x3f
16:53:03.248 -> EN_RXADDR	= 0x03
16:53:03.295 -> RF_CH		= 0x4c
16:53:03.295 -> RF_SETUP	= 0x07
16:53:03.295 -> CONFIG		= 0x0e
16:53:03.342 -> DYNPD/FEATURE	= 0x00 0x00
16:53:03.342 -> Data Rate	= 1MBPS
16:53:03.387 -> Model		= nRF24L01+
16:53:03.387 -> CRC Length	= 16 bits
16:53:03.433 -> PA Power	= PA_MAX
16:53:03.433 -> 
16:53:03.433 -> 
16:53:03.433 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
16:53:03.480 ->  and 250KBPS data rate
16:53:03.526 -> 
16:53:03.526 -> SPI Speedz	= 10 Mhz
16:53:03.573 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
16:53:03.619 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
16:53:03.665 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
16:53:03.712 -> TX_ADDR		= 0xe7e7e7e7e7
16:53:03.712 -> RX_PW_P0-6	= 0x00 0x20 0x00 0x00 0x00 0x00
16:53:03.758 -> EN_AA		= 0x3f
16:53:03.805 -> EN_RXADDR	= 0x03
16:53:03.805 -> RF_CH		= 0x4c
16:53:03.805 -> RF_SETUP	= 0x27
16:53:03.852 -> CONFIG		= 0x0e
16:53:03.852 -> DYNPD/FEATURE	= 0x00 0x00
16:53:03.899 -> Data Rate	= 250KBPS
16:53:03.899 -> Model		= nRF24L01+
16:53:03.946 -> CRC Length	= 16 bits
16:53:03.946 -> PA Power	= PA_MAX
16:53:03.992 -> 
16:53:03.992 ->

I did manage to test the original code and was not able to get the two boards to communicate.

Mscampbell7:
I did manage to test the original code and was not able to get the two boards to communicate.

The two connection tests are showing success, but they do not test the wireless.

If it was my problem I would temporarily power the nRF24s from a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

I would also make sure the high-power modules are separated by about 3 metres.

And it is a good idea to have some spare nRF24s in case one of them faulty.

...R

Good afternoon,
last night I ran a test from two laptops from across the room and was able to get the receive Arduino to count from 0 to 9 in time the appropriate time intervals. I got the same results this morning, but now the transmit says fail and the receive says it keeps receiving zero over and over. During control testing last night, we found that the angle of the antenna was the difference between passing and failing, and along with this moving the antenna away from the Arduino was far more successful in sending and receiving 100% of the time. Is there a recommended distance from the board, as well as antenna angle?

Thanks,

Mike

Mscampbell7:
Is there a recommended distance from the board, as well as antenna angle?

I have no experience with the high-power nRF24s and I have never noticed any special requirement for orienting the low-power modules when operating within the distance of a room.

I think it would if you provide a photo of your arrangements and tell us how far apart the wireless modules are.

It might also help, if you are working over a short distance, to set the power level to low. I think the default is high power.

...R

PS ... I recommend that you do your initial testing with a pair of low-power modules. The software will be identical so, if something works with the low power modules but not with the high power modules it will help to pinpoint the problem.

Sorry, it has been so long since I have posted, the holidays have been crazy. The current setup is included in a video and was tested at both PA_MAX and PA_MIN, roughly 6 feet apart.

Here is the link to the test video:

The problem with leaving a long interval between replies is that I have completely forgotten about your project.

A drawing or a still photo would have been better for showing the orientation of the radios and the video did not stay long enough on the PC screen to provide any useful insight.

Have you dismantled and re-assembled your Arduinos and nRF24s since the working test that you reported in Reply #14 ?

What is powering the nRF24s? Have you tried my suggestion of using batteries?

Have you tried the connection tests with your present setup?

Have you some spare nRF24s?

...R

I have included five pictures of my current setup, with the boards placed roughly 8.5 feet apart. Since the last test, I have not changed the wiring configuration of either board nor has it been disassembled and reassembled. I have tried powering the nRF24s directly from the Arduino, as well as directly from the Arduino with 10µF capacitors, and I am currently powering them with 3.3V regulator chips (link provided below). I have swapped out the nRF24s numerous times on either side, as well as the 3.3V regulator chips and have the same problem regardless.

3.3V Regulator Chips:

Current pin connections for each board:

[Arduino Pin]
[Voltage Regulator]
5V
V+
GND
GND
9
CE
10
CSN
50
MISO
51
MOSI
52
SCK

(The code was modified for the CE and CSN pins)
In each test run, regardless of the result in the serial monitor, on both sides, the tx light on the transmitting Arduino and the rx light on the receiving Arduino blinked at the same time.
Additionally, the only code that was changed from time to time was the "txIntervalMillis". This was to confirm that the rx light was indeed blinking at the same rate as the tx light, rather than running off its own timer. Each side blinked at the same time with two scenarios as the result.

Scenario 1:

[Tx Serial Monitor]
[Rx Serial Monitor]
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0

Scenario 2:

[Tx Serial Monitor]
[Rx Serial Monitor]
Tx failed
Acknowledge received 0
Tx failed
Acknowledge received 0
Acknowledge Received
Acknowledge received 1
Tx failed
Acknowledge received 1
Acknowledge Received
Acknowledge received 2
Acknowledge Received
Acknowledge received 3
Acknowledge Received
Acknowledge received 4
Acknowledge Received
Acknowledge received 5
Tx failed
Acknowledge received 5
Tx failed
Acknowledge received 5
Tx failed
Acknowledge received 5
Acknowledge Received
Acknowledge received 6
Acknowledge Received
Acknowledge received 7
Tx failed
Acknowledge received 7
Acknowledge Received
Acknowledge received 8
Acknowledge Received
Acknowledge received 9
Acknowledge Received
Acknowledge received 0

Debugging a wireless system can be very tedious and it must be done in a systematic way with every minor change carefully noted.

I'm not sure where to start.

The Arduino Tx and Rx lights are completely irrelevant - they are not part of the wireless communication system. Just ignore them.

The second block of text output suggests that some of the messages are getting through and others are not. But you have not said whether that is a routine behaviour or whether it only happened on one occasion and all the others showed no successful communication.

If the part-successful communication is routine (i.e. every time you try the system it behaves like that) then it seems that the Arduinos and the nRF24s are working properly. That intermittent failure might be due to external interference from some other 2.4GHz equipment, such as WiFi.

If the part-successful communication is rare then you may need to consider the following

It seems to me unlikely that you left all that gear on the table untouched since the successful test that you reported in Reply #14 and if not, what did you do?

You say "I have swapped out the nRF24s numerous times on either side". What exactly does that mean. Do you have several nRF24s - if so, how many, and are they all HIGH power modules?

Did you run the connection test program after every change of nRF24?

Also you say "swapped out ... as well as the 3.3V regulator chips". But have you tried my suggestion to use batteries instead of those regulators?

Have you a pair of low power nRF24 modules that you can try? The software will be identical.

...R