Skip to main content

Control Hardware PWM on the Raspberry Pi

Reason this release was yanked:

bad code

Project description

rpi hardware pwm

CI status PyPI version

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.
  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

from rpi_hardware_pwm import HardwarePWM

pwm = HardwarePWM(pwm_channel=0, hz=60)
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


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

rpi_hardware_pwm-0.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file rpi_hardware_pwm-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rpi_hardware_pwm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 367283cfb8e947eb5dc72d7ce9a51da0b2b102f33c9555e0d233d4ba50e3d25a
MD5 7f7ceeb298302539d8f5c0f32c536319
BLAKE2b-256 35fbdc5e3a4289c4f0ce517b2d20f74efc5300cf7999d3da252b0cd155e6c0e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page