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/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
For Rpi 1,2,3,4, use chip=0; For Rpi 5, use chip=2
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for rpi_hardware_pwm-0.2.2-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 81ecbb876952b910c6bebe3b0a003310bb9ac0a86d913938fb3f5e1acc4ccdb4 |
|
| MD5 | 1f76006edd5c5b8e6040ef8fa46fe243 |
|
| BLAKE2b-256 | 992a300e1c9bd2e7aac9c12ed8401732798179396d2a69152585dce24da43bb3 |