Problems with NRF24L01

Hi guys:
I am trying to get the temperature sent to me by a sensor with an Arduino mega 2560 remotely with an NRF24L01. This information is received by an Arduino nano with another NRF24L01 and should be displayed on the serial port. When connecting the two boards, it doesn't show me anything on the serial monitor, and with serial.print commands that I have been introducing in the codes of both, I have realized that on the Arduino Mega 2560 (emitter) its code runs perfectly no crashes, but on the Arduino Nano (receiver), it never goes into the if statement in the void loop. Can somebody help me? Here I put the codes.

This is the receiver.

#include <SPI.h>
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
const int CE = 8;
const int CSN = 10;
float tempC;
const uint64_t canal= {0xE8E8F0F0E1LL};
RF24 rf (CE, CSN);
void setup() {
  Serial.begin(115200);
  rf.begin();
  rf.setRetries(5, 10);
  rf.openReadingPipe(1, 76);
  rf.setPALevel(RF24_PA_MAX);
}

void loop() {
  rf.startListening();
  if (rf.available()){
    Serial.println("Bien");
    rf.read(&tempC, sizeof(tempC));
    Serial.print(tempC);
    Serial.println("ÂșC");
    delay(500);
  }
  delay(10);
}

This is the emitter:

#include <SPI.h>
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
const int CE = 9;
const int CSN = 10;
int tempPin = 0;
int tempReading;
float tempC;
float tempF;
double tempK;
const uint64_t canal= {0xE8E8F0F0E1LL};
RF24 rf (CE, CSN);
void setup() {
  rf.begin();
  rf.setRetries(5, 10);
  rf.openWritingPipe(76);
  rf.setPALevel(RF24_PA_MAX);

}
void loop() {
  int tempReading = analogRead(tempPin); // This is OK
  tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK)) * tempK);  //  Temp Kelvin
  tempC = tempK - 273.15;                                                           // Convert Kelvin to Celcius
  tempF = (tempC * 9.0) / 5.0 + 32.0;                                               // Convert Celcius to Fahrenheit
  /*  replaced
    float tempVolts = tempReading * 5.0 / 1024.0;
    float tempC = (tempVolts - 0.5) * 10.0;
    float tempF = tempC * 9.0 / 5.0 + 32.0;
  */
  rf.stopListening();
  rf.write(&tempC, sizeof(tempC));
  delay(500);
}

I just tried unplugging the power to the NRF24L01 from the receiver to test. It has a separate power supply, although I have connected a negative cable between its power supply and the Arduino nano gnd. When I disconnect the 3.3 volts and GND of the NRF24 module, the Arduino nano already enters the if statement, although in the serial monitor it gives me a temperature value of 0 because it is not receiving anything.

Try the examples in Simple nRF24L01+ 2.4GHz transceiver demo

They are known to work and the topic also has a sketch to test connections to the nRF module

From experience most problems are caused by an inadequate power supply at one or both ends of the link

Do you have 10uF capacitors on the nRF24L01 power pins? They can be the difference between not working and working with power supplies that can't handle the suddenly changing current demands of the nRF24L01s.

Even better, use these https://www.aliexpress.com/item/1005005348463764.html

Hi, yes. I have a 10 uF electrolitic capacitor un both NRF 24 modules.

Hello, the modules already work with the example, but I still have doubts when using them. How do I send more than 32 bytes? I need to send the value of a button (1 or 0), one or two voltages that I have to measure (with decimals), the rpm of a motor, the temperature of that motor (with decimals) and the amps consumed by the motor (also with decimals). In principle I have solved the issue of the sensors, but I need to know how to pass the data, since being of type long due to decimals, all 32 bytes are passed if they are in an array. Apart from that, do you know of any program for Windows that reads these values from the serial port and displays them on a graph, for example?
Thank you.

By sending multiple packets.

Type "long" is an integer type. It does not have decimal points. Type "float" has decimal points.

Send the float values as binary, not ASCII. That only requires 4 bytes per value and you won't loose accuracy.

Put your data into a struct. A struct is like an array, but can take data of any type.

For example:

struct Data
{
   int tempPin;          // 2 bytes
   int tempReading;     // 2 bytes
   float tempC;         //  4 bytes
   float tempF;         //  4 bytes
   double tempK;        //  4 bytes in Arduino float and double are the same
} data;

The Data struct takes 16 bytes.

To enter a value to an element:

data.tempC = 25;

To send:

radio.write( &data, sizeof(data) );

Hello.
Sorry, I'm a beginner in the Arduino world. How do I send the values in binary?

If you put the data into a struct, like I showed, the data is effectively sent in binary.

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