[Tutorial] Raspberry Pi NRF24l01 direct connection

  • [EDIT] - I uploaded a script in the next post that does everything I explained below

    I have installed MINImal raspBIAN which is a raspBIAN without a gui. So this should work for you guys.

    First of all you have to
    1. Undo your Overclock. If you have any. (SPI does not like Overclocked pi's)

    2. Enable SPI


    On a normal raspbian image this can be done either on a fresh install (when you config your pi) or you can type in terminal sudo raspi-config
    From there you go into ADVANCED OPTIONS -> SPI

    On a minimal image you don't have the luxury of raspi-config. You have to manually activate it.
    (I already had it enabled but you can check)
    (If you don't have sudo installed on your image just run apt-get install sudo)

    sudo nano /etc/modprobe.d/raspi-blacklist.conf

    Make sure there IS a # before blacklist spi-bcm2708, so it looks like this…
    #blacklist spi-bcm2708

    If there is no line like that, you can add it. It won't do any harm.
    CTRL+O - Save
    ENTER - Confirm
    CTRL+X - Exit


    CTRL+X - Exit
    y - I want to save the file
    ENTER - Confirm

    We have to edit now the config.txt.
    sudo nano /boot/config.txt

    add this to the end of the line

    Save and exit.

    Reboot your pi.
    sudo reboot

    Enjoy using SPI. (Source)

    3.Downloading the files


    You have 2 options. wget and git-clone. I'll start with:

    a. git-clone

    If you don't have git-clone you need to install the git tools. (Yes, git is related to github)
    sudo apt-get install git

    After you installed git you simply navigate to the folder that you wish to install the program and type:
    sudo git-clone https://github.com/mysensors/Raspberry.git

    This will download a zip, unarchive it and.. It does all the jobs for you.

    b. wget

    Some ppl are old-school and go the hard way or they just enjoy it done this way.

    Navigate to the folder that you wish to install the program and type:
    wget https://github.com/mysensors/Raspberry/archive/master.zip (this will download you the zip)

    Unzip the file

    If you don't have unzip installed just type
    sudo apt-get install unzip

    unzip master.zip -d /home/pi/Raspberry (you can specify any directory that you want instead of the /home/pi/Raspberry)

    4.Edit and compile what you downloaded

    In the Raspberry folder you have some files and some folders.
    The majority of ppl (including me) forget to complile the libs for the NRF24l01.
    This is the library provided by [TMRH20]{http://tmrh20.github.io} (He has some interesting stuff there including an audio library for NRF24l01.)
    Back to our stuff.
    Go to the Raspberry folder then into librf24-bcm.
    cd Raspberry/librf24-bcm/


    Go back to the Raspberry folder
    cd ..

    5.Connecting the NRF

    Mister TMRH20 tells us that we need to connect the NRF24l01 this way

    PIN		NRF24L01	RPI				RPi -P1 Connector
    1		GND			rpi-gnd			(25)
    2		VCC			rpi-3v3			(17)
    3		CE			rpi-gpio22		(15)
    4		CSN			rpi-gpio8		(24)
    5		SCK			rpi-sckl		(23)
    6		MOSI		rpi-mosi		(19)
    7		MISO		rpi-miso		(21)
    8		IRQ			Not Connected

    Connect everything like that except for the CE pin

    Run the PiGatewaySerial

    It shoud prin something like this:

    Starting PiGatewaySerial...
    Protocol version - 1.4
    Created PTY '/dev/pts/1'
    Gateway tty: /dev/ttyMySensorsGateway
    ================ SPI Configuration ================
    CSN Pin          = CE0 (PI Hardware Driven)
    CE Pin           = Custom GPIO25
    Clock Speed      = 8 Mhz
    ================ NRF Configuration ================
    STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1     = 0xe7e7e7e7e7 0xc2c2c2c2c2
    RX_ADDR_P2-5     = 0xff 0xc4 0xc5 0xc6
    TX_ADDR          = 0xe7e7e7e7e7
    RX_PW_P0-6       = 0x00 0x00 0x20 0x00 0x00 0x00
    EN_AA            = 0x3b
    EN_RXADDR        = 0x07
    RF_CH            = 0x10
    RF_SETUP         = 0x23
    CONFIG           = 0x0e
    DYNPD/FEATURE    = 0x3f 0x06
    Data Rate        = 250KBPS
    Model            = nRF24L01+
    CRC Length       = 16 bits
    PA Power         = PA_LOW

    Look at line 7 CE Pin = Custom GPIO25
    Connect the CE pin where it says you should.

    Here are some pictures with the GPIO connector on the rPi.

  • Here is a script I made that does all the things above
    Tell me how it went. Did it helped you? Did you found a bug? Any input, bad or good is appreciated.

  • @Vladut-Grecu

    The instructions didn't work for me until I did a sudo make install in the librf24-bcm folder. After the libraries were installed, I was able to make the PiGateway and PiGatewaySerial executables.
    Also, PiGatewaySerial will only run as root (or sudo).

    Thanks for the instructions, it was a great starting point! Now to install a controller....

  • Hey folks,

    big THX for the tut.

    But i have some problems after starting the GW.

    My output is only:

    Starting PiGatewaySerial...
    Protocol version - 1.4
    Created PTY '/dev/pts/1'
    Gateway tty: /dev/ttyMySensorsGateway
    check wires

    and a 100% CPU Load.


    issue in GIT:

    n3roGit created this issue in mysensors/Raspberry

    closed cant start Gateway #11

  • No ideas?

  • the ttyMysensorsGateway can only be accessed as root (user root, group root).
    Other serialports seem to have the group "dialout" attached.

    I am running node-red which is unable the gateway and I guess this has to do with it. Anyone a solution ?

  • ? Are you using the code that is available on github now?

    This behavior was Change by Holger a month ago. You can configure the Groups in the makefile:

    The standard configuration will build the Serial Gateway with a tty name of
    '/dev/ttyMySensorsGateway' and PTS group ownership of 'tty' the PTS will be group read
    and write. The default install location will be /usr/local/sbin. If you want to change
    that edit the variables in the head of the Makefile.

  • @Andreas-Maurer Thanks for the quick answer. I used the code from github. I am going to check your suggestions tonight. (right now I am at work πŸ˜‰


  • Sorry for my naive question: does it means I ca use a raspi as a nrd24l01 based gateway?

  • @Roberto-Brunialti Yes. Works perfectly ! (apart from the root access πŸ˜‰
    As stated by blksun813 you need to "sudo make install in the librf24-bcm folder". (add the sudo...)

  • I'm currently at work, but there's a question: will it run on orangepi? (bananapi-like clone of RPi)
    I'll take a look at the code and try to manage... GPIOs are working almost the same (it's compatible).

    Maybe if I make a diff-file of things changed, you will be able to merge it and do some 'ifs' so code will be clone-compatible?

    Oh well... The library has -bcm in name so I guess it will be rather hard to get it to work...

  • @Andreas-Maurer

    to run the gateway:
    sudo ./PiGatewaySerial (without sudo I get the error below)

    Could not create a symlink '/dev/ttyMySensorsGateway' to PTY! (13) Permission denied

    ls -l ttyMySensorsGateway

    gives the following:

    lrwxrwxrwx 1 root root 10 May  7 17:27 ttyMySensorsGateway -> /dev/pts/2

    I checked the makefile and it says

    TTY_GROUPNAME := tty

    But it doesn't seem to do anything...Any ideas ?

  • The symlink alwayshas 777. Everyone can use it.
    Please have a look at /dev/pts/2 This device should have the configured groups.


  • @Andreas-Maurer said:

    The symlink alwayshas 777. Everyone can use it.
    Please have a look at /dev/pts/2 This device should have the configured groups.


    Yes. Ok!
    It works.
    Thanks !

  • I tested it on my Rpi B+ its working fine, but the cpu load is always 100%. Is this normal?

  • An other silly question: can I install a controller into the same raspberry pi (the one with this gateway and nrf )? Are all controllers suitable for such a configuration ?

  • For my Point of view, every Controller which is able to use the Serial Gateway.

  • @Sweebee

    Same here. I'm afraid that with the PI at 100% there is no much use of this code becasue we can't do anything else...

    Strange that the PI that is much powerfull than an arduino gets so high CPU for something that an arduino nano can do...

    Could it be something that could be improved?


  • I have no problem with it. fhem as controler and mysql as DB is running on the same PI.
    The Gateway is not even listed in "top"

  • @Andreas-Maurer

    Do you mean you don't have any problems with the fact the CPU is at 100% or you simply don't have the same sympthom?

    Thanks for replying,

Log in to reply





Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.