Trying and Failing to use NRF24L01

I'm trying to build a US plastic ant combat robot controlled with NRF modules, but I'm having a hell of a time getting them working. The system worked for two days. Then it just stopped functioning. One of two things was happening. Either the transmitter was sending the wrong joystick data to the receiver, or the receiver wasn't reading the data correctly. Either way, the system was connected, but something didn't work. Thinking this was a hardware issue, I replaced all of the parts on the controller, and suddenly the problem changed. Now, whenever the controller is instructed to send data to the transmitter, it refuses, and the code stops running. I won't say how I tested this unless someone asks because it was quite complicated. The receiver doesn't connect at all. Thinking this was a problem with the new Arduino in the transmitter, I switched back to the old one, and the problem persisted. I'm now just trying the simple task of sending a single number from TX to RX, and it still doesn't work.

I have a few questions. What on God's Earth am I doing wrong? It's so inconsistent. Should I just use RF Nanos?

I'm using modified code to send the number from the transmitter to the receiver like I mentioned, but I don't have access to it right now. I based the framework off of this instructable.

Please post your schematic and modified code using the code tags.

Using batteries for the project?

Tried both LiPos and USB.

Code will be posted when I have access. Schematics are just an NRF in a breakout connected to an Arduino UNO, and an NRF in a breakout connected to an Arduino Nano.

CE, CSN is 7 and 8.

Help will probably be more forthcoming after you have the chance to do that :smiley:

I should probably mention that the code from the Instructable doesn't work either. Here is what the code basically says.

Receiver

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

RF24 myRadio (7, 8); 
struct package
{
  int X=1;
};

byte addresses[][6] = {"0"}; 

typedef struct package Package;
Package data;

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

  myRadio.begin(); 
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}


void loop()  
{
  if ( myRadio.available()) 
  {
    while (myRadio.available())
    {
      myRadio.read( &data, sizeof(data) );
    }
    Serial.print("X:");
    Serial.print(data.X);
    int X = data.X;
  }

}

Transmitter

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

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};

struct package
{
  int X=1;
};


typedef struct package Package;
Package data;


void setup()
{
  Serial.begin(9600);
  delay(100);
  myRadio.begin();  
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MIN);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openWritingPipe( addresses[0]);
  delay(100);
}

void loop()
{
 
  myRadio.write(&data, sizeof(data)); 

  Serial.print("X:");
  Serial.print(data.X);
  data.X = 1;
  delay(100);
}

It should just be sending the number 1, but either the transmitter hangs while trying to send the code, or it says that it sends but the receiver doesn't receive the data.

When I implemented an NRF network I ran into every snafu conceivable. If I were you I would start with an example sketch supplied with the library, get the two NRFs talking to each other and take it from there.

Whichever library I'm using, it has the most complex sketch I've ever seen as it's "getting started" example. I don't know enough about the programming language to do anything with the madness they supply with the library.

If you don't use pin 10 (CS on 328p) for the NRF, it should be set to output,
IIRC the SPI library needs that for master mode.

The used pipe address will match a lot of noise, but should not really prohibit operation.

The transmitter strategy is fire and forget,
you have no clue whether the hardware thinks it transmitted something.

The transmitter is missing a stopListening call in setup, that is needed for newer library versions.

Loose the while in the receiver, it is just wrong.

structs don't need typedefs, they are already types.

I'll make the corrections you mentioned.

For the stopListening - should I just put:

myRadio.stopListening();

Where does it go? I assume under:

myRadio.setChannel(115);

I would make it the last statement of the nrf initialization.

1 Like

Speaking of which, do you think the transmitter freezes when trying to send data because of that missing statement?

I used Robin2's simple rf24 tutorial to get my radios to work. He has proven good example code and covers some of the common pitfalls including getting sufficient power to the radios. There is also a sketch that tests the physical connection between the radio module and its processor (Arduino). See reply #30. Guaranteed better than Instructables.

No. Maybe there is a chance to hang the Arduino by screwing up the SPI connections.

Like @groundFungus wrote, the best way to troubleshoot is to verify the connection
between the Arduinos and the chip on both nodes first.

Ah. So, um, this is embarrassing. None of my eight nRF modules work. I used Robin's test using two Arduino UNOs and two different breakouts. Guess I'm buying some RF Nanos to replace these things.

If all eight of something has failed is it safe to assume there's a chance they are not being tested correctly?

That would nearly guarantee a working setup.
Of course, you could connect things to that module to make the NRF fail also.

I used the exact code from the hardware test in Robin2's tutorial thread. If you are curious it is reply #29. I might have changed the CE/CSN pins to match mine but other than that I think they are all dead.

Can you post photos of the rf24 modules front and back and clear photos that show the wiring of the modules to your Arduino.

1 Like