Skip to main content

rpi hardware pwm

CI status PyPI version

Access the hardware PWM of a Raspberry Pi with Python. More lightweight than alternatives.

Installation

  1. On the Raspberry Pi, add dtoverlay=pwm-2chan to /boot/firmware/config.txt. This defaults to GPIO_18 as the pin for PWM0 and GPIO_19 as the pin for PWM1.
    • Alternatively, you can change GPIO_18 to GPIO_12 and GPIO_19 to GPIO_13 using dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4.
    • On the Pi 5, use channels 0 and 1 to control GPIO_12 and GPIO13, respectively; use channels 2 and 3 to control GPIO_18 and GPIO_19, respectively
    • On all other models, use channels 0 and 1 to control GPIO-18 and GPIO_19, respectively
  2. Reboot your Raspberry Pi.
    • You can check everything is working on running lsmod | grep pwm and looking for pwm_bcm2835
  3. Install this library: sudo pip3 install rpi-hardware-pwm

Examples

from rpi_hardware_pwm import HardwarePWM

pwm = HardwarePWM(pwm_channel=0, hz=60, chip=0)
pwm.start(100) # full duty cycle

pwm.change_duty_cycle(50)
pwm.change_frequency(25_000)

pwm.stop()

History

The original code is from jdimpson/syspwm, We've updated it to Python3 and made it look like the RPi.GPIO library's API (but more Pythonic than that.), and we use it in Pioreactor bioreactor system.

Metadata

Release files for rpi-hardware-pwm 0.3.1

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

Source distribution (sdist)

Source distribution for rpi-hardware-pwm 0.3.1
File Size Uploaded Provenance Actions
rpi_hardware_pwm-0.3.1.tar.gz 5.3 kB Without provenance Details for rpi_hardware_pwm-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rpi-hardware-pwm 0.3.1
File Interpreter ABI Platform Actions
rpi_hardware_pwm-0.3.1-py3-none-any.whl Python 3 none any Details for rpi_hardware_pwm-0.3.1-py3-none-any.whl

Total release size: 10.4 kB

Release files / rpi_hardware_pwm-0.3.1.tar.gz

Download URL rpi_hardware_pwm-0.3.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dcb2627ab1248a9c532c86e013914416c55f11bd70976dd6ec6ecfd1109b0fe8
BLAKE2b-256 checksum
How to use checksums
4332ecd3e230a806c7894a13780a1c7d614f0d316d85cde7a2256626e2af2c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / rpi_hardware_pwm-0.3.1-py3-none-any.whl

Download URL rpi_hardware_pwm-0.3.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad0f7f3e8ec83dd76a552cff92ea1dbb1bf773210316519ea66e3e85d3ac9ae0
BLAKE2b-256 checksum
How to use checksums
b217c8d4d2efa5bb1af38644a6202c26e4d990d30cf6124ace32f33e7c488e9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for rpi-hardware-pwm 0.3.1

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