NRF24L01 problem

I am trying to get some NRF24L01 comms added to a project. I am having no joy with it yet. I have done it before, but feel free to remind me about wiring, ports and so forth, obviously I am overlooking something.

But. Right now I am going back to square one, using this code which you will recognize as exactly a simple example found on the web, with the addition of a call to “radio.printDetails();” :

// 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.printDetails();
    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;
}

It compiles and runs, but prints just

SimpleTx Starting
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx fail…

forever, that is to say printDetails() doesn’t. Print anything.

I peeked at the library source code, it seems like printDetails() should print something, even nonsense, regardless of whether there was an NRF24L01 even connected.

I have tried this after installing and re-installing several of the recommended NRF24 libraries, as googling has suggested.

Where am I going wrong? Right now i have two NRF24L01 and simply want to see if I have managed to break them up to now - just want to have a little SPI conversation with them individually as a means to check wiring and life of the radio before trying any actual RF comms.

alto777

Start with the examples that come with the actual version of the RF24 library you are using.
Make sure you only have one RF24 library installed too.

You should have an#include <printf.h>
and in setup

printf_begin();

then printDetails should be able to print.

alto777:
But. Right now I am going back to square one, using this code which you will recognize as exactly a simple example found on the web,

Try the first pair of examples completely unchanged from my Simple nRF24L01+ Tutorial.

They do work and it will be much easier to help when you use code I am familiar with.

You have not said what Arduino boards you are using. Not all of them can provide enough 3.3v power for the nRF24 module. At the very least make sure you have 10µF capacitors across Vcc and GND for the nRF24s.

I assume you are using nRF24s with the PCB antenna? The high power modules with the external antenna definitely need a separate 3.3v power supply.

Do you have a 3rd nRF24 that you can substitute in order to see if either of the first pair is faulty?

...R

Thank you for the help and suggestions.

You would think I had run into the printf thing by now. My friend google helped me in the meantime, although the solution written here to that part of it is much cleaner than what I found. And something to remember.

I did then see print[ed]Details() and was able to confirm proper operation and wiring at the SPI level of both modules.

I have them running on a 3.3 volt pro mini and a 5 volt pro mini. I will try again with a real Uno, which gave some odd different behaviour nothing to worry you all about just now. Or should I say yet.

The last detail was noticing that the "getting started" program needs to be the tiniest bit different for each instance, namely radioNumber. Seems obvious now, but everything led me thinking that the program could serve as either side in this test. Which of course it does to the largest extent.

In any case, the happy news is that I have them talking. The rest, as they say, is all downhill.

Issues about supply voltages noted. My modules have a "real" antenna.

BTW - From another hobby (never mind) I have a nearly unlimited supply of tiny XN297 radio modules. I know they are very related to the NRF24L01, but the IC package only has 8 leads and only 5 pins on the carrier PCB are used, V+, GND and 3 for data transfer, I assume. The PCB is marked but illegible. Is anyone familiar with this version of the XN297 IC? I suppose if I value my time at all I should just get cheap real NRF24L01 modules, but that offends my conservative nature and takes away a bit of a challenge.

Thank you!

alto777

Did you have a look at Arduino library for NRF24L01+ clones: RFM73, RFM75, LCX24G, XN297?

Yes, thank you. I'll have to brush up on my Chinese to read those datasheets.

It looks like the I/O pins are not 5-volt tolerant, no large deal.

I think the three pins on my modules are for so-called 2 wire SPI. It won't take much time to try this theory, but it mightn't be the next thing that gets my attention… I am working on a larger project of which the RF link is but a part, I (now) have enough of that working to leave the XN297s for a rainy day.

Again, I appreciate your rapid and kind responses. What did we do before the internets?

alto777

alto777:
Again, I appreciate your rapid and kind responses. What did we do before the internets?

I read books, datasheets, documentation, journals, everything I could get and I had to remember it.
Some of it is still there...

alto777:
What did we do before the internets?

We solved problems by investigating them ourselves.