Control Hardware PWM on the Raspberry Pi
Project description
rpi hardware pwm
Access the hardware PWM of a Raspberry Pi with Python. More lightweight than alternatives.
Installation
- On the Raspberry Pi, add
dtoverlay=pwm-2chanto/boot/firmware/config.txt. This defaults toGPIO_18as the pin forPWM0andGPIO_19as the pin forPWM1.- Alternatively, you can change
GPIO_18toGPIO_12andGPIO_19toGPIO_13usingdtoverlay=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
- Alternatively, you can change
- Reboot your Raspberry Pi.
- You can check everything is working on running
lsmod | grep pwmand looking forpwm_bcm2835
- You can check everything is working on running
- 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpi_hardware_pwm-0.3.1.tar.gz.
File metadata
- Download URL: rpi_hardware_pwm-0.3.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb2627ab1248a9c532c86e013914416c55f11bd70976dd6ec6ecfd1109b0fe8
|
|
| MD5 |
b5ce5eba30c93594f4b0256386845674
|
|
| BLAKE2b-256 |
4332ecd3e230a806c7894a13780a1c7d614f0d316d85cde7a2256626e2af2c45
|
File details
Details for the file rpi_hardware_pwm-0.3.1-py3-none-any.whl.
File metadata
- Download URL: rpi_hardware_pwm-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad0f7f3e8ec83dd76a552cff92ea1dbb1bf773210316519ea66e3e85d3ac9ae0
|
|
| MD5 |
96d27fb15ed3a055e3509ad874757ad0
|
|
| BLAKE2b-256 |
b217c8d4d2efa5bb1af38644a6202c26e4d990d30cf6124ace32f33e7c488e9e
|