Skip to main content
# RGB LED Driver

This software can be used to drive an analog RGB LED strip using a raspberry pi
and Adafruit's [16-channel 12-bit PWM/Servo Driver - PCA9685](https://raw2.github.com/apexskier/rgbLED/master/LED_Strip_bb.png):

## The Circuit

Here's the basic idea:

- Hook up the pi to the PCA9685 breakout board using the I2C connections.
- Connect the pi's 3.3V output to VCC on the PCA9685 breakout board. Leave V+
floating.
- Follow this tutorial for the RGB LED strips:
http://learn.adafruit.com/rgb-led-strips/usage
- I used N-channel MOSFETs - three of them, one for each channel
- Connect the +12V from the LED strip to an external power supply (do NOT
use your pi for this!)
- Connect the ground side of the power supply to the pi ground
- Instead of using the PWM outputs from the arduino, we'll use the PWM
outputs from the PCA9685.
- Connect up the PWM output 0 to the MOSFET with the red wire from the
LED strip. Output 1 goes to green, output 2 goes to blue.

![Breadboard image](https://raw2.github.com/apexskier/rgbLED/master/LED_Strip_bb.png)


## Dependencies

- [WiringPi2 Python](https://github.com/WiringPi/WiringPi2-Python)

## Usage

This program is designed to be included as a python module, but also has some
command line options. It, or any python code importing it, must be run as root
(sudo), because of the I2C interface.

### CLI Options

- `-c [hex color]` - Sets the led strip to the color specified.
- `-t` - Runs a test of a couple things. Use as a demo.
- `-o` - Turn the led strip off after other actions.

### As a module

```
from rgbDriver import RGBDriver
rgb_driver = RGBDriver()
```

Methods in the module use tuples to describe rgb colors: `(red_value,
green_value, blue_value)`. Each color value can range between 0 and 4095, due
to the PWM driver's 12 bit resolution. The `convert_eight_to_twelve_bit()`
method can convert a standard 0 to 255 color value to this scale.

To describe a color you can use the string representation of a hex color code
and the method `hex_to_rgb()` to convert it or `set_hex_color()` and
`to_hex_color()` to use it directly.

The driver keeps a property `current_color` that stores the led strip's current
color (in theory). This is used internally to smoothly transition from one
color to another.

Two types of color setting methods exist. `to_...` will transition a color
change over a set time. The last argument of any `to_...` method is that
transition time in milliseconds (default 300ms). `set_...` will set a color
immediately.

Currently supported methods are:

- `to_rgb(rgb, fade=DEFAULT)`, `set_rgb(rgb)`
- `to_rand(r_range=(0, 4095), g_range=(0, 4095), b_range=(0, 4095), fade=DEFAULT)`, `set_rand(r_range=(0, 4095), g_range=(0, 4095), b_range=(0, 4095))`
- `to_hex_color(color, fade=DEFAULT)`, `set_hex_color(color)`


## TODO

- I've got a basic single color led strip and an extra N-channel MOSFET that I
want to control.
- Set current_color var after setting up pwm.

Download files

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

Source Distribution

ledDriver-1.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file ledDriver-1.0.tar.gz.

File metadata

  • Download URL: ledDriver-1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ledDriver-1.0.tar.gz
Algorithm Hash digest
SHA256 a0ccef0fd51f5154d64730c72ef75c0b8d414e77f505046536ef1c9a81bad19c
MD5 23d9d0f88095878ccdc4750e1d7a3f3f
BLAKE2b-256 9b0c8ff29ee8f2120b36ff6fa3b031736984e2470c72d191cbdac6ce9df2fae7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page