nRF24L01 wireless communication (Failed)

Hello All,

I recently purchased one nRF24L01+PA+LNA unit and one nRF24L01+ unit.
I have connected nRF24L01+PA+LNA to Arduino Nano (using jumper wire cables), and connected nRF24L01+ to Arduino Uno (using jumper wire cables),and both Adruino are connected to the same computer. I downloaded Maniacbug’s RF24 library, and am now trying to have they communicate with each other(see code below).

However, I keep getting the following message “failed”.(see “Serial Display” below)
Many people have suggested using smoothing capacitors between Vcc and ground. I have tried this, but I am still not having any success.I would really appreciate any suggestions.

Thanks,

I am using the code copied from the Internet
Here is the code:

Send(nRF24L01+PA+LNA )(Nano):

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
 
//RF24(cePin, csnPi)
RF24 radio(9,10);
 

const uint64_t pipe = 0xE8E8F0F0E1LL;
 
int data = 0;
 
void setup(void)
{
  Serial.begin(57600);
  radio.begin();
  radio.openWritingPipe(pipe);
}

void loop(void)
{
      Serial.print("Sending:");
      Serial.print(data);
       
      bool ok = radio.write(&data,sizeof(int));
      if(ok)
        Serial.println(".....successed");
      else
        Serial.println(".....failed");
 
      data++;
      delay(200);
}

receive(nRF24L01+)(Uno):

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
 
// RF24(cePin, csnPi)
RF24 radio(9,10);
 
const uint64_t pipe = 0xE8E8F0F0E1LL;
 

int recibeData;
 
void setup(void){
  Serial.begin(57600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}
 
void loop(void){
 
  if (radio.available()){
    Serial.print("recibe:");

    //radio.read(const void *buf, uint8_t len)
    radio.read( &recibeData, sizeof(int));     
    Serial.println(recibeData);
  }
}

Serial Display:
Sending:0…failed
Sending:1…failed
Sending:2…failed
Sending:3…failed
Sending:4…failed
Sending:5…failed
Sending:6…failed
Sending:7…failed
Sending:8…failed
Sending:9…failed
.
.
.
…all failed…

Below are the debug info

Send(Nano)(nRF24L01+PA+LNA):

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		 = 0x0c
DYNPD/FEATURE= 0x00 0x00
Data Rate	         = 1MBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	         = PA_HIGH

Receive(Uno)(nRF24L01+):

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1= 0x0000000100 0xe8e8f0f0e1
RX_ADDR_P2-5= 0xc3 0xc4 0xc5 0xc6 
TX_ADDR		 = 0x0000000100 
RX_PW_P0-6	= 0x20 0x20 0x00 0x00 0x00 0x00 
EN_AA		 = 0x3f
EN_RXADDR	= 0x02 
RF_CH		 = 0x4c
RF_SETUP	         = 0x06
CONFIG		 = 0x0c 
DYNPD/FEATURE = 0x00 0x00 
Data Rate	         = 1MBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	         = PA_HIGH

nRF24L01+PA+LNA - Nano
GND - GND
Vcc - 3V3
CE - Pin 9
CSN - Pin10
SCK - Pin13
MOSI -Pin11
MISO -Pin12

nRF24L01+ - Uno
GND - GND
Vcc - 3.3V
CE - Pin 9
CSN - Pin10
SCK - Pin13
MOSI -Pin11
MISO -Pin12

Maybe the current gotten from the Arduino board aren’t enough, so I have tried to use the external power supply to run my two nRF24L01 boards, but nothing changed.
I have tried several code copied from the NET but the results were bad.

Any pointers would be appreciated.

Thanks

Have a look at this Simple nRF24L01+ Tutorial. It uses the newer TMRh20 version of the RF24 library. And I have deliberately kept the examples as simple as possible.

I don't have a high-power nRF24 but I have read that the output power can overwhelm another device that is too close to it.

Maybe do your initial tests with two nRF24s with the PCB antenna.

...R

Today I try to power both nRF24L01 boards with external power supply again. I have fixed some problem of my circuit,adding 10uf capacitors between Vcc and ground . I am using the same code as I posted yesterday , but add this line "radio.setPALevel(RF24_PA_MIN);"

Well , the result is not so bad. The first data have been sent and received , but others don't . It seems that my boards aren't broken.

Here is the result:

Send:

Sending:0.....successed
Sending:1.....failed
Sending:2.....failed
Sending:3.....failed
Sending:4.....failed
Sending:5.....failed
Sending:6.....failed
Sending:7.....failed
Sending:8.....failed
Sending:9.....failed
Sending:10.....failed
Sending:11.....failed
Sending:12.....failed
Sending:13.....failed

Receive:

recibe:0

When I changed the sent data, the data the receptor got was also changed too, so I think the data did be sent and received successfully.

The question is , Why there was only one data be sent successfully but others weren't?

@Robin2
I have tried your "Simple one way transmission" code but they actually didn't work. In fact , I am connecting my Arduino boards and nRF24L01 boards with jumping wires. I wondered if the jumper hell will cause my fail or not. Thanks for your help.

My English is terrible , but I really want to solve the problem.
Any pointers would be appreciated.

Thanks

nekosaikou:
@Robin2
I have tried your "Simple one way transmission" code but they actually didn't work. In fact , I am connecting my Arduino boards and nRF24L01 boards with jumping wires. I wondered if the jumper hell will cause my fail or not. Thanks for your help.

The jumper connections should not be a problem - I have several low power nRF24s working like that. But I would not expect a high-power nRF24 to work from the Arduino 3,3v output.

Debugging wireless problems can be very difficult - especially over the internet.

Can you post the exact programs that YOU loaded to your Arduinos and provide a diagram showing the exact connections YOU have between your devices. Also please make it very clear what each device in your diagram is.

...R

Here is the diagram

Send

If the diagram isn’t visible, click

Receive

If the diagram isn’t visible,click

I want to make the diagram simple, so I only mark the pins on the nRF24L01 boards without drawing wires.

And here is the code I loading to my boards.

Send(Nano)

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

RF24 radio(9,10);
 
const uint64_t pipe = 0xE8E8F0F0E1LL;
 

int data = 0;
 
void setup(void){
  Serial.begin(57600);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_250KBPS);  

  radio.openWritingPipe(pipe);
}
 
void loop(void)
{
      Serial.print("Sending:");
      Serial.print(data);
       
      bool ok = radio.write(&data,sizeof(int));
      if(ok)
        Serial.println(".....successed");
      else
        Serial.println(".....failed");
 
      data++;
      delay(200);
}

Receive(Uno)

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
 
RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;
 
int recibeData;
 
void setup(void){
  Serial.begin(57600);
  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}
 
void loop(void){

  if (radio.available()){
    Serial.print("recibe:");
    radio.read( &recibeData, sizeof(int));     
    Serial.println(recibeData);
  }
  else
  {
  }
}

I am a beginner in wireless communication and Arduino , and I have few friends playing with Arduino.
Thank you very much for helping me , Robin2.

I always use these to power my radios. The 3.3v reg on the uno and nano will not power them reliably.

Neither of your diagrams show the connections to the data pins on the nRF24s.

You said my programs would not work and I was hoping you would post the versions of those that you have used as I am familiar with them.

...R

@Robin2

The Code I used:

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

I did not draw the connection because it will make my diagrams look messy , so I marked them on the nRF24L01 boards on the diagrams I drew yesterday.
The connection I used is the same as your demo

Today I haved tried the GettingStarted Example of the maniacbug’s RF24Library ,and everything works pretty well. Two boards start to communicate. But I really don’t know why they decided to work :smiley: :smiley:
It is a sudden success.

@SamlAm93

I have noticed that so I decided to power my nRF24L01 boards with External Power Supply(diagram1 , diagram2) , not the Arduino :slight_smile:

nekosaikou:
@Robin2

The Code I used:

....SNIP....

Today I haved tried the GettingStarted Example of the maniacbug's RF24Library ,and everything works pretty well. Two boards start to communicate. But I really don't know why they decided to work :smiley: :smiley:
It is a sudden success.

This is too confusing. You are jumping from issue to issue without dealing with either in detail.

My code assumes the use of the newer TMRh20 version of the RF24 library. AFAIK it won't work with the maniacbug version. Based on the last paragraph I have quoted it sounds like you have the maniacbug library installed. Unfortunately TMRh20 used the same file names for his version of the library.

...R

@Robin2
I didn't realize that there are several RF24 Libraries until this day. I blame myself for making you confused.

The power's and jumping wires' problem were solved.
Since I find that the hardware I am using aren't broken , I am now turning to the code again.

I think I should restart my program.

Again, thank you very much, Robin2.And sorry for making you confused.

No need to apologize.

And the multiple libraries is very confusing. My suggestion is to completely remove all traces of the RF24 library from your system and then download and install the TMRh20 version.

If you know how to do it you can rename the library files so you can have both versions. But then your code will not match the examples are available.

...R

@Robin2
I install TMRh20 RF24 library on my another PC(Other version is never installed before), and load your code. It do work, but there is something strange.

The connection of the devices are the same as I have posted.
Send
Receive

Here is the result,
Send:

SimpleTx Starting
Data Sent Message 0  Tx failed
Data Sent Message 0  Tx failed
Data Sent Message 0  Tx failed
.
.
.

Receive:

SimpleRx Starting
Data received Message 0
Data received Message 0
Data received Message 0
.
.
.

It seems that the receptor do receive the data , but the response sent to the transmitter isn't received by the transmitter.
The code I used is copied form yours.

I have same problem that the auto response isn't received when I was using ManiacBug's RF24 Library.

I simply do some changes to the send() function

void send() {
//////////////////////////////add radio.stopListening();//////////////////////
radio.stopListening();
    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");
    }

////////////////////add radio.startListening();//////////////////
    radio.startListening();
}

The result
Send:

SimpleTx Starting
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Acknowledge received
Data Sent Message 2  Acknowledge received
Data Sent Message 3  Acknowledge received
Data Sent Message 4  Acknowledge received
Data Sent Message 5  Acknowledge received
Data Sent Message 6  Acknowledge received
Data Sent Message 7  Acknowledge received
Data Sent Message 8  Acknowledge received
Data Sent Message 9  Acknowledge received
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Acknowledge received
Data Sent Message 2  Acknowledge received

Receive:

SimpleRx Starting
Data received Message 0
Data received Message 1
Data received Message 2
Data received Message 3
Data received Message 4
Data received Message 5
Data received Message 6
Data received Message 7
Data received Message 8
Data received Message 9
Data received Message 0
Data received Message 1
Data received Message 2

I don't know why these two lines( radio.stopListening(); and radio.startListening(); ) solve the problem. Do you have any ideas?

Any pointers would be appreciated.

Thanks

Short answer is I have no idea.

Comment out those lines you added and try the two programs again. But this time disconnect and reconnect the Tx Arduino from the power to ensure the nRF24 restarts. The normal Arduino reset does not reset the nRF24.

Are you trying this with the high-power versions of the nRF24?

...R

Yes , I use nRF24L01+PA+LNA and nRF24L01+ boards.
I disconnect and reconnect the Tx Arduino from the power this time.

Result:
Send
SimpleTx Starting

Data Sent Message 0  Tx failed
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Acknowledge received
Data Sent Message 2  Acknowledge received
Data Sent Message 3  Tx failed
Data Sent Message 3  Acknowledge received
Data Sent Message 4  Acknowledge received
Data Sent Message 5  Acknowledge received
Data Sent Message 6  Tx failed
Data Sent Message 6  Acknowledge received
Data Sent Message 7  Tx failed
Data Sent Message 7  Tx failed
Data Sent Message 7  Acknowledge received
Data Sent Message 8  Acknowledge received
Data Sent Message 9  Acknowledge received
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Tx failed
Data Sent Message 1  Tx failed
Data Sent Message 1  Tx failed
Data Sent Message 1  Acknowledge received
Data Sent Message 2  Tx failed
Data Sent Message 2  Acknowledge received
Data Sent Message 3  Acknowledge received
Data Sent Message 4  Acknowledge received
Data Sent Message 5  Acknowledge received
Data Sent Message 6  Tx failed
Data Sent Message 6  Tx failed
Data Sent Message 6  Tx failed
Data Sent Message 6  Acknowledge received
Data Sent Message 7  Acknowledge received
Data Sent Message 8  Acknowledge received
Data Sent Message 9  Acknowledge received
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Tx failed
Data Sent Message 1  Tx failed

Receive:

Data received Message 0
Data received Message 1
Data received Message 2
Data received Message 3
Data received Message 3
Data received Message 4
Data received Message 5
Data received Message 6
Data received Message 7
Data received Message 8
Data received Message 9
Data received Message 0
Data received Message 1

It sometimes works but sometimes doesn't.
I have same problem when using MPU6050 gyrometer. Sometimes I have to reconnect the power to make it restart or it will get error sometimes.

Are both boards working at full power?
How far apart are they?

...R

Okay I know this is very old, but since there was no final answer and I just hit something much the same I wanted to share what I found.

Using
radio.setDataRate( RF24_250KBPS );
radio.openWritingPipe(slaveAddress);

and the sketch works. Omitting the "radio.setDataRate" causes the same issue, TX Failed.

This is contrary to the library source code which states that the speeds will be set with the radio.begin (lines 659 - 661 of RF24.CPP.

So regardless of what the docs say, you will need to set the DataRate for the tx to work.

GhostInThePistachio:
So regardless of what the docs say, you will need to set the DataRate for the tx to work.

All my examples set the data rate. I can't remember if I ever tried a program where I did not set it.

...R

Robin2:
All my examples set the data rate. I can't remember if I ever tried a program where I did not set it.

...R

You are very smart, for noobs like myself I take your tagline to heart: "Two or three hours spent thinking and reading documentation solves most programming problems." (RTFM!) In this case documentation caused the problem.

Looking at the tmrh20 github class page "setDataRate" is listed under Optional Configurators. It even goes so far as to say "None are required. Calling begin() sets up a reasonable set of defaults.".

Testing has proven otherwise. It's what caused the OP's issue I think and thought I'd share the information for anyone else who hits it. I believed it was optional and was pulling my hair out trying to figure why I couldn't transmit data when I wrote my own sketch following the docs vs copy and pasting.