I have decided to use NRF24L01+’s for my Arduino project for wireless communication. I am using the RF24 library by TMRh20 to talk back and forth.
Github Link: https://github.com/nRF24/RF24
I want to be able to send and receive data as fast as possible between the remote, and the receiver. After reading through the library I was able to create a some simple code that allowed the remote to transmit ~600 32-byte messages a second and the receiver was able to read ~490 messages a second.
Transmitter Loop Code:
if (radio.available())
{ radio.read( &myData, sizeof(myData) ); }
Receiver Loop Code:
radio.write( &myData, sizeof(myData), 1);
With this code however, the remote control cannot receive telemetry data back from the receiver. It is only a one way communication with no acknowledgments.
I have a few questions about wireless communication with the NRF24L01+. First, what is an acknowledgement? I understand it is a way for the transmitter to know that the receiver got the message, but what is being sent in the acknowledgment?
What is the difference between commands such as radio.write, radio.writefast, radio.startwrite, and radio.startwritefast. The RF24.h file has explnations of these commands but their desrciption does not make too much sense to me.
After doing some research, I found that to write, I must stop listening, write the message, and then start listening again for messages. The issue with this code is that the NRF is never listening long enough to receive a message (unless I add in a delay where it stays in RX mode). Is there anyway to keep a reading pipe open while writing and then pick it up from the FIFO when I am ready to read?
It seems that it is possible to write an ACK Payload, and this allows the NRF to transmit a message without leaving RX mode. Is this a possibility, and what is an ACK Payload?
What is the best practice for achieving the fastest speed two-way communication. Is it common practice to have two NRF’s and have one dedicated to listening and one dedicated to writing on each Arduino? Is there a good way to achieve high speed two-way communication rates with a single NRF?
2 Answers 2
firstly, the radio.write
command is used for checking for the acknowledgement from the RX after the FIFOs
are full for a single write. But radio.writefast
will not wait for the acknowledgement from the RX and would continuously transmit the payload for a single write. Similarly for radio.startwrite
and
radio.startwritefast
commands.
Coming to the keeping the NRF in listening mode, even I haven't tried it before so I cannot suggest an exact solution for this problem. But as far as I know, you can go for writestart
command to keep the reading pipes open while you are sending. But I would personally suggest you to confirm this from datasheet again before experimenting.
For ACK payload, it depends upon the master unit controlling the SPI communication
with the NRF chip and thus, by maintaining a mutual understanding between the RX and TX units, you can define the payload for acknowledgement signal as well.
Coming to best speed possibility, To increase speed, NRF has three speeds from which you can select the highest value available. Also see which pipe/channel
works the best for you so that you can achieve the least number of lost packets.
Just to add to the conversation, the NRF24L01 radios support Ack-Payloads. That is the receiving radio can place data in the ACK it sends back to acknowledge a received payload. Using this method at 2MBPS, you can achieve a 1MBPs bidirectional communication channel fast enough for audio, remote control and telemetry, etc.
void setup
after the rest of your radio setup.