Rotary Encoder
A rotary encoder package for the Raspberry pi that "just works".
Tested with a KY-040 Rotary Encoder on a Raspberry pi 3 B+
Installation
Install via pip:
pip install rpi-rotary-encoder
Example
import rotary_encoder
counter = 0
def increment():
global counter
counter += 1
print(counter)
def decrement():
global counter
counter -= 1
print(counter)
def press():
print("PRESS")
def release():
print("RELEASE")
with rotary_encoder.connect(
clk_pin=20, # required
dt_pin=21, # required
sw_pin=26, # optional
on_clockwise_turn=increment, # optional
on_counter_clockwise_turn=decrement, # optional
on_button_down=press, # optional
on_button_up=release, # optional
):
input("press enter to quit\n")
Advanced Usage
When calling connect you can pass in an optional callback_handling argument. This controls how the callbacks are executed. The options are:
CallbackHandling.GLOBAL_WORKER_THREAD: The default. Callbacks are called in a global worker thread. This means all callbacks across all rotary encoders are called in the same thread. This ensures that all callbacks are executed sequentially. This is the least likely to cause problems with race conditions.CallbackHandling.LOCAL_WORKER_THREAD: Similar to the above, except that each individual rotary encoders callbacks are executed on a different thread. This means that sequential execution of the callbacks of one encoder is still guaranteed, but not across several encoders. The responsiveness of the individual encoders may be slightly improved.CallbackHandling.SPAWN_THREAD: Spawn a new thread for every callback. The execution of your callbacks is no longer sequential, and you will have to make sure that your callbacks are thread safe.CallbackHandling.GPIO_INTERUPT_THREAD: Not recommended. Similar in behavior toCallbackHandling.SPAWN_THREADexcept that the threads are spawned by the underlying C extension library.
Similar Projects:
The pigpio-encoder is a similar library based on pigpio.
Metadata
Release files for rpi-rotary-encoder 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rpi_rotary_encoder-0.2.0.tar.gz | 4.2 kB | Without provenance | Details for rpi_rotary_encoder-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rpi_rotary_encoder-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for rpi_rotary_encoder-0.2.0-py3-none-any.whl |
Total release size: 8.7 kB
Release files / rpi_rotary_encoder-0.2.0.tar.gz
| Download URL | rpi_rotary_encoder-0.2.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95eb0bae21f21d077fd863b95b09f58b6dd13c9c434e1fb88f620f39325f9d86
|
|
BLAKE2b-256 checksum How to use checksums |
abf38cbe54ab13f6846ccce5032c0e8f6d8ae94f18df3b211be28142af7f3030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.0 Darwin/21.6.0
|
Release files / rpi_rotary_encoder-0.2.0-py3-none-any.whl
| Download URL | rpi_rotary_encoder-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff2ad0448990a593badd9d5e8b2d1e0b600a065352e5302b816ab5482b0628b4
|
|
BLAKE2b-256 checksum How to use checksums |
7420134aacfd822cc73440ae600fd14599aa322d3c9c28b3210df7b6129e7f45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.0 Darwin/21.6.0
|
Security for rpi-rotary-encoder 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.