Optimized high speed nRF24L01+ driver class documentation v1.4.10
TMRh20 2020 - Optimized fork of the nRF24L01+ driver
|
A more modern approach instead of using hand-crafted Makefiles & configure scripts to build & install software. Please note that these instructions are not needed if you have already installed the library using these older instructions
You can install the library in a few different ways.
The librf24-bcm.so file may not exist if you used CMake to install the library.
There is a newer automatic install script that makes use of the CMake approach.
Run it and choose your options
SPIDEV
is now always selected as the default driver because all other Linux drivers are being removed in the future. See RF24 issue #971 for rationale.It will also ask to install a python package named pyRF24. This is not the same as the traditionally provided python wrappers as the pyRF24 package can be used independent of the C++ installed libraries. For more information on this newer python package, please check out the pyRF24 documentation.
Try an example from one of the libraries
Edit the gettingstarted example, to set your pin configuration
Build the examples. Remember to set the RF24_DRIVER
option according to the one that was selected during the scripted install.
Run the example
Install prerequisites if there are any (PiGPIO, WiringPi, MRAA, LittleWire libraries, and enable the SPI bus(es) in the OS).
CMake may need to be installed
Configure build environment
RF24_DRIVER
option is only needed for the RF24 library and examples as well as the examples for RF24Network, RF24Mesh, and RF24Gateway. The RF24_DRIVER
option is not needed when installing the libraries for RF24Network, RF24Mesh, and RF24Gateway.Instead of specifying the RF24_DRIVER
option in the CLI, it is recommended to use a environment variable named RF24_DRIVER
.
These instructions assume you have not set an environment variable.
Instead of using SPIDEV
driver (recommended), you can also specify the RPi
, wiringPi
, MRAA
, or LittleWire
as alternative drivers.
SPIDEV
is now always selected as the default driver because all other Linux drivers are being removed in the future. See RF24 issue #971 for rationale.Build the examples
Navigate to the examples_linux directory
Make sure the pins used in the examples match the pins you used to connect the radio module
and edit the pin numbers as directed in the linux/RPi general documentation. Create a build directory in the examples_linux directory and navigate to it.
Now you are ready to build the examples.
If using the MRAA
or wiringPi
drivers, then you may need to specify the RF24_DRIVER
option again.
Remember that the RF24_DRIVER
option is needed for the RF24Network, RF24Mesh, and RF24Gateway examples if you specified that option (via CLI or environment variable) when installing the RF24 library and examples.
The RF24 library now (as of v1.4.1) has pre-built packages (.deb or .rpm files) that can be installed on a Raspberry Pi. These packages can be found on the library's GitHub release page
Download the appropriate package for your machine
Go to the library's GitHub release page, and look for the latest release's assets.
For all Raspberry Pi variants using the Raspberry Pi OS (aka Raspbian), you need the file marked for armhf architecture.
For Raspberry Pi variants using a 64-bit OS (like Ubuntu), you need the file marked for arm64 architecture.
Notice that the filenames will include the name of the utility driver that the package was built with. This does not mean that the LittleWire, MRAA, or wiringPi libraries are included in the package (you will still need to install those yourself beforehand).
Install the downloaded pkg
If you downloaded the file directly from your target machine using the desktop environment, then you only need to double-click the package (deb or rpm) file, and the OS should do the rest.
If you downloaded the file remotely and want to copy it over ssh, then use the scp
command in a terminal.
The scp
command will ask you for a password belonging to the user's name on the remote machine (we used pi
in the above example).
Now you can open up a ssh session and install the copied package from the terminal.
The RF24 library comes with some pre-made toolchain files (located in the RF24/cmake/toolchains directory) to use in CMake. To use these toolchain files, additional command line options are needed when configuring CMake to build the library (step 5 in the above instructions to build from source).
If you plan on using the cross-compiled library with your personal cross-compiled project, then it is advised to specify the path that your project will look in when linking to the RF24 library:
Remember to also specify the RF24_DRIVER
option (via CLI or environment variable) if not using the auto-configuration feature (see step 5 in the above instructions to build from source).
To install remotely, you can create an installable package file using CMake's built-in program called CPack.
This will create a deb file and a rpm file in a new sub-directory called "pkgs" within the build directory. You can use either of these packages to install the library to your target machine (see the above instructions about using a package manager).