Range Tester / Structure - nRF24L01 / nRF24L01 + PA + LNA

One project using nRF24L01 WiFi modules is already on the forum. I used them to create WiFi points for Capture Points / DOMINATION game mode. To remind the modules, they communicate at a frequency of 2.4 GHz and it is possible to use up to 120 channels for transmission. It is possible to utilize communication with the transmitter to up to eight receivers through eight pipelines. Each nRF24L01 module supports up to 4 independent power modes - MIN, LOW, HIGH, MAX.

Each requires a specific resource. For HIGH / MAX mode, it is recommended to use an external source. The power supply of the module is 3.3V, while the terminals have 5V tolerant, i. SPI bus data wires can also be connected to Arduina 5V pins. The most commonly used for HIGH / MAX power mode is traction battery and under module nRF24L01 additional adapter - YL-105, which contains 3.3V controller. Using the MAX Direct View Power Mode, the nRF24L01 + PA + LNA (with external antenna) can be used up to 1100 meters in an undisturbed environment.

A low data rate setting will also help to increase transmission reliability and increase range. You can set 250kbps, 1Mbps, 2Mbps. An important element in the implementation of a new project is to test communication over the nominal distance over which we want to use the project. That's why I created a simple program for the transmitter and receiver.

Transmitter always transmits values from 0 to 3 in a cycle. It uses a 200ms pause between the values it sends. In addition, the transmitter receives data from the receiver (if available), which responds back to the received data. Sends the value it received.

Receiver waits for data from the transmitter in a cycle. After receiving the data, it will send it back to the transmitter. If the receiver receives a value of 1, it sends a signal to the detector that sounds. This makes it possible to monitor, along with distance, whether the transmission is successful and whether the detector beeps regularly.
Reach tester program can be found at: https://arduino.php5.sk/airsoft-wifi.php?lang=en

Connection diagram for transmitter and receiver (from another project):


The next point of the article is the possibility of using the structure for data transmission. As a result, it is possible to transmit several data in a single data package - a "packet", which can also be easily processed on the receiver side. Thus, the same data structure can serve both to send and receive data. The transmitter and receiver must use the same data structure. The data structure uses 2 entries, an int entry and a float entry. The transmitter transmits T = 100 and A = 3.14. The receiver transmits T = 200 and A = 6.28 in response to the transmitter.
Transmitter program:

//Autor: Martin Chlebovec (martinius96)
//Web: https://arduino.php5.sk

#include <SPI.h>
#include "RF24.h"
#define CE 4
#define CS 3
RF24 nRF(CE, CS);

typedef struct {
int T;
float A;
} dataPacket;

byte adresaPrijimac[] = "prijimac00";
byte adresaVysilac[] = "vysilac00";
void setup() {
Serial.begin(9600);
nRF.begin();
nRF.setDataRate( RF24_250KBPS );
nRF.setPALevel(RF24_PA_LOW);
nRF.openWritingPipe(adresaVysilac);
nRF.openReadingPipe(1, adresaPrijimac);
nRF.startListening();
}

void loop() {
dataPacket packet;
packet.T = 100;
packet.A = 3.14;
nRF.stopListening();
nRF.write(&packet, sizeof(dataPacket));
nRF.startListening();
while (nRF.available()) {
nRF.read(&packet, sizeof(dataPacket));
Serial.print("Prijata hodnota T: ");
Serial.println(packet.T);
Serial.print("Prijata hodnota A: ");
Serial.println(packet.A);
}
delay(50);
}

Program for receiver:

//Autor: Martin Chlebovec (martinius96)
//Web: https://arduino.php5.sk

#include <SPI.h>
#include "RF24.h"
#define CE 4
#define CS 3
RF24 nRF(CE, CS);

typedef struct {
int T;
float A;
} dataPacket;

byte adresaPrijimac[] = "prijimac00";
byte adresaVysilac[] = "vysilac00";
void setup() {
Serial.begin(9600);
nRF.begin();
nRF.setDataRate( RF24_250KBPS );
nRF.setPALevel(RF24_PA_LOW);
nRF.openWritingPipe(adresaPrijimac);
nRF.openReadingPipe(1, adresaVysilac);
nRF.startListening();
}

void loop() {
dataPacket packet;
if ( nRF.available()) {
while (nRF.available()) {
nRF.read(&packet, sizeof(dataPacket));
Serial.print("Prijata hodnota T: ");
Serial.println(packet.T);
Serial.print("Prijata hodnota A: ");
Serial.println(packet.A);
}
nRF.stopListening();
packet.T = 200;
packet.A = 6.28;
nRF.write(&packet, sizeof(dataPacket));
nRF.startListening();
}
}