I've been working on a project to send water level info from the well to our cottage - a distance of only about a hundred meters. I've been experimenting with different models of the NRF24L01. I've found that the range and quality differs greatly - even between similar units.
What I'd really like to find is a sketch that would provide signal strength and quality of a transmitting unit so I could sort out the poorer quality units. Does anyone know of such a program?
As far as I know, nRF24L01 doesn't have any (useful) way to measure signal strenght.
Do you have use these modules? If not, how about something in the 434 or 868 MHz band (instead of the 2.4 GHz nRF24 uses)?
Yes i agree there is no good way to check the signal strength, but you can use the rpd register to compare modules.
Received Power Detector (RPD), located in register 09, bit 0, triggers at received power levels above -64
dBm that are present in the RF channel you receive on. If the received power is less than -64 dBm,
RDP = 0.
So if you set the transmitter to minimal power and then compare the range where the rpd register are set you can get a idea what modules you should use. With the ordinary black ones i get around 30cm range and with a pa module around 3 meters.
The modules i had problems to get to work reliable did not set rpd at all or i had to almost touch the receiver for the rpd to set....
anyway here is the code i used to test:
TX:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//RF24 radio(7,8);
RF24 radio(9, 10);
const uint64_t ADDRESS = 0x2043b1a123;
void setup(void)
{
Serial.begin(115200);
printf_begin();
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.enableDynamicPayloads();
radio.setDataRate(RF24_250KBPS);
radio.setCRCLength(RF24_CRC_16 );
radio.setChannel(25);
radio.openWritingPipe(ADDRESS);
radio.openReadingPipe(0, ADDRESS);
radio.setAutoAck(0);
radio.printDetails();
}
void loop(void)
{
if (!radio.write( millis(), sizeof(unsigned long) )) {
Serial.println(F("failed"));
}
delay(100);
}
RX:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//RF24 radio(7,8);
RF24 radio(9, 10);
//#define ADR_WIDTH 3 // 5 unsigned chars TX(RX) address width
#define PLOAD_WIDTH 32 // 32 unsigned chars TX payload
uint8_t pip = 0;
uint8_t pload_width_now = 0;
byte newdata = 0;
const uint64_t ADDRESS = 0x2043b1a123;
//------------------------------------------
unsigned char rx_buf[PLOAD_WIDTH] = {0};
void setup(void)
{
Serial.begin(115200);
printf_begin();
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.enableDynamicPayloads();
radio.setDataRate(RF24_250KBPS);
radio.setCRCLength(RF24_CRC_16 );
radio.setChannel(25);
radio.openWritingPipe(ADDRESS);
radio.openReadingPipe(0, ADDRESS);
radio.setAutoAck(0);
radio.startListening();
radio.printDetails();
}
void loop(void)
{
if ( radio.available(&pip) )
{
byte rpd = radio.testRPD();
pload_width_now = radio.getDynamicPayloadSize();
// If a corrupt dynamic payload is received, it will be flushed
if (!pload_width_now) {
}
else
{
radio.read( rx_buf, pload_width_now );
// Spew it
Serial.print(F("RPD= "));
Serial.print(rpd);
Serial.print(F(" Data on pip= "));
Serial.print(pip);
Serial.print(F(" Got data size="));
Serial.print(pload_width_now);
Serial.print(F(" data="));
for (byte i = 0; i < pload_width_now; i++)
{
Serial.print(" ");
Serial.print(rx_buf[i]); // print rx_buf
}
Serial.print(" ");
}
Serial.println("");
}
}
best of luck
swe-dude:
With the ordinary black ones i get around 30cm range and with a pa module around 3 meters.
How should one interpret that?
In my own limited tests I had successful communication between a pair of low-power nRF24 modules (with PCB antenna) at a range of 110 metres out doors. And I have seen YouTube tests of the high-power modules (with external antenna) working at 1000m.
...R
That is the range it will set the rpd register with minimal power not the actual max distance...
swe-dude:
That is the range it will set the rpd register with minimal power not the actual max distance...
I did understand that. What I don't understand is what I might do with that information.
...R
well if 10 modules set rpc at 30cm and the 11th only set it at 2cm i probably wouldn't use that one to communicate with something 100m away...
swe-dude:
well if 10 modules set rpc at 30cm and the 11th only set it at 2cm i probably wouldn't use that one to communicate with something 100m away...
Does that mean that 4cm would be fine?
Or would you reject any unit that could not do 28cm?
Have you any data for the range of values from tests that you did?
...R
As i wrote in the first sentence i agree there is no GOOD way to do this, this is only to compare module A and B (like when you get 10 modules from china loose in a plastic shipping bag... )
and yes as i also wrote before the ones with minimal range match up to the ones that never worked reliable...
I still think nRF24 is not a good choice for this. "Water level info" does not sound like something that needs 2Mbps data rate.