NRF24L01 module not stable

Hello,

First, i want to thank you all for this forum and participations.
I'm a beginner in arduino and eletronics (since few weeks).

I faced an issue and i can't find any way to resolve :frowning: i checked lots of videos and tutorials but still no solution.

Let me explain :
My project is simple -->to drive a 2 wheels robot.

1)
I use a transmitter with just a joystick, an NRF24L01+ and an arduino nano (connected on my computer or with an extenal 9V battery).

Here is my code :

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

RF24 radio(7, 8); // CE, CSN du module wireless
int VRx = A5; // Pin A5, Axe des X du Joystick --> entre 0 (gauche) et 1023 (droite)
int VRy = A4; // Pin A4, Axe des Y du Joystick --> entre 1023 (bas) et 0 (haut)
int SW = 6; // Pin D6 pour le bouton du Joystick

int vX = 0;
int vY = 0;
int SW_state = 0;

const byte address[6] = "00001"; // Canal de communication entre les modules wireless

void setup() {
  Serial.begin(115200);  
  // initialisation pour le module Wireless
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);

  // initialisation des pin du Joystick
  pinMode(VRx, INPUT);
  pinMode(VRy, INPUT);
  pinMode(SW, INPUT_PULLUP);
}

void loop() {    
  radio.stopListening();
  
  vX = analogRead(VRx);
  vY = analogRead(VRy);
  SW_state = digitalRead(SW);
    
  radio.write(&vX, sizeof(vX));
  radio.write(&vY, sizeof(vY));
  radio.write(&SW_state, sizeof(SW_state));

  Serial.print("X: ");
  Serial.print(vX);
  Serial.print(" | Y: ");
  Serial.print(vY);
  Serial.print(" | Bouton: ");
  Serial.println(SW_state);
  delay(100);
}

and the result in my Serial Monitor of this code is giving a stable information as follow :

X: 517 | Y: 513 | Bouton: 1
X: 517 | Y: 513 | Bouton: 1
X: 518 | Y: 513 | Bouton: 1
X: 517 | Y: 513 | Bouton: 1
X: 517 | Y: 513 | Bouton: 1
X: 517 | Y: 513 | Bouton: 1
X: 517 | Y: 513 | Bouton: 1

This is OK.

2)
I use a receiver with a NRF24L01+, an arduino Uno (and a Shield Pololu to manage motors) (connected on my computer or with an extenal 9V battery).

Here is my code :

#include "DualVNH5019MotorShield.h"

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

DualVNH5019MotorShield md; // declaration pour le shield Pololu
RF24 radio(5, 3); // CE, CSN du module wireless

const byte address[6] = "00001"; // Canal de communication entre les modules wireless

int vX = 0;
int vY = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;

void setup()
{
  Serial.begin(115200);
  md.init(); // initialisation pour utiliser les fonctions du shield
  
  // initialisation pour le module Wireless
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
}

void loop()
{ 
  radio.startListening();

while  (radio.available()) {
    radio.read(&vX, sizeof(vX));
    radio.read(&vY, sizeof(vY));
    radio.read(&SW_state, sizeof(SW_state));

  mapX = map(vX, 0, 1023, -200, 200);
  mapY = map(vY, 0, 1023, 200, -200);

  if (mapY > 50) { // en avant
    md.setSpeeds(mapY,mapY);
  }
  if (mapY < -50) { // en arriere
    md.setSpeeds(mapY,mapY);
  }
  if ((mapX > 50) && (mapY > 50)) { // en avant a droite
    md.setM1Speed(mapY-mapX); // moteur de droite
    md.setM2Speed(mapY); // moteur de gauche
  }
  if ((mapX < -50) && (mapY > 50)) { // en avant a gauche
    md.setM1Speed(mapY); // moteur de droite
    md.setM2Speed(mapY+mapX); // moteur de gauche
  }
  if ((mapX > 50) && (mapY < -50)) { // en arriere a droite
    md.setM1Speed(mapY+mapX); // moteur de droite
    md.setM2Speed(mapY); // moteur de gauche
  }
  if ((mapX < -50) && (mapY < -50)) { // en arriere a gauche
    md.setM1Speed(mapY); // moteur de droite
    md.setM2Speed(mapY-mapX); // moteur de gauche
  }
  if ((mapY >= -50) && (mapY <= 50)) { // a l'arret
    md.setSpeeds(0,0);
  }
}

  Serial.print("X: ");
  Serial.print(mapX);
  Serial.print(" | Y: ");
  Serial.print(mapY);
  Serial.print(" | Bouton: ");
  Serial.println(SW_state);
  delay(100);
  
}

and the result in my Serial Monitor of this code is giving a NOT stable information as follow :

X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: -200 | Y: 200 | Bouton: 0
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: -200 | Y: 200 | Bouton: 0
X: -200 | Y: 200 | Bouton: 0
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1
X: 2 | Y: 0 | Bouton: 1

When i move the joystick, it works well but sometimes data like above is coming.

For more stability, i read some tutorials and forum that it is better to add capacitor --> what i did !
I added a 10uF capacitor on each side between GND and VCC.
I also try to change my NRF24L01 modules in case of any degraded module, but still the same.

I really can't find anything else to do :frowning: if you have any idea to share with me would be great for me to try ...

Thank you for reading me and for your help.
Cheers !! :slight_smile:

If you are powering the radio's from the 3.3V pin on the arduino, that might be the problem. Even thought many guides and how to's does that, the radios may exceed the current limit's of the VRM's on the arduino. Also mind that the higher voltage is given to the VIN-pin on the arduino, the less current can be drawn from the 3.3V pin before it buckles. Try to power the radios from another power source and remember the common ground.

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. If the first example does not work be sure to try the connection test for both of your Arduinos. Nothing will work if the connection test fails.

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.

If you are using the high-power nRF24s (with the external antenna) it may help to have a distance of about 3 metres between the two nRF24s so that the signal does not overwhelm the receiver. However someone on the Forum has had them working without that separation - I don't have any personal experience with them. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.

...R

Thank you for your quick answers ! :slight_smile:

@Danois90, i tried to power directly on 3,3V of the arduino and i also tried to power it with 5V of arduino but with the adaptator (to convert the 5V to 3,3V) :confused:

@Robin2, i already found your tutorial and test the SimpleRX, SimpleTx and the result is the same ... i mean i have the transmission is almost always good like "Data Sent Message 4 Acknowledge received" --> "Data received Message 4"
But sometimes, it's not good. It comes really rarely because the delay is slower than my delay (i guess).
i have nRF24s (with the external antenna) but i'm using the others first (without the antenna).

fasstoch:
@Danois90, i tried to power directly on 3,3V of the arduino and i also tried to power it with 5V of arduino but with the adaptator (to convert the 5V to 3,3V) :confused:

You are supposed to NOT power the NRF's through the arduino. The NRF's should be connected directly to THEIR OWN power source.

fasstoch:
It comes really rarely because the delay is slower than my delay

You can always change the txIntervalMillis in my program to test at different update intervals.

I reckon if the receiver gets a valid message which is not what you expect it is because the sender did not send what you expected. There is a lot of error-checking within the nRF24 and I doubt very much that the Tx would send "ABCD" and the Rx would receive "ABCE". If the Rx gets "ABCE" then that is almost certainly what the Tx sent.

...R

Robin2:
You can always change the txIntervalMillis in my program to test at different update intervals.

well ... ok i copy again your SimpleRX and Tx and change the txIntervalMillis to 100 and seems to be good ... (!?) maybe not the same module as the first time (as i changed several times to test).

Robin2:
I reckon if the receiver gets a valid message which is not what you expect it is because the sender did not send what you expected. There is a lot of error-checking within the nRF24 and I doubt very much that the Tx would send "ABCD" and the Rx would receive "ABCE". If the Rx gets "ABCE" then that is almost certainly what the Tx sent.

i understand but the Serial Monitor clearly show the good information in the Tx and the information is clearly not good in the Rx as i paste my results in #1 :confused:
Here below a screen shot of my 2 Monitor each lines Tx in front of Rx :

Tx-Rx.png

Tx-Rx.png

@Danois90, i didn't understand you were speaking about a specific power supply just for the module ... ok, i' will try that !
But it looks curious to imagine at the end of your project to have 1 battery for each module :wink:

fasstoch:
But it looks curious to imagine at the end of your project to have 1 battery for each module :wink:

You don't need a separate battery for each module. What you need is a power supply with enough capacity to power the NRF24L01. The 3.3V regulator on the Arduino does not have said capacity. If you had a separate 3.3V regulator with sufficient capacity, you could run it (and hence the NRF24L01) and the Arduino off the SAME 5V power supply (assuming IT had the capacity).

Danois90:
You are supposed to NOT power the NRF's through the arduino. The NRF's should be connected directly to THEIR OWN power source.

just tried with 2 battries 3,7V in serial directly on the adaptater (converter to 3,3V) of NRF24L01 and it goes in the same.
It's worst because it start with same data as when i plug on 5V of arduino (with some few erroneous data) and then it lost the communication (something else i guess) but anyway, i had time to see that some data are arriving with bad info :confused:

fasstoch:
Here below a screen shot of my 2 Monitor each lines Tx in front of Rx :

Please make your image visible in your Post. See this Simple Image Posting Guide

...R

fasstoch:
just tried with 2 battries 3,7V in serial directly on the adaptater (converter to 3,3V)

I assume your "adaptater" (sic) is a 3.3V regulator. If so, is 0.4V enough head room for it to work? Did you measure its output with a DMM?

gfvalvo:
You don't need a separate battery for each module. What you need is a power supply with enough capacity to power the NRF24L01. The 3.3V regulator on the Arduino does not have said capacity. If you had a separate 3.3V regulator with sufficient capacity, you could run it (and hence the NRF24L01) and the Arduino off the SAME 5V power supply (assuming IT had the capacity).

when i connect my module with his adaptator on 5V of arduino and i powered my arduino (nano or Uno) with a 9V battery looks good no ?

Robin2:
Please make your image visible in your Post. See this Simple Image Posting Guide

...R

did it ! thanks for the help link

gfvalvo:
I assume your "adaptater" (sic) is a 3.3V regulator. If so, is 0.4V enough head room for it to work? Did you measure its output with a DMM?

Just tested :
on my Receiver : 3.314V
on my Transmitter : 3.296V
looks good :frowning:

How much is actually drawing current from the Arduino; A NRF24 (with an 5V->3.3V adapter) and a shield with motors?

When the arduino is powered from a 9V battery, the 5V regulator has to convert ((9V-5V) / 5V ~=) 80% of the total current draw into heat. Since the regulator has a max. rating of 1W, that would give you ~250mA@5V total with 9V input voltage.

sorry Danois90, i don't understand the question :frowning:

The voltage i shared above is the V directly incoming in the NRF24L01.

Does the receiver work with USB-power / 5V? Can you supply a wiring diagram?

fasstoch:
did it ! thanks for the help link

Based on your comments at the top of Reply #6 I had assumed that the image would be showing the output from my Tutorial programs.

Now I'm wondering if this "i copy again your SimpleRX and Tx and change the txIntervalMillis to 100 and seems to be good" means that there were no errors when running my Tutorial programs. If so then the error you are seeing with your programs is somewhere in your software and not in the nRF24s

...R

Danois90:
Does the receiver work with USB-power / 5V? Can you supply a wiring diagram?

I tried both as i mentionned in #1.
Tx with USB and NRF24 (with support on 5V Nano) --> Rx with USB and NRF24 (with support on 5V Uno)
Tx with USB and NRF24 (with support on 5V Nano) --> Rx with USB and NRF24 (without support on 3,3V Uno)
Tx with Extenral 9V and NRF24 (with support on 5V Nano) --> Rx with Extenral 9V and NRF24 (with support on 5V Uno)
Tx with Extenral 9V and NRF24 (with support on 5V Nano) --> Rx with Extenral 9V and NRF24 (without support on 3,3V Uno)

Robin2:
Based on your comments at the top of Reply #6 I had assumed that the image would be showing the output from my Tutorial programs.

Now I'm wondering if this "i copy again your SimpleRX and Tx and change the txIntervalMillis to 100 and seems to be good" means that there were no errors when running my Tutorial programs. If so then the error you are seeing with your programs is somewhere in your software and not in the nRF24s

...R

Yes ! It seems to and this is my best hope ... but what can be the mistakes in my code !?
i tried to change the following code in my inital code :
*radio.setPALevel(RF24_PA_MIN); * --> radio.setDataRate( RF24_250KBPS );
*const byte address[6] = "00001"; * --> const byte slaveAddress[5] = {'R','x','A','A','A'};

But it's not changing the result ... still not stable
the only other difference from your code is that the write is sent through a void procedure ...
Any idea about my code ?