Hi all im new to arduino with zero programing experience but i have purchased books etc yet struggling to piece things together.
i currently have a uno r3 with ide 1.0.4 and i am trying to put together a spectrum analyser/visualizer by using a 8x8 led matrix hooked up to max7219 and the adafruit electret microphone module as the audio in.
Im really struggling to figure out how to write the code to display the output from the fft to the matrix below is what i have so far
#include <fix_fft.h>
#include "LedControl.h"
int audioPin = A0;
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
const int maxExpectedAudio = 20; // Change this value to adjust the sensitivity
char data[128], im[128], data_avgs[8]; // FFT array variables
int i, j, x, y;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
for (int i = 0; i < 8; i++);
}
void loop() {
// Build table of audio samples
for (i = 0; i < 128; i++) {
data[i] = analogRead(audioPin);
im[i] = 0;
}
for (i = 0; i < 64; i++)
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // Make values positive
for (i = 0; i < 8; i++) {
// Average values
j = i << 3;
data_avgs[i] = data[j] + data[j + 1] + data[j + 2] + data[j + 3]
+ data[j + 4] + data[j + 5] + data[j + 6] + data[j + 7];
if (i == 0);
data_avgs[i] >>= 1; // KK: De-emphasize first audio band (too sensitive)
data_avgs[i] = map(data_avgs[i], 0, maxExpectedAudio, 0, 7); // Map for output to 8x8 display
}
}
writeArduinoMatrix();
for (y = 0; y < 8; y++);
for (x = 0; x < data_avgs[y]; x++)
delayMicroseconds(500);
for (x = 0; x < data_avgs[y]; x++)
}
this is what im trying to achieve: this is by lady ada using i2c rgb led matrix i wouldnt have a clue where to begin to adapt the sketch to work with my setup Piccolo Music Visualizer - YouTube <<<<<ladyada piccolo
thanks in advance guys and girls i do hope someone can help
Hi johnwasser thanks for replying, but as i stated in my original post, the code i put up is what i have come up with so far and is incomplete and this is where i am struggling. I am struggling with writing the end piece of code to write to the led matrix i was really hoping someone on the forum may have been able to help me fit the missing piece
You have a library called LedControl that you are using to manipulate the MAX7219. You don't say where you found that library or point to any documentation so it is hard to know how to use it.
thankyou johnwasser for taking the time to helpi really appreciate it. i took up the arduino after ready it was really easy, apart from flashing leds im finding it really hard to hang in there with it. Ive gone back over my sketch and cleaned it up a bit it will auto format fine but i now get a compile error with the code you suggested saying x and y not declared in this scope heres where i am with it and once again thank you
/*
FFT for 8x8 with adafruit electretmicrophone module
code adapted from Andy Doro FFT for LoL shield code (http://andydoro.com)
adafruit recomends using 3.3v rail for mic
based on FFT library and code from the Arduino forum
BIG thanks to johnwasser on the arduino forum for his assistance
*/
#include <LedControl.h> //library fot the 8x8 matrix
#include <fix_fft.h> //library for fft
#define AUDIOPIN 5 //define mic to A5
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 11 is connected to the DataIn
pin 13 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(11,13,10,1); //DIN, CLK, LD pins and number of displays 1
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
char im[128], data[128];
char data_avgs[14];
int i=0,val;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
lc.setIntensity(0,8); //set the brightness 0 darkest 15 brightest
lc.clearDisplay(0); //clear the display ready to begin
}
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, 8, 0, 8); // remap values 8x8
}
// set 8x8
for (y = 0; y < 8; y++) {
for (x = 0; x < 8; x++) {
if (y < data_avgs[8-x]) { // 18-x reverses the bars so low to high frequences are represented from left to right.
lc.setLed(0, x, y, x < data_avgs[y]);
}
}
}
}
Hi all ive got this to compile but the matrix flashes for a split secound then nothing does anyone have any ideas where im going wrong
/*
FFT for 8x8 with adafruit electretmicrophone module
code adapted from Andy Doro FFT for LoL shield code (http://andydoro.com)
adafruit recomends using 3.3v rail for mic
based on FFT library and code from the Arduino forum
BIG thanks to johnwasser on the arduino forum for his assistance
*/
#include <LedControl.h> //library fot the 8x8 matrix
#include <fix_fft.h> //library for fft
#define AUDIOPIN 5 //define mic to A5
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 11 is connected to the DataIn
pin 13 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(11,13,10,1); //DIN, CLK, LD pins and number of displays 1
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
char im[128], data[128];
char data_avgs[14];
int i=0,val;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
lc.setIntensity(0,8); //set the brightness 0 darkest 15 brightest
lc.clearDisplay(0); //clear the display ready to begin
}
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, 8, 0, 8); // remap values 8x8
}
// set 8x8
for (int col = 0; col < 8; col++) {
for (int row = 0; row < 8; row++) {
if (row < data_avgs[8-row]) { // 18-x reverses the bars so low to high frequences are represented from left to right.
lc.setLed(0, row, col, row < data_avgs[i]);
}
}
}
}
hi john i have looked but the display used for the piccolo uses the i2c interface where as the max7219 is spi, so to my understanding the two are completly different and the code cant be 'just modified' and if it could its well beyond me
For those who tried to help me with this i thank you very much here is the working code if anyone wishes to make use of it
/*
FFT for 8x8 max7219 with adafruit electretmicrophone module
code adapted from Andy Doro FFT for LoL shield code (http://andydoro.com)
adafruit recomends using 3.3v rail for mic
*/
#include <LedControl.h> //library fot the 8x8 matrix
#include <fix_fft.h> //library for fft
#define AUDIOPIN 5 //define mic to A5
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 11 is connected to the DataIn
pin 13 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(11,13,10,1); //DIN, CLK, LD pins and number of displays 1
/* we always wait a bit between updates of the display */
unsigned long delaytime=50;
int audioPin = A0;
char im[128], data[128], data_avgs[8]; //FFt variables
int i, j, col, row;
int maxExpectedAudio = 5;
void setup(){
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
lc.setIntensity(0,8); //set the brightness 0 darkest 15 brightest
lc.clearDisplay(0); //clear the display ready to begin
}
void loop() {
// Build table of audio samples
for (i = 0; i < 128; i++) {
data[i] = analogRead(audioPin);
im[i] = 0;
}
fix_fft(data, im, 7, 0); // FFT processing
for (i = 0; i < 64; i++)
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // Make values positive
for (i = 0; i < 8; i++) {
// Average values
j = i << 3;
data_avgs[i] = data[j] + data[j + 1] + data[j + 2] + data[j + 3]
+ data[j + 4] + data[j + 5] + data[j + 6] + data[j + 7];
if (i == 0);
data_avgs[i] >>= 1; // KK: De-emphasize first audio band (too sensitive)
data_avgs[i] = map(data_avgs[i], 0, maxExpectedAudio, 0, 7); // Map for output to 8x8 display
{
}
for(int e = 0; e < 8; e++)
{
for(int i = 0; i < 9; i++)
{
if(i <= data_avgs[e] && data_avgs[e] < 8)
{
lc.setLed(0, 7-e, i-1, true);
}
else
{
lc.setLed(0, 7-e, i-1, false);
}
}
}
}
}