NRF24L01 "Available" even when it's disconnected from board

Hi everyone,

I’m trying to get one Arduino Uno to send a signal to another Arduino Uno as part of a parking sensor project.

To do this, I’m using two NRF24L01s with the standard RF42 Library.

Everything was working fine last night, but this morning they stopped working. I’ve narrowed the problem down to being that the available() method always returns true even when the module is completely disconnected from the arduino which wasn’t happening last night.

I’ve seen a few ways to fix this including soldering a capacitor onto the GND and VCC pins of the RF24 module, which I’ve sort-of done by using an additional circuit board designed for the RF24 chip which regulates the power just like a capacitor would.

Even when there is a signal being transmitted, it still just captures this “blank” packet of information, so I can’t even botch a fix by having it filter out the blank information.

I’ve tried getting this to work on two Arduino Unos and an Arduino Nano and get the same result. I think it’s a software issue rather than a hardware issue since the RF24 doesn’t even need to be plugged in.

I’ve reinstalled the library a few times but again, same result.

Here is the code for the receiving end:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define CE 7
#define CSN 8

RF24 radio (CE, CSN);
byte address[6] = "00001";

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

  radio.begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.openReadingPipe(0, address);
  radio.startListening();

}

void loop()
{

  if (radio.available())
  {
    int Distance = 5;
    radio.read(&Distance, sizeof(Distance));
    Serial.println(Distance);
  }

}

And here is the code for the transmitter, although I don’t think this is relevant at all:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <hcsr04.h>


#define TRIG 2
#define ECHO 3

#define CE 7
#define CSN 8

RF24 radio (CE, CSN);
byte address[6] = "00001";

HCSR04 sensor (TRIG, ECHO);

int Distance;
int delayTime;

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

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.stopListening();
}

void loop()
{
  Distance = sensor.distanceInMillimeters();
  Serial.println("SENDING: " + (String)Distance);

  radio.write(&Distance, sizeof(Distance));
  
  delay(500);
}

Thanks in advance for any help I receive!

Maybe some initialization method like begin() returns an error code that you can check.

aarg:
Maybe some initialization method like begin() returns an error code that you can check.

radio.begin() doesn't return throwback any errors

You should be calling init(). It returns pass/fail status.
From a library example:

  if (!rf24.init())
    Serial.println("init failed");

There is no "init" in the TMRh20 Library

begin returns a bool:

bool begin(void);

Perhaps check it.

EDIT::
I always call 'isChipConnected' after setting everything up, just to make sure the RF24 is actually there.

  /**
   * Checks if the chip is connected to the SPI bus
   */
  bool isChipConnected();

Neither of these return true:

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

  if (radio.begin()) {
    Serial.println("BEGIN == TRUE");
  }

  radio.setPALevel(RF24_PA_MIN);
  radio.openReadingPipe(0, address);
  radio.startListening();

  if (radio.isChipConnected()) {
    Serial.println("CHIP CONNECTED");
  }

}

How can this be fixed? It’s the same with my other 4 chips, so I doubt this is a hardware issue.

EDIT: It also doesn’t throw any errors
EDIT2: radio.Available() is still returning True thinks it’s receiving signal

If both begin() and isChipConnected() return false, then it makes no sense to try calling available().

Maybe a electrical connection or powering problem.

I've tried USB and 9v Battery power. Both of them worked last night. I've also rewired everything and started from scratch and am having the same issue no matter which arduino and RF24 I use. The reason why I mentioned available() still returning true, is surely there is no way it should be able to do that... this is why I think it must be a software issue.

What are your thoughts?

Thanks for all the help btw! :slight_smile:

Try running the connection test from @Robin2’s nRF24L01+ Tutorial. My money is still on a hardware / power problem.

alexwalker0398:
The reason why I mentioned available() still returning true, is surely there is no way it should be able to do that... this is why I think it must be a software issue.

What are your thoughts?

I think it's usually the programmers responsibility to obey the rules of an API. The authors and maintainers cannot imagine all the wrong ways someone could use it, and it would be impractical to implement complete software checks on all possible uses of each API method. That would also lead to hugely inefficient code.

gfvalvo:
Try running the connection test from @Robin2's nRF24L01+ Tutorial. My money is still on a hardware / power problem.

That is also my suspicion.

It would also be a good idea to try a spare nRF24 in case a module is faulty.

...R

[quote] 've sort-of done by using an additional circuit board designed for the RF24 chip which regulates the power just like a capacitor would.

Presumably with a capacitor? A voltage regulator is not a capacitor.

Show how you have things connected. Hopefully you haven’t tried to connect directly and always used the board, as the UNO is 5v and the NRF24 must have 3.3v power only.

gfvalvo:
Try running the connection test from @Robin2's nRF24L01+ Tutorial. My money is still on a hardware / power problem.

Yep, looks like you might be right...

CheckConnection Starting

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 = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1 = 0x0000000000 0x0000000000
RX_ADDR_P2-5 = 0x00 0x00 0x00 0x00
TX_ADDR = 0x0000000000
RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x00
RF_CH = 0x00
RF_SETUP = 0x00
CONFIG = 0x00
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN


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

STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1 = 0x0000000000 0x0000000000
RX_ADDR_P2-5 = 0x00 0x00 0x00 0x00
TX_ADDR = 0x0000000000
RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x00
RF_CH = 0x00
RF_SETUP = 0x00
CONFIG = 0x00
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN