nRF24L01 Communication Issue

I'm using nRF24L01+PA+LNA to communicate between my Arduino Mega and ESP32. I'm trying to run a basic bidirectional sketch that worked well just a few weeks ago but now, on the Mega side, I see bad data coming back from the ESP32. My bidirectional sketch is to test acknowledgement payloads - the Mega transmits "Hello ESP32" to the ESP32 while the ESP32 returns dummy data after it has received the Mega's message. Now, on the Mega side, all I see coming back is 216 | ovf | ovf | 55512. Attached is my code below.

// Mega Code

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

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

const byte address[6] = "00001";

struct __attribute__((packed)) returnData {
uint8_t gpsStatus;
float lat;
float lon;
uint16_t hdg;
} ackData;

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

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

  if (radio.isAckPayloadAvailable()) {
     radio.read(&ackData, sizeof(ackData));
     Serial.print(ackData.gpsStatus); Serial.print("|"); 
     Serial.print(ackData.lat); Serial.print("|"); Serial.print(ackData.lon); 
     Serial.print("|"); Serial.print(ackData.hdg);
     Serial.println();
  }
  delay(1000);
}

// ESP32 Code

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

RF24 radio(4, 5); // CE, CSN

const byte address[6] = "00001";

struct __attribute__((packed)) returnData {
uint8_t gpsStatus;
float lat;
float lon;
uint16_t hdg;
} ackData;

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

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

    ackData.gpsStatus = 1;
    ackData.lat = 50.8759;
    ackData.lon = -110.5749;
    ackData.hdg = 200;

    radio.writeAckPayload(0, &ackData, sizeof(ackData));
  }
}

Any help would be very much appreciated! Thank you!

Great job on posting code, now can you post an annotated schematic showing exactly how you have wired each module. Be sure to show all power, ground, power sources, and not any leads over 10"/25 cm in length.

1 Like

The wiring is pretty standard for both. CE and CSN pins are 7 and 8 respectively on the Mega while on the ESP32, they are 4 and 5, respectively. On the Mega, MISO - pin 50, SCK - pin 52 and MOSI - pin 51. On the ESP32, MISO - pin 19, SCK - pin 18 and MOSI - pin 23. The nRF24L01 is powered through an external power supply and has a 10 uF capacitor soldered between VCC and GND.

I suspect the delay should go between the radio.write and the test to see if the ack has been received.

So finding an annotated schematic showing exactly how you have wired it should be easy, please post it, I do not work with word diagrams, to much chance for error.

I was receiving the ack data fine using this setup. However, I had tried it without the delay and it made no difference here. Swapped out my board (Elegoo Mega) with an Arduino Mega I had lying around and everything worked. So the Elegoo Mega is the problem - I have to dig into exactly what caused this to stop working.

Apologies for the delayed response, @gilshultz, I've been away traveling since I posted here. I can provide you with a schematic once I'm back. The last thing I checked before I left was to test out the setup by replacing my Elegoo Mega with an original Arduino Mega and everything worked which makes me think that something happened to the Elegoo Mega at some point. Reading online, I've seen folks suggest reducing the SPI clock speed on 3rd party boards so I'll try that once I'm at my desk again. Have you experienced something like this before? I guess 3rd party boards need a little extra attention sometimes.

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