[NRF24L01] Trying out and debugging Robin2's SimpleRX.ino and SimpleTX.ino

Hi there! I've been researching around how to work out a serial communication between two Arduinos. I've tried out loads of tutorials from YouTube, but was also recommended this tutorial here on the Arduino forums by Robin2.

However, whatever tutorial I do, none of it seems to establish connection. Let's try to look at the one by Robin2 and my methodology in debugging my system.

I am also currently using the base module recommended by ArduinoInfo so that I don't need to worry about the 3.3V or 5V/Capacitor issue.

Hoping that someone out there also experienced an issue like this and is willing to share their solution!

SimpleRX I copied off of his tutorial

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

SimpleTX I copied off of his tutorial

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

Output of COM ports:

Hypothesis 1: Checking for known IDE compatiblity issues

First, I took note of my IDE version, which is currently Arduino 1.8.16. I didn't see any issues with the version as far as I know. Please do inform me, however, if there is a known issue that I am now aware of! :smile:

Hypothesis 2: Checking for known library compatiblity issues

The next thing I did was a fresh-install of the TMRh20 version of the RF24 library via Github, which I manually placed into my libraries folder.

When a connection was still not established, I instead uninstalled and re-installed the Arduino IDE so that I could use the TMRh20 version from the built in Arduino Library Manager. Though, the issue still persisted.

Hypothesis 3: Wire connections between the modules

I made sure if I experienced errors, I would do a clean up of my Arduinos; I removed each and every connection and put them back together. If no connection was established, I would switch components (hey, what's the harm in that, am I right?). Still, nothing.

Then I bought extra jumper cables, because it might have been a continuity issue. Nevertheless, still a no-go on new cables.

I also made sure that my CN, CSE, etc. wiring was based off of Robin2's tutorial, so that I have a point of reference.

Hypothesis 4: Voltage, maybe?

Currently using the base module recommended by ArduinoInfo. I'm not sure if that would mean I might experience any issue, but if it does, please do inform me!

Hypothesis 5: Is this a hardware-related issue?

Last, but certainly not the least: it could be that my antennas are broken. I bought three (the one is an extra), and switched them up, and none of them are still able to establish a connection, so I'm not sure with that. I wanted to get a second opinion, however, on whether or not this could be a hardware-related issue.

I tried out Robin2's CheckConnection.ino as well, so here is the output I got:

Using Antenna 1

13:12:58.804 -> CheckConnection Starting
13:12:58.851 -> 
13:12:58.851 -> FIRST WITH THE DEFAULT ADDRESSES after power on
13:12:58.897 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
13:12:58.989 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
13:12:59.081 ->      communicating with the nRF24
13:12:59.129 -> 
13:12:59.129 -> SPI Speedz	= 10 Mhz
13:12:59.129 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:12:59.174 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
13:12:59.219 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
13:12:59.266 -> TX_ADDR		= 0xe7e7e7e7e7
13:12:59.313 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
13:12:59.359 -> EN_AA		= 0x3f
13:12:59.359 -> EN_RXADDR	= 0x03
13:12:59.359 -> RF_CH		= 0x4c
13:12:59.406 -> RF_SETUP	= 0x01
13:12:59.406 -> CONFIG		= 0x0e
13:12:59.406 -> DYNPD/FEATURE	= 0x00 0x00
13:12:59.452 -> Data Rate	= 1 MBPS
13:12:59.500 -> Model		= nRF24L01+
13:12:59.500 -> CRC Length	= 16 bits
13:12:59.500 -> PA Power	= PA_MIN
13:12:59.546 -> ARC		= 0
13:12:59.546 -> 
13:12:59.546 -> 
13:12:59.546 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
13:12:59.593 ->  and 250KBPS data rate
13:12:59.639 -> 
13:12:59.639 -> SPI Speedz	= 10 Mhz
13:12:59.639 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:12:59.731 -> RX_ADDR_P0-1	= 0xe7e7e7e7e7 0x4141417852
13:12:59.778 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
13:12:59.823 -> TX_ADDR		= 0xe7e7e7e7e7
13:12:59.823 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
13:12:59.870 -> EN_AA		= 0x3f
13:12:59.870 -> EN_RXADDR	= 0x03
13:12:59.917 -> RF_CH		= 0x4c
13:12:59.917 -> RF_SETUP	= 0x21
13:12:59.965 -> CONFIG		= 0x0e
13:12:59.965 -> DYNPD/FEATURE	= 0x00 0x00
13:13:00.011 -> Data Rate	= 250 KBPS
13:13:00.011 -> Model		= nRF24L01+
13:13:00.011 -> CRC Length	= 16 bits
13:13:00.057 -> PA Power	= PA_MIN
13:13:00.057 -> ARC		= 0
13:13:00.102 -> 
13:13:00.102 -> 

Using Antenna 2

13:13:03.140 -> CheckConnection Starting
13:13:03.187 -> 
13:13:03.187 -> FIRST WITH THE DEFAULT ADDRESSES after power on
13:13:03.233 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
13:13:03.326 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
13:13:03.371 ->      communicating with the nRF24
13:13:03.417 -> 
13:13:03.417 -> SPI Speedz	= 10 Mhz
13:13:03.463 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:13:03.510 -> RX_ADDR_P0-1	= 0x4141417852 0x4141417852
13:13:03.556 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
13:13:03.602 -> TX_ADDR		= 0x4141417852
13:13:03.602 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
13:13:03.649 -> EN_AA		= 0x3f
13:13:03.695 -> EN_RXADDR	= 0x03
13:13:03.695 -> RF_CH		= 0x4c
13:13:03.695 -> RF_SETUP	= 0x01
13:13:03.742 -> CONFIG		= 0x0e
13:13:03.742 -> DYNPD/FEATURE	= 0x00 0x00
13:13:03.789 -> Data Rate	= 1 MBPS
13:13:03.789 -> Model		= nRF24L01+
13:13:03.835 -> CRC Length	= 16 bits
13:13:03.835 -> PA Power	= PA_MIN
13:13:03.882 -> ARC		= 5
13:13:03.882 -> 
13:13:03.882 -> 
13:13:03.882 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
13:13:03.928 ->  and 250KBPS data rate
13:13:03.975 -> 
13:13:03.975 -> SPI Speedz	= 10 Mhz
13:13:03.975 -> STATUS		= 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:13:04.022 -> RX_ADDR_P0-1	= 0x4141417852 0x4141417852
13:13:04.068 -> RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
13:13:04.114 -> TX_ADDR		= 0x4141417852
13:13:04.159 -> RX_PW_P0-6	= 0x20 0x20 0x20 0x20 0x20 0x20
13:13:04.206 -> EN_AA		= 0x3f
13:13:04.206 -> EN_RXADDR	= 0x03
13:13:04.252 -> RF_CH		= 0x4c
13:13:04.252 -> RF_SETUP	= 0x21
13:13:04.252 -> CONFIG		= 0x0e
13:13:04.299 -> DYNPD/FEATURE	= 0x00 0x00
13:13:04.299 -> Data Rate	= 250 KBPS
13:13:04.346 -> Model		= nRF24L01+
13:13:04.346 -> CRC Length	= 16 bits
13:13:04.393 -> PA Power	= PA_MIN
13:13:04.393 -> ARC		= 5
13:13:04.393 -> 
13:13:04.393 -> 

They both use the same code:

// 18 Mar 2018 - simple program to verify connection between Arduino
//      and nRF24L01+
//  This program does NOT attempt any communication with another nRF24

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

#include <printf.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);
    printf_begin();

    Serial.println("CheckConnection Starting");
    Serial.println();
    Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
    Serial.println("  Note that RF24 does NOT reset when Arduino resets - only when power is removed");
    Serial.println("  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
    Serial.println("     communicating with the nRF24");
    Serial.println();
    radio.begin();
    radio.printDetails();
    Serial.println();
    Serial.println();
    Serial.println("AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1");
    Serial.println(" and 250KBPS data rate");
    Serial.println();
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.setDataRate( RF24_250KBPS );
    radio.printDetails();
    Serial.println();
    Serial.println();
}


void loop() {

}

What is the question ?

The code in Robins tutorial is known to work, so the conclusion would be that you have faulty modules, if you have checked that they are connected and powered correctly.

Just wanted a second opinion on what could possibly be the issue of my setup.

I initially hypothesized that it could be the NRF24L01s themselves, but then again it could be the base module. However, it is very difficult to find out whether or not which component really is the faulty one, since we're dealing with wireless stuff.

I don't want to rule out the antennas, though it did seem impossible that all three antennas I bought happened to not work, unless I'm really unlucky in the silicon draw

I had a bunch of 10 or 12 NRF24s, and when I fianlly got a pair working, I was able to test the rest, 50% of them would not work and went in the bin.

If you have 3 modules then you need at least two of them to work, so its not the case thats its unlikely that all 3 are faulty .......

The examples in the NRF24 and Radiohead libraries also work, when you have working modules.

Ah, I tried switching pairs as well because I wanted to know if one of the three were faulty (module 1 & module 2; module 2 & module 3; module 3 & module 1), but it seems no connection was still established. That led to the hypothesis that all or two were a dud, but that means that I am just unlucky

Though, that's just one hypothesis; I'm just wondering if someone might point out that it's an IDE/incompatible library version kind of thing before I fully commit to buying more NRF24L01s. My budget unfortunately is not my friend hahaha

At least for the high-power modules you should use minimal RF power for testing,
and a lot more distance between the modules.

I had a lot of connection problems with jumper cables,
I prefer soldered connections between the sockets of the MCU and the NRF.

For testing (with a Nano) I like to use

1 Like

For some of the PA modules the RF power out (of the PA) varies very little depending on the power out of the NRF24, the measured RF power outs of two of the LNAPA modules I tested were;

Module A, MAX 22dBm, HIGH 19dBm, LOW 2dBm, MIN -8dBm.
Module B, MAX, 19dBm, HIGH, 19dBm, LOW, 19dBm, MIN 15dBm.

So not all LNAPA modules are alike.

If I was debugging a setup, I would start with the plain non LNAPA modules, there should be less to worry about.

1 Like

Oh, I see. I'll try out increasing the distance. Maybe a meter or two away from each other.

But you're right, I didn't take into consideration the environment itself; I just tested it out in my room (with the pandemic and all), with the distance between the modules to be less than inches away from one another.

I always assumed that putting both antennas close to each other would give a high performance hahaha

I guess that means I'll try the good ol' capacitor method. Though, I really wanted to test my setup out without soldering. But if it means getting to the bottom of the issue, might as well try without the modules first

You've opened 2 serial monitors simultaneously on your PC and the messages (or lack of them) cause you to conclude that there is no communication.
The TX part will register a failure if the primary transmission succeeds but the acknowlegement goes missing. You have to check the receiver serial output as well.

The connectivity test output looks good.
You have used the 5v output of the Uno to power these modules and not the 3.3volt output? The pictures are not clear enough to see.

One simple test you can apply is to unscrew the antenna from both modules to see if that helps.

Oh, yeah, derp, I forgot to show the output of both terminals. I'll update the post ASAP. Here is what both shows:

Thanks for checking the connectivity; at least I'm glad that there appears to be no issues there. On using 5V and 3.3V, I used them for both tests. Once the 3.3V don't appear to do anything with the module, I switch to the 5V.

The guide by ArduinoInfo mentions using 5V if I'm connected to the base module, but I just wanted to try if it's a power-related issue.

I'll try unscrewing the antenna thing and see if anything happens

Something is odd. A quick check of the TX sketch you say you used indicates that this message number should increment.

image

EDIT
Sorry. It updates only in the case of a successful transmission.

Tried unscrewing the antennas. Here's my setup:

Still a no-go, unfortunately. Seems everyone else is suggesting it to be completely antenna-related, meaning I am incredibly unlucky and that all three of my antennas are duds.

Like I said, you need two of the modules working to tell.

Whilst the transmitter might say 'Tx failed' it does not mean that there was no packet sent, it means the transmit and receive of the acknowledge failed. For transmit and receive of acknowledge to suceed there needs to be two working modules.

And even if the antenna part of the module was faulty its likley that at close range the modules would work.

Yes, that message occurs after 15 transmissions, under the default configuration.

Just some other things to try.

Instead of powering both modules from the same PC, power the TX part by a smart phone charger or similar. You won't see its serial console of course but you can see that of the RX part.

Comment this out of both sketches. Some clones/fakes support only the default 1MBs:

 radio.setDataRate( RF24_250KBPS );

If you want to read more about the weird observed behaviour of some NRF24L01 clones and fakes, this is a good starting point: We are mostly using fake nRF24L01+'s, but worse fakes are emerging. | MySensors Forum

1 Like

Holy moly, this works hahaha. Welp, apparently mine's a fake then, because commenting it out lets me receive messages.

Oh man, well this explains a lot. Thanks for this, @6v6gt ! I hope now this thread can serve as a warning to those to buy from some reliable sources (I used aliexpress). If anyone else can't solve their transmission problems, there is a large chance it may be fake

Can you produce a reasonable quality close up picture of just the module, hopefully with the chip markings (if any) clearly visible ? Also a link to the Aliexpress page where you purchased the 3 items.

1 Like

It could be an explanation, but 250 KB has a longer reach,
so probably also a bigger zone of overpowering,
which regularly needs real distance between the nodes.

1 Like

Ah, yeah, sure, these are what I bought:

The NRF24L01 module

The base module (so I don't have to solder a capacitor on it)

I just bought them at a random here, basing it off of reviews