SEARCH
TOOLBOX
LANGUAGES
modified on 18 November 2010 at 20:36 ••• 49,636 views

USB RGB LED VU Meter

From WFFwiki

Jump to: navigation, search

Contents

Introduction

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.

VU Meter board.JPG

YouTube Demonstration Video


Hardware

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:

RGB Bargraph Schematic.png

Firmware

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. Theroetically you should be able to control around 20xTLC5940s from a single PIC (meaning you would have 16x20 = 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:

VU Meter GUI.PNG

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

PCB and Schematic - The PCB artwork and schematics in expressSCH and expressPCB format (these are freely available programs)

PIC18F2550 Firmware - The PIC18F2550 firmware source code including the TLC5940 library (for HiTech C18)

MS VS C# 2010 host software source - The Windows 7 and Vista (NOT XP!) source code in Microsoft Visual Studio 2010 C#.



Donate to waitingforfriday.com:

If you like this site and want to help support future projects, or you just want to show appreciation for a project you built, used or enjoyed, please consider leaving a PayPal donation. It's quick, secure and helps us to run the site and fund future projects!


PayPal, fast, easy and secure




Join the EFF:

Join the Electronic Frontier Foundation


The owner of this site is a member of the EFF and you should be a member too! The EFF protects the rights of open-source, open-hardware authors all over the world.



Most popular pages:

  1. Building a PIC18F USB device ‎(252,918 views)
  2. Home ‎(238,394 views)
  3. 4-Bit Computer ‎(104,195 views)
  4. Projects ‎(103,463 views)
  5. Open Source Framework for USB Generic HID devices based on the PIC18F and Windows ‎(103,331 views)
  6. Open Source Visual C++ Class for USB Generic HID Communication ‎(62,759 views)
  7. Real-Time Audio Spectrum Analyser ‎(60,997 views)
  8. Controlling LED brightness using PWM ‎(51,231 views)
  9. USB RGB LED VU Meter ‎(49,636 views)
  10. PIC USB Development Board ‎(48,666 views)
  11. 16x8 LED Matrix Display ‎(43,962 views)
  12. C64 VICE Front-End ‎(36,611 views)
  13. USB Performance Monitor ‎(33,205 views)
  14. PC Case USB LCD ‎(30,048 views)
  15. Rotary Encoder Demonstration ‎(28,174 views)
  16. Commodore SID 6581 Datasheet ‎(26,967 views)
  17. Reverse engineering an MB Electronic Simon game ‎(24,029 views)
  18. Retro Computing ‎(22,929 views)
  19. LED Colour Organ ‎(22,797 views)
  20. Vetinari's Clock ‎(18,592 views)

more >>