LoL Shield Audio Spectrum VU Meter

103K25970

Intro: LoL Shield Audio Spectrum VU Meter

This is an audio spectrum VU meter using the LoL Shield for Arduino .

The LoL Shield is a 14 x 9 LED matrix which fits onto the Arduino as a shield and is controlled through an efficient method known as Charlieplexing . It was designed by Jimmie P. Rodgers .

This project uses a Fast Fourier Transform library for Arduino to analyze an audio signal, break it up into frequency bands, and display that information on the LoL Shield.

The Arduino microcontroller is fast enough to calculate a fast Fourier transformation. It lives up to its name and is surprisingly fast and accurate.

Since all the work is done by the microcontroller, this project is completely portable if you use batteries.

The webpage for this project is located at http://andydoro.com/vulol/



Parts required:
  • LoL Shield
  • Arduino (Diavolino recommended)
  • audio jack (I used a male mono 1/8" phone plug)
  • Arduino code
  • power supply (DC power supply, USB cable, 9V battery, etc.)

STEP 1: Assemble LoL Shield


Follow the instructions to assemble the LoL Shield here .

See, that didn't take long at all!

STEP 2: Solder Wires to the Audio Jack


I am using a male mono 1/8" phone plug, as it's called at Radioshack, but you can use whatever audio cable is appropriate for your audio system setup. You could use a microphone if you wanted to.

For this type of plug, I soldered two wires. I used red and black.

The LoL Shield leaves analog pins 4 and 5 free for inputs. My code uses pin 5.

You can attach the red wire to analog pin 5 of the LoL Shield and the black wire to GND. You don't need to solder it in, I just put the wire through and bent it.

STEP 3: Program Arduino

Now we need to program the Arduino to control the LoL Shield.

It is recommended to use the Diavolino to control the LoL Shield in order to prevent "ghosting" effects on the LEDs due to the green surface mount LED connected to pin 13 on the standard Arduino, but a standard Arduino will work fine.

This requires two Arduino libraries:
- the FFT library found on the Arduino forum
- the Charlieplexing library for the LoL Shield

Installing libraries for Arduino can be slightly daunting if you haven't done it before, but you'll do fine!

Follow the instructions on installing Arduino libraries here:

http://www.arduino.cc/en/guide/libraries

The FFT library breaks the audio signal in 64 frequency bands.
The LoL Shield is 14 x 9 LEDs. We average the 64 frequency bands together into 14 frequency bands. We're throwing away some data because 14 doesn't divide into 64 evenly, but whatevs.
The value of each frequency range is remapped from 0 to 9.

You can copy the Arduino code below, get the code from GitHub (recommended), or download the .ZIP file, which includes the libraries and Arduino code.

Here is the GitHub link:

https://github.com/andydoro/LoLShield-FFT

Below is the Arduino code:

/*
FFT for LoL Shield v0.9
by Andy Doro
http://andydoro.com/
based on FFT library and code from the Arduino forums and
the Charlieplexing library for the LoL Shield.
*/

#include "Charliplexing.h"

#include "fix_fft.h"

#define AUDIOPIN 5
char im[128], data[128];
char data_avgs[14];

int i=0,val;

void setup() {
LedSign::Init(); //Initilizes the LoL Shield
}

void loop() {

for (i=0; i < 128; i++){
val = analogRead(AUDIOPIN);
data[i] = val;
im[i] = 0;
};

fix_fft(data,im,7,0);

for (i=0; i< 64;i++){
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // this gets the absolute value of the values in the array, so we're only dealing with positive numbers
};

// average bars together
for (i=0; i<14; i++) {
data_avgs[i] = data[i*4] + data[i*4 + 1] + data[i*4 + 2] + data[i*4 + 3]; // average together
data_avgs[i] = map(data_avgs[i], 0, 30, 0, 9); // remap values for LoL
}

// set LoLShield

for (int x=0; x < 14; x++) {
for (int y=0; y < 9; y++) {
if (y < data_avgs[13-x]) { // 13-x reverses the bars so low to high frequences are represented from left to right.
LedSign::Set(x,y,1); // set the LED on
} else {
LedSign::Set(x,y,0); // set the LED off
}
}
}

}

STEP 4: Enjoy!!

Plug the audio jack to your stereo, iPod, computer, etc.

Power the Arduino with a DC power supply, USB from your computer or batteries- this is completely portable. You could put it into a hat or belt buckle.

The white LEDs are so bright it's difficult to capture on video. It looks like there is purple flame coming off of them!

Sit back and enjoy!





69 Comments

I have attempted the build of this code, and it is not working for me, with the same error messages as mentioned by others above.

I think that the key questions to ask are:

1) What version of the Arduino IDE was used to initially build and demonstrate the code? The fact that so many people are having problems suggest that some detail is missing from the instructions!

2) I haven't bothered to post my code, as it is the same code as provided by the links above. As a side note - I do have my LoL shield working, and the Library for it is installed.

What I suspect is happening here is that there is simply a version conflict for many people who are using different versions of the Arduino IDE to what the author used to demonstrate the project initially.

May we have the IDE version of Arduino used to compile the demonstration unit please?

Many thanks in advance and keep up the good work.

Cheers,

SirWaldy

Replying to my own post here - I got mine to work using the Arduino V1.0 IDE.

Make sure that the charlieplexing and FIX_FFT libraries are in the arduino 1.0 Libraries folder.

Also, there is an ERROR in the code above - the #include statements just after the initial comments at the top of the code do not mention what to include. If you copy and paste this code as it is, it will not work.

Change the lines below the initial comment to:

#include <Charlieplexing.h>

#include <Fix_FFT.h>

See how that goes for you :)

Hey it's been fixed, the code will work now.

Hello, i have this error:

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

In file included from LoLShield_FFT.ino:9:0:

C:\Users\Uporabnik\Documents\Arduino\libraries\FFT/fix_fft.h:4:22: fatal error: WProgram.h: No such file or directory

#include <WProgram.h>

^

compilation terminated.

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

hey, I'm using your code for a school project and it's not working for me. I'm using an electret microphone instead of the audio jack.

https://www.sparkfun.com/products/8635. This is the one I'm using.

Hey, thanks for sharing! However, it seems like I'm not the only one getting this error and there doesn't seem to be a resolution online. I am quite used to adding new libraries and don't think I messed up here. I realize this was posted a while ago ... Appreciate your response!

Arduino: 1.5.8 (Mac OS X), Board: "Arduino Yún"

sketch_feb23a.ino:11:21: fatal error: fix_fft.h: No such file or directory

Thanks!

hi! It seems like the fix_fft library isn't installed correctly. please follow instructions here.

can you please provide the data sheet of the lol shield sir i could not order it

It shows the following error when I try to compile:

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp:31:22: error: WProgram.h: No such file or directory

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp:48: error: 'boolean' does not name a type

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp: In function 'void LedSign::Flip(bool)':

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp:185: error: 'videoFlipPage' was not declared in this scope

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp:189: error: 'delay' was not declared in this scope

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp: In function 'void __vector_9()':

C:\Users\Lenovo\Documents\Arduino\libraries\LoLShield\Charliplexing.cpp:290: error: 'videoFlipPage' was not declared in this scope

When compiling I always get this error: "fix_fft" was not declared in this scope , can someone please tell me how to fix it?

i have the same problem^^

hi, i have one question: where do I buy a lol shield?
hi, when i try to vertify the code in arduino it says theres an error, this is what it high lights : LedSign::Init(); //Initilizes the LoL Shield what does this mean? it says led sign has not been declared, what do i do?
hi there! it sounds like perhaps the Charlieplexing LoL library hasn't been installed correctly- make sure the libraries are installed correctly!
Awesome project andydoro, got it working in a couple of days!

Quick question: If I have it using Analog in 5, I hear a lot of electrical back noise (comes out as a high pitch noise on a speaker attached to a y-plug with the visualizer), but using Analog in 4, I don't get this. Any clue why?
if I were to make two of them and wanted one to be an exact mirror of the other, how could I do that?
Wait.When you plug the audio jack in then you cannot hear the music or? :/
According to your tutorial you are just running the positive lead of the audio from a headphone jack into the analog input, But doesn't the signal need to be scaled to a DC range first? In other projects it's done with a pair of resisters and a capacitor. Is this not necessary?
More Comments