Problem receiving data using nRF24L01

Hi guys, I facing with problem using radio data xchange. My setup is:

  • Nano (clone) as the sender and
  • nodeMCU V2 as the receiver
    Both are using same version of RF24 and are set up the same:
RF24 radio(CE_PIN, CSN_PIN);
const byte address[] = {'R','x','A','A','A'};

radio.begin();
radio.setChannel(12);
radio.setCRCLength(RF24_CRC_16);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(address);  // openReadingPipe(1, address) at the receiver
radio.stopListening();  // radio.startListening(); at the receiver
radio.printPrettyDetails();

but the printed default values are already different:

// sender side:

SPI Frequency           = 10 Mhz
Channel                 = **255** (~ 2655 MHz)
Model                   = nRF24L01+
RF Data Rate            = 1 MBPS   
RF Power Amplifier      = **PA_MAX**
RF Low Noise Amplifier  = Disabled
CRC Length              = **16 bits** 
Address Length          = 2 bytes
Static Payload Length   = 32 bytes
Auto Retry Delay        = 250 microseconds
Auto Retry Attempts     = 0 maximum
Packets lost on    
    current channel     = 7
Retry attempts made for    
    last transmission   = 15
Multicast               = Allowed
Custom ACK Payload      = Enabled
Dynamic Payloads        = Disabled
Auto Acknowledgment     = Disabled
Primary Mode            = RX      
TX address              = 0x0000000000
pipe 0 (closed) bound   = 0x0000000000
pipe 1 (closed) bound   = 0x0000000000
pipe 2 (closed) bound   = 0x00
pipe 3 (closed) bound   = 0xff
pipe 4 (closed) bound   = 0x00
pipe 5 (closed) bound   = 0x00
Tempsensors:1
Transmitted Data was :  tmp = 21.06

and

SPI Frequency             = 10 Mhz
Channel                 = 0 (~ 2400 MHz)
Model                   = nRF24L01+
RF Data Rate            = 1 MBPS
RF Power Amplifier      = PA_MIN
RF Low Noise Amplifier  = Disabled
CRC Length              = Disabled
Address Length          = 2 bytes
Static Payload Length   = 32 bytes
Auto Retry Delay        = 250 microseconds
Auto Retry Attempts     = 0 maximum
Packets lost on
    current channel     = 0
Retry attempts made for
    last transmission   = 0
Multicast               = Disabled
Custom ACK Payload      = Disabled
Dynamic Payloads        = Disabled
Auto Acknowledgment     = Disabled
Primary Mode            = TX
TX address              = 0x0000000000
pipe 0 (closed) bound   = 0x0000000000
pipe 1 (closed) bound   = 0x0000000000
pipe 2 (closed) bound   = 0x00
pipe 3 (closed) bound   = 0x00
pipe 4 (closed) bound   = 0x00
pipe 5 (closed) bound   = 0x00
Received Data is :  tmp = 0.00

Even though I set the same channels and other values, they were different when running. Of course, the sent data is not received either. And even I check wether data is available the loop is printing millions of line with zero value:

void loop() {
  static uint32_t lastReception;
  uint32_t topLoop = millis();
  if (radio.available()) {
    radio.read(&dataToRead, sizeof(dataToRead));
    dataToRead.display(F("Received Data is : "));
    lastReception = topLoop;
  }
  if (topLoop - lastReception >= 10000) {
    Serial.println(F("no reception for ten seconds"));
    lastReception = topLoop;
  }
}

Help me please what should I change?

Have you had successful comms with basic code?

The "go to" page for nRF24L01 is:

I would make sure that one of the basic demos works with your hardware setup before creating your own project.

1 Like

You have not posted full sketches (HINT) but it is possible that the problem is caused by the fact that an int uses 2 bytes on the Nano and 4 bytes on the NodeMCU

If the data that you are transmitting is declared as an int this could be a problem. Declare them on both ends as type uint16_t to ensure that the number of bytes in the payload is consistent for both ends

I made what you asked and here are both sketches. Since the first run wasn't success I added the usual enhancements via printDetails(). Thats all what I modified on the basic samples.
The sender:

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

#define CE_PIN  8
#define CSN_PIN 7

RF24 radio(CE_PIN, CSN_PIN);

const byte slaveAddress[5] = {'R','x','A','A','A'};
char dataToSend[10] = "Message 0";
char txNum = '0';
void send();
void updateMessage();

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second

void setup() {
    Serial.begin(9600);
    printf_begin();
    Serial.println("SimpleTx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
    radio.printPrettyDetails();
}

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

void updateMessage() {
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

it's output is:

--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
SimpleTx Starting
SPI Frequency           = 10 Mhz
Channel                 = **255 (~ 2655 MHz)**
Model                   = nRF24L01+
RF Data Rate            = 1 MBPS
RF Power Amplifier      = PA_MAX
RF Low Noise Amplifier  = Disabled
CRC Length              = Disabled
Address Length          = 2 bytes
Static Payload Length   = 32 bytes
Auto Retry Delay        = 250 microseconds
Auto Retry Attempts     = 0 maximum
Packets lost on
    current channel     = 0
Retry attempts made for
    last transmission   = 0
Multicast               = Allowed
Custom ACK Payload      = Enabled
Dynamic Payloads        = Enabled
Auto Acknowledgment     = Disabled
Primary Mode            = RX
TX address              = 0x0000000000
pipe 0 (closed) bound   = 0x0000000000
pipe 1 (closed) bound   = 0x0000000000
pipe 2 (closed) bound   = 0x00
pipe 3 (closed) bound   = 0xff
pipe 4 (closed) bound   = 0x00
pipe 5 (closed) bound   = 0x00
Data Sent Message 0  Acknowledge received
Data Sent Message 1  Acknowledge received
Data Sent Message 2  Acknowledge received
...

Seems to me weird only, that any acknowledgement were received?
the receiver's sketch:

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

#define CE_PIN   4
#define CSN_PIN  2

RF24 radio(CE_PIN, CSN_PIN);

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
char dataReceived[10];
bool newData = false;
void getData();
void showData();

void setup() {
    Serial.begin(9600);
    printf_begin();
    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
    radio.printPrettyDetails();
}

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 it's output:

|�O��␁@LH�␆�2���M@X���GP�@ESimpleRx Starting
SPI Frequency           = 10 Mhz
Channel                 = 76 (~ 2476 MHz)
Model                   = nRF24L01+      
RF Data Rate            = 250 KBPS       
RF Power Amplifier      = PA_MAX 
RF Low Noise Amplifier  = Enabled
CRC Length              = 16 bits
Address Length          = 5 bytes
Static Payload Length   = 32 bytes
Auto Retry Delay        = 1500 microseconds
Auto Retry Attempts     = 15 maximum
Packets lost on
    current channel     = 0
Retry attempts made for        
    last transmission   = 0    
Multicast               = Disabled
Custom ACK Payload      = Disabled
Dynamic Payloads        = Disabled
Auto Acknowledgment     = Enabled
Primary Mode            = RX     
TX address              = 0xe7e7e7e7e7
pipe 0 (closed) bound   = 0xe7e7e7e7e7
pipe 1 ( open ) bound   = 0x4141417852
pipe 2 (closed) bound   = 0xc3
pipe 3 (closed) bound   = 0xc4
pipe 4 (closed) bound   = 0xc5
pipe 5 (closed) bound   = 0xc6

nothing more
Almost every important data is different. Should I reset the RF chip anyhow?
The channels are't the same even I set them up (this experiment isn't in this code).
The boards are wired after this page: see fritzings

Any help 'll be appreciate, please!

The Nano is not correctly connected, or the NRF is faulty,
it does not take any config commands and returns bogus settings.

You can also try the CheckConnection.ino sketch in post #30 of that link I posted. It may well verify what @Whandall has already pointed out.

I think either nano's ports or the NRF is faulty. Even the channel is set to anything the debug is reporting some random value both on sender or on receiver side, too.
Thank you guys, I going to turn to ESP/Wifi.

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