USB RGB LED VU Meter
This project creates a RGB LED VU Meter which is controlled via USB by a Windows 7 or Vista host machine. The project serves several purposes: Firstly, it demonstrates how to read audio information from the Windows machine and pass this over USB to the device (which is a question which popped up several times after my USB Performance Monitor project). Secondly, it implements an open source TLC5940 driver. Although a library has been available for the AVR microcontroller, I wasn’t able to find an open source library for the PIC. Hopefully this demonstration will be useful to anyone wanting to control a large number of LEDs with PWM brightness control.
YouTube Demonstration Video
The hardware in this project is very straight forward. The demonstration board consists of a 5V regulator (switching), a PIC18F2550 with the required USB components, 3xTLC5940 16 channel serial LED drivers with PWM and 16 high intensity RGB LEDs.
The only real thing of ‘note’ in the circuit design is the two large capacitors placed next to the crystal oscillator. The high-speed switching performed by the 5940s when controlling the LEDs via PWM generates a lot of power-rail noise (and I mean a lot!). The two capacitors help to ensure that the PIC’s timing circuitry remains stable. During breadboarding the 5940s would cause the PIC to reset as well as other nasty side-effects.
As I wanted to test and demonstrate cascaded TLC5940s the LEDs are not multiplexed. Each LED is under direct control. However, given the big amount of brightness generated by the LEDs the end result would not suffer due to multiplexing and the code can be readily adapted if required.
The PCB artwork required to build the demonstration board is available in the zip files at the end of this article.
Here is the circuit schematic for the VU meter:
The firmware is based on the software available from my Open Source Framework for USB Generic HID devices based on the PIC18F and Windows. I’ve added two layers to this base, the lowest level is a generic TLC5940 driver library. The TLC5940 is a 16 channel LED driver which supports both 4096 brightness levels (using PWM) and has independent brightness level correction for each LED. The driver can support a single TLC5940 chip, or you can cascade them together. Theoretically you should be able to control around 20xTLC5940s from a single PIC (meaning you would have 16×20 = 320 LEDs in total). Although I haven’t tested it up to that maximum, this example project uses 3 chips cascaded to provide the 48 channels required for the 16 RGB LEDs.
Layered over the TLC5940 is another library which implements RGB control via the 5940 library. This includes fade on, fade off, colour balancing and a number of other useful functions to make controlling the LEDs easy.
USB control is provided by two commands, the first command allows the host to specify the colour intensities of all 16 LEDs using ‘standard’ 0-255 values for the red, green and blue channels. The second command allows the host to specify the required fade-out time for the LEDs (the libraries support fade-on also, however this is not required by the VU meter demonstration).
Windows host software
The host software is written using Visual Studio C# 2010 and is compatible with both Windows 7 and Vista. Due to the fact it uses the core audio API it will not work on Windows XP (simply because XP doesn’t supply the API).
The host software is made up of 3 parts. My open source C# library performs the USB generic HID communication. The core audio API is provided by Ray Molenkamp who published the API wrapper over on The Code Project. The API is really very powerful, you can even use it to grab the track information and display it on an LCD, or implement USB audio control surfaces. The final part of the host software is the VU Meter display code itself.
Here is a screenshot of the GUI:
As you can see from the screenshot there are a number of options available. You can set the ‘damping’ time of the display (the rate at which it drops to follow the audio – slower damping makes the display smoother but at the cost of accuracy). The fade-off time configures the time it takes for the LEDs to fade off. You can also set the start and end colours of the display (the host software automatically performs the fading between the colours across the display). The ‘peak colour length allows you to specify how many LEDs should be in the ‘end colour’ which lets you extend the colour out a little (this is nice with certain colour schemes).
There are also 3 types of display. A single bar showing the average of both the right and left channels. 2 bars using 8 LEDs each which are ‘zeroed’ in the centre and the same thing but zeroed on the outside of the display.
The status line at the bottom shows the connection state of the USB device. Note that the software works with or without the hardware connected since you can monitor the LED status from within the GUI, this runs even if no USB device is detected.
Files for download
The PCB artwork and schematics in expressSCH and expressPCB format (these are freely available programs):
The PIC18F2550 firmware source code including the TLC5940 library (for HiTech C18):
The Windows 7 and Vista (NOT XP!) source code in Microsoft Visual Studio 2010 C#: