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.2.tar.gz (426.7 kB view details)

Uploaded Source

Built Distributions

pyrf24-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (614.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (552.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (614.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (552.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (615.3 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (553.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (612.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (642.2 kB view details)

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

pyrf24-0.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (579.7 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pyrf24-0.2.2.tar.gz
Algorithm Hash digest
SHA256 33a77f5391a648330601f8c82d315b969226784e9d64e2f20dd3ec1979708c02
MD5 14b759bd1d3067df061e7d123799390b
BLAKE2b-256 520771c33c88290ac94867baa96a57911621fe821c4b9e319d2890b55becd0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9780bced4ecf9eab8a910b607b63ad304582587a052987a0a4cf4bee8a4d9e28
MD5 5e981a766f075c63b800745a003ac889
BLAKE2b-256 56e5a1f088bf6c0b4154684be55faf4ce3436291c7644c8810f2cdf031edf105

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5fa4005737c65548345fa247980f5923388f0611b7fc16d4094f033b2d49bc0c
MD5 ff154ec50a92f7eea38db63bd0741de2
BLAKE2b-256 35109d922350d26b287ece473292ce495b31b89a207e00c053f49e17a4414ce0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 01d021a8b53900db15739f91b7892d6d7d7583fd27d158c9a664c7af8bdc4224
MD5 a3e4fa9e6fb3799ee106bbb430b61d3d
BLAKE2b-256 93aa216e580a009e2ab145955c22774f1f671c0c2d3d2b4a552f6fe9c3355ee9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 df04a6658f1ca549d119cbc11e2d5f28fe96688f943d2b4c108b561f84273cad
MD5 fee0457fe3d3f2849d367d8ddc08fa9b
BLAKE2b-256 13239ac76fcf46231bdd7520dfe563db02495ba10d927397e5a7a0160a69e747

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d04170756c20c54cecffc713a7370c47bace1d017c96103c0547f6640d4ef38c
MD5 3ca0897fa532f499f784557972073913
BLAKE2b-256 f5e8855a06d16a89096082bc7fa5cbca1533e7b751df3394ddc5ed851038c287

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef6f595eb98a1e0acbe32ebd06de5c377d2fea61ba28c4c3ede121bc4a3ade06
MD5 ee53424241876c94bda3c8c78c493963
BLAKE2b-256 1f52b13ec4b19559ff02dee8f075a8ee42d6ea86fe84659cc064e97b9b8cc7a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cafc16619c02e7b7be33005b92a32b54246bce164894f9fa1ab81faf7194b988
MD5 52cbe0834eaddd77a20403355ea09583
BLAKE2b-256 d870751f5100cdcaa8e0a432f338126f45ac15eec38bf679472b46e42fbf5b6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bfbc30f22d89059b566bb29b38488307f432f05890c4e4a27bac1cf94265ee87
MD5 d2c2b2b6c621218c4418d52ff7a99283
BLAKE2b-256 4da80cefbd0bf594daf9f149979874cdeadd06bfa017cdcd0042a71282c787fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8d7fdff383aa583ca669ef095192d3a5af4bb0159ff68b30ff4e55864d3d399
MD5 d0e091e749fc817499cfc86887705f59
BLAKE2b-256 1070f3d48a0d4b0f77a2ba4a57e2ffa899f3e59e5491cd8b32cd104cfa321d19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0e5d1ee685bff618be0254961833d890a2b1a8dafcb28b3e24d8b68e1ab112b5
MD5 107b4be33f15071cd3204fa8f26d12e8
BLAKE2b-256 497cb7aa2dc2e33f294c7b125c5e40fe68a8a2d34139e2d40652f5332f34d99d

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