Optimized high speed nRF24L01+ driver class documentation  1.4.2
TMRh20 2020 - Optimized fork of the nRF24L01+ driver
Python Wrapper

By mz-fuzzy

Python Wrapper Prerequisites

RF24

The RF24 lib needs to be built in C++ & installed for the python wrapper to wrap it.

See Linux Installation (or installing with CMake alternatively) and Linux/RPi General

Python2

sudo apt-get install python-dev libboost-python-dev python-pip python-rpi.gpio

Next, install some up-to-date python packages.

python -m pip install --upgrade pip setuptools

Python3

sudo apt-get install python3-dev libboost-python-dev python3-pip python3-rpi.gpio

Next, install some up-to-date python3 packages.

python3 -m pip install --upgrade pip setuptools

Installation

Note
Steps 2 and 3 have to be repeated if installing the python wrappers for RF24Network and RF24Mesh libraries. The prerequisites stated above still apply to each library.
  1. For python3, setup.py needs a manually created symlink for the boost.python library:
    sudo ln -s $(ls /usr/lib/$(ls /usr/lib/gcc | tail -1)/libboost_python3*.so | tail -1) /usr/lib/$(ls /usr/lib/gcc | tail -1)/libboost_python3.so
  2. Build the library.

    This step and the next step need to be executed from the appropriate directory of the cloned RF24* repository:

    • navigate to pyRF24 directory in the RF24 cloned repository
    • navigate to RPi/pyRF24Network directory in the RF24Network cloned repository
    • navigate to pyRF24Mesh directory in the RF24Mesh cloned repository

    When in the correct directory, run the following command:

    ./setup.py build

    or for python3

    python3 setup.py build
    Note
    Build takes several minutes on arm-based machines. Machines with RAM less than 1GB may need to increase amount of swap for build.
  3. Install the library

    sudo ./setup.py install

    or for python3

    sudo python3 setup.py install

    See the additional Platform Support pages for information on connecting your hardware.

    See the included *.py files in the "examples_linux" folder for usage information.

  4. Running the Example

    The python examples location differ for each RF24* resopitories.

    • navigate to examples_linux directory in the RF24 cloned repository
    • navigate to RPi/pyRF24Network/examples directory in the RF24Network cloned repository
    • navigate to examples_RPi directory in the RF24Mesh cloned repository

    Navigate to the examples_linux directory

    cd ../examples_linux

    Edit the getting_started.py example to configure the appropriate pins per the Linux/RPi General documentation.

    nano getting_started.py

    Configure another device, Arduino or RPi with the same example code. It could be C++ or python (see the list of available examples), but we'll use the same example file on a different device in this tutorial.

    Run the example

    sudo python getting_started.py

    or for python3

    sudo python3 getting_started.py