Skip to main content

A python package for the wrapping nRF24 related C++ libraries.

Project description

piwheels Documentation Status PyPI Downloads Build CI

Introduction

This is the official home of the python wrappers for the RF24 stack. It is meant for Linux-based SoC boards like the Raspberry Pi. Documentation is hosted at http://pyrf24.rtfd.io/.

Pinout

https://lastminuteengineers.com/wp-content/uploads/2018/07/Pinout-nRF24L01-Wireless-Transceiver-Module.png

The nRF24L01’s CE and IRQ pins can be connected to other GPIO pins on the SoC. The MISO, MOSI, SCK are limited to the corresponding counterparts on the SoC’s SPI bus. The CSN pin is limited to the chosen SPI bus’s “Chip Select” options (also labeled as “CE” pins on many Raspberry Pi pinout diagrams). The following table shows the default pins used in all the examples for this package.

nRF24L01

Raspberry Pi

GND

GND

VCC

3V

CE

GPIO22

CSN

GPIO8 (CE0)

SCK

GPIO11 (SCK)

MOSI

GPIO10 (MOSI)

MISO

GPIO9 (MISO)

IRQ

GPIO12

The IRQ pin is not typically connected, and it is only used in the interrupt_configure example.

Installing from PyPI

Simply use:

python -m pip install pyrf24

We have distributed binary wheels to pypi.org for easy installation and automated dependency. These wheels specifically target any Linux platform on aarch64 architecture. If you’re using Raspberry Pi OS (32 bit), then the above command will fetch armv7l binary wheels from the piwheels index (which is already configured for use in the Raspberry Pi OS).

Installing from Github

Installing from source will require CMake and CPython headers:

sudo apt install python3-dev cmake

To build this python package locally, you need to have cloned this library’s repository with its submodules.

git clone --recurse-submodules https://github.com/nRF24/pyRF24.git
cd pyRF24
python -m pip install . -v

Building a wheel

Building a somewhat portable binary distribution for python packages involves building a .whl file known as a wheel. This wheel can be used to install the pyrf24 package on systems using the same version of CPython, CPU architecture, and C standard lib.

  1. Because building wheels is not done in an isolated build environment, it is advised that some build-time dependencies be installed manually to ensure up-to-date stable releases are used. Execute the following from the root directory of this repo:

    python -m pip install -r requirements.txt
  2. Using the same directory that you cloned the pyrf24 library into:

    python -m pip wheel -w dist .
  3. To install a built wheel, simply pass the wheel’s path and file name to pip install:

    python -m pip install dist/pyrf24-MAJOR.MINOR.PATCH-cp3X-cp3X-linux_ARCH.whl

    Where the following would be replaced accordingly:

    • MAJOR.MINOR.PATCH is the current version of the pyrf24 package.

      • If not building a tagged commit, then the version will describe the commit relative to the number of commits since the latest tag. For example, 0.1.1.post1.dev3 is the third commit (dev3) since the first “post release” (post1) after the tagged version 0.1.1. This adhere’s to PEP440.

    • cp3X is the version of python used to build the wheel (ie cp39 for CPython 3.9) The second occurrence of cp3X describes the CPython ABI compatibility.

    • ARCH is the architecture type of the CPU. This corresponds to the compiler used. On Raspberry Pi OS (32 bit), this will be armv7l.

Using a specific RF24 driver

By default, this package is built using the RF24 driver SPIDEV. If you want to build the package using a different RF24 driver (like RPi, MRAA, wiringPi, etc), then it is necessary to use an environment variable containing additional arguments for CMake:

export CMAKE_ARGS="-DRF4_DRIVER=RPi"

Then just build and install the package from source as usual.

python -m pip install . -v

Differences in API

This package intentionally adheres to PEP8 standards as much as possible. This means that class members’ names use snake casing (eg. get_dynamic_payload_size()) instead of using the C++ conventional camel casing (eg. getDynamicPayloadSize()). However, the older python wrappers provided with each C++ library (RF24, RF24Network, & RF24Mesh) had used camel casing. So, the API provided by this package exposes both snake cased and camel cased versions of the API. The camel cased API is not documented to avoid duplicate and complicated documentation.

radio.print_details()  # documented
# can also be invoked as
radio.printDetails()  # not documented

Some of the C++ functions that do not accept arguments are wrapped as a class property. But, the C++ style functions are still exposed. For example:

radio.listen = False
# is equivalent to
radio.stopListening()  # not documented

radio.listen = True
# is equivalent to
radio.startListening()  # not documented

Migrating to pyrf24

If you have a project that uses code from the older individually installed wrappers, then you can use this package as a drop-in replacement. You only need to change the import statements in your project’s source. Everything from the old individual wrappers is exposed through the pyrf24 package.

Using the old individual wrappers

Using the pyrf24 package

from RF24 import RF24, RF24_PA_LOW
from pyrf24 import RF24, RF24_PA_LOW
from RF24 import RF24
from RF24Network import RF24Network, RF24NetworkHeader
from pyrf24 import RF24, RF24Network, RF24NetworkHeader
from RF24 import RF24
from RF24Network import RF24Network
from RF24Mesh import RF24Mesh
from pyrf24 import RF24, RF24Network, RF24Mesh

Python Type Hints

This package is designed to only function on Linux devices. But, it is possible to install this package on non-Linux devices to get the stub files which help auto-completion and type checking in various development environments.

Documentation

Each release has corresponding documentation hosted at http://pyrf24.rtfd.io/.

Before submitting contributions, you should make sure that any documentation changes build successfully. This can be done locally but on Linux only. The documentation of API requires this package (& all its latest changes) be installed.

This package’s documentation is built with the python package Sphinx and the sphinx-immaterial theme. It also uses the dot tool provided by the graphviz software to generate graphs.

  1. Install Graphviz

    sudo apt-get install graphviz
  2. Installing Sphinx necessities

    python -m pip install -r docs/requirements.txt
  3. Building the Documentation

    To build the documentation locally, the pyrf24 package needs to be installed first. Then run:

    cd docs
    sphinx-build -E -W . _build

    The docs/_build folder should now contain the html files that would be hosted on deployment. Direct your internet browser to the html files in this folder to make sure your changes have been rendered correctly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrf24-0.2.3.tar.gz (428.2 kB view details)

Uploaded Source

Built Distributions

pyrf24-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (613.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (613.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (613.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (611.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (641.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (579.5 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

File details

Details for the file pyrf24-0.2.3.tar.gz.

File metadata

  • Download URL: pyrf24-0.2.3.tar.gz
  • Upload date:
  • Size: 428.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyrf24-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5ee2d38fac2bcc4f6664329d8bb3509660cb86c7c510434b29dc626f271351ce
MD5 0d96eba178ebffe8efb446915713d364
BLAKE2b-256 e7a5ffb9dba2ff13f29efa20a3b6d283fcf572d59345eb5c441a126e8903f50e

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64a6e0a9e41e0efe8203d63e3b14c08b246bf66d0225dc8e42d14e2ee2651d0d
MD5 285b2ff2e795fefebeac9f993a69d086
BLAKE2b-256 e11a0f467c2609be8a101efc24d5e76bb0e739270acc6adb377aa8b01271f04a

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5088e1adc61e1adc57dbdec66e08e8c1cb8d997b026aba44063175f12cf55f1a
MD5 249002edfea087a4aa6d1ad604b8201c
BLAKE2b-256 38d41728485a365a3cd268bdceea2d5c026006ecb50258a320bad7b9949f2698

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec5705d4431e01f8e4089e41ad0149c31e87ed2f54ec624c4f3bb82003f9dc90
MD5 377a77a05bec4dce726f2ebc164c19f1
BLAKE2b-256 5f110369c8a9f7d47f0a9289194b47e3f1cbbce2825162e7c20e7c2e43d18e3f

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 23749d99316b16e652eb72c91e5b7c6e6ffbc14f391f7de4bcd8be5a46557b2d
MD5 496bfc03d5e41bc0921efde98f8fac47
BLAKE2b-256 8539de8cc95ecef802e3d9995387d64056f601ea8dc03f1eea36cb14bd56c715

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72ea859aa4c97087c20314012ab31128a00d5c4f470444acf1c0fabd71c7be31
MD5 d1123fc7da728d851f8cea187fe888a0
BLAKE2b-256 306eaefb24d09a491ddea2c72096df079e7f30bfb75bbe0aa1a9605a6b5ec196

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a3e687f21c2df6f64879d750361088aa145861691471ff4850def0e6c8893930
MD5 fa883b6725c686cf37ef2be8f30b329c
BLAKE2b-256 2aa910285c387aeebb88511d04ee8b4b82c333141f1fe09e19e6c93cdc2e7b55

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f719871c59f669520fa740ec950663094dabe009a1dcec4642c7bc17f063f2f
MD5 64cc32c9d4cb16ecc1d11c7cef14ebe2
BLAKE2b-256 665386cf60d2f6fe382c365477f8bab5225eaf1e4b24c98b75b8125154c65c74

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a2ec29fc659df0b3bb0a547e09337661bfc06d1c9ead5c719adafc17a02d9f3
MD5 ce2d3e21db6fee55795d7f599bbd816d
BLAKE2b-256 d3dd89cd21303d5f9386182f3fb2237d69830a6b62ba22c75a5239f6a95a83cd

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e1fa6bec4f5d1df95cff3ae7d1a8d03e1b0bd973fa0be7dbff99b28f97451535
MD5 7f3c8cdedd38628c11260e8c4abfa55a
BLAKE2b-256 b92cd03d9d915f359488ddbd7ffd09d7c99f217ee7830e4161613297f489ff25

See more details on using hashes here.

File details

Details for the file pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrf24-0.2.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 64e476b56ee5e66233d2fe69145864a0b04189cdbcece5e09ec98a019139814b
MD5 0800fb7ae48a27fbb33b6bfbea70dc38
BLAKE2b-256 4ae76cfa945b2dcec4adc3cdb20a8bbcbda7cf811dbccad4c1baa0108a7ca453

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page