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.