Circuitpython driver library for the nRF24L01 transceiver
Project description
Introduction
Circuitpython driver library for the nRF24L01 transceiver
Features currently supported
change the addresses’ length (can be 3 to 5 bytes long)
dynamically sized payloads (max 32 bytes each) or statically sized payloads
automatic responding acknowledgment (ACK) for verifying transmission success
custom acknowledgment (ACK) payloads for bi-directional communication
flag a single payload for no acknowledgment (ACK) from the receiving nRF24L01
“re-use the same payload” feature (for manually re-transmitting failed transmissions that remain in the buffer)
multiple payload transmissions with one function call (MUST read documentation on the “send()” function)
context manager compatible for easily switching between different radio configurations using “with” statements
configure the interrupt (IRQ) pin to trigger (active low) on received, sent, and/or failed transmissions (these 3 flags control the 1 IRQ pin). There’s also virtual representations of these interrupt flags available (see “irq_DR”, “irq_DS”, “irq_DF” attributes)
invoke sleep mode (AKA power down mode) for ultra-low current consumption
cycle redundancy checking (CRC) up to 2 bytes long
adjust the nRF24L01’s builtin automatic re-transmit feature’s parameters (arc: number of attempts, ard: delay between attempts)
adjust the nRF24L01’s frequency channel (2.4-2.525 GHz)
adjust the nRF24L01’s power amplifier level (0, -6, -12, or -18 dBm)
adjust the nRF24L01’s RF data rate (250Kbps is buggy due to hardware design, but 1Mbps and 2Mbps are reliable)
Features currently unsupported
as of yet, no [intended] implementation for Multiceiver mode (up to 6 TX nRF24L01 “talking” to 1 RX nRF24L01 simultaneously). Although this might be acheived easily using the “automatic retry delay” (ard) and “automatic retry count” (arc) attributes set accordingly (varyingly high).
for reason(s) unknown, a nRF24L01 driven by this library will not “talk” to a nRF24L01 on an Arduino driven by the TMRh20 RF24 library. There is no problems when a nRF24L01 driven by this library “talks” to another nRF24L01 that’s also driven by this library. Other Arduino-based nRF24L01 libraries are available, but they have not been tested to communicate with this CircuitPython-nRF24L01 library.
Dependencies
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Installing from PyPI
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install circuitpython-nrf24l01
To install system-wide (this may be required in some cases):
sudo pip3 install circuitpython-nrf24l01
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install circuitpython-nrf24l01
Pinout
The nRF24L01 is controlled through SPI so there are 3 pins (SCK, MOSI, & MISO) that can only be connected to their counterparts on the MCU (microcontroller unit). The other 2 essential pins (CE & CSN) can be connected to any digital output pins. Lastly, the only optional pin on the nRf24L01 GPIOs is the IRQ (interrupt; a digital output that’s active when low) pin and is only connected to the MCU via a digital input pin during the interrupt example. The following pinout is used in the example codes of this repo’s example directory.
nRF24L01 |
Raspberry Pi |
ItsyBitsy M4 |
---|---|---|
GND |
GND |
GND |
VCC |
3V |
3.3V |
CE |
GPIO8 (CE0) |
D7 |
CSN |
GPIO5 |
D5 |
SCK |
GPIO11 (SCK) |
SCK |
MOSI |
GPIO10 (MOSI) |
MOSI |
MISO |
GPIO9 (MISO) |
MISO |
IRQ |
GPIO4 |
D4 |
Using The Examples
See examples/ for an certain features of this the library. Notice that there are 2 files in each scenario/folder; one file titled “pi_test.py” for testing on the raspberry pi, and another file titled “m4_test.py” for testing on an adafruit boards with atsamd51. This was developed and tested on both Raspberry Pi and ItsyBitsy M4. Pins have been hard coded in the examples for the corresponding device, so please adjust these accordingly to your circuitpython device if necessary.
To run the simple example, open a python terminal in this repo’s example/simple folder and run the following:
# if using an adafruit feather, try using "from m4_test import *"
>>> from pi_test import *
nRF24L01 Simple test\n\
Run slave() on receiver\n\
Run master() on transmitter
>>> master(3)
Sending: 3 as struct: b'\x03\x00\x00\x00'
send() succeessful
Transmission took 86.0 ms
Sending: 2 as struct: b'\x02\x00\x00\x00'
send() succeessful
Transmission took 109.0 ms
Sending: 1 as struct: b'\x01\x00\x00\x00'
send() succeessful
Transmission took 109.0 ms
About the nRF24L01
Here are the features listed directly from the datasheet (refered to as the nRF24L01+ Specification Sheet):
nRF24L01+ Single Chip 2.4GHz Transceiver Preliminary Product Specification v1.0
Key Features:
Worldwide 2.4GHz ISM band operation
250kbps, 1Mbps and 2Mbps on air data rates
Ultra low power operation
11.3mA TX at 0dBm output power
13.5mA RX at 2Mbps air data rate
900nA in power down
26μA in standby-I
On chip voltage regulator
1.9 to 3.6V supply range
Enhanced ShockBurst™
Automatic packet handling
Auto packet transaction handling
6 data pipe MultiCeiver™
Drop-in compatibility with nRF24L01
On-air compatible in 250kbps and 1Mbps with nRF2401A, nRF2402, nRF24E1 and nRF24E2
Low cost BOM
±60ppm 16MHz crystal
5V tolerant inputs
Compact 20-pin 4x4mm QFN package
Applications
Wireless PC Peripherals
Mouse, keyboards and remotes
3-in-1 desktop bundles
Advanced Media center remote controls
VoIP headsets
Game controllers
Sports watches and sensors
RF remote controls for consumer electronics
Home and commercial automation
Ultra low power sensor networks
Active RFID
Asset tracking systems
Toys
Future Project Ideas/Additions using the nRF24L01 (not currently supported by this circuitpython library):
There’s a few blog posts by Nerd Ralph demonstrating how to use the nRF24L01 via 2 or 3 pins (uses custom bitbanging SPI functions and an external circuit involving a resistor and a capacitor)
network linking layer, maybe something like TMRh29’s RF24Network
Where do I get 1?
See the store links on the sidebar or just google “nRF24L01”. It is worth noting that you generally don’t want to buy just 1 as you need 2 for testing – 1 to send & 1 to receive and vise versa. This library has been tested on a cheaply bought 10 pack from Amazon.com using a recommended capacitor (>100nF) on the power pins. Don’t get lost on Amazon or eBay! There are other wireless transceivers that are NOT compatible with this library. For instance, the esp8266-01 (also sold in packs) is NOT compatible with this library, but looks very similar to the nRF24L01(+) and could lead to an accidental purchase.
Contributing
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Sphinx documentation
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to locally verify it will pass.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for circuitpython-nrf24l01-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee39d07272520a506e2260fe7857a715e07280527a9e8c7491961651f47b2588 |
|
MD5 | 3d90deaf326c720f2d82e57538b08291 |
|
BLAKE2b-256 | d277e4f107eaa7e0d1338e76017778b5416dfb31478981f31e53ad51f412462e |