Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pioreactor/rpi_hardware_pwm
Access the hardware PWM of a Raspberry Pi
https://github.com/pioreactor/rpi_hardware_pwm
gpio hardware python raspberry-pi raspberrypi
Last synced: about 1 month ago
JSON representation
Access the hardware PWM of a Raspberry Pi
- Host: GitHub
- URL: https://github.com/pioreactor/rpi_hardware_pwm
- Owner: Pioreactor
- License: other
- Created: 2021-05-05T13:31:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T03:04:05.000Z (9 months ago)
- Last Synced: 2024-10-11T16:43:28.095Z (about 1 month ago)
- Topics: gpio, hardware, python, raspberry-pi, raspberrypi
- Language: Python
- Homepage:
- Size: 36.1 KB
- Stars: 61
- Watchers: 5
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rpi hardware pwm
![CI status](https://github.com/pioreactor/rpi_hardware_pwm/actions/workflows/ci.yaml/badge.svg)
[![PyPI version](https://badge.fury.io/py/rpi-hardware-pwm.svg)](https://badge.fury.io/py/rpi-hardware-pwm)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/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
> For Rpi 1,2,3,4, use chip=0; For Rpi 5, use chip=2
```python
from rpi_hardware_pwm import HardwarePWMpwm = HardwarePWM(pwm_channel=0, hz=60, chip=0)
pwm.start(100) # full duty cyclepwm.change_duty_cycle(50)
pwm.change_frequency(25_000)pwm.stop()
```
### History
The original code is from [jdimpson/syspwm](https://github.com/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](https://pioreactor.com) bioreactor system.