You are here

JAL nRF24L01+ Library

There was a request for a JAL Library of the nRF24L01+ wireless transmitter/receiver module. The nice thing about this module is that it uses its own protocol to transmit and receive data, including automatic acknowledge handling. This reduces the amount of work that needs to be done by the PIC. You just have to send some bytes and verify if the transmission was OK. It has sufficient FIFO’s on board to buffer the received messages and it interfaces with the PIC via an SPI interface.

I made this library based on a draft version made by Sebastien Lelong who on his turn based it on a C Library for the Arduino. As said it was a draft library and the status was unknown. Next to that it missed some features and the structure was not always clear (maybe because of the port from the C library). When I create a library I find it important that it is understandable for a user and not only for the compiler. This means that my code is not optimized for speed but for readability. I finalized this library, added some more features and tested it using 3 nRF24L01+ modules. One module sends a message to two receiving modules and these 2 modules respond by sending the received message back after some modification. The reason to test with 3 modules was to see if one transmitter was able to handle more than one module using the different ‘pipes’ that the nRF24L01+ module has. The module is capable of handling 6 other modules.

The nRF24L01+ operates on 3.3 Volt but the pins can work with 5 Volt so the PIC can be connected directly without the need of level shifters. Initially I could not get the modules working and after searching the internet it seemed that the modules are very sensitive to noise on the 3.3 Volt power supply. Adding an electrolytic capacitor of 100 uF close to the module solved this problem. Next to that the range of the devices is influenced by various factors like, antenna, bitrate and payload (bytes in one message) so keep that in mind when using them.

The library is made ‘ready for use’ that is after initialization and setting the transmit address you are ready to go. Of course you can change all kind of settings that the module offers like, channel, automatic repeat count, automatic repeat delay, etc. I tried to document the API as good as possible. By default the library initializes the device with a dynamic payload instead of a fixed payload, which means that the length of the transmission depends on the number of bytes sent. There is a function available to support old non-plus devices. If this function is activated some features are disabled as to be able to communicate with these older devices but I am not sure if these old devices are still used.

Attached you find the schematic diagram of the module that starts the sending of message to the 2 other modules. Via the USART the transmission status and the received message can be displayed on a terminal emulator on a computer. This program is one of the sample files called 16f1825_nrf24l01.jal. Another sample file with the name 16f1823_nrf24l01.jal was used for the receiving devices that return the received message back to the transmitting device. This sample program uses some LEDs to indicate when a message was received and to show the transmission status.

In general making a library for something that needs a transmitter and receiver is not always easy because of 2 main reasons:
• If the library does not work you do not know if the problem is in the transmitter or the receive side. This makes debugging a bit more complex.
• You need 2 programmers to make development easy. Luckily I had my JALPIC One boards to solve this. For the transmitter I used a PicKit3 with JALIDE and for the receiver I used the JALPIC One board with JALEdit. In this way I was capable of changing and testing the transmitter and the receiver code without the need to switch programmer. Very convenient.

File: