The RF24 Libraries

"Optimized High Speed Arduino/Raspberry Pi driver for nRF24L01"

On this page

Install Arduino Libraries

Go to the TMRh20 project page and download both the RF24 and RF24Network libraries (look for the Download links under "Newly Optimized RF24 NRF24L01 Radio Library for Arduino" and "Newly Optimized RF24Network Library Fork").

Note: at the time of writing, I found some issues with the main RF24Network library but the Development Fork worked fine, so to be safe you could download that one instead - it's on that same page near the top.

To install, extract both zip files to your Arduino libraries folder (usually My Documents > Arduino > libraries) and rename the folders to remove the -Master or -Development part.

Arduino library location

Install Raspberry Pi Libraries

Recently the author added an installer that makes installing these modules a little easier. All you need to do is download and run it:

chmod +x

This will download and install everything - answer "y" to the questions about installing RF24 and RF24Network. You don't need RF24Mesh or RF24Ethernet for now, but it doesn't hurt to install them too. You might see some warnings while it's compiling the libraries but you can ignore those.

Now clean up the installer file and we can move on to testing it.


Sample Pi Program

At this point, it might be worth taking a little detour and install samba. It will make working with files on the Pi a lot easier. Every time you would open a file in nano, you can just open it in Windows (for example in the excellent (& free) Notepad++ editor)

On the Raspberry Pi, use the following commands to download the rf24receiver code from this site together with the instruction file for the C compiler, then open the file to look at it:

cd ~/rf24libs
sudo nano rf24receiver.cpp

This program assumes you'll be receiving data from an Arduino with a DHT temperature sensor. There are comments throughout the code that explain what's going on. When you're satisfied you understand what's going on you can exit nano and then compile the code & run it:

sudo ./hareceiver

You'll see a printout of some radio details, followed by a dot every 2 seconds while the Pi patiently waits for data until the Arduino starts sending.

Sample Arduino Program

Now for the Arduino, download the sketch and upload it to your Arduino, or use the codebender plugin below to send it directly. This sketch assumes your Arduino has a DHT temperature sensor, as explained in this guide.

Have a look at the code - the comments should explain what's going on. Once the Arduino code is uploaded and executing, you can open the Serial Monitor to see it send temperature data. In the Pi terminal window you should see the Pi receiving data and writing it out.

If you're using an Arduino Nano: when I tested this setup with the Nano instead of the Uno, having the Serial Monitor open made it not work. If you're having trouble with the Nano, try closing the Monitor and just check the Pi terminal to see if it's receiving data.

If the example doesn't work, try using the RF24Network files from the Development version mentioned earlier for the Pi (they're the same files as for the Arduino). Copy them to your Pi - overwriting the previous files - and compile using "sudo make install" while in the RF24Network folder.

Go Back