nRF24L01 pipe question
As most of the people have posted, the values for the pipe are arbitrary, but must follow the rules per the API:
Pipes 1-5 should share the first 32 bits. Only the least significant byte should be unique, e.g.
Before I answer your question, I think an explanation on Hex and Decimal values are needed.
The 40 bit hexadecimal is a number representation of base 16. A decimal is of base 10. So you can convert a Hex Value to Decimal. As this is out of scope for the question, you can google on how to convert from one to another. There are some online converters:
Hex to Decimal Converter
You will see when you convert the Hex value to decimal, that its just a number representation. When you convert, you drop the 0x
and LL
. As stated the 0x
indicates the value is a hex value and LL
means type Long Long.
So to answer your question, use the a converter to find a hex number like:
F0F0F0F0A1
F0F0F0F0A2
F0F0F0F0B4
F0F0F0F0E9
Just change the last 2 digits (least significant bit):
Pipes 1-5 should share the first 32 bits. Only the least significant byte should be unique, e.g.
openReadingPipe(1,0xF0F0F0F0AA);
openReadingPipe(2,0xF0F0F0F066);
Add the 0x
and LL
0xF0F0F0F0A1LL
0xF0F0F0F0A2LL
0xF0F0F0F0B4LL
0xF0F0F0F0E9LL
All should work.
I am no expert on hex, as I am learning, so if I am incorrect, then please someone correct me.
Finally, the nRF24L01 datasheet makes the following point that the choice of address is not completely arbitrary:
Note: Addresses where the level shifts only one time (that is, 000FFFFFFF) can often be detected in noise and can give a false detection, which may give a raised Packet Error Rate. Addresses as a continuation of the preamble (hi-low toggling) also raises the Packet Error Rate.
The values 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL
are arbitrary values and define the adresses of the senders and receivers to talk to.
If you use the Mirf library
Mirf.setRADDR((byte *)"serv1");
they can be also strings like serv1
.
RF24
uses
write_register(RX_ADDR_P0, &value, 5);
write_register(TX_ADDR, &value, 5);
There's something that everyone forgets to tell you:
Pipes at receiver should be shortened after the first one
const uint64_t pipe01 = 0xE8E8F0F0A1LL;
const uint64_t pipe02 = 0xA2LL;
const uint64_t pipe03 = 0xA3LL;
const uint64_t pipe04 = 0xA4LL;
const uint64_t pipe05 = 0xA5LL;
const uint64_t pipe06 = 0xA6LL;
radio.openReadingPipe(1, pipe01);
radio.openReadingPipe(2, pipe02);
radio.openReadingPipe(3, pipe03);
radio.openReadingPipe(4, pipe04);
radio.openReadingPipe(5, pipe05);
Pipes at transmitter should be
const uint64_t pipe01 = 0xE8E8F0F0A1LL;
const uint64_t pipe02 = 0xE8E8F0F0A2LL;
const uint64_t pipe03 = 0xE8E8F0F0A3LL;
const uint64_t pipe04 = 0xE8E8F0F0A4LL;
const uint64_t pipe05 = 0xE8E8F0F0A5LL;
const uint64_t pipe06 = 0xE8E8F0F0A6LL;
uint64_t setPipeToSend = pipe01; // or pipe02 or pipe03 or pipe04 or pipe05
radio.openWritingPipe(setPipeToSend );
If you want to know which pipe's message has come, use
uint8_t someVariable;
if (radio.available(&someVariable))
{
Serial.print("pipe number ");
Serial.printLn(someVariable);
}
Also pipe number 6 is used for receiving acknowledge messages.
In addition, the initialization code must have radio.enableDynamicPayloads();
This one works well for me:
radio.begin();
//radio.setChannel(0x57); //if set should be the same at the both sides
radio.setPALevel(RF24_PA_LOW); // "LOW" is more stable mode
radio.enableAckPayload(); //for autoanswers
radio.openWritingPipe(pipe01); //for sending
//link pipe numbers to the pipe addresses
//radio.openReadingPipe(1, pipe01); // I use pipe01 for sending
radio.openReadingPipe(2, pipe02);
radio.openReadingPipe(3, pipe03);
radio.openReadingPipe(4, pipe04);
radio.openReadingPipe(5, pipe05);
radio.enableDynamicPayloads(); //must have for multi pipe receiving
radio.startListening(); //start listening
Good luck...