Problems with nRF24L01 pair

Hi all

Trying to make up a set of 2 way data transfer between an UNO (transmitter) and a Nano (Receiver).

100% certain the wiring is correct. Checked and checked again. Each nRF24L01 has it's own 3.3v supply, so no power issues.

But... zip. No data transfer.

I have been using this resource:
https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/?utm_content=cmp-true

Transmitter code:

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

RF24 radio(10, 9); // CE, CSN

//const byte address[6] = "00001";
const byte addresses [][6] = {"00001", "00002"};                                                        // Setting the two radio addresses (RX and TX)

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte a = 0;
  byte b = 125;
  byte c = 255;
  int d = 1024;
  float e = 3.141592;
  String f = "Test";
};

Data_Package data; // Create a variable with the above structure

void setup() {

  Serial.begin(9600);
  
  radio.begin();
  radio.openWritingPipe(addresses[1]);          // 00002
  radio.openReadingPipe(1, addresses[0]);       // 00001
  radio.setAutoAck(true);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);                                                         // RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_max.
  //radio.startListening();                                                               // Set the module as receiver
  radio.stopListening();                                                                  // This sets the module as transmitter
}

void loop() {
  // Send the whole data from the structure to the receiver
  radio.write(&data, sizeof(Data_Package));
  Serial.println("Transmit...");
  delay(500);
}

Receiver code:

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

RF24 radio(10, 9); // CE, CSN

const byte addresses [][6] = {"00001", "00002"};                                                        // Setting the two radio addresses (RX and TX)

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte a = 0;
  byte b = 125;
  byte c = 255;
  int d = 1024;
  float e = 3.141592;
  String f = "Test";
};

Data_Package data; //Create a variable with the above structure

void setup() {
  Serial.begin(9600);

  radio.begin();
  radio.openWritingPipe(addresses[0]);    // 00001
  radio.openReadingPipe(1, addresses[1]); // 00002
  radio.setAutoAck(true);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MIN);                                                          // RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_max.
  radio.startListening();                                                                 // Set the module as receiver

  Serial.println("ONLINE");
  delay(1000);
}

void loop() {
  // Check whether there is data to be received
  if (radio.available()) {
    radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
  
  Serial.print("a: ");
  Serial.print(data.a);
  Serial.print(" b: ");
  Serial.print(data.b);
  Serial.print(" c: ");
  Serial.print(data.c);
  Serial.print(" d: ");
  Serial.print(data.d);
  Serial.print(" e: ");
  Serial.print(data.e);
  Serial.print(" f: ");
  Serial.print(data.f);

  data.a = 0;
  data.b = 0;
  data.c = 0;
  data.d = 0;
  data.e = 0;
  data.f = "";

  }
}

Any ideas?

Not sure what radio.setAutoAck(true); does. But either state makes no difference.

Others in the comments have said that #const byte addresses [][6] = {"00001", "00002"}; should actually be const byte addresses [][5] = {"00001", "00002"};
But that makes no difference either

The 2 way demo code on that webpage isn't very good. It displays the received variables, even if they are not arriving. At first I thought it all worked until I noticed that turning off the transmitter made no difference to the received displayed data.

Have You tried IDE built in example code? Robin2 has made examples.
Posting schematics would make us sure....
Insufficient powering has been a reason in many transmitter projects.

I'll have to draw the schematic... but there isn't much to draw.

nRF24L01:

GND and 3.3v supply (1.5A)
SCK = 13
MISO = 12
MOSI = 11
CE = 10
CSN = 9

Same connections for both devices. Swapped out the Nano and the UNO just in case.
Only got one pair of the nRF24L01's, but they are new.

I'll have to look for the demo code

You can't send a String in a struct. All you will send is the address of the String object in the local context. Use a char array instead example char f[5] = "Test" ; // + 1 for terminator

Tried the NF24.h demo 'Getting started'. I assume that will work with a nRF24L01 (couldn't see a demo for the nRF24L01).

Nope... nothing.

Just tested my connections with a multimeter... all correct and continuity is good.

Can only assume dead RX/TX

I need a better hobby. This one sucks

You say you can't send a string... so why so they use it on that webpage.
PET HATE... Examples that are incorrect.

I had a quick look through the comments in that tutorial to see if anyone else had spotted that error.

I gave up after having to scroll through reams of sycophantic claptrap like: "Congratulations my friend, your videos and explanations have helped and motivated an immensity of students and professionals, thank you for sharing your knowledge, we thank you from the heart."

If I swap the CE/CSN pins, then I kinda get some results... but it's not right.
But, by swapping them, it's not wired as I understand it should be and I think I am just getting random results.

Been hours on this. I think I need another RX/TX pair to eliminate the possibility one is dud.

Pretty sure I have has this working before

Try the sample code in post #2 of this tutorial: Simple nRF24L01+ 2.4GHz transceiver demo
Ignore the advice to install a specific old release of the nRF24 library.
This should confirm if your hardware is OK.

Just tried the simple RX/TX examples at the top of that LONG page...

Nope, don't work.

Yet, if I load the nRF20L01 tester routine also on that page, it returns all the correct data from the module and appears to be communicating fine.

The fact that the post is 66+ replies long, makes me thing these things are not exactly reliable.

This indeed now might be a stupid Arduino Library issue

Many nrf24L01 problems are related to an inadequate power supply. The 3.3 volts from a Nano is usually derived from the USB chip and is unsuitable for powering an nrf24L01.
See here also for some trouble shooting suggestions:

I have dedicated 3.3v 1.5A supplies for the TX and the RX with local smoothing caps.
It's certainly not the PSUs.

What is the separation between RX and TX? Should be at least 2 meters or 7 feet.

Your original sketches, just slightly simplified (checking return values, only setting Tx stuff for the transmitter, only setting RX stuff for the receiver, and leaving sensibly set defaults alone). Worked just fine with an Uno transmitter and a Nano receiver. Both with external 3.3V regulators and appropriate caps. Still the same problem the String in the struct, but the transmit/ack/receive parts are functional.

Transmitter:

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

RF24 radio(10, 9);  // CE, CSN

const byte address[6] = "00001";

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
   byte a = 0;
   byte b = 125;
   byte c = 255;
   int d = 1024;
   float e = 3.141592;
   String f = "Test";
};

Data_Package data;  // Create a variable with the above structure

void setup() {

   Serial.begin(115200);

   if( !radio.begin() ) {
      Serial.println(F("radio hardware not responding!"));
      while( 1 ) {}
   }
   if( !radio.isChipConnected() ) {
      Serial.println(F("Chip not connected to SPI bus!"));
      while( 1 ) {}
   }
   radio.openWritingPipe(address);  // 00001
   radio.setPALevel(RF24_PA_MIN);   // RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_max.
   radio.stopListening();           // This sets the module as transmitter
}

void loop() {
   // Send the whole data from the structure to the receiver
   radio.write(&data, sizeof(Data_Package));
   Serial.println("Transmit...");
   data.d++;
   delay(500);
}

Receiver:

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

RF24 radio(10, 9);  // CE, CSN

const byte address[6] = "00001";

// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
   byte a = 0;
   byte b = 125;
   byte c = 255;
   int d = 1024;
   float e = 3.141592;
   String f = "Test";
};

Data_Package data;  //Create a variable with the above structure

void setup() {
   Serial.begin(115200);

   if( !radio.begin() ) {
      Serial.println(F("radio hardware not responding!"));
      while( 1 ) {}
   }
   if( !radio.isChipConnected() ) {
      Serial.println(F("Chip not connected to SPI bus!"));
      while( 1 ) {}
   }
   radio.openReadingPipe(0, address);       // 00001
   radio.setPALevel(RF24_PA_MIN);           // RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_max.
   radio.startListening();                  // Set the module as receiver

   Serial.println("ONLINE");
   delay(1000);
}

void loop() {
   // Check whether there is data to be received
   if( radio.available() ) {
      radio.read(&data, sizeof(Data_Package));  // Read the whole data and store it into the 'data' structure

      Serial.print("a: ");
      Serial.print(data.a);
      Serial.print(" b: ");
      Serial.print(data.b);
      Serial.print(" c: ");
      Serial.print(data.c);
      Serial.print(" d: ");
      Serial.print(data.d);
      Serial.print(" e: ");
      Serial.print(data.e);
      Serial.print(" f: ");
      Serial.print(data.f);

      data.a = 0;
      data.b = 0;
      data.c = 0;
      data.d = 0;
      data.e = 0;
      data.f = "";
   }
}

With common ground?

No.... otherwise what would be the point of a wireless link!

Each have their own PSU and breadboard

Supply a schematic, which you have already talked about in post #3, then it will be clear if there is a common ground between one Nrf24L01 module, its power supply and its driving Arduino.

I know you don't believe me... but the wiring is correct. Common ground between the radio modules and the processor.
Been doing electronics long enough to know that basic check.

I'm not drawing out something that has 7 wires

I suspect this is a dud module.

Well.... I am baffled.

I thought maybe my CSN and CE were not working. I allocated CE as pin 10 and CSN as Pin 9.

But, swapping those around makes no difference.

If you run the nRF24L01 test routine you get back:

Receiver:


FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR		 = 0xe7e7e7e7e7
RX_PW_P0-6	 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA		 = 0x3f
EN_RXADDR	 = 0x03
RF_CH		 = 0x4c
RF_SETUP	 = 0x07
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x00 0x00
Data Rate	 = 1MBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	 = PA_MAX


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0x4141417852
RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR		 = 0xe7e7e7e7e7
RX_PW_P0-6	 = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA		 = 0x3f
EN_RXADDR	 = 0x03
RF_CH		 = 0x4c
RF_SETUP	 = 0x27
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x00 0x00
Data Rate	 = 250KBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	 = PA_MAX

and the transmitter:

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x0000000070 0x0000000070
RX_ADDR_P2-5	 = 0x38 0x38 0x1c 0xc6
TX_ADDR		 = 0x4141417852
RX_PW_P0-6	 = 0x20 0x1c 0x00 0x38 0x38 0x1c
EN_AA		 = 0x3f
EN_RXADDR	 = 0x1c
RF_CH		 = 0x38
RF_SETUP	 = 0x1c
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x38 0x38
Data Rate	 = 2MBPS
Model		 = nRF24L01
CRC Length	 = 16 bits
PA Power	 = PA_HIGH


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x0000000070 0x0000000070
RX_ADDR_P2-5	 = 0x38 0x38 0x1c 0xc6
TX_ADDR		 = 0x4141417852
RX_PW_P0-6	 = 0x20 0x1c 0x00 0x38 0x38 0x1c
EN_AA		 = 0x3f
EN_RXADDR	 = 0x1c
RF_CH		 = 0x38
RF_SETUP	 = 0x1c
CONFIG		 = 0x0e
DYNPD/FEATURE	 = 0x38 0x38
Data Rate	 = 2MBPS
Model		 = nRF24L01
CRC Length	 = 16 bits
PA Power	 = PA_HIGH

And yet.... I can't get them to talk to each-other.
The simple RX/TX demo results in the RX serial debug just scrolling saying data received... even if the TX board s turned off.

Oh, and the boards are about 5m apart = max length of my USB leads

This RX code scrolls 'Data received' constantly, even if the TX is switched off...

// 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 demo code from that page.
What would cause it to think that there is constant data arriving?

I hate these things.... what a waste of hours