Can't get nRF2401 to work

I have spent many days trying to connect two nRF24L01s.
I have tried various examples, including Ralf Bacon’s. Copying and pasting the code.
Not one seems to work.

This one says it's simple:
https://forum.arduino.cc/index.php?topic=421081.0
seemed to be the easiest and I saw it had a small test program at the end.

The code:

/// SimpleTx - the master or the transmitter

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

And the Rx

/// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

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);

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

The Tx part tells me "Tx failed" and the Rx "Data Received" but without any delay.

The test program:

// 18 Mar 2018 - simple program to verify connection between Arduino
//      and nRF24L01+
//  This program does NOT attempt any communication with another nRF24

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

#include <printf.h>

#define CE_PIN   9
#define CSN_PIN 10

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);
   printf_begin();

   Serial.println("CheckConnection Starting");
   Serial.println();
   Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
   Serial.println("  Note that RF24 does NOT reset when Arduino resets - only when power is removed");
   Serial.println("  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
   Serial.println("     communicating with the nRF24");
   Serial.println();
   radio.begin();
   radio.printDetails();
   Serial.println();
   Serial.println();
   Serial.println("AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1");
   Serial.println(" and 250KBPS data rate");
   Serial.println();
   radio.openReadingPipe(1, thisSlaveAddress);
   radio.setDataRate( RF24_250KBPS );
   radio.printDetails();
   Serial.println();
   Serial.println();
}


void loop() {

}

Gives these results:

/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

I have bought and tried various nRF modules with and without the adapters.
I have checked and rechecked my connections numerous times.
I have used different UNOs and Nanos.
I have connected an external power supply to both Transmitter and Receiver.

I really do not know what to do.
Any help would be much appreciated.

When you are posting code or the results from it please use the code button </>

so your code 
looks like this

and is easy to copy to a text editor See How to use the forum

If the connection test program in my Tutorial is not showing the correct results the usual cause is faulty connections.

Make a pencil drawing showing how YOU have everything connected and post a photo of the drawing. See this Simple Image Posting Guide

Please DO NOT use Fritzing.

The examples in my Tutorial do work and have been used by several other Forum members.

...R

Thanks, this is how I connected:


OP image. How to post images.

Did you change the CE and CSN pin definitions to match your wiring?

From the simpleRX example:

#define CE_PIN   9
#define CSN_PIN 10

The radio modules do not reset when the Arduino board resets. After you load a new program, cycle the power to the Arduino board to reset the radio module. Or cycle the power to the radio module power if an external module power supply. I find that that often helps.

Sorry, in the mean time I tried another sketch from the libray samples, hence I changed the pins to match that sketch.
Whilst running your code I was using 9&10.
I also disconnected the power numerous times and re-ran the program.

Can you post a photo of the rf24 modules that you have? I got some a while back that had a round blob instead of a multi-pin chip. They would not work no matter what I tried. I did get my money back, though.

None of these values look correct to me...

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

Everything is zeros, even after you set an address.

If you look at the power on defaults in the datasheet the Tx address, even before you set anything, should be...
0xE7E7E7E7E7

Have you tried....

  if (!radio.isChipConnected())
  {
    Serial.println(F("NO RADIO!"));
    while(true);
  }

That performs a read of the SETUP_AW register and does a sanity check that there is something valid returned (range 0x01-0x03).

pcbbc:
None of these values look correct to me...

Thanks, I had not noticed that - I had assumed the problem was only with the second set.

I don't recall ever having that problem - I wonder does it signify a faulty nRF24, or completely incorrect wiring.

...R

This is the first pair with antenna I used. as I couldnt get them to work, I bought a second set which came with the capacitor.

Thanks again for the comments. I will try and insert the code tomorrow and publish the results

I am having problems uploading the 2 picture.

Here is the second picture.
I initially connected direct but in the mean time I have purchased the adapters.

My initial guess would be incorrect wiring. But could be a fault unit also.

They can be a faff to get working correctly. I have a 10uF electrolytic cap solder across the pins on the breakout board, and mine are working well.

But just one small change to a setting and you can break the link. My best advice is to start with as few changes from the default parameters at both ends as possible. However it doesn't help that some libraries start by configuring their own set of defaults, different from the power on hardware ones, in software.

Recently I've been spending my time getting the wireless bootloader to work.

Very useful if your Arduino is going to be inside something, and so not easy to flash locally...

Currently, for security reasons, I'm adding a firmware checksum and encryption to the bootloader.

Have you by chance switched the CE and CSN wires? Is the radio sharing GND with the arduino? Are you using cheap dupont wires (with round connectors), they are notoriously poor constructed, so check your wires with a DMM or try different wires. The arduino is not recognizing the radio(s), so the code is not the issue.

I have tried switching the CE & CSN during my many attempts. I am using dupont but the square ones. Again this experimenting has been going on for many weeks (off & on) so there have been differnet wires as well as different Arduino boards.

Makes no sense that it borks on you.. I've tried different types of the NRF24 and I've never had a bad one.. It would be nice if your could post a picture that clearly shows the radio, the arduino and the wiring / breadboard in between.

@Herrid, I suggest you get a few of the low power nRF24s (with the PCB antenna) and get them working first. Their power requirement is considerably lower and also they work when they are close together on the work bench whereas the high-power units probably need to be separated by a few metres as the signal is more powerful.

By the way, always buy more than two units so you can swap them around if you suspect one of them is faulty.

...R

I have found 2 small NRF modules and tried those.
The results of running the test sketch are the same.

Although it is difficult to believe they are all u/s, I have just ordered 4 new ones.

I have attached some pictures of my set up.
I must be doing something wrong :frowning:



[Right click the attachment link, Copy Image Address.
Click More: Modify
Type [ img ], paste the link, type [ /img ] (leaving out the spaces)
Save.
Really quite simple.
Moderator]

Herrid:
I have attached some pictures of my set up.

Please make your images visible in your Post. You were given a link to the instruction earlier.

...R

Robin2:
Please make your images visible in your Post. You were given a link to the instruction earlier.

...R

Also please add some image of the actual NRF module wiring. You've only shown the Arduino side.

Robin2:
Please make your images visible in your Post. You were given a link to the instruction earlier.

...R

Sorry again.
The instructions for an attachment say

"If you right-click on the link and then click "Copy image location" you will have the URL for the image. You can paste that to your text editor if you want to look at it, but that is not normally necessary. "

If I right click the attachment, I do not get that option.

upload your image to Imgur: The magic of the Internet and use the link to the image. also have you tried different cables?