Skip to content

Commit 3916bcd

Browse files
support rpi5, bump version
1 parent b3ecd52 commit 3916bcd

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ Access the hardware PWM of a Raspberry Pi with Python. More lightweight than alt
1616

1717
### Examples
1818

19+
20+
> For Rpi 1,2,3,4, use chip=0; For Rpi 5, use chip=2
21+
22+
23+
1924
```python
2025
from rpi_hardware_pwm import HardwarePWM
2126

22-
pwm = HardwarePWM(pwm_channel=0, hz=60)
27+
pwm = HardwarePWM(pwm_channel=0, hz=60, chip=0)
2328
pwm.start(100) # full duty cycle
2429

2530
pwm.change_duty_cycle(50)

rpi_hardware_pwm/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@ class HardwarePWM:
2727
2828
Notes
2929
--------
30+
- For Rpi 1,2,3,4, use chip=0; For Rpi 5, use chip=2
3031
- If you get "write error: Invalid argument" - you have to set duty_cycle to 0 before changing period
3132
- /sys/ pwm interface described here: https://jumpnowtek.com/rpi/Using-the-Raspberry-Pi-Hardware-PWM-timers.html
3233
3334
"""
3435

3536
_duty_cycle: float
3637
_hz: float
37-
chippath: str = "/sys/class/pwm/pwmchip0"
3838

39-
def __init__(self, pwm_channel: int, hz: float) -> None:
39+
def __init__(self, pwm_channel: int, hz: float, chip: int = 0) -> None:
4040

4141
if pwm_channel not in {0, 1}:
4242
raise HardwarePWMException("Only channel 0 and 1 are available on the Rpi.")
4343

44+
self.chippath: str = f"/sys/class/pwm/pwmchip{chip}"
4445
self.pwm_channel = pwm_channel
4546
self.pwm_dir = f"{self.chippath}/pwm{self.pwm_channel}"
4647
self._duty_cycle = 0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
setup(
1414
name="rpi_hardware_pwm",
1515
packages=find_packages('.'),
16-
version='0.1.4',
16+
version='0.2.0',
1717
license='OSI Approved :: GNU General Public License v3 (GPLv3)',
1818
description='Control Hardware PWM on the Raspberry Pi',
1919
long_description = long_description,

0 commit comments

Comments
 (0)