Strange behavior nRF24L01+ communication

Hallo everyone,
I am quite new in the Arduino world and I must say: I'm impressed and enthusiast about the products, their capabilities and the community that applies it for a fast range of diverse targets.

My objective is to apply two nRF24L01+ 2.4GHz communication modules (with PA+LNA and external antenna) for the remote control of a dog-training device. Both the training device (the 'launcher') and the control unit (the 'controller') have an Arduino UNO (cheap Chinese clones) as local processor for various functions, including the driving of the nRF24 modules.

I did a lot of reading of all kind of information about these comm. modules, with a focus on the discussions in this forum. So I learned to use the preferred library (nRF24) and to go back to the most simple example sketches, preferably unchanged (as Robin2 is pointing out many times). I almost obey to this statement, I just added some print() statements to clarify the results, plus handle the return value of 'radio.write(...)' to gain a bit extra information.

Further, I realized how many combinations can be made with 2 RF-modules, 2 UNO's and 2 roles (Transmit vs. Receive), so I started to label the four pieces of HW and chose descriptions for the other variables. Luckily my main problem is already clearly visible with two tests only, I give a description of the to tests:

######################################
Test #1
######################################
Unit-1:
Arduino UNO: red
nRF24L01+PA+LNA: white
Location: on couche living room
PC: laptop (connection with long USB cable)
Conditions:
Role: transmitter
Code: nRF24L01_1way_Transmitter_v1.0
**Serial-monitor text (partly): Serial.Monitor_Transmitter_Test-1.txt **
=====================================================
Unit-2:
Arduino UNO: blue
nRF24L01+PA+LNA: black
Location: on table near desktop display
PC: desktop (connection with short USB cable)
Conditions:
Role: receiver
Code: nRF24L01_1way_Receiver_v1.0
**Serial-monitor text (partly): Serial.Monitor_Receiver_Test-1.txt **
==================================================

########################################
Test #2
########################################
No physical changes in setup, the only modification is swapping of roles.
Unit-1 is now receiver,
PC: laptop
Code: nRF24L01_1way_Receiver_v1.0
**Serial-monitor text (partly): Serial.Monitor_Receiver_Test-2.txt **
==================================================
Unit-2 is now transmitter,
PC: desktop
Code: nRF24L01_1way_Transmitter_v1.0

**Serial-monitor text (partly): Serial.Monitor_Transmitter_Test-2.txt **
====================================================

The 'transmitter' sketch looks like:

/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

RF24 radio(2, 3); // CE, CSN

const byte address[6] = "00001";

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
//  radio.setAutoAck(true);
//  radio.setDataRate(RF24_250KBPS);
//  radio.setCRCLength(RF24_CRC_8);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  Serial.println("TEST nRF24L01+ transmitter");
}

void loop() {
  bool        result;
  const char  text[18] = "Hello World";
  
  result = radio.write(&text, sizeof(text));
  Serial.print("send 'Hello World', strlen=");
  Serial.print(strlen(text));
  Serial.print(", size=");
  Serial.print(sizeof(text));
  Serial.print(", result=");
  Serial.println(result);
  
  delay(1000);
}

and the 'receiver' sketch:

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

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

RF24 radio(2, 3); // CE, CSN

const byte address[6] = "00001";

void setup() {
  
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
//  radio.setAutoAck(true);
//  radio.setDataRate(RF24_250KBPS);
//  radio.setCRCLength(RF24_CRC_8);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println("TEST nRF24L0+1 Receiver");
}

void loop() {
static  uint16_t    count;
  if (radio.available()) {
    char text[18] = "aap";
    radio.read(&text, sizeof(text));
//    if (strlen(text) > 0) {
      Serial.print("count=");
      Serial.print(count++);
      Serial.print(", text:");
      Serial.println(text);
      
  }
  delay(10);
}

The results of 'Test-1' looked promising, see text in the Serial.Monitor:
for the transmitter:

send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=1
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0
send 'Hello World', strlen=11, size=18, result=0

and for the receiver:

TEST nRF24L0+1 Receiver
count=0, text:$$$$$$$$$$$$$$$$$$
count=1, text:$$$$$$$$$$$$$$$$$$
count=2, text:$$$$$$$$$$$$$$$$$$
count=3, text:$$$$$$$$$$$$$$$$$$
count=4, text:$$$$$$$$$$$$$$$$$$
count=5, text:$$$$$$$$$$$$$$$$$$
count=6, text:$$$$$$$$$$$$$$$$$$
count=7, text:$$$$$$$$$$$$$$$$$$
count=8, text:$$$$$$$$$$$$$$$$$$
count=9, text:$$$$$$$$$$$$$$$$$$
count=10, text:$$$$$$$$$$$$$$$$$$
count=11, text:$$$$$$$$$$$$$$$$$$
count=12, text:$$$$$$$$$$$$$$$$$$
count=13, text:$$$$$$$$$$$$$$$$$$
count=14, text:$$$$$$$$$$$$$$$$$$
count=15, text:$$$$$$$$$$$$$$$$$$
count=16, text:$$$$$$$$$$$$$$$$$$
count=17, text:$$$$$$$$$$$$$$$$$$
count=18, text:$$$$$$$$$$$$$$$$$$
count=19, text:$$$$$$$$$$$$$$$$$$
count=20, text:$$$$$$$$$$$$$$$$$$
count=21, text:$$$$$$$$$$$$$$$$$$
count=22, text:$$$$$$$$$$$$$$$$$$
count=23, text:$$$$$$$$$$$$$$$$$$
count=24, text:$$$$$$$$$$$$$$$$$$
count=25, text:$$$$$$$$$$$$$$$$$$
count=26, text:$$$$$$$$$$$$$$$$$$
count=27, text:$2667+7962
count=28, text:
count=29, text:
count=30, text:
count=31, text:
count=32, text:
.......
.......
count=78, text:
count=79, text:
count=80, text:
count=81, text:
count=82, text:
count=83, text:$2667+7962
count=84, text:
count=85, text:
count=86, text:
count=87, text:
count=88, text:
......

The number lines with $$$ seems to depend on the number of send, but unread messages, due to later startup of the receiver.

To make my long story short: when I swapped the roles, the communication was ok, every "Hello World" is received.

The weird part of my observations is that the sometimes received '$2667+7962' is in fact also the "Hello World" string, where every byte is missing its LSB !! I created a small offline program that shows this correlation clearly. To prove myself, I modified the send-string, the result obeyed the same rule.

The fact that the receiver programs produces so many empty receive-strings gives me the impression the function 'radio.available()' always returns 'true'. The time a "real" message is received the decoding is not correct.
From the observation in 'Test-2' I conclude there is no connection/wiring problem, so what should I think? Is one of the RF-modules a bit crappy? At this moment I don't have spare modules, yesterday I ordered 3 new modules, this time with factory added shieding, the ' NRF24L01 Pa Lna 2.4Ghz Rf Module E01-ML01DP5'. They cost me only Euro 3.62 / pc plus about Euro 2.20 transport, for that price I cannot buy a "bare" nRF24L01+ plus a box for the shielding.

When I get new results I will update this post.
My apologies for the long text, I wanted to share all details which may be usefull.

Thanks for your attention,
Fred Schimmel, a new arduino-adeptor

Can you help us please by describing the actual problem ?

It seems to have something to do with 'partly' (whatever that means) but not sure ............

You will need a separate 3.3V supply for the NRFs on both sides.

@ srnet: my actual problem is described at the end: in one situation I got communication as expected, when I swapped the 'roles' (Transmitter and Receiver sketch on the "other HW set"), I get many empty "messages" and sometimes one that is crippled, but very consequently.
@ Whandall: I did not correctly describe my HW. Each nRF20L01+ has an YL-106 adapter which reduces the supply to 3.3V. I also soldered a 10uF electrolyte + a 0.1uF ceramic decoupling capacitor directly on the nRF20L01+ board.
The final question is: can I throw away these boards? After more and intensive testing, I don't get any communication. Also the transmitter returns now a 'false' on every 'radio.write(....)' command, whatever I try.
As I wrote before: I wait for three new modules.

Thanks for your suggestions, Fred

Hello everyone,
As promised, I will report my progress with nRF24L01 communication.

After many experiments with changes in code, in location of the modules (w.r.t. each other and my FritzBox modem that also does the WiFi at home, swapping the roles (Tx <=> Rx), swapping equipment (nRF24L01 and Arduino), I finally got a working situation !! It is not really clear (yet) what is the key of the solution, there are three candidates.
Yesterday I received the new E01-ML01RD modules, produced by Ebyte in China. These modules have a nice aluminum shielding on the component side of the PCB, so that issue is solved. Also I added a 10uF tantalium plus a 0.1uf ceramic capacitor directly on the power pins on the component side of the board.
I ran a scanner sketch to find out which channels of the 2.4GHz band are heavily used and which hardly. At first I got lines of '-' signs only, that could not be correct. In other sketches I had set a channel, but the readback still showed channel 4 (the default ??) This made me suspicious about the SPI communication, although I could not find reports of this on internet. In the RF-library files I found a definition of the SPI frequency, set to 10MHz. This value amazes me a bit, it can not be derived from 16MHz by division.... Anyway, I changed the SPI speed to 1.0MHz. After this change the readback channel shows the channel I have specified AND the scanner sketch gave a kind of profile which I can believe to be real. From this profile I chose channel 55 for my communication and now I can run examples for 1-way and 2-way communication with success!!

From here I intend to investigate the details and test if running SPI at 10MHz, communication on channel 55 will be possible. Another test will be an increase of the distance between the two modules, that will mean walking around with my laptop and connected Arduino Plus nRF24 module, in house and on the street.

If I have gathered the details I will report my findings,

greetings,
Fred

I wanted to chime in here on what I've discovered as to why some of these nRF24L01 radios will just stop working and maybe restart again.
Someone here mentioned some that have a shield on the PCB.

So here's my situation.
I've been having a horrible time to get any stability out of these device. They'd work for a bit then just stop.

I tried every bit of coding and several libraries to no avail.

So last week, I made up 2 new cables, for Rx and Tx.
I used a 6 conductor, SHIELDED cable. There are 6 conductors surrounded by an aluminum sheath with the ground wire following and touching the aluminum sheath.

The ground wire makes a total of 7 conductors!

When I used these, without even changing my code,
IT ALL WORKED PERFECTLY!
I let it run for 48 hours, having my code make note of any errors or drops. I send all the data to a Nextion display.

So then, 2 days ago, I made a new cable for a 3rd Rx, but this time, I used this very nice Silicone wire that is very pliable and nice to work with.
There are 7 wires, loose, and I used Dupont Connectors to assure good fits.

HERE'S THE THING.... The working Tx that I put it on, WOULDN'T WORK!
I checked each wire to assure no breaks and all was well.

Then, I got an idea that MAYBE there's interference happening due to not shielding!
So I attached 2 Ferrite Ring Cores to reduce RFI EMI Noise. One at each end (radio and Arduino).

IT ALL STARTED TO WORK AGAIN!

So then, I tested by wrapping the wires into an aluminum foil wrap with a ground wire attached, which I attached to ground on the Arduino. I took off the Ferrite cores to test.

This KINDA worked as the radio would Tx, but it would stop as soon as I'd put my hand close to it!!! BINGO!

So I just added back the 2 Ferrite cores, over top the Aluminum shield and now Tx is solid with no errors, not even with my hand close or right on the sheath!

So I wanted to throw that out there in case anyone else is having disconnection issues.
You might want to try Ferrite Cores or using 6 conductor, shielded cable.

Hope that helps.

Lots of good details, but how long were these 'cables' ?

1 Like

That tells me the antenna you used is not matched, impedance and resonant frequency, the transmitter, so your board and wire leads are also radiating RF and the signals are also being corrupted by the stray RF.
Do you have other antennas that you can try?

1 Like

Paul,
Oh you know, I didn't even consider that!
This easily could be the actual problem and I won't be able to confirm this until I an separate the units.

Right now, the 3 units, 2 Rx, 1 Tx are just less that a foot apart. I know that's not ideal.

I actually remove the antennas so as to not over saturate as well, I set the radios to LOW.

I really should have thought of that because it's the most logical.
Well, at least, the upside of this is that using shielded wire (possibly with the Ferrite core) could help in locations, outside this environment, that could get some RF from other sources.

Another thing I'm trying right now as I type this, is to test with different SPI frequencies.

I should have mentioned that my main goal here is to get these radios working flawlessly on
Nano Every boards.

Today was the first time I got them to work in a stable manner.

Also, as I've read that so many others have problems with these radios and power cycling seems to work, I'm just about to build a circuit with a MOSFET.

Right now, I have code that powers down the radio, powers it back up and re-initializes things on the push of a button on the Nextion display. This was to see if it actually works.

It does, so now I'm building the MOSFET circuit that will actually power the radios and modify my code to detect X number of failures and at a certain number, to run the physically powering down and back up of the radio, then re-running the initialization.

Considering where the final products will be located, I do want to have some automation to try to auto-fix and problems.

So far, so good, at least.

200 feet!

ROFL
Just kidding. These ones are about 8" long. Before, I even used shorter ones, but those were crappy.

This using of shielded cable has solved the problem.

I think that the main problem, is perhaps what Paul has suggested that the antennas or signals are at issue (not matched). Which makes sense as I removed the antennas for testing as the units are sitting very close together.
Sadly, my Lab is pretty small as is my work bench. So I don't have room to put several feet between them.
But I suspect that is part of the issue, so I'm not going to worry about it at this point.
The shielded cables are doing their job and I'm about to make a bunch more.

I need at least 8 cables. 6 for each TX module and 2 for receivers.
One receiver will be my portable test Rx, where I can change channels on the fly to check each station on site.

The 2nd Rx uses a large Nextion display and displays all 6 channels at one time. So that one is not portable. :slight_smile:

Replace the antenna with a 50 ohm 1/4 watt carbon resistor. Not a metal resistor.

Some nRF24L01+ modules will be very close to maximum power, regardless of the power setting.

Not good, you may now have damadged units, especially if they are the type that are on max power regardless, so test results could now be compromised.

A further consideration with using long wires to connect RF modules to an Arduino is that the wires may be at resonant lengths for the frequencies involved, which can make the wires very effective at picking up RF.

A 1/4wave antenna at 2.4Ghz would be 3.1cm .......

1 Like

No, the units are not damaged. These units do respond to the power setting.
I've run tests to confirm that.
As you know, the higher the power, the more current these things draw.

If I set to LOW, they draw very little, but when set to MAX, the current draw is considerably more. So they are fine as I always run at LOW.... now! I used to set to MIN but I learned that there can be some instability as the libraries or the units don't actually handle MIN every well.
I believe that, because immediately after changing from MIN to LOW, things started to work where they just wouldn't before.

I do have a lot of these nRF24 units, so when I'm done this project, I'm going to make a little test Jig and write code to cycle through the power settings and monitor the current draw.
I might even just have the Arduino measure the current so that I can log each unit.

There is ONE unit that I've marked with a RED X as "bad", because just plugging that one into power, it sucks up 140mA ! LOL THAT'S NOT GOOD. ROFL :grinning:

I've actually got all 3 radios, (1, Tx, 2RX) working solidly without a single drop or error.

One Rx is on a regular Nano and the 2nd one is on a Nano Every, which was my main desire as there's a lot more coding space on those.

Yeah, wires of 6" - 8" or so would be a problem, but with the shielding and Ferrite cores, the problem is resolved for now.
I only use wires like this when in design mode.

When I design the new cases for these, I'll design it in such a way as to have the nRF24 connected as close to the Arduino as possible.

I will also add shielding inside the case to lower any external forces.

I'm no longer concerned as things are working well as long as I don't move around those wires too much. LOL

Come to think of it, just for fun, today, I'll attach their antennas to them to see if they stay stable or if there's just too much power going on.

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