Kevin Mehall

USB Controlled RGB LED

2009-07-20

The article on my RGB LED fader has been one of the most-visited articles on this blog. Since posting it, I've designed and built another microcontroller-based RGB LED project, this time controlling the colors from the computer over USB.

View video: Ogg Theora | YouTube

Hardware

Here's the schematic:

Schematic of USB RGB Microcontroller circuit

AVR Code

The avr source is in the avr/ directory. It uses the OBDEV AVR-USB/V-USB library and the source tree is based on OBDEV's example code.

Read the V-USB docs for more information.

The AVR needs to be overclocked to run the USB code without a separate oscillator. The osccal.c source file watches the USB frame clock and calibrates the AVR internal RC oscillator with the OSCCAL register. This technique was adapted from the V-USB wiki.

Host code

The host sources are in the host/ directory. A 32bit Linux binary is included, or it can be built from source with the included Makefile. Libusb is required.

Run it with sudo ./ledcontrol. It accepts lines on stdin of the format 0 <red val> <green val> <blue val> with color values ranging from 0-31.

The python scripts included can be piped into ledcontrol for a variety of control methods:

The demo shown in the video can be run with python colorgui.py | sudo ./ledcontrol.

Download

Download source code

My next step is a multi-LED panel...