NRF24 RADIO is never available

Hi everyone!
I'm working with 2 nRF24L01 (with the RF24 library) and a SFR05.
My idea is to send the distance measured by the SFR05 over to the receiver.
The problem that I have is that I'm not able to have the radio available (I have based my code on another one that works).
This is the Tx code:

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

#define TRIG_PIN 3
#define ECHO_PIN 2
long duration;
float distancia;
float medida;
const int pinCE = 9;
const int pinCSM = 10;
RF24 radio(pinCE,pinCSM);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
   {  
       Serial.begin(9600);
       radio.begin();
       radio.openWritingPipe(pipe);
    }

void loop(void)
  {  
    if(radio.available()){
      Serial.println("zi");
    }
    delay(30);
    medida = medirm();
    radio.write(&medida, sizeof distancia);
   }

float medirm(){
  //medir la distancia usando trig: 3 y echo: 2 (devuelve cm)
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN,HIGH);
  digitalWrite(TRIG_PIN,LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distancia = duration*0.034/2;
  return distancia;
}

And this is the Rx code:

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

const int pinCE = 9;
const int pinCSM = 10;
RF24 radio(pinCE,pinCSM);
const uint64_t pipe = 0xE8E8F0F0E1LL;
float distancia;
void setup(void)
   {  Serial.begin(9600); 
      radio.begin();
      radio.openReadingPipe(1,pipe);
      radio.startListening();
   }
void loop()
   {   if (radio.available())
          {   
              radio.read(&distancia, sizeof distancia);
              Serial.println(distancia);
          }
        else{
          Serial.println("no");
        }
   }

Thanks for your help :wink:

Posting an annotated schematic showing exactly how you have wired it helps us help you. By showing all connections, power, components, ground and power sources you will save a lot of clarifying questions and time for
all of us. Be sure to note any logic wires over 10/25 inches/cm in length. Post links to technical information on the hardware items including the motors, shield, and Arduino. This should include all component values or model numbers and details of all power supplies used (which could be USB power for example). Posting the code following forum guidelines using code tags will also help. With this information we should be able to answer your question accurately. "How to get the best from this forum".

If you don't understand what a schematic is, please Google to find out. It is not the same thing as a wiring diagram. Hand-drawn is OK. Some bright, sharp photos of the circuit may also be useful.

The thing I see is many of the users do not want to draw schematics yet a large portion of there problems are in the connections, power etc. It appears they spend about a week or so with lots of questions and then maybe, give up, and some get lucky. It is amazing how many problems you find when doing a real labeled schematic including Technical links. That schematic makes them look like a pro. It appears to me that most of the time when a proper schematic is posted the solution is usually within day or so. Good schematic capture software can be gotten for the downloading. Months later a wire comes off, looking at the schematic and putting it back saves lots of headaches.

What is a schematic What Is a Schematic Diagram?
https://learn.sparkfun.com/tutorials/how-to-read-a-schematic/all
HOW to READ a Schematic: https://www.youtube.com/watch?v=9cps7Q_IrX0&t=15s

KiCad: There are many out there and you will find just like color different people like different colors, some blue, red, ..etc. CAD (Computer Aided Design) programs are like that. You will need to learn a schematic capture program that will work for you.

it is a good idea to call radio.isChipConnected() to check if the NRF24L01 is connected ok, e.g.

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("\n\nESP32_S3 > NRF24L01 Receive text");
  radio.begin();
  if (radio.isChipConnected())
    Serial.println("Receiver NF24 connected to SPI");
  else {
    Serial.println("NF24 is NOT connected to SPI");
    while (1)
      ;
  }

Hi everyone!
Firstly:
I am using two NRF24L01+PA with the socket to convert to from 5V to 3.3V.
In the receiver side I use an Arduino Uno and on the transmitter side I use an Arduino Uno R3.
This is the schematic for the Tx:


And this is for the Rx:

Please note that the CE pin in the schematic is connected to the Arduino Uno PIN number 4 whilst in reality is connected to the 9th (I couldn't change sorry).
Secondly:
I used the function radio.isChipConnected() on both the Tx and the Rx and it says that both are connected.
Thanks for your help.

Do you have pair of sketches that works with the hardware as it is currently configured?

Post those sketches. Some subtle change to what yo are doing with the "real" sketches may be killing you.

a7

  • Powering the nRF24L01 with the Arduino 3V3 will probably not work.
    Try an external 3V3 supply that can supply the required current.
    A 220uF to 470uF capacitor on 3V3 might be helpful too.

Shouldn't there be a short delay between these two...??? (10)
Also the first delay, 2 is normally enough....

digitalWrite(TRIG_PIN,HIGH);
  digitalWrite(TRIG_PIN,LOW);

Hi!

  • How can I get an external 3V3? Besides I'm using a module to convert the 5V to 3V3

    This is a picture of the NRF24 + socket.
    *This is the Tx code that worked for me:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

const int pinCE = 9;
const int pinCSM = 10;
RF24 radio(pinCE,pinCSM);
const uint64_t pipe = 0xE8E8F0F0E1LL;
char data[16]="Hola mundo";
void setup(void)
   {  
       radio.begin();
       radio.openWritingPipe(pipe);
    }
int msg[1] ;

void loop(void)
  {  
    radio.write(data, sizeof data);
    delay(1000);
   }

And this for the Rx:

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

const int pinCE = 9;
const int pinCSM = 10;
RF24 radio(pinCE,pinCSM);
const uint64_t pipe = 0xE8E8F0F0E1LL;
char data[16]="Hola mundo";
void setup(void)
   {  
       radio.begin();
       radio.openWritingPipe(pipe);
    }
int msg[1] ;

void loop(void)
  {  
    radio.write(data, sizeof data);
    delay(1000);
   }

Once again, thanks everyone for your help!.

Using digitalWrite() introduces a delay, forming what might be a long enough pukse.

But when I went to look at the sensor library code and examples, I find that using the NewPing library means not having to do the usual steps by hand,

@arduino_fan7 why don't you use the simpler calls that NewPing allows?

And have you tried just eliminating, temporarily, the ultrasonic stuff, instead send a value you can recognize as having been sent successfully?

Is your hardware unchanged since the two sketches that worked? Any wiring, lead dress or power supply changes may be at the bottom of this; I cannot compare your code to the code that worked just now.

a7

Good to know. That's 10000 nanoseconds, quite the pulse if we were talking about something else.

And a good point about the variability of digitalWrite().

The NewPing library goes conservative to account, it seems, for some instances of the sensor, viz:

#define TRIGGER_WIDTH 12  

and uses direct port manipulation, so that's the width.

I have the opportunity to ask again of @arduino_fan7 why not just use the library method

Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)

and enjoy the benefits that the author feels were improvements over the way ppl do it without?

a7

The Tx and Rx programs in post #9 bear a remarkable similarly to each other.

The hardware has not been changed from the first project to this one except adding the sonar.
I've just tried to send just a float, without using the sonar or measuring with it… and I still have the same issue.
The radio (on the receiver end) is still not available.
Does anyone have and idea on how to solve this?
Thanks everyone.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.