nRF24l01 Not Writing

Hello,

I'm new to wireless hardware, and have been having issues with the nRF24l01. After a few hours of troubleshooting, I've consistently found that the write() function has always returned false and the receiver has always received nothing or noise (right now it's nothing). I have yet to find a reason for why these issues are occurring.

Here are the things I've been keeping an eye out for:

  1. Power/Voltage: The Transmitter is an Arduino Uno, powered via USB, which is sending 3.3v to the nRF. The Receiver is an Arduino Nano Every, powered via 5v Power Supply, and the nRF is being powered by its own 3.3v supply, with a decoupling capacitor to reduce noise.

  2. Pins: All SPI and digital pins are in the correct ports.

  3. Distance: nRFs are far enough apart that the signal should not be overwhelming.

  4. Code: Code is taken from this post. Below is what I've been importing into the Arduinos. I believe the only change I've made is which ports are the CE and CSNs.

  5. Hardware: Swapped antenna and had the same issue, so it's unlikely that they are broken.

Right now, the Transmitter simply repeats "Data Sent Message 0 Tx failed", and the receiver prints "SimpleRx Starting" and then nothing.

Transmitter Code

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

Receiver Code

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

#define CE_PIN 5
#define CSN_PIN 8
#define led 2 //for debugging only

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);
    pinMode(led, OUTPUT);
    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 also took photos of the two, shown below.


Your problem is most likely lack of power. The Uno 3.3V is marginal. Sometimes the addition of a 10uF cap across the radio module power input can help, but the high power radios take more current so that is no guarantee. I do not know how good the Nano Every 3.3V is, but on the classic Nano the 3.3V is not up to the task at all.

I use homemade adapters like these to supply a solid 3.3V to the radio modules.

image

Since posting, I've tried a few new things:

  1. The adapters you showed, with a 5v supply.
  2. Introducing a capacitor to the transmitter and receiver power lines, instead of just the receiver.
  3. Powering both radios with an external power supply.

So far, none have helped.

This concerns me because the nRF24L01 has the antenna on the CIRCUIT BOARD and cannot be removed or replaced. What are you actually using?

Sorry, I should've been more clear. I swapped the entire nRF unit.

The first thing to do here would probably be to identify where the problem is occurring.

I would suggest running the gettingstarted example that comes with the RF24 library, but you could also modify your example to do the same thing.

A: If radio.begin() returns false, there is a SPI communication issue with the radio. You will get a message "radio hardware is not responding!!" with the gettingstarted example. Double and triple check wiring and hardware to resolve this issue.
B: If radio.begin returns true, but communication is still failing, try calling radio.setPALevel(RF24_PA_MIN,0); to help rule out power supply issues.

The PA+LNA modules almost always need shielding to work properly at high power as well, so you can take a look at the PA+LNA section to see what I mean: Optimized high speed nRF24L01+ driver class documentation: Common Issues

Thanks for the reply,

  1. radio.begin always returns true.
  2. radio.setPALevel(RF24_PA_MIN,0) had no effect.
  3. Shielding had no effect.
  4. The GettingStarted example has a similar issue. The TX node repeats "Transmission failed or timed out" while the RX node prints nothing.

I'm not sure what this means about where the problem might be. Any ideas?
Thanks.

That means your "receiver" did not acknowledge receipt of the transmission. Focus on your "receiver" to fix the problem.

Well your code is fine, the radios are responding to SPI commands, just not working. I would start thinking about hardware issues with the radios themselves. It could be other things though.
What do you get if you do the following?:

#include "printf.h"

then after serial.begin call

printf_begin(); 

and after radio.begin call

radio.printDetails();

Hello texturelesshorse

For a long time I have been following the topic with the use of this type of wireless module and the associated software functions.

For wireless projects I recommend the use of 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. transmitter and receiver are contained in one radio module.

hth

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

1 Like

The radio I've been using as the TX returns
image

While the RX returns
image

So the TX looks fine but there is a problem on the RX side though with SPI communication. I would guess the wires are a bit too long.

You can lower the SPI speed to 1Mhz by calling

RF24 radio(CE_PIN, CSN_PIN, 1000000);

Why do you have the big difference in transmit power between the two boards?

They're both powered with the same source now, and both call radio.setPALevel(RF24_PA_MIN,0); I'm not sure why the PA Power is different.

printDetails() now shows 1Mhz, but there's still no communication happening.
image

Hmm, that still indicates you are getting bad SPI communication between the radio and the Nano Every. The two devices are not 'talking' together correctly. The output should look very similar to the TX device which appears to be functional. The PA power is showing incorrect because of this, along with other settings.

I don't have any more suggestions other than to shorten the wires and verify you have your pins correct. It seems to be a hardware issue of some sort.

Swapped some wires and the Nano, and I think the SPI communication is working now. Unfortunately, there's still no communication happening. Here's what the details look like now.

image

image

OK looking good, that's a big step in the right direction!

You've got your main SPI pins correct, the next thing to verify is that you have the CE and CS pins correct as well. They need to be correct to transmit/receive.

There shouldn't be much else that can be wrong now besides software problems, so as long as you are using working code, like the gettingstarted examples or the initial code you posted, it should start working.

Is it possible that the radios are broken without SPI communication being disrupted? I've verified that every pin is in the right spot, and I've tried both the example code I showed earlier, as well as the GettingStarted file. Every time the write() function is called, the reciever gets nothing.

While I've been swapping the radios out to check if it's a hardware issue, I only have 3. It's not too unlikely that more than 1 is broken.

Yes, usually at this point things start working. If you got all the radios from the same place, there is a chance they are faulty. The easiest way to know is to test with some known working modules to verify.