BeagleBone

Get nRF24L01+ Radios Working on BeagleBone Black

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.

Equipment Prerequisites:

BeagleBone Black (rev B) with standard Debian image as of 5/2014 from BeagleBoard.org
nRF24L01+ Radio

1. Wire up equipment

Screen Shot 2014-06-01 at 3.50.18 PM

 

 

beaglebone connectors:

beagleboneblack-pins

2. Enable SPI on the BeagleBone Black. Note that the libraries are coded to use SPI1, and to do this we need to disable the onboard HDMI pins. Go into “/boot/uboot/uEnv.txt”, add the following line to the end (all one line!):


optargs=quiet drm.debug=7 capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN capemgr.enable_partno=BB-SPIDEV1

Then shut down and restart the BBB. You should now see something like the following when you look at devices:


# ls /dev/spi*
/dev/spidev1.0 /dev/spidev1.1

3. Get the code. Do a “git clone https://github.com/mlsorensen/RF24.git”

4. Compile the code

cd RF24/librf24-bbb/librf24/
make
make install

5. Run examples

cd examples
make
./pingtest

 

You should now have some output that looks like this:


RF24/examples/pingpair/
ROLE: Ping out
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 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xf0f0f0f0e1
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x00
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0f
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_HIGH
Now sending 153...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 BeagleBone Black or Raspberry Pi, follow this but run ./pongtest for the receiver. Once you have two sides working you should see successful pings like this:
Screen Shot 2014-06-01 at 4.02.05 PM

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/

10 comments

  1. Takeshi

    Hi,
    Thanks for the fantastic writeup! Exactly what I was looking for. I have one question about the connections though. Pin P9_25 seems to be GPIO321 and P9_27 seems to be GPIO319. GPIO 117 is associated with P9_21 and GPIO 115 seems to be on P8_15 (the other connector). Now I’m not sure how to hook the whole thing up. Did you modify the initialization in the example codes?
    Thanks!
    Takeshi

  2. marcusmarcus Post author

    The Beaglebone Black pins are labeled differently, depending on the document you’re looking at. Some have them broken out into which gpio ccontroller assignments (e.g. gpio3 pin 21, like I think you’re referring to), but this graphic here shows how they’re referred to in software:

    http://electron14.com/wp-content/uploads/2014/08/beagleboneblack-pins.jpg

    You can see 117, 125 are on P9 about half way down.

    EDIT: Here are the details… BeagleBone Black has four GPIO controllers, each with 32 pins. your ‘GPIO321’ is GPIO controller 3 pin 21, 3 * 32 + 21 = 117, so that’s labeled GPIO117 in sysfs.

  3. Takeshi

    Hi Marcus,

    Thank you very much for the explanations!! You saved me a lot of trouble!

    Best,
    Takeshi

  4. Ufuk Şafak

    Hi,
    I am a newbie with BBB and i want to use it with nRF24 chips. But when i tried to compile the code, i get some weird error. When i write to console make install, it gives errors like that:

    root@beaglebone:/dev/RF24/librf24-bbb/librf24# make
    g++ -shared -Wl,-soname,librf24.so.1 -o librf24.so.1.0 compatibility.o gpio.o spi.o RF24.o
    root@beaglebone:/dev/RF24/librf24-bbb/librf24# make install
    cp librf24.so.1.0 /usr/local/lib/librf24.so.1.0
    cp: cannot create regular file `/usr/local/lib/librf24.so.1.0′: No such file or directory
    make: *** [install] Error 1

    I think, it is about directories. But i am confused with my little knowledge of linux systems. Can anyone help me 🙂

    By the way, i see that file when i use ls command within librf24 directory, but i have no idea about /usr/local/lib directory.

    Thanks..

  5. marcusmarcus Post author

    You can open the file “Make file” and see what the install target is trying to do. The end result is that you want the .so file to be usable as a library on your system. Are you installing on the beaglebone black?

  6. Jody Whitlock

    The error tells you “no such file or directory” and combined with the copy operation this tells us the path is missing. Make sure /usr/local/lib exists and that you have permissions to it. Make sure to run the command as superuser via the sudo utility and make sure the path exists.

  7. Jody Whitlock

    My funness is I can’t get the examples to compile for some reason. I keep getting

    scanner.cpp:(.text+0x1a): undefined reference to `RF24::begin()’

    I have tried everything my C++ brain can think of. ldconfig shows it knows about the libs:

    librf24.so.1 (libc6,hard-float) => /usr/local/lib/librf24.so.1
    librf24.so (libc6,hard-float) => /usr/local/lib/librf24.so

    so I am really stumped. I even modified the include in the pingtest.cpp to be “../RF24.h” with no luck.

    This is a BBB running Ubuntu 14.04 (Robert Nelsons 3.8.13-bone56 image).

  8. Jody Whitlock

    Wanted to update that I got it working by modifying the Makefile. Make the compiler portion look like this:

    ${PROGRAMS}: ${SOURCES}
    # g++ ${CCFLAGS} -Wall -L../librf24/ -lrf24 $@.cpp -o $@
    # g++ ${CCFLAGS} -L../librf24/ -lrf24 $@.cpp -o $@
    g++ ${CCFLAGS} -Wall -g -o $@ $@.cpp -I /usr/local/lib -l:librf24.so

    Notice the static linking…

  9. Redi

    Hi, I’ve followed your tutorial, but it keeps getting the same error:

    Now sending 114…failed.
    Failed, response timed out.
    Now sending 1409…failed.
    Failed, response timed out.

    I’ve already changed wires, tested with 3 different nRF24.
    When i change MISO-MOSI, it gets allways the same response as you said, so the MISO-MOSI are ok.

    Do you have any idea of what can be happening?

Leave a Reply

Your email address will not be published. Required fields are marked *