NRF24L01+ and Nano ESP32

I have a Mega R3, NRF24L01+, the socket adapter module board for NRF24L01+, Nano ESP32, and an UNO R3.

When transmitting data between the Mega and UNO (UNO as transmitter) everything works perfectly. Data received! When wiring it up the exact same way to use the Nano ESP32 as transmitter, no data is sent. I even tried using a logic converter to bring the Nano's 3.3v up to 5 since the UNO logic pins are 5v. I'm not sure if I'm doing something wrong or if its not meant to work with ESP32 infrastructure.

Transmitter Code:

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

  #define radioce 7
  #define radiocsn 8

  RF24 radio(radioce, radiocsn); // CE, CSN
  const byte address[6] = "00001";

  struct Data_Package_T {
    int x = 5;
    int y = -5;
  };

  Data_Package_T datat;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  radio.stopListening();

  Serial.println("Made it through Setup");
}

void loop() {
  delay(1000);
  radio.write(&datat, sizeof(Data_Package_T));
}

Receiver Code:

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

  RF24 radio(7, 8); // CE, CSN
  const byte address[6] = "00001";
  
  struct Data_Package_T {
    int x;
    int y;
  };
  Data_Package_T datat;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {}  // hold in infinite loop
  }

  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();

  Serial.println("Made it through Setup");

}

void loop() {
  radio.startListening();
  while (!radio.available());
  if (radio.available()){
    radio.read(&datat, sizeof(Data_Package_T));
  }
  Serial.print("X RPM: "); Serial.println(datat.x);
  Serial.print("Y RPM: "); Serial.println(datat.y);
}

I actually got it to send data using Nano ESP32 as transmitter. But the -5 comes in as 0 where on the UNO it came in as -5. Not sure why?? I need to be able to send negative numbers when I actually put this into practice.

I have a transmitter code that uses an ESP32 and a RF24. I think that I wrote it to go with an Uno transmitter and it did work well (testing for Robin2). Unfortunately I cannot test it right now, but maybe it will be of some use.

// SimpleRx - the slave or the receiver

//name >> rf24 pin >> ESP32 pin
//MOSI     6            23
//MISO     7            19
//SCK      5            18
//Vcc      2            3.3V
//                      10uF across 1 & 2
//GND      1            GND

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

#define CE_PIN   22  // rf24 pin 3
#define CSN_PIN 21   // rf24 pin 4

const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[32]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup()
{

   Serial.begin(115200);
   Serial.println("SimpleRx Starting");
   
   radio.begin();
   radio.setDataRate( RF24_250KBPS );
   radio.setRetries(3, 5); // delay, count
   //radio.setChannel(10);
   //RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
   radio.setPALevel(RF24_PA_LOW);
   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;
   }
}

Try an external power supply and be sure the radios are at least 1 meter apart.

Signed vs. unsigned declaration?

I was actually able to get it working. And for some reason when sending a negative number it increases the size substantially. The negatives came through when I assigned them as a long variable

1 Like