Instructables

Arduino / Processing Audio Spectrum Analyzer

Picture of Arduino / Processing Audio Spectrum Analyzer
2012-02-24 17-35-52.729.jpg
In this Instructable I am going to show how to make a program in Processing that analyzes sound on your computer and sends data to an Arduino that controls an LED matrix to show the spectrum analysis.

I will be explaining where to get materials, explaining the coding and wiring needed and providing example programs that can be adapted.

I will be using an Arduino Nano and and a 32x16 LED Matrix from Sure Electronics.
 
Remove these adsRemove these ads by Signing Up

Step 1: Required Materials/Software and Where to Get Them

Picture of Required Materials/Software and Where to Get Them
The required materials are:
  1) An Arduino(doesn't really matter which version/variant)
  2) LED Matrix (for this Instructable, I use a 32x16 bicolor matrix, but any matrix should work)
  3) A driver chip if your LED matrix doesn't have them integrated, I will be explaining this in more depth.

Inexpensive LED Matrices: Sure Electronics: http://stores.ebay.com/Sure-Electronics
The display I use: http://www.ebay.com/itm/P4-32X16-RG-Bicolor-LED-3mm-Dot-Matrix-Unit-Board-/350527814626?

Required Software:
  1) Arduino IDE (I am using version 1.0) found here: http://arduino.cc/en/Main/Software
  2) Processing IDE found here: http://processing.org/download/

Thanks for the tutorial! Unfortunately, I'm using a different LED matrix which includes different driver chips as well. Here is the matrix I'm using: http://www.adafruit.com/product/420

Is there an easy way to convert the code to work with the Adafruit_GFX or RGBmatrixPanel libraries? Thanks!

Keanan (author)  nicholasjackson8271 month ago

Well that display would be better driven by a more powerful microcontroller or FPGA, but it is possible. First wiring will require 12 pins on the Arduino. Using Adafruits GFX library will be a very smooth transition though. Mainly just replace and add the libraries, and change the line calls in the code to match the format of the GFX line methods: matrix.drawLine(X1,Y1,X2,Y2, matrix.Color333(r, g, b));

I'm not sure if the Color333(r,g,b) method understands a single uint32_t value instead of 3 r,g,b values, I'll look into it.

You don't need to call the dotmatrix.sendframe(); as the board automatically draws the lines when you call each drawLine method.

As I don't have this board, it will be difficult to help further, but if you have more questions, feel free to ask.

Also for more info, follow the tutorial at https://learn.adafruit.com/32x16-32x32-rgb-led-mat...



EDIT:
Okay, I've been looking through the RGBmatrixPanel and the Color333 method does not recognize uint32_t variables, so my function above would not work, but I have submitted an issue request to Adafruit to add the feature, so maybe they'll add it, but I doubt it as they haven't changed it in 6 months.

But good news for now, I have forked the project and included the changes:
https://github.com/Aerospacesmith/RGB-matrix-Panel


I also added the ability to call a Color(r,g,b) method.

Example:

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
uint32_t BLACK = matrix.Color(0,0,0);
uint32_t ORANGE = matrix.Color(7,3,0); //Color333 uses values of 0-7.

void setup() {
matrix.begin();
matrix.drawLine(X1,Y1,X2,Y2,matrix.Color333(BLACK));
matrix.drawLine(X1,Y1,X2,Y2,matrix.Color333(ORANGE));
}
void loop(){}


I have created test sketches and they compile so it should work, but again, I do not have this board so I cannot test if it actually works.

Please let me know if my altered library works.

Wow, I'm not sure what you did to the library, but it worked! I copied your example code directly, inserted some coordinates to draw an X on the matrix, and it worked! I also had to change the colors for BLACK real quick because the black didn't show up on the matrix (obviously).

What next steps do I need to take to get your rendition of the code to work? Thanks again for your time!

Keanan (author)  nicholasjackson82729 days ago

Sorry for not replying sooner. Life tends to get in the way very often.

Anyway, I'm not sure if you figured it out yet, but should be most/all the changes needed (hopefully):

#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2

Make your new matrix library call:
RGBmatrixPanel dotmatrix(A, B, C, CLK, LAT, OE, false);

Then before setup() add the various colors, example Orange is 7,3,0; Red 7,0,0; Green 0,7,0 or ANY color you want since you have that board.
Just make sure to declare them as uint32_t types like

uint32_t BLACK = dotmatrix.Color333(0,0,0);
uint32_t GREEN = dotmatrix.Color333(0,7,0);
uint32_t RED = dotmatrix.Color333(7,0,0);
uint32_t YELLOW = dotmatrix.Color333(7,3,0);

Remove the dotmatrix.clear(); and replace it with
dotmatrix.fillScreen(BLACK);
this essentially fills the screen with black and clears it.


Then in each line call: dotmatrix.line(x1,y1,x2,y2,color); change the method from line to match the new libraries drawLine.
ex: dotmatrix.drawLine(x1,y1,x2,y2,GREEN);

Change the pixel calls from dotmatrix.plot(x,y,color); to dotmatrix.drawPixel(x,y,color).

And finally remove the dotmatrix.sendframe(); as this library/matrix driver pushes and draws the screen on every draw command and doesn't need a draw screen command. However this is also a caveat as drawing the screen on each command will slow down the display.

jmcclaire iii3 months ago

Nice job! I'm looking for some help with a project I'm working on. I'd like to display different animations on different LED matrix panels and control them all with one Arduino or BeagleBone Black. Any ideas? My failsafe is to combine several animations into one file and space them out so they look as if the different matrices are showing different animations.

Thanks for any advice or help anyone can offer!

- John

Romeo19814 months ago

how do I change the audio source? I want to use my music on my PC that is connected to my surround stereo system via Toslink and I would like to have the line in set to my speaker out (optical) so when I play music in media player or games or what not I want the sounds to display on the 32x16 bicolour matrix display. any help would be great, PS stereo system does not have preouts so I can't hook up a cable from my stereo, back to my computer line in.

also is there a way to change the speed it seems to have a delay from what comes out of the speakers to what is being displayed

mnedix7 months ago
It's a wonderful project, is it possible to make this without Arduino?
Keanan (author)  mnedix7 months ago
A microprocessor of some kind is required to drive the display.
mnedix Keanan7 months ago
Yes, an ATMega or a PIC will be required, I am really interested in a schematic + source code.

Anyone has such a thing?
hi.
how to make ardunio source for max7219 (8x8matrix use)
it was too hard to make source
help~~
Keanan (author) 1 year ago
Sorry i haven't replied in a while, things have come up. I am currently working on an Arduino stand-alone spectrum analyzer. I am waiting for the Due to come out before resuming my work.
Hello , I am doing almost the same thing as your project, except that I'll be using RGB LEDs and actually solder them onto a PCB and not use an already built LED matrix. I'm using the Arduino Leonardo and a MSGEQ7 IC which is a graphic equalizer IC with 7 bands. I'll be making 7 columns of RGB LEDs. Each column will somehow correspond to the 7 different frequencies through the digital output pins (CLK, Data, Latch) with 74HC595 shift registers in series.

Since i'll be using 7 frequencies, will i need to connect each of the 7 columns to 7 different digital output pins on arduino leonardo?

--or-- just connect the shift registers from all the 7 columns in series (daisy-chained) and let the arduino know what frequency band will correspond to each column? (if so, does the arduino need to be programmed already to know what frequency will correspond to each band?)

--or-- all the Shift registers from each column be hardwired in series independently from the other columns??

I'm stuck here and have a deadline for this... Please help!
Keanan (author)  osmsoses1 year ago
Here's a library for the MSGEQ7.
https://github.com/justinb26/MSGEQ7-library
I just ran across this and remembered you.
Keanan (author)  osmsoses1 year ago
Okay, so if I understand correctly, you will use MSGEQ7 IC to process your audio. The MSGEQ7 then sends 7 Analog signals in sequence that represent the max peak of these frequencies: 63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25kHz and
16kHz. You then will use a Leonardo to read the data and output corresponding levels to seven columns of RGB LEDs. The seven columns of LEDs will be driven by shift registers. Every 3 shift registers can control 8 RGB LEDs(1 for 8 red, 1 for 8 blue, 1 for 8 green). So for a matrix of 7x8 RGB LEDs, 21 shift registers will be needed. These could be daisy chained to only use 3 digital pins on the Leonardo, or they could be split up.
The MSGEQ7 will need to be hooked up as stated in it's datasheet: https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf
mfdupuis1 year ago
Hey! This is an awesome project, and I got it working. But now I'm trying to make a stand-alone system. Have you had any luck? What signal processing board do you use?
Hi, great project! I have been looking into something like this for a while. I saw you're working on a stand alone version. I just was this by adafruit. http://www.youtube.com/watch?v=Tmpl5KA02S4
It may be a help. I just made a one color 8x8 matrix with a max7219. I wonder how easy or hard it would be to transfer adafruits code to use a max7219. It's a bit over my head but I'd be very interested if you have any ideas. Thanks,
Matt
sstrunks131 year ago
Hi! Great project, looking forward to building me one of these some day. Just out of curiosity, have you been able to daisy chain more than two displays using this library?
Keanan (author)  sstrunks131 year ago
I only have one display. I'm not sure if this library supports more than two displays. Even if it did, the Arduino isn't fast enough to really drive more than two, unless low frame rate wasn't an issue. Maybe the Due could control more.
jimdsouza1 year ago
Is this the same as a real time sound/music graphic equalizer? Or are they different?
tomtortoise2 years ago
I finally got it working, its a little annoying to get the sound input right but it works and looks really cool.
First congratulations for your work:
I wonder how can I use instead of using pixel dot matrix Ws 2801, you have video on this Youtobe spectral analyzer
HI,
This is very good. But I have only one question. Can I connect directly the sound to the arduino?

PedroRamalho
srainsdon2 years ago
kinda off topic, what about going the other way around. ie audio in to arduino vu on computer
So if it takes it from the stereo mix:

Does it work with windows and mac?

Could you modify the code so that it takes a line in from a device?

Thanks
Keanan (author)  recordmasta0012 years ago
Windows will work without any problems. "An AudioInput is a connection to the current record source of the computer. How the record source for a computer is set will depend on the sound-card and OS, but typically a user can open a control panel and set the source from there. Unfortunately, there is no way to set the record source from Java. This is particularly problematic on the Mac because the input will always wind up being connected to the Mic-In, even if the user has set the input differently using their audio control panel."

Source: http://code.compartmental.net/tools/minim/manual-audioinput/
I was looking at this the other day:
http://www.instructables.com/id/LoL-Shield-Audio-Spectrum-VU-Meter/

Could you do something similar in that a line in is connected to the arduinos analogue pins in an analogue read type setup. Then the device would be completely separate from the computer, thus eliminating os problems.

Cheers for the response
mfdupuis2 years ago
This project looks awesome, thanks for posting!

Questions: what exactly is the .ino file? Did you mean to say that the .pde is for Arduino and .ino for Processing? Do they do the same thing?

Thanks!

PS: Commented previously but found what I was looking for.
Keanan (author)  mfdupuis2 years ago
the .ino file is for Arduino IDE 1.0
the .pde is for Processing
they do not do the same thing.
the processing sketch runs on the computer while the Arduino sketch is uploaded to the Arduino and runs on the Arduino
mfdupuis Keanan2 years ago
Thanks for getting back to me! I didn't realize that there was a software update that used new extensions.
Ghild.Zero2 years ago
Wow very cool man !!!