1

Following this tutorial I attempted making an NRF transmitter and receiver using an Arduino Nano. On the transmitter side I used the following 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;
}

The serial monitor prints

13:05:22.966 -> Data Sent Message 3  SimpleTx Starting
13:05:25.437 -> Data Sent Message 0  Acknowledge received
13:05:26.436 -> Data Sent Message 1  Acknowledge received
13:05:27.434 -> Data Sent Message 2  Acknowledge received
13:05:28.432 -> Data Sent Message 3  Acknowledge received
13:05:29.432 -> Data Sent Message 4  Acknowledge received
13:05:30.432 -> Data Sent Message 5  Acknowledge received
13:05:31.427 -> Data Sent Message 6  Acknowledge received

at 1 second intervals. I assume this points to an 'okay' transmitter. On the receiver side, I used the code

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

And the receiver gets flooded with data packets

13:06:20.318 -> Data received⸮SimpleRx Starting
13:06:21.798 -> Data received 
13:06:21.831 -> Data received 
13:06:21.831 -> Data received 
13:06:21.864 -> Data received 

The post also mentions that this is due to "most likely the Arduino is not communicating properly with its nRF24." Following the recommendations of post #30, later in the thread, the output of radio.printDetails() for the transmitter is

19:43:56.897 -> CheckConnection Starting
19:43:56.897 -> 
19:43:56.897 -> FIRST WITH THE DEFAULT ADDRESSES aftCheckConnection Starting
19:43:58.355 -> 
19:43:58.355 -> FIRST WITH THE DEFAULT ADDRESSES after power on
19:43:58.422 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
19:43:58.488 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
19:43:58.574 ->      communicating with the nRF24
19:43:58.621 -> 
19:43:58.621 -> SPI Speedz  = 10 Mhz
19:43:58.654 -> STATUS      = 0x7f RX_DR=1 TX_DS=1 MAX_RT=1 RX_P_NO=7 TX_FULL=1
19:43:58.721 -> RX_ADDR_P0-1    = 0xffffffffff 0xffffffffff
19:43:58.754 -> RX_ADDR_P2-5    = 0xff 0xff 0x7f 0xff
19:43:58.788 -> TX_ADDR     = 0xffffffff7f
19:43:58.821 -> RX_PW_P0-6  = 0x00 0x00 0x00 0x00 0x00 0x00
19:43:58.854 -> EN_AA       = 0x00
19:43:58.887 -> EN_RXADDR   = 0x7f
19:43:58.887 -> RF_CH       = 0x00
19:43:58.920 -> RF_SETUP    = 0x00
19:43:58.920 -> CONFIG      = 0x00
19:43:58.954 -> DYNPD/FEATURE   = 0x00 0x00
19:43:58.954 -> Data Rate   = 1 MBPS
19:43:58.987 -> Model       = nRF24L01+
19:43:59.020 -> CRC Length  = Disabled
19:43:59.020 -> PA Power    = PA_MIN
19:43:59.053 -> ARC     = 0
19:43:59.053 -> 
19:43:59.053 -> 
19:43:59.053 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
19:43:59.120 ->  and 250KBPS data rate
19:43:59.154 -> 
19:43:59.154 -> SPI Speedz  = 10 Mhz
19:43:59.186 -> STATUS      = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
19:43:59.253 -> RX_ADDR_P0-1    = 0x0000000000 0x0000000000
19:43:59.286 -> RX_ADDR_P2-5    = 0x00 0x00 0x00 0x00
19:43:59.320 -> TX_ADDR     = 0x0000000000
19:43:59.353 -> RX_PW_P0-6  = 0x00 0x00 0x00 0x00 0x00 0x00
19:43:59.386 -> EN_AA       = 0x00
19:43:59.419 -> EN_RXADDR   = 0x00
19:43:59.419 -> RF_CH       = 0x00
19:43:59.452 -> RF_SETUP    = 0x00
19:43:59.452 -> CONFIG      = 0x00
19:43:59.486 -> DYNPD/FEATURE   = 0x00 0x00
19:43:59.486 -> Data Rate   = 1 MBPS
19:43:59.519 -> Model       = nRF24L01+
19:43:59.552 -> CRC Length  = Disabled
19:43:59.552 -> PA Power    = PA_MIN
19:43:59.585 -> ARC     = 0
19:43:59.585 -> 
19:43:59.585 ->

The same sketch when uploaded on the receiver gives,

19:48:38.260 -> CheckConnection Starting
19:48:38.260 -> 
19:48:38.260 -> 
19:48:38.260 -> 
19:48:38.260 -> FIRST WITH THE DEFAULT ADDRESSES aftCheckConnection Starting
19:48:39.708 -> 
19:48:39.708 -> FIRST WITH THE DEFAULT ADDRESSES after power on
19:48:39.774 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
19:48:39.841 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
19:48:39.941 ->      communicating with the nRF24
19:48:39.974 -> 
19:48:39.974 -> SPI Speedz  = 10 Mhz
19:48:40.008 -> STATUS      = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
19:48:40.075 -> RX_ADDR_P0-1    = 0x0000000000 0x0000000000
19:48:40.109 -> RX_ADDR_P2-5    = 0x00 0x00 0x00 0x00
19:48:40.141 -> TX_ADDR     = 0x0000000000
19:48:40.175 -> RX_PW_P0-6  = 0x00 0x00 0x00 0x00 0x00 0x00
19:48:40.208 -> EN_AA       = 0x00
19:48:40.242 -> EN_RXADDR   = 0x00
19:48:40.242 -> RF_CH       = 0x00
19:48:40.274 -> RF_SETUP    = 0x00
19:48:40.274 -> CONFIG      = 0x00
19:48:40.308 -> DYNPD/FEATURE   = 0x00 0x00
19:48:40.308 -> Data Rate   = 1 MBPS
19:48:40.341 -> Model       = nRF24L01+
19:48:40.374 -> CRC Length  = Disabled
19:48:40.374 -> PA Power    = PA_MIN
19:48:40.407 -> ARC     = 0
19:48:40.407 -> 
19:48:40.407 -> 
19:48:40.407 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
19:48:40.474 ->  and 250KBPS data rate
19:48:40.508 -> 
19:48:40.508 -> SPI Speedz  = 10 Mhz
19:48:40.541 -> STATUS      = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
19:48:40.607 -> RX_ADDR_P0-1    = 0x0000000000 0x0000000000
19:48:40.640 -> RX_ADDR_P2-5    = 0x00 0x00 0x00 0x00
19:48:40.674 -> TX_ADDR     = 0x0000000000
19:48:40.707 -> RX_PW_P0-6  = 0x00 0x00 0x00 0x00 0x00 0x00
19:48:40.740 -> EN_AA       = 0x00
19:48:40.773 -> EN_RXADDR   = 0x00
19:48:40.773 -> RF_CH       = 0x00
19:48:40.806 -> RF_SETUP    = 0x00
19:48:40.806 -> CONFIG      = 0x00
19:48:40.840 -> DYNPD/FEATURE   = 0x00 0x00
19:48:40.840 -> Data Rate   = 1 MBPS
19:48:40.873 -> Model       = nRF24L01+
19:48:40.906 -> CRC Length  = Disabled
19:48:40.906 -> PA Power    = PA_MIN
19:48:40.939 -> ARC     = 0
19:48:40.939 -> 
19:48:40.939 ->

There is some miscommunication as claimed by that post. I tried changing the pins of CE, CSN to 7,8 but the problem persisted for the receiver. I changed the power supply to the NRF using two alkaline AA batteries, but that didn't solve the problem either. I also connected a 10 μF capacitor between the power supply pins of the NRF, but no luck. Next, I tried changing the NRF module. I used an NRF module which was working correctly as a transmitter(printing "Data Sent Message X Acknowledge received") at 1 second, as intervals as a receiver in place, still the same problem.

Any help would oblige.

P.S: I am using Arduino clones, but they work for other purposes. The NRF's have "NRF24L01" stamped on the chip, and seem to be fine.

8
  • The radio.printDetails() information are coming from the sender or the receiver ?
    – Vincent
    Aug 2, 2021 at 11:39
  • 1
    According to reply #30 on the Arduino Forum thread "Simple nRF24L01+ 2.4GHz transceiver demo", radio.printDetails() is run twice: once for unintialised and a second time for initialised. This should give you two sets of results, but you've only posted one set in your question. Are both sets of results identical?
    – tim
    Aug 2, 2021 at 16:41
  • @Vincent, sorry for the incomplete information. I have updated the question. What strikes me, is that #reply #30 sets radio.setDataRate( RF24_250KBPS ); but radio.printDetails(); report Data Rate = 1 MBPS.
    – Ranjit Pal
    Aug 4, 2021 at 14:33
  • @tim, sorry for the incomplete details too. I have posted both sets now. They are identical for the receiver, but STATUS, RX_ADDR_P0-1, RX_ADDR_P2-5, TX_ADDR and EN_RXADDR differ for the transmitter.
    – Ranjit Pal
    Aug 4, 2021 at 14:35
  • @RanjitPal About DataRate, nRF24L01 can transmit only with 1MBPS or 2MBPS, while nRF24L01+ (upgraded version) can also transmit with 250KBPS (which is useful for polluted environment or longer distance communication). This is why you can not set your nRF24L01 to a 250KBPS datarate. But it surprises me that the printDetails() command indicates the upgraded version to be honest. The pipe1 address also remains the same even if you execute openReadingPipe(1, thisSlaveAddress) which is another problem.
    – Vincent
    Aug 5, 2021 at 15:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.