Basic NRF24L01 sketch

I started out this morning trying to get a gesture control system I had working a few months ago running again, it wasn't. I determined that the receiver wasn't getting the data correctly. To make a long story short, I've tried 4 different Nanos, 3 NRF24's and wiring. Then I got a couple of basic sketches off of the howtomechatronics.com website, his project usually work pretty good. He has a simple test, one sketch sends "Hello World" the other reads it. This is where I'm at now. It's probably something dumb but I don't understand.

If I set CE and CSN to the digital pins I have them wired to, 7,8, nothing works, I put a print statement inside the if radio.available() statement and it doesn't print so it must not be available. If I set CE and CSN to 8,9 but keep the wires on 7,8 it does print that it's available but prints all question marks. I expected it not to read correctly but don't understand why when wired wrong it's available.

Here's the sketch then sends Hello World

/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  Serial.println(text);
  delay(1000);
}

Here's the sketch that reads it

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

RF24 radio(8,9); // CE, CSN 7, 8

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  
  if (radio.available()) {
    Serial.println("available");
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    
  }
  
}

What is the problem?

thanks
John

Have you tried the basic example sketches from the NRF library, to confirm the hardware independently from your sketch?

Try the sketches and advice from this topic

Simple nRF24L01+ 2.4GHz transceiver demo

I have 2 Unos with rf24 radios attached. I uploaded your code to them and I get

available
Hello World
available
Hello World
available
Hello World
available
Hello World

in the receiver serial monitor. So there is nothing wrong with the code.

How are your radios powered? The number one cause of problems with those radio modules is power.

What modules do you have? The high power modules (with external antenna) can have trouble talking to each other if they are too close together. Try moving them a few meters apart.

CE and CSN must be wired correctly.

I would suggest that you look at Robin2's simple rf24 tutorial. There is a discussion of the power problem and how to solve it in the tutorial. That tutorial is what I used to get my radios to work. Also there is a sketch in reply #30 of the tutorial to test the wired connection between a radio module and its processor that can help with troubleshooting..

Thanks all.

I didn't know of the other basic examples, that's what I was looking for when I got the examples I used. I will try them.

I did know about the power problem, right now it's just a Nano and the NRF powered by the 3.3v from the Nano. I connected a 9v battery to the Vin on them and it didn't make much of a difference. Will add a capacitor across the power feeds as well.

I actually didn't think the codes where the problem but after 3 different set ups I wanted to check. I've triple checked my wiring but obviously it's something on my end that is the problem

I'll go back and check it all and use the other examples

thanks again, really appreciate the help
John

I use these or ones like them 1/2/3/5/10 Arduino NRF24L01+ 2.4GHz Wireless RF Transceiver Module Shield UK | eBay and never have power problems as they have their own 3V3 regulator on board to supply the radio module

I have been using homemade versions of those adapters for years with 100% success.

The 3.3V regulator on the Nano is known to be too weak for the rf24 radio modules. The cap may help, but the adapters mentioned by @UKHeliBob (or a version thereof) will be better.

I like those adaptors for the NRF. But, I wish the header pins were on the other side so it could be mounted on a PWB.

I had a long, drawn-out email exchange regarding this with the Chinese manufacturer. I just wanted them to supply the board with the header pins NOT installed, I'd solder them in the way I want. Bottom line ... couldn't make it happen, mostly because they are unable or unwilling to have a meaningful exchange in the English language.

It's easy enough to get the pins off and put them on the other side, which is what I have done, but a nuisance, I agree

Even more of a nuisance is that the power pins are not on a 0.1 inch grid pitch with the line of pins

Depending on which Nano / clone you have, the 3.3volts may be derived from the USB interface chip and works only when the Nano is powered via the USB port. In this case it is anyway only about 50mA and is, as already pointed out, insufficient for these NRF24L01 modules.

It must have been the power, I had a couple of the adapters and wired them in and bingo, the sketches I was using worked fine. I'll still go through the other examples mentioned. Especially robin2's, he's helped me on a few other issues. Always get great feedback from this forum.

Thanks all, now back to the original project that I started on
John

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