Skip to main content

cjn_PiTools - A collection of modules for Raspberry Pi projects

NOTE: These links point to the github repo since relative links to other .md files do not work on PyPI.

Module Description/Purpose
PiBlinky A multiple threaded LED driver for Raspberry Pi
rgpio_shared_gpios Central owner of GPIO pins for sharing across tool scripts
PiOLED Display multi-line messages on a shared Raspberry Pi connected OLED display
DS18B20 DS18B20 temperature sensor library using the w1_therm kernel driver
initW1buses Initialize the W1 buses and set write permission on found therm_bulk_read file(s)
ADC121C ADC121C* 12-bit ADC library for Raspberry Pi
SHT3x SHT3x Temperature/RH sensor library for Raspberry Pi
HTU21D HTU21D Temperature/RH sensor library for Raspberry Pi
MCP23008 MCP23008 8-Bit I/O Expander library for Raspberry Pi
PCA9548 PCA9548A/TCA9548A I2C port expander library for Raspberry Pi
shared Classes and functions used across cjn_PiTools

These drivers work with RPi.GPIO / smbus2 and lgpio / rgpio apis. Using the rgpio api enables remote operation of GPIOs, I2C and SPI (PiOLED)

Tested on Python 3.13, Trixie (Linux 6.18.60+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.18.60-1+rpt1 (2026-11-03) aarch64 GNU/Linux)

In this documentation, "tool script" refers to a Python project that imports and uses cjn_PiTools. Some may be simple scripts, and others may themselves be installed packages.


Installation and usage

If using only the RPi.GPIO and smbus2 (or lgpio) drivers (not rgpio):

pip install cjn_PiTools
  • lgpio is pulled from PyPI by this install. If that fails see the official install instructions.

If using the rgpio driver:

There is no downside to using rgpio, other than a bit more setup complexity.

rgpio is required for the rgpio_shared_gpios module to own GPIO pins and share them across tool script processes (not possible with smbus or lgpio). These modules are dependent on rgpio_shared_gpios (thus rgpio):

  • initW1buses - only if GPIOs need to be sequenced before discovering DS18B20 devices and Use_rgpio_shared_gpios is set True in the config file
  • PiBlinky - only if more than one process needs access to the same LED(s)

rgpio also optionally enables a tool script to run on one machine and access GPIO resources on another machine via a socket interface. These file are enabled for rgpio remote access:

  • PCA9548.py - Provides a CLI for setting/getting the port select register on local or remote PCA9548 chips
  • PCA9548-demo.py
  • PiBlinky-demo.py
  • shared-demo.py
  • SHT3x-demo.py

To install the rgpiod daemon:

apt install rgpiod

Here's a systemd service file for starting rgpiod at boot, if needed (the above apt install may install a rgpiod.service file):

[Unit]
Description=        Remote GPIO Daemon
After=              network.target

[Service]
Type=simple
EnvironmentFile=    -/etc/default/rgpiod
ExecStart=          /usr/bin/rgpiod -c ${DAEMON_CONF} -w ${DAEMON_WORK} ${DAEMON_OPTS}
TimeoutStopSec=     20

[Install]
WantedBy=           multi-user.target

If you wish to allow remote access, enable it in the rgpiod configuration

Edit /etc/default/rgpiod:
  Comment out the line DAEMON_OPTS="-l"
  Set up the DAEMON_OPTS="-x" permits and users features, as needed

Restart the rgpiod daemon

sudo systemctl restart rgpiod

Finally, install cjn_PiTools with rgpio support:

pip install cjn_PiTools[rgpio]

Key changes since the prior major public release (1.2.2)

V2.0 Changes

  • Upgrade to Trixie and rgpio/lgpio (pigpio removed)
  • Expanded i2c methods and reworked all I2C-based modules
  • Added rgpio_shared_gpios to provide a gpio sharing workaround for the kernel enforcement of single process access
  • Reworked initW1buses, enabling non-root access for all DS18B20 api

A fundamental change in more recent kernels is that GPIOs can be claimed and by only one process at a time. This plays havoc in having more than one tool script using PiBlinky and/or receiving notifications of button pushes, for example. The provided solution is via the rgpio_shared_gpios module, which, coordinating with rgpiod, takes ownership of specified GPIOs and shares them with multiple tool scripts. Note that I2C and SPI ports don't have the same single-owner requirement, it seems.


Revision history

  • 2.0 261127 - Upgrade to Trixie and rgpio/lgpio (pigpio removed), expanded i2c methods, rgpio_shared_gpios, rework initW1buses
  • 1.2.2 260828 - Corrected PiOLED logging of IPC handle names
  • 1.2.1 260526
    • HTU21D dummy user reg reads for measurement reads stability
    • PCA9548 monitor_ch
    • ADC121C read_conversion_result force_address switch added
    • PiOLED tweaks
    • HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
  • 1.2 260506
    • PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
    • PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
    • PiOLED taillog command
    • Debug logging of MCP23008 set_register() and set_bits() values
  • 1.1.1 260401 - pyproject.toml cleanup, keywords
  • 1.1 260401 - Added ADC121C, HTU21D, MCP23008, PCA9548, and SHT3x drivers
  • 1.0 260207 - New. Bundled PiBlinky, PiOLED, initW1buses, and DS18B20 modules

Metadata

Release files for cjn-PiTools 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cjn-PiTools 2.0
File Size Uploaded Provenance Actions
cjn_pitools-2.0.tar.gz 4.1 MB Without provenance Details for cjn_pitools-2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cjn-PiTools 2.0
File Interpreter ABI Platform Actions
cjn_pitools-2.0-py3-none-any.whl Python 3 none any Details for cjn_pitools-2.0-py3-none-any.whl

Total release size: 8.3 MB

Release files / cjn_pitools-2.0.tar.gz

Download URL cjn_pitools-2.0.tar.gz
Size 4.1 MB
Tags Source
SHA-256 checksum
How to use checksums
25cb365be82853ea17a40fee3a773a12ee8c4b13d03701877654e6a4b6f9567e
BLAKE2b-256 checksum
How to use checksums
91ae96c53305fa258969cd8d6d293d8370465ae18a9a2c6c50df0152e0558ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / cjn_pitools-2.0-py3-none-any.whl

Download URL cjn_pitools-2.0-py3-none-any.whl
Size 4.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c45de4c57675e80298a43d42af4de7d240fc14f03853ba670add796e3e188735
BLAKE2b-256 checksum
How to use checksums
149c57706807a6044728a02c2641bfc44ee702d1dcd09516c5d9a6a2d249ab27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Security for cjn-PiTools 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page