I have some projects that I’m planning with Raspberry Pi, Arduino, and BeagleBone Black. I’ve heard good things about the nRF24L01+ radios and they’re very inexpensive (I paid $6 for a set on Amazon), so I thought I’d give them a try. There’s no official documentation, however, and I found that while there were several resources online, many were inaccurate or had partial information for newcomers. While I have boards with stock operating systems, I didn’t know how to get the SPI bus working, how to wire them, or how to use the code, and each of those things were in a different place. This made things far more complex than they needed to be. My intent here is to provide a simple ‘jumpstart’ for someone wanting to just get it working as a starting point.
I actually have one Raspberry Pi and one BeagleBone Black, and am communicating between them. There’s not a lot of utility to this in the real world, as many other connectivity options are available and easy (e.g. ethernet, wifi), but it’s also easier than programming an Arduino, if you just want to do some testing on the platforms.
Raspberry Pi rev 2 (512MB), running stock Raspbian (Installed from NOOBS 1.3.7, I believe)
2. Enable SPI on the Raspberry Pi. Go into “/etc/modprobe.d/raspi-blacklist.conf”, and comment out the line “blacklist spi-bcm2708”, then reboot. You should now see something like the following when you look at devices:
# ls /dev/spi*
3. Get the code. Do a “git clone https://github.com/mlsorensen/RF24.git”
4. Compile the code
5. Run examples
You should now have some output that looks like this:
ROLE: Ping out
SPI device = /dev/spidev0.0
SPI speed = 8000000
CE GPIO = 25
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xf0f0f0f0e1 0xf0f0f0f0d2
RX_ADDR_P2-5 = 0xe2 0xe3 0xe4 0xe5
TX_ADDR = 0xf0f0f0f0e1
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x00
EN_RXADDR = 0x3f
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0f
DYNPD/FEATURE = 0x00 0x04
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
Now sending 1498841111...ok...Failed, response timed out.
Now sending 1498842326...ok...Failed, response timed out.
If you see strange repetitions in the hex values, it might mean your pins are mis-wired, or that your SPI device is missing. If you do see the above, you’re ready to set up another node. If you do a second Raspberry Pi, follow this but run ./pongtest for the receiver. Once you have two sides working you should see successful pings like this:
For developers, you should now have a /usr/local/lib/RF24.h that you can include in your code and a library at /usr/local/lib/librf24.so. For documentation, refer to http://maniacbug.github.io/RF24/