Skip to main content

Control LEDs connected to a micro controller using pwm.

Project description

python-pwmled PyPI version

python-pwmled controls LEDs connected to a micro controller using pulse-width modulation. It supports one-color, RGB and RGBW leds driven by GPIOs of an Raspberry Pi or a PCA9685 controller.


python-pwmled requires Python 3. It can be installed using pip:

pip install pwmled

When directly controlling the GPIOs of a Raspberry Pi using the GpioDriver(see below), the pigpio C library is required. It can be installed with the following commands:

sudo make install

Besides the library, the pigpiod utility is installed, which starts pigpio as daemon. The daemon must be running when using the GpioDriver.

sudo pigpiod



python-pwmled supports several possibilities for connecting LEDs to your micro controller:

  • GPIO: LEDs can be connected directly to the GPIOs of a Raspberry Pi.
  • PCA9885: A PCA9685 can be used as I2C-bus PWM controller.
from pwmled.driver.gpio import GpioDriver
from pwmled.driver.pca9685 import Pca9685Driver

# GPIO driver, which controls pins 17, 22, 23
driver = GpioDriver([17, 22, 23])
driver = GpioDriver([17, 22, 23], freq=200)
# To control the pigpio on a other machine use the host parameter
driver = GpioDriver([17, 22, 23], host='')

# PCA9685 driver which controls pins 1, 2, 3
driver = Pca9685Driver([1, 2, 3])
driver = Pca9685Driver([1, 2, 3], freq=200, address=0x40)


Each LED needs a separated driver, which controls the corresponding pins. The number and order of pins depends on the led type:

  • One-color: 1 pin
  • RGB: 3 pins ([R, G, B])
  • RGBW: 4 pins ([R, G, B, W])

The supported operations are shown in the following example:

from pwmled import Color
from pwmled.led import SimpleLed
from pwmled.led.rgb import RgbLed
from pwmled.led.rgbw import RgbwLed
from pwmled.driver.gpio import GpioDriver

# One-color led
driver = GpioDriver([C])
led = SimpleLed(driver)
led.brightness = 0.5
led.transition(5, brightness=0)

# RGB led
driver = GpioDriver([R, G, B])
led = RgbLed(driver)
led.color = Color(255, 0, 0)
led.set(color=Color(0, 255, 0), brightness=0.5) # set two properties simultaneously
led.transition(5, color=Color(0, 0, 255), brightness=1)

# RGBW led
driver = GpioDriver([R, G, B, W])
led = RgbwLed(driver)
# RgbwLed has same interface as RgbLed


Pull-requests are welcome, especially for adding new drivers or led types.


This library is provided under MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwmled-1.6.3.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

pwmled-1.6.3-py2-none-any.whl (11.8 kB view hashes)

Uploaded Python 2

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