Skip to content

Commit

Permalink
support rpi5, bump vresion
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 8, 2024
1 parent a02d9e1 commit dc8d01e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
python-version: ["3.7", "3.8", "3.9"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout source
Expand Down
7 changes: 4 additions & 3 deletions rpi_hardware_pwm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HardwarePWM:
Example
----------
>pwm = HardwarePWM(0, hz=20)
>pwm = HardwarePWM(0, hz=20, chip=0)
>pwm.start(100)
>
>pwm.change_duty_cycle(50)
Expand All @@ -28,20 +28,21 @@ class HardwarePWM:
Notes
--------
- For Raspberry Pi 1,2,3,4, use chip=0 (default), for Raspberry Pi 5, use chip=2
- If you get "write error: Invalid argument" - you have to set duty_cycle to 0 before changing period
- /sys/ pwm interface described here: https://jumpnowtek.com/rpi/Using-the-Raspberry-Pi-Hardware-PWM-timers.html
"""

_duty_cycle: float
_hz: float
chippath: str = "/sys/class/pwm/pwmchip0"

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

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

self.chippath: str = f"/sys/class/pwm/pwmchip{chip}"
self.pwm_channel = pwm_channel
self.pwm_dir = f"{self.chippath}/pwm{self.pwm_channel}"
self._duty_cycle = 0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
setup(
name="rpi_hardware_pwm",
packages=find_packages('.'),
version='0.1.4',
version='0.2.0',
license='OSI Approved :: GNU General Public License v3 (GPLv3)',
description='Control Hardware PWM on the Raspberry Pi',
long_description = long_description,
Expand Down

0 comments on commit dc8d01e

Please sign in to comment.