Pages: [1]   Go Down
Author Topic: Bliptronics Spectrum Analyzer Help  (Read 1962 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I have been reading a lot about the arduino with hopes of making a large spectrum analyzer on a table. I found the Bliptronics post in the read-only forum and purchased the Pixel LED's and shield.

I know the LED's work, cause the pattern code for them lights everything up as it should. However, the Spectrum code will light up the first 5 LED's a light blue, and a random 10 or so near the end of the 50 LED strip will flick on and off bright white.

Has anyone had issues with this shield?

Here is a video of what happens:


And here is the code in use:
Code:
#include <LEDPixels.h>

//Example to control RGB LED Modules with Spectrum Analyzer
//Bliptronics.com
//Ben Moyes 2010
//Use this as you wish, but please give credit, or at least buy some of my LEDs!
//


LEDPixels LP;  //Our LEDPixels library - see http://www.bliptronics.com/ArduinoCode/LEDPixels.zip
   
//For spectrum analyzer shield, these three pins are used.
//You can move pinds 4 and 5, but you must cut the trace on the shield and re-route from the 2 jumpers.
int spectrumReset=5;
int spectrumStrobe=4;
int spectrumAnalog=0;  //0 for left channel, 1 for right.

//This holds the 15 bit RGB values for each LED.
//You'll need one for each LED, we're using 25 LEDs here.
//Note you've only got limited memory, so you can only control
//Several hundred LEDs on a normal arduino. Double that on a Duemilanove.

int MyDisplay[49];

// Spectrum analyzer read values will be kept here.
int Spectrum[7];

void setup() {
  byte Counter;

  //Initialize the LEDPixels library.
  //            refresh delay, address of data, number of LEDs, clock pin, data pin.
  LP.initialize(25, &MyDisplay[0],49, 12, 11 );

  //Setup pins to drive the spectrum analyzer.
  pinMode(spectrumReset, OUTPUT);
  pinMode(spectrumStrobe, OUTPUT);

  //Init spectrum analyzer
  digitalWrite(spectrumStrobe,LOW);
    delay(1);
  digitalWrite(spectrumReset,HIGH);
    delay(1);
  digitalWrite(spectrumStrobe,HIGH);
    delay(1);
  digitalWrite(spectrumStrobe,LOW);
    delay(1);
  digitalWrite(spectrumReset,LOW);
    delay(5);
  // Reading the analyzer now will read the lowest frequency.
 
  // Turn all LEDs off.
  LP.setRange(0,48,LP.color(0,0,0));
  LP.show();                             //Write out display to LEDs

}

void loop() {

  int Counter, Counter2, Counter3;
   
  showSpectrum();
  delay(15);  //We wait here for a little while until all the values to the LEDs are written out.
              //This is being done in the background by an interrupt.
}

// Read 7 band equalizer.
void readSpectrum()
{
  // Band 0 = Lowest Frequencies.
  byte Band;
  for(Band=0;Band <7; Band++)
  {
    Spectrum[Band] = (analogRead(spectrumAnalog) + analogRead(spectrumAnalog) ) >>1; //Read twice and take the average by dividing by 2
    digitalWrite(spectrumStrobe,HIGH);
    digitalWrite(spectrumStrobe,LOW);     
  }
}


void showSpectrum()
{
  //Not I don;t use any floating point numbers - all integers to keep it zippy.
   readSpectrum();
   byte Band, BarSize, MaxLevel;
   static unsigned int  Divisor = 80, ChangeTimer=0; //, ReminderDivisor,
   unsigned int works, Remainder;
 
  MaxLevel = 0;
       
  for(Band=0;Band<7;Band++)//We only graph the lowest 5 bands here, there is 2 more unused!
  {
  //If value is 0, we don;t show anything on graph
     works = Spectrum[Band]/Divisor; //Bands are read in as 10 bit values. Scale them down to be 0 - 5
     if(works > MaxLevel)  //Check if this value is the largest so far.
       MaxLevel = works;                       
     for(BarSize=1;BarSize <=7; BarSize++) 
        {
        if( works > BarSize) LP.setLEDFast( LP.Translate(Band,BarSize-1),BarSize*6,31-(BarSize*5),0);
          else if ( works == BarSize) LP.setLEDFast( LP.Translate(Band,BarSize-1),BarSize*6,31-(BarSize*5),0); //Was remainder
            else LP.setLEDFast( LP.Translate(Band,BarSize-1),5,0,5);
        }
  }
  LP.show();

 // Adjust the Divisor if levels are too high/low.
 // If  below 4 happens 20 times, then very slowly turn up.
  if (MaxLevel >= 5)
  {
    Divisor=Divisor+1;
    ChangeTimer=0;
  }
  else
    if(MaxLevel < 4)
    {
      if(Divisor > 65)
        if(ChangeTimer++ > 20)
        {
          Divisor--;
          ChangeTimer=0;
        }
    }
    else
    {
      ChangeTimer=0;
    }
  }




 
   
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What audio are you feeding into your spectrum analyzer shield?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The audio in the video is from the headphones jack on my PC. I've also used an iPhone which has no additional result. In the section of the video where I shut the music off, it looks like that regardless of audio input. 7 blue lights, and the funky white pattern near the end of the strip.

It strikes me as odd considering there is a section in the code to shut all LED's off.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, one problem is that the .Translate(x,y) function uses a global variable called gridHeight.  The variable is initialized to 5 and you are given no way to set it with a library function.

In setup() set gridHeight to 7.  You may need to add "extern int gridHeight;" near the top of your program.

It looks like the LED's are supposed to be in a grid by folding the strip every 'n' LEDs.  In your case, n=7.

I don't know if that will fix the problem but it should get you closer.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the replies. I had a friend take a look at things and work his magic.

He did add the call to GridHeight:

Code:
  //Initialize the LEDPixels library.
  //            refresh delay, address of data, number of LEDs, clock pin, data pin.
  LP.initialize(25, &MyDisplay[0],49, 12, 11 );
[b]  LP.gridWidth = 7;
  LP.gridHeight = 7;[/b]

  //Setup pins to drive the spectrum analyzer.
  pinMode(spectrumReset, OUTPUT);
  pinMode(spectrumStrobe, OUTPUT);

but the main issue was a missing call to setLEDfast:

Code:
for(BarSize=1;BarSize <=7; BarSize++) 
    {
      if(works > BarSize)
        LP.setLEDFast(LP.Translate(Band,BarSize-1),BarSize*6,31-(BarSize*5),0);
      else if (works == BarSize)
        LP.setLEDFast(LP.Translate(Band,BarSize-1),BarSize*6,31-(BarSize*5),0); //Was remainder
      else
        LP.setLEDFast(LP.Translate(Band,BarSize-1),0,0,31);
    }
  }

It works great now. He then had some fun tweaking the level adjust to come back up and down at a faster rate. Then added an idle sequence for no input. No code on that yet, but will post once all is set.

Working Spectrum Analyzer:


Idle sequence for no input:


I take no credit on making this work.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. I'm looking to get a similar EQ visualizer project up and running. Could you post your final working code? Thanks!
Logged

Pages: [1]   Go Up
Jump to: