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