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.

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

Before submitting contributions, you should make sure that any documentation changes builds 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.1.tar.gz (417.2 kB view details)

Uploaded Source

Built Distributions

pyrf24-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (617.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (556.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (618.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (556.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (616.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyrf24-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (555.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pyrf24-0.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (646.1 kB view details)

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

pyrf24-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (586.0 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: pyrf24-0.2.1.tar.gz
  • Upload date:
  • Size: 417.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyrf24-0.2.1.tar.gz
Algorithm Hash digest
SHA256 40c7bfbc1463898b0ae76c0f45c8319642b7e1b092d981a8fda79b619866d123
MD5 7937679d54627b71e018cf5d6a39dcad
BLAKE2b-256 c3531dbe684af145cb2dacf2ccb058d6df7db111f23aeef78caccc3bbeb5f96b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0783d0f173ad16d342519731edb5f1ae53c4aa36cc60555545df10fce63f50fc
MD5 d714bbda75de10fdec2a7ef7f62d743a
BLAKE2b-256 901bdcfef3a8a94c9f15c09a089d66bab9b29e00617c0b6cf6de7aabf0e1a911

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 89147d3920b7610c6d78ba450f104f4cb9a23651cf2b0a5c32b8ec5d8d773faf
MD5 d58d22835f8be4280cc99a857aa77750
BLAKE2b-256 a7b508300e36161660c1dc05affd550ff32401fec0994f59c40182bc4253fcdf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63cf269e15b86dd5134944738736d261d42fa85128247b6c167cca1376348d84
MD5 ee54352849df7582e79981a0bf78cc47
BLAKE2b-256 8ed4405a0e025bc654b5cdaefba695f2860c75da5bdfdcd9f33adb304beb110c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2f9bbebcf0f6bfa2b49ad2a792de573da355721989bc4624c3de695697a816a4
MD5 656437fe78336c3ce1be5e97f7191a0b
BLAKE2b-256 985c67186957621e8c7a74b05766c7df785b28fa12691f8e6696a07a3635a2b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76fb9a478a1a2f218665ce4e6e59d87472a9575e4a1997d5750ebbda29afdecd
MD5 6d9ea1a6ed43a2944f594d96eebaf5e4
BLAKE2b-256 c724781442d5d05eef5eb34c51f2c52318f0e75952fec447bb89477686dd555f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 10bf2816dccc2e246d0912045263f16722b927e3bd57e37e96a49dcb92f03cf5
MD5 1857203bd6fdc63ea4653853f5a0c5f5
BLAKE2b-256 0383a83772a41468ef36b71510390c78438546cf1adc56e3090547ca137282eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b52a78968d8adee22337ce071b69426a1e4cd79a3d98dbadf6a434df40183298
MD5 4ea1bd00d0b7e7776576128d8dbc8354
BLAKE2b-256 d0c2e72de6d8965f6f9a0a1a0dab6b2160252d191dc60e018100091d86b66e27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrf24-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b4d885afeed337979f7bf35d9f2497cada5e106c7853c63df29b51cc308e9912
MD5 e5650e96af96672bfc3af9446d4d7be0
BLAKE2b-256 d6cbe1b6e6365b4a5ecedad784a725e32260d9528f942a7db6f49ddde5d6a552

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