nRF24L01 Just receiving variable 2 times.

Friends good night.
Can you give me a hand ?

For some time I’m trying to make these modules work and am having the same problem with different modules / codes : the receiver receives the data and prints 2 times in the serial monitor and then enters the event of failure (radio not found).
I tried with other similar code like this that sends the value of the temperature sensor to the other module and does the same thing : Send 2x the value and then stops working .
( Http://www.elec-cafe.com/arduino-wireless-temperature-lcd-display-nrf24l01-dht11/ )

Test I’ve already done : replace the two nRF24L01 , put the capacitor 3.3v 4,7uf in the NRF terminals (to give a boost in transmission) and so far nothing . The same problem.
I’m posting this private video on youtube to see the bizarre behavior. LOL.

It´s in Portuguese but Im sure that you can understand just watching the hardware and codes :slight_smile:

Other infos:

  • Im using the Maniacbug RF24 Lib.
  • The main objective of this project is to send the temperature and humidity by RF. But to simplify and focus on the problem um just sending a simple value (21)
  • Asking in other brazilian forum a friend sugested to put this line in TX code: radio.stopListening(); after openWritePipe (2)…

Thank you very much.

RX:

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


int status[1];

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}

void loop(void)
{
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
      done = radio.read( status, sizeof(status) );
      Serial.println(status[0]);

    }
  }
  else
  {
    Serial.println("Radio nao disponivel");
  }
  // Delay para facilitar a visualização das informações no serial monitor
  delay(1000);

}

TX:

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


RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;

int status[1];

void setup(void)
{ Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  radio.stopListening();
}

void loop(void)
{
    status[0] = 21;
    
    radio.write(status, sizeof(status));
    
    Serial.println(status[0]);
    
    delay(1000);
}

Automatrox_RX.ino (2.6 KB)

Automatrox_TX.ino (393 Bytes)

  1. In your RX code, move the delay statement to the else clause to prevent RX and TX getting out of sync. It is bad if TX sends and RX is in a delay state. Or even remove it.
  else
  {
    Serial.println("Radio nao disponivel");
    // Delay para facilitar a visualização das informações no serial monitor
    delay(1000);
  }
  1. Try Adding a radio.powerUp() statement after radio.begin() in both sketches.

Tip: more people here will look if your code is copied in-line between code tags instead of appearing in attachments.

I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version including with powerDown()

The pair of programs in this link may be useful.

...R

6v6gt: 1. In your RX code, move the delay statement to the else clause to prevent RX and TX getting out of sync. It is bad if TX sends and RX is in a delay state. Or even remove it.

  else
  {
    Serial.println("Radio nao disponivel");
    // Delay para facilitar a visualização das informações no serial monitor
    delay(1000);
  }
  1. Try Adding a radio.powerUp() statement after radio.begin() in both sketches.

Tip: more people here will look if your code is copied in-line between code tags instead of appearing in attachments.

First , thank you for the reply and tip. I will try later and return with the result. But ... on the issue of time synchronization. This is a question I've always had : There's no way to leave a radio ( RX ) always listening and the other ( TX ) is sending in a set time ? Because in the future I intend to put several other transmitters with other sensor readings . It seems to me impossible to synchronize all the radio is based on the time of " transmission / listening ."

rptmatrox: . . . But ... on the issue of time synchronization. This is a question I've always had : There's no way to leave a radio ( RX ) always listening and the other ( TX ) is sending in a set time ? Because in the future I intend to put several other transmitters with other sensor readings . It seems to me impossible to synchronize all the radio is based on the time of " transmission / listening ."

Yes. You can have the radio permanently listening and the transmitter sending only occasionally. That is quite normal. The way you coded your solution originally, with both transmitter and receiver going into a regular wait does not work because, when the transmitter sends something, the receiver must be available immediately to receive it.

Robin2: I got my nRF24s working with this Tutorial

I suggest you use the TMRh20 version of the RF24 library - it solves some problems from the ManiacBug version including with powerDown()

The pair of programs in this link may be useful.

...R

Thank you Robin2 for the information. I will study and meke some tests with this library and Tutorial. First I´ll try the simple way (ajust my code). If I can´t I will try this tutorial.

Regards.

6v6gt: Yes. You can have the radio permanently listening and the transmitter sending only occasionally. That is quite normal. The way you coded your solution originally, with both transmitter and receiver going into a regular wait does not work because, when the transmitter sends something, the receiver must be available immediately to receive it.

Thats great. You know how may I do it?

Probably I would make something like this:

void loop(){ radio.read( status, sizeof(status) ); Serial.println(status[0]); }

Its just remove this condition? -> if ( radio.available()

I’d just change the receiver part as follows:
You may see see quite a few “Radio not available” messages, but if these are a problem, use a variable based on millis() to ensure that you don’t see these too often.

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


int status[1];

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}

void loop(void)
{
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
      done = radio.read( status, sizeof(status) );
      Serial.println(status[0]);

    }
  }
  else
  {
    Serial.println("Radio nao disponivel");
  }
  
}

I would just drop the part that prints 'radio not available' which should read 'no packet received' anyway.

It worked! =D

Thank you all for the help, tips and advices. (6v6gt, Whandall, Robin2)
The code is now reading the value. All the main problem was about the DELAY and syncronization os TX / RX timming.

And good news: I could use the original code to send Temp and Humi values.
MY NEXT challenge: Use more than 1 nRF to receive various sensors value =D

Thank you again.

The final code below:

RX:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//#include "DHT11.h"
#include <Wire.h>

float temperature[2];

RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void) {
 Serial.begin(9600);
 radio.begin();
 radio.powerUp();
 radio.openReadingPipe(1, pipe);
 radio.startListening();

 delay(1000);

 Serial.begin(9600);
}

void loop(void)
{
 if ( radio.available() )
 {
   bool done = false;
   while (!done)
   {
     done = radio.read(temperature, sizeof(temperature));

     Serial.print("Temperatura: ");
     Serial.print(temperature[0]);
     Serial.println(" C");

     Serial.print("Humidade: ");
     Serial.print(temperature[1]);
     Serial.println(" %");

     delay(1000);
   }
 }
 else
 {
   Serial.println("No radio available");
 }
}

TX:

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

int pin = A0;
DHT11 dht11(pin);
float temperature[2];

double Fahrenheit(double celsius) {
 return ((double)(9 / 5) * celsius) + 32;
}

double Kelvin(double celsius) {
 return celsius + 273.15;
}

RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void) {
 radio.begin();
 radio.powerUp();
 radio.openWritingPipe(pipe);
 radio.stopListening();
 Serial.begin(9600);
}

void loop(void)
{
 float temp, humi;
 dht11.read(humi, temp);
 temperature[0] = temp;
 temperature[1] = humi;
 radio.write(temperature, sizeof(temperature));

 Serial.print("Temperatura: ");
 Serial.print(temp);
 Serial.println(" C");

 Serial.print("Humidade: ");
 Serial.print(humi);
 Serial.println(" %");
}

@rptmatrox, Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

…R

Robin2:
@rptmatrox, Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

…R

Thanks for the advice Robin. You are right.
Ajust made in last post above =D

I posted without because in Quick Edit mode the formating option are not show.