I cant get consistent communication between two nRF24L01 modules,

For the past week I have tried to connect two arduinos wirelessly using the nRF24L01 modules. The modules are the ones with the antenna and breakout board.

I have followed various different tutorials, the last one being Robin2's tutorial. I have managed successful communication twice over the past week, but I with different tutorials. I also have not been able to recreate the communication.
Here is the current code I'm using for the transmitter:

// SimpleTx - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

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 = 1000; // 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;
}

And here is the current code I am using for the receiver:

// 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 is the current communication, which is none.
Screenshot 2024-08-30 at 23.35.35

I have new parts coming in in a few, incase it is a hardware issue. However, I doubt that since I did get them to communicate. I have no idea what the issue is right now, and hope one of you can help me out here.

Nice pictures post an annotated schematic showing all power sources. This is not a unique problem on this forum.

I write only to be sure they all said provide adequate power and filtering for the radios, and they all said to have them separated quite well during testing so they don't overwhelm one the other.

And that you heeded such advices.

a7

1 Like

Hello gewinner1001

Welcome to the world's best Arduino forum ever.

I have been following the topic of using this type of wireless module and the associated software functions for some time now.

For wireless projects, I recommend using the HC12 module.

What are the advantages:

  1. no external functions from a library are needed.
  2. the development of a communication protocol is in your hands
  3. the necessary development steps can be programmed and tested without using the wireless module
  4. the radio module can be easily configured for the project requirements
  5. both transmitter and receiver are contained in one radio module.

hth

Have a nice day and enjoy coding in C++.

it is a good idea after radio.begin() to check if the SPI connection is OK, e.g.

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("\n\nNRF24L01 transmit text");
  radio.begin();
  if (radio.isChipConnected())
    Serial.println("Transmitter NF24 connected to SPI");
  else Serial.println("NF24 is NOT connected to SPI");

what microcontroller are you using?

Edit: recommendation by @paulpaulson of using a HC-12 is worth consideration - in addition to the advantages outlined in post 4 there is the reduction in interconnections which will reduce the problems of poor connections, e.g. the NRF24 requires eight connections the HC-12 only four

There are many clone devices from obvious places that are not worth a cracker.
Tx Rx too close, too far, data rate set too high, not enough battery power, list goes on and on and sadly there is very little to identify the dodgy ones other that where you actually buy them from and after they arrive in your hands. (check details on the web)
You have used the appropriate regulator adaptor though which is a plus.
No mention of what you use for power and no circuit diagram sadly a big minus.

All one can do is follow Robin2's instructions to the letter, start with basic data and work it out from there.

To answer @alto777 , I have done what the tutorials said, like distance, power and filtering. The tutorials I used said, that there was no need for a separate power source, and that the breakout board works fine as filtering.

The board I am using for this is the Arduino Nano. I have attached two pictures, one is a picture of the connection, and the other is a drawn schematic. I just use the normal 5V power from the arduino, as again the tutorials have said it should be fine. Same reason, as to why I don't have a capacitor connected.


I have also tried @horace idea of doing an SPI check, and that came back good.

I also want to add, that the two times I did manage to connect the two arduinos, it worked flawlessly. Data was being sent from one arduino to the other without issues. Only when I tried it again after tweaking the code, or just loading the code again, it would work. Same when unplugging and plugging them back in.

I guess I could try the HC-12, but right now I already have bought new nRF24L01 modules, and would rather have them work than buy new modules now. If nothing helps, I will switch.

Your success though brief may lead you to believe that. I remain skeptical.

The breakout board provides filtering, but the supplied voltage from the Nano may not be beefy enough.

That's odd. The tutorials I read all state very clearly that power is a huge issue.

Even one I just found that did not had this suggestion from the writer in her questions section:

Try to use decoupling capacitors or use an external power supply.

Indulge us and try it with a separate way powerful enough voltage source (each radio) and try more again.

a7

Ok I will try that. As I do not have any power source on hand, can you give me examples of power sources to use and buy? I assume the Arduino Uno and Mega wont be powerful enough either as an external power source.

Googling just now I can only find that an nRF24L02 with the PA and LNA draws a maximum of 120 milliamperes, which seems like it shouldn't be all that hard to come up with. But power is def a problem.

So maybe the filter capacitor(s) are more or equally critical, or my research is incomplete.

A handy source of 5 volts at respectable current is a cell phone charger wall wart. A 5 watt unit would provide 1 amp, a ten watt would do 2 amps.

You might have a few of those around. I just use a USB cable that I sacrifice for this exact purpose. You might have some older cables ready to take on their retirement task.

I don't know how it might be done with the breakout board, but ppl have also had success supply 3 volts using 2xAA batteries - you'd have to apply that directly to the radio Vcc.

a7

You can also try the test here with both the transmitter and the receiver: Simple nRF24L01+ 2.4GHz transceiver demo - #30 by Robin2

What this does is dump the register contents and some diagnostic information which you can attach to this thread.

You can also look here for other ideas: RF24/COMMON_ISSUES.md at master · nRF24/RF24 · GitHub

I have tried out the external power source, like @alto777 told me to. This has caused more weird behavior. Using the code mentioned at the beginning, the transmitter now said that the data was acknowledged (when plugged to external power source) even if the receiver wasn't active. If the power was supplied through the Arduino, it would say "TX failed" .


The receiver displayed similar weird behavior. When plugged into the external power source, it would just spam data received followed by the question mark diamond symbol. If switched to arduino power, it would not display anything.


I also did what @6v6gt suggested, and ran the testing code. I have now idea what it means and will post the results below. Again in two posts, as only 3 pictures are allowed per post.

Transmitter Arduino powered:

Transmitter Externally Powered:

Receiver Arduino Powered:

Receiver Externally Powered:

ThX. If those were copy pasted instead of

wait never mind, if you look at whatever the screenshot is, and hit the arrow, you get a blink test and can see the differences. Not quite diff but workable.

Truly bizarre. I have nothing.

I was also reminded that the radio module does not reset until power cycling. This may explain some observations, and it may be cause for you to repeat any experiments done where you were thinking the radio would start up correctly. If you hadn't remembered or seen that advice.

a7

I always unplug the whole arduino and plug it back in afterwards, because I have also read that unplugging and plugging it back helps. I also don't know what you mean by the blink test.

I was also thinking that there may be too much electrical interference on the same frequency. So I have tried with less interference, but that also didn't help. I guess that it is a faulty nRF24L01 then. I will have to wait for the new modules then, and try again.

How did you do that?


Your screen shots are worth less than copy/pasted text, the two outputs as text could be analyzed with tools used to find differences, otherwise it's a bit of work to find them. Work which like all work I am loathe to undertake.

But I noticed that if you are looking at one screen shot, and then arrow over back and forth to the other and squint just right you can see what data are different between the two, same for the other pair.

It's an old astronomy thing to find a planet wandering amongst the fixed stars, for example.

Blink Comparator

a7

I went to a different room in my house, and only had my laptop and the two arduinos + nRF24L01 with me. Normally there would also be a mouse and a speaker, as well as wifi and other electronic devices, which could interfere. I'm not too sure if they actually do, and just wanted to test it out.

Here are the copied test codes. I did rerun the tests for that. I also have pasted them in as code, as I think that should not mess with the way they were originally displayed.

Transmitter Arduino Powered:

00:41:15.865 -> CheckConnection Starting
00:41:15.865 -> 
00:41:15.865 -> FIRST WITH THE DEFAULT ADDRESSES aftCheckConnection Starting
00:41:17.401 -> 
00:41:17.401 -> FIRST WITH THE DEFAULT ADDRESSES after power on
00:41:17.466 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
00:41:17.562 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
00:41:17.661 ->      communicating with the nRF24
00:41:17.694 -> 
00:41:17.694 -> SPI Speedz	= 10 Mhz
00:41:17.727 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:41:17.793 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
00:41:17.826 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
00:41:17.858 -> TX_ADDR		= 0xe7e7e7e7e7
00:41:17.891 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
00:41:17.925 -> EN_AA		= 0x3f
00:41:17.957 -> EN_RXADDR	= 0x03
00:41:17.957 -> RF_CH		= 0x4c
00:41:17.990 -> RF_SETUP	= 0x07
00:41:17.990 -> CONFIG		= 0x0e
00:41:18.024 -> DYNPD/FEATURE	= 0x00 0x00
00:41:18.024 -> Data Rate	= 1 MBPS
00:41:18.056 -> Model		= nRF24L01+
00:41:18.089 -> CRC Length	= 16 bits
00:41:18.089 -> PA Power	= PA_MAX
00:41:18.123 -> ARC		= 0
00:41:18.123 -> 
00:41:18.123 -> 
00:41:18.123 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
00:41:18.188 ->  and 250KBPS data rate
00:41:18.220 -> 
00:41:18.220 -> SPI Speedz	= 10 Mhz
00:41:18.254 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:41:18.287 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
00:41:18.351 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
00:41:18.384 -> TX_ADDR		= 0xe7e7e7e7e7
00:41:18.417 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
00:41:18.450 -> EN_AA		= 0x3f
00:41:18.483 -> EN_RXADDR	= 0x03
00:41:18.483 -> RF_CH		= 0x4c
00:41:18.515 -> RF_SETUP	= 0x27
00:41:18.515 -> CONFIG		= 0x0e
00:41:18.548 -> DYNPD/FEATURE	= 0x00 0x00
00:41:18.548 -> Data Rate	= 250 KBPS
00:41:18.582 -> Model		= nRF24L01+
00:41:18.615 -> CRC Length	= 16 bits
00:41:18.615 -> PA Power	= PA_MAX
00:41:18.648 -> ARC		= 0
00:41:18.648 -> 
00:41:18.648 -> 

Transmitter Externally Powered:

00:46:23.566 -> CheckConnection Starting
00:46:23.566 -> 
00:46:23.566 -> FIRST WITH THE DEFAULT ADDRESSES aft�CheckConnection Starting
00:46:25.111 -> 
00:46:25.111 -> FIRST WITH THE DEFAULT ADDRESSES after power on
00:46:25.175 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
00:46:25.242 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
00:46:25.372 ->      communicating with the nRF24
00:46:25.404 -> 
00:46:25.404 -> SPI Speedz	= 10 Mhz
00:46:25.436 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:46:25.502 -> RX_ADDR_P0-1	= 0x00000000e0 0x00000000e0
00:46:25.534 -> RX_ADDR_P2-5	= 0x70 0x70 0x38 0xc6
00:46:25.567 -> TX_ADDR		= 0xe7e7e7e7e7
00:46:25.600 -> RX_PW_P0-6	= 0x20 0x38 0x20 0x70 0x70 0x38
00:46:25.632 -> EN_AA		= 0x3f
00:46:25.665 -> EN_RXADDR	= 0x38
00:46:25.665 -> RF_CH		= 0x70
00:46:25.698 -> RF_SETUP	= 0x38
00:46:25.698 -> CONFIG		= 0x0e
00:46:25.732 -> DYNPD/FEATURE	= 0x70 0x70
00:46:25.732 -> Data Rate	= 1 MBPS
00:46:25.764 -> Model		= nRF24L01+
00:46:25.797 -> CRC Length	= 16 bits
00:46:25.797 -> PA Power	= PA_MIN
00:46:25.830 -> ARC		= 0
00:46:25.830 -> 
00:46:25.830 -> 
00:46:25.830 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
00:46:25.897 ->  and 250KBPS data rate
00:46:25.930 -> 
00:46:25.930 -> SPI Speedz	= 10 Mhz
00:46:25.962 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:46:25.994 -> RX_ADDR_P0-1	= 0x00000000e0 0x00000000e0
00:46:26.058 -> RX_ADDR_P2-5	= 0x60 0x70 0x38 0xc6
00:46:26.091 -> TX_ADDR		= 0xe7e7e7e7e7
00:46:26.123 -> RX_PW_P0-6	= 0x20 0x38 0x20 0x70 0x70 0x38
00:46:26.155 -> EN_AA		= 0x3f
00:46:26.189 -> EN_RXADDR	= 0x38
00:46:26.189 -> RF_CH		= 0x70
00:46:26.222 -> RF_SETUP	= 0x30
00:46:26.222 -> CONFIG		= 0x0e
00:46:26.255 -> DYNPD/FEATURE	= 0x70 0x70
00:46:26.255 -> Data Rate	= 1 MBPS
00:46:26.288 -> Model		= nRF24L01+
00:46:26.321 -> CRC Length	= 16 bits
00:46:26.321 -> PA Power	= PA_MIN
00:46:26.354 -> ARC		= 0
00:46:26.354 -> 
00:46:26.354 -> 

Receiver Arduino Powered:

00:47:57.201 -> CheckConnection Starting
00:47:57.201 -> 
00:47:57.201 -> FIRST WITH THE DEFAULT ADDRESSES aftCheckConnection Starting
00:47:58.774 -> 
00:47:58.774 -> FIRST WITH THE DEFAULT ADDRESSES after power on
00:47:58.840 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
00:47:58.905 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
00:47:59.004 ->      communicating with the nRF24
00:47:59.036 -> 
00:47:59.036 -> SPI Speedz	= 10 Mhz
00:47:59.069 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:47:59.134 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
00:47:59.167 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
00:47:59.200 -> TX_ADDR		= 0xe7e7e7e7e7
00:47:59.232 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
00:47:59.264 -> EN_AA		= 0x3f
00:47:59.297 -> EN_RXADDR	= 0x03
00:47:59.297 -> RF_CH		= 0x4c
00:47:59.331 -> RF_SETUP	= 0x07
00:47:59.331 -> CONFIG		= 0x0e
00:47:59.363 -> DYNPD/FEATURE	= 0x00 0x00
00:47:59.363 -> Data Rate	= 1 MBPS
00:47:59.397 -> Model		= nRF24L01+
00:47:59.429 -> CRC Length	= 16 bits
00:47:59.429 -> PA Power	= PA_MAX
00:47:59.462 -> ARC		= 0
00:47:59.462 -> 
00:47:59.462 -> 
00:47:59.462 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
00:47:59.527 ->  and 250KBPS data rate
00:47:59.559 -> 
00:47:59.559 -> SPI Speedz	= 10 Mhz
00:47:59.591 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
00:47:59.656 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
00:47:59.721 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
00:47:59.754 -> TX_ADDR		= 0xe7e7e7e7e7
00:47:59.787 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
00:47:59.822 -> EN_AA		= 0x3f
00:47:59.854 -> EN_RXADDR	= 0x03
00:47:59.854 -> RF_CH		= 0x4c
00:47:59.887 -> RF_SETUP	= 0x27
00:47:59.887 -> CONFIG		= 0x0e
00:47:59.919 -> DYNPD/FEATURE	= 0x00 0x00
00:47:59.919 -> Data Rate	= 250 KBPS
00:47:59.952 -> Model		= nRF24L01+
00:47:59.986 -> CRC Length	= 16 bits
00:47:59.986 -> PA Power	= PA_MAX
00:48:00.019 -> ARC		= 0
00:48:00.019 -> 
00:48:00.019 -> 

Receiver Externally Powered:

00:52:40.332 -> CheckConnection Starting
00:52:40.332 -> 
00:52:40.332 -> FIRST WITH THE DEFAULT ADDRESSES aftCheckConnection Starting
00:52:41.900 -> 
00:52:41.900 -> FIRST WITH THE DEFAULT ADDRESSES after power on
00:52:41.999 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
00:52:42.065 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
00:52:42.164 ->      communicating with the nRF24
00:52:42.196 -> 
00:52:42.196 -> SPI Speedz	= 10 Mhz
00:52:42.229 -> STATUS		= 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
00:52:42.295 -> RX_ADDR_P0-1	= 0x00000000c0 0x00000000c0
00:52:42.328 -> RX_ADDR_P2-5	= 0x60 0x18 0x30 0x28
00:52:42.362 -> TX_ADDR		= 0x0000000010
00:52:42.395 -> RX_PW_P0-6	= 0xc0 0x00 0x00 0x00 0x01 0x80
00:52:42.428 -> EN_AA		= 0xc0
00:52:42.461 -> EN_RXADDR	= 0xc0
00:52:42.461 -> RF_CH		= 0x11
00:52:42.493 -> RF_SETUP	= 0x18
00:52:42.493 -> CONFIG		= 0x10
00:52:42.526 -> DYNPD/FEATURE	= 0x80 0x01
00:52:42.526 -> Data Rate	= 1 MBPS
00:52:42.559 -> Model		= nRF24L01
00:52:42.592 -> CRC Length	= 8 bits
00:52:42.592 -> PA Power	= PA_MIN
00:52:42.625 -> ARC		= 1
00:52:42.625 -> 
00:52:42.625 -> 
00:52:42.625 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
00:52:42.688 ->  and 250KBPS data rate
00:52:42.721 -> 
00:52:42.721 -> SPI Speedz	= 10 Mhz
00:52:42.754 -> STATUS		= 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
00:52:42.787 -> RX_ADDR_P0-1	= 0x00000000e0 0x0000040000
00:52:42.853 -> RX_ADDR_P2-5	= 0x00 0x80 0x00 0x28
00:52:42.886 -> TX_ADDR		= 0x000000c080
00:52:42.919 -> RX_PW_P0-6	= 0x80 0xc0 0xc0 0x22 0x44 0x80
00:52:42.952 -> EN_AA		= 0xa2
00:52:42.952 -> EN_RXADDR	= 0x11
00:52:42.985 -> RF_CH		= 0x00
00:52:43.018 -> RF_SETUP	= 0x22
00:52:43.018 -> CONFIG		= 0xe8
00:52:43.051 -> DYNPD/FEATURE	= 0x60 0x00
00:52:43.051 -> Data Rate	= 1 MBPS
00:52:43.083 -> Model		= nRF24L01
00:52:43.116 -> CRC Length	= 8 bits
00:52:43.116 -> PA Power	= PA_MIN
00:52:43.148 -> ARC		= 0
00:52:43.148 -> 
00:52:43.148 -> 

The externally powered devices have problems because they do not appear to respond to the attempts to reduce the data rate from 1MBPS to 250KBPS. This is usually caused by a missing common ground. Each external power supply must have a ground connection to the attached Nano and radio module.
This can also be caused by long wires between the Arduino and the radio module.

1 Like