Can't send temperature with nRF24L01

Hi Guys,
I have a problem with my program. With an Arduino Nano [TX] I have to send the results of 2 temperature sensors to an Arduino Mega [RX] with LCD display via an nRF24L01.
The problem is that the data from [TX] is not sent, at least that says the program where I have built a function for it.

The fact is that [RX] does not receive any results.

And just that you know, i speak german, but i think this shoulden't be a problem.

I would be happy if someone could help me.

Arduino Nano [TX]:

#include <OneWire.h>                    //Benötigten Bibliotheken
#include <DallasTemperature.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

               
float temp1, temp2;         


OneWire ds_1(4);                        //Verbindung zu Pin 4
OneWire ds_2(5);                        //Verbindung zu Pin 5


DallasTemperature sensor_1(&ds_1);      //Sensor 1 = Pin 4 = Innen
DallasTemperature sensor_2(&ds_2);      //Sensor 2 = Pin 5 = Außen


RF24 radio(7, 8); // CE, CSN
const byte address[6] = "MF0SP";



void setup(void)                                                //Setup: läuft 1 mal
{
  Serial.begin(9600);

  Serial.println("---Programm startet---");                     //Visuelle Ausgabe, dass das Programm startet

  sensor_1.begin();                                             //Sensor 1 wird initialisiert
  sensor_2.begin();                                             //Sensor 2 wird initialisiert

  radio.begin();
  radio.setPALevel(RF24_PA_LOW);            //LOW weil kein großer Abstand
  radio.setDataRate( RF24_250KBPS );
  radio.openWritingPipe(address[1]);
  radio.openReadingPipe(1,address[0]);
  radio.stopListening();

  Serial.println("Setup beendet");
  Serial.println("Loop wird gestartet");
  Serial.println("");                                           //Setup beendet: Absatz für Monitor

  delay(1000);
}



void loop(void)                             //Loop: wiederholt sich immer wieder
{
  radio.stopListening();
  
  sensor_1.requestTemperatures();           //Sensor 1 wird nach Temperatur gefragt
  sensor_2.requestTemperatures();           //Sensor 2 wird nach Temperatur gefragt
  
  temp1=sensor_1.getTempCByIndex(0);      //Temperatur wird in °Celsius gewandelt
    Serial.print("Innen: ");
    Serial.print(temp1);                  //Ausgabe
    Serial.println(" °Celsius");

  temp2=sensor_2.getTempCByIndex(0);      //Temperatur wird in °Celsius gewandelt
    Serial.print("Außen: ");
    Serial.print(temp2);                  //Ausgabe
    Serial.println(" °Celsius");



    //Transmit data
    bool ok_1;
    ok_1 = radio.write(&temp1, sizeof(temp1));
    if (ok_1) {  Serial.println("Innen gesendet");  }
    else      {  Serial.println("Innen nicht gesendet");  }
    
    bool ok_2;
    ok_2 = radio.write(&temp2, sizeof(temp2));
    if (ok_2) {  Serial.println("Aussen gesendet");  }
    else      {  Serial.println("Aussen nicht gesendet");  }

    Serial.println();
      
  delay(1000);                              //2 Sekunden warten, bevor sich loop wiederholt
}

Arduino Mega [RX]:

  #include <OneWire.h>                    //Benötigten Bibliotheken
  #include <DallasTemperature.h>
  #include <LiquidCrystal.h>
  #include <RF24.h>
  #include <SPI.h>
  #include <nRF24L01.h>


  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


  float temp1, temp2;


RF24 radio(9, 10);  // CE, CSN
const byte address[6] = "MF0SP";



void setup(void) 
{
  Serial.begin(9600);
  
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);            //LOW weil kein großer Abstand
  radio.setDataRate( RF24_250KBPS );
  radio.openWritingPipe(address[0]);
  radio.openReadingPipe(1,address[1]);
  radio.startListening();
  
  lcd.begin(16, 2);
  lcd.print("Connecting.....");
  
  delay(1000);
}


void loop(void)
{
  radio.startListening();
  
  lcd.clear();

  radio.available();
  //Temperatur = EmpfangenerWert / 100.0
  
  radio.read(&temp1, sizeof(temp1));
  lcd.setCursor(0, 0);
  lcd.print("Innen:");
  lcd.setCursor(9, 0);
  lcd.print(temp1);
  lcd.print(" C");
  
  Serial.print("Innen: ");
  Serial.println(temp1);

  radio.read(&temp2, sizeof(temp2));
  lcd.setCursor(0, 1);
  lcd.print("Aussen:");
  lcd.setCursor(9, 1);
  lcd.print(temp2);
  lcd.print(" C");
 
  Serial.print("Aussen: ");
  Serial.println(temp2);
  Serial.println();
  

delay(1000);
}

[Edit] You can find the final code at reply #8

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.

A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

...R

Thank you Robin for the quick reply!

I will try it and tell you if it worked.

Hey Robin,

I have now tested your one-way program and only came to these results:

SimpleTx Starting
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed

SimpleRx Starting
Data received
Data received
Data received

So of course no data was received ...

I then tested the connection between the Arduinos and the nRF24 and came to the following results:

Arduino Nano [TX]:

CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
Note that RF24 does NOT reset when Arduino resets - only when power is removed
If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
communicating with the nRF24

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x4141417852 0x4141417852
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0x4141417852
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX

AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
and 250KBPS data rate

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x4141417852 0x4141417852
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0x4141417852
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x27
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX

Arduino Mega [RX]

CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
Note that RF24 does NOT reset when Arduino resets - only when power is removed
If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
communicating with the nRF24

STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1 = 0x0000000000 0x0000000000
RX_ADDR_P2-5 = 0x00 0x00 0x00 0x00
TX_ADDR = 0x0000000000
RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x00
RF_CH = 0x00
RF_SETUP = 0x00
CONFIG = 0x00
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN

AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
and 250KBPS data rate

STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1 = 0x0000000000 0x0000000000
RX_ADDR_P2-5 = 0x00 0x00 0x00 0x00
TX_ADDR = 0x0000000000
RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x00
RF_CH = 0x00
RF_SETUP = 0x00
CONFIG = 0x00
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN

So you can clearly see that there is a big problem with the Mega and some with the Nano, but how can i fix this? I conncted it to the pins the belong to...???

The nano seems to be communicating OK with its nRF24 but the Mega is not. The most common cause of failure is incorrect wiring or a loose connection. I presume you are aware that the SPI pins on a Mega are different from an Uno and nano.

...R

Yes i am, but i will double check it and have a look on it. I will also try to use a new nRF to see if it works then.

Ok, i checked the pins and 3 of them really were playced wrong.

Now i also get this:
SimpleRx Starting
Data received Message 0
Data received Message 1
Data received Message 2
Data received Message 3
....

But there is still 1 problem.

In my program it then said "Data received!", but my RX didn't get the temperature, it just says 0.00°C.
I edited a little bit and then it didn't receive even more so i continued and now the first 3 times it says "Data received!", but it still just said 0.00°C. All data after the first 3 failed to receive...

But i hope i can solve this one alone, it shouden't be much left to edit...

manueljoel:
But i hope i can solve this one alone, it shouden't be much left to edit...

If you need more help please post the latest versions of both your Tx and Rx programs and tell us exactly what they do and what you want them to do that is different.

...R

I finally did it! :slight_smile:

For everyone who has a similar projekt, here is a discription:

I have an Arduino Nano [TX] and Arduino Mega [RX],

My TX has 2 temperature sensors and 1 nRF24L01, it has to measure the temperature with both sensors and then send it to the RX.

My RX has 1 LCD-Display and 1 nRF24L01, it just has to get the temperatures of both sensors and then show them on the display.

TX:

  #include <OneWire.h>                                          //Benötigten Bibliotheken
  #include <DallasTemperature.h>
  #include <SPI.h>
  #include <RF24.h>

  float temp1, temp2;
  float temp100, temp200;

  OneWire ds_1(4);                                              //Verbindung zu Pin 4
  OneWire ds_2(5);                                              //Verbindung zu Pin 5

  DallasTemperature sensor_1(&ds_1);                            //Sensor 1 = Pin 4 = Innen
  DallasTemperature sensor_2(&ds_2);                            //Sensor 2 = Pin 5 = Außen

  RF24 radio(9, 10); // CE, CSN
  const byte slaveAddress[5] = {'R','x','A','A','A'};           //Adresse des nRF24L01

//----------------------------------------------------------------------------------

void setup(void)                                                //Setup: läuft 1 mal
{
  Serial.begin(9600);

  Serial.println("---Programm startet---");                     //Visuelle Ausgabe, dass das Programm startet

  sensor_1.begin();                                             //Sensor 1 wird initialisiert
  sensor_2.begin();                                             //Sensor 2 wird initialisiert

  radio.begin();                                                //nRF24L01 wird initialisiert
  radio.setDataRate( RF24_250KBPS );
  radio.setRetries(3,5); // delay, count
  radio.openWritingPipe(slaveAddress);

  Serial.println("Setup beendet");
  Serial.println("Loop wird gestartet");
  Serial.println("");                                           //Setup beendet
  delay(1000);
}

//----------------------------------------------------------------------------------

void loop(void)                                                 //Loop: wiederholt sich immer wieder
{
  sensor_1.requestTemperatures();                               //Sensor 1 wird nach Temperatur gefragt
  sensor_2.requestTemperatures();                               //Sensor 2 wird nach Temperatur gefragt
  
  temp1=sensor_1.getTempCByIndex(0);                            //Temperatur wird in °Celsius gewandelt
    Serial.print("Innen: ");
    Serial.print(temp1);                                        //Ausgabe
    Serial.print(" °Celsius   ");
    temp100 = temp1 * 100;                                      //muss *100 gerechnet werden, da
    Serial.println(temp100);                                    //Kommazahlen verloren gehen

  temp2=sensor_2.getTempCByIndex(0);                            //Temperatur wird in °Celsius gewandelt
    Serial.print("Außen: ");
    Serial.print(temp2);                                        //Ausgabe
    Serial.print(" °Celsius   ");
    temp200 = temp2 * 100;                                      //muss *100 gerechnet werden, da
    Serial.println(temp200);                                    //Kommazahlen verloren gehen

    bool ok_1;
    ok_1 = radio.write(&temp100, sizeof(temp100));              //temp100 wird übertragen
    if (ok_1) {  Serial.println("TX 1 received");  }            //Meldung ob die Übertragung
    else      {  Serial.println("TX 1 failed");  }              //gelungen ist
    
    bool ok_2;
    ok_2 = radio.write(&temp200, sizeof(temp200));              //temp200 wird übertragen
    if (ok_2) {  Serial.println("TX 2 received");  }            //Meldung ob die Übertragung
    else      {  Serial.println("TX 2 failed");  }              //gelungen ist

    Serial.println();

  delay(1000);                                                  //1 Sekunden warten, bevor sich loop wiederholt
}

RX:

  #include <LiquidCrystal.h>                              //Benötigten Bibliotheken
  #include <RF24.h>
  #include <SPI.h>

  LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

  float temp1, temp2;
  float temp100, temp200;

  RF24 radio(9, 10);  // CE, CSN
  const byte slaveAddress[5] = {'R','x','A','A','A'};     //Adresse des nRF24L01

//----------------------------------------------------------------------------------

void setup(void) 
{
  Serial.begin(9600);                                     //Setup startet
  Serial.println("---Programm startet---");               //Visuelle Ausgabe, dass das Programm startet
  
  radio.begin();                                          //nRF24L01 wird initialisiert
  radio.setDataRate( RF24_250KBPS );
  radio.openReadingPipe(1, slaveAddress);
  radio.startListening();
  
  lcd.begin(16, 2);                                       //LCD Display wird initialisiert
  lcd.print("Connecting.....");
  
  delay(1000);
}

//----------------------------------------------------------------------------------

void loop(void )                                          //Unterteilung, dass es übersichtlicher wird
{
    getData();                                            //Abteil für die Daten
    showData();                                           //Abteil für die Ausgabe
}

//----------------------------------------------------------------------------------

void getData() 
{
  if ( radio.available() ) {
      radio.read(&temp100, sizeof(temp100));              //temp100 wird abgefragt
      temp1 = temp100 / 100;                              //temp100 wird /100 geteilt

      radio.read(&temp200, sizeof(temp200));              //temp200 wird abgefragt
      temp2 = temp200 / 100;                              //temp200 wird /100 geteilt
  }
}

//----------------------------------------------------------------------------------
    
void showData()
{
  lcd.clear();

    if ( (temp1 == 0.00 ) && (temp2 == 0.00) ) {
      lcd.setCursor(0, 0);
      lcd.print("RX failed");                             //wenn temp1 und 2 = 0.00
      lcd.setCursor(0, 1);                                //wird eine Fehlermeldung am
      lcd.print("TX 1: 0.00");                            //Dispaly angezeigt
      Serial.print("temp1: ");
      Serial.println(temp1);  

      lcd.setCursor(9, 1);
      lcd.print("TX 2: 0.00");
      Serial.print("temp2: ");
      Serial.println(temp2);
      Serial.println();
    }

    else 
    {
      lcd.setCursor(0, 0);                                //wenn es keinen Fehler gibt
      lcd.print("Innen:");                                //wird temp1 normal
      lcd.setCursor(9, 0);                                //am Display angezeigt
      lcd.print(temp1);
      lcd.print(" C");
  
      Serial.print("Innen: ");                            //Serieller Monitor temp1
      Serial.println(temp1);

      lcd.setCursor(0, 1);                                //das selbe für temp2
      lcd.print("Aussen:");
      lcd.setCursor(9, 1);
      lcd.print(temp2);
      lcd.print(" C");
 
      Serial.print("Aussen: ");                           //Serieller Monitor temp2
      Serial.println(temp2);
      Serial.println();
     }
  delay(1000);
}

manueljoel:
I finally did it! :slight_smile:

Good to hear it's working.

For the benefit of other readers perhaps you can describe what you needed to change to go from the behaviour you reported in Reply #6 to the working version in Reply #8.

Was it only a software change? Or was there also a hardware change?

...R