Very weird data read from MSGEQ7 chip..

So I just got my MSGEQ7 spectrum analyzer all hooked up using this schematic:

http://cdn.instructables.com/FG1/DMZM/HSRZMA35/FG1DMZMHSRZMA35.LARGE.jpg.

Here’s the code I’m using. I pulled it from a different tutorial, but I don’t see why it wouldn’t work with the pins adjusted a little…

/* 
  Test Sketch for the MSGEQ7
  from Mixed Signal Integration

  the IOs in this Sketch are 
  compatible with the Shield
  from Sparkfun:

  http://www.sparkfun.com/products/10306

  Author: Simon Waldherr
  License: MIT
*/

int AnalogIn = 0;    // read from multiplexer using analog input 0
int NextBand = 4;    // strobe (next band) is attached to digital pin 4
int ResetPin = 5;    // reset is attached to digital pin 5
int Spectrum[7];     // array to store analog values


void setup()
  {

    // init IO
    delay(250);
    pinMode(AnalogIn, INPUT);
    pinMode(NextBand, OUTPUT);
    pinMode(ResetPin, OUTPUT);
    analogReference(DEFAULT);
    digitalWrite(ResetPin, LOW);
    digitalWrite(NextBand, HIGH);

    // init Serial
    delay(250);
    Serial.begin(115200);
    Serial.println("|______________________________|");
    Serial.println("|            MSGEQ7            |");
    Serial.println("|------------------------------|");
    Serial.println("| Seven Band Graphic Equalizer |");
    Serial.println("|------------------------------|");
    Serial.println("|     on an Arduino Shield     |");
    Serial.println("|------------------------------|");
    Serial.println("|      with Serial output      |");
    Serial.println("|------------------------------|");
    // wait
    delay(5000);
  }

void loop()
  {
    digitalWrite(ResetPin, HIGH);                          // reset band to 63 Hz
    digitalWrite(ResetPin, LOW);

    for (int i = 0; i < 7; i++)                            // for loop to save values to array
      {
        digitalWrite(NextBand, LOW);
        delayMicroseconds(22);                             // to allow the output to settle
        Spectrum[i] = doMath(analogRead(AnalogIn));        // read actual value to array
        digitalWrite(NextBand, HIGH);                      // select next band (160Hz, 400Hz, 1000Hz, 2500Hz, 6250Hz, 16kHz)
        delayMicroseconds(3);
      }

    for (int i = 0; i < 7; i++)                            // for loop to print array to Serial
      {
        if (Spectrum[i] < 10 )                             // ignore values lower than 100 (you also can use doMath())
          {
            Serial.print("\t");
            Serial.print("0");
          }
        else
          {
            Serial.print("\t");
            Serial.print(Spectrum[i]);
          }
      }
    Serial.println();                                      // Serial new line
    //delay(500);                                          // this sketch prints really much data, you can slow down if you have to.
  }

int doMath(int analogvalue)                                // you can filter the analog data and do your own math
  {
    int result;
    result = (analogvalue-32)/10;
    return result;
  }

The problem is that when I look at the Serial Monitor output, it shows a bunch of zeros… If I take the Analog pin from the chip out of A0, the monitor prints out a bunch of rows counting down from 41… I’m guessing that doesn’t really mater since it’s not even reading the input from the chip…

Anyways anyone have any idea what could be causing this? I’ve been double-checking my circuit and the code for hours and can’t figure it out… :expressionless:

Thanks!

100+ views and no one has any ideas? =(

Here's what the output looks like without the analogin going to A0:

|_______________________| | MSGEQ7 | |------------------------------| | Seven Band Graphic Equalizer | |------------------------------| | on an Arduino Shield | |------------------------------| | with Serial output | |------------------------------| 42 42 42 42 42 42 42 42 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33

I made some changes to your code and it now works good on my spectrum analyzer. The new code has comments for each change. Let me know if you have any questions as to why the change. I try to keep each program as simple as possible, so I marked some things as “not necessary”. These changes don’t make or break the program they just make it smaller.

As for the reading the EQ7 analog output and applying a noise filter, there are different ways to do it. I put the one that gives the best results in your code. Trust me, I’ve tried all sorts of math filters and “map” with various scales, and “constrain” seems to work the best.
Regards,
Dennis

/* 
  Test Sketch for the MSGEQ7
  from Mixed Signal Integration

  the IOs in this Sketch are 
  compatible with the Shield
  from Sparkfun:

  http://www.sparkfun.com/products/10306

  Author: Simon Waldherr
  License: MIT
*/

int AnalogIn = 0;    // read from multiplexer using analog input 0
int NextBand = 4;    // strobe (next band) is attached to digital pin 4
int ResetPin = 5;    // reset is attached to digital pin 5
int Spectrum[7];     // array to store analog values
int filter = 80;  // *** added min level above noise

void setup()
  {

    // init IO
 //   delay(250);  // *** not necessary
 //   pinMode(AnalogIn, INPUT);  // *** not necessary
    pinMode(NextBand, OUTPUT);
    pinMode(ResetPin, OUTPUT);
    analogReference(DEFAULT);
    digitalWrite(ResetPin, HIGH);
    digitalWrite(ResetPin, LOW);  // *** added
//    digitalWrite(NextBand, HIGH);  //*** removed

    // init Serial
 //   delay(250);  // *** not necessary
    Serial.begin(9600);  //*** chg'd from 115200 to 9600
                         //*** make sure Monitor is 9600
    Serial.println("|______________________________|");
    Serial.println("|            MSGEQ7            |");
    Serial.println("|------------------------------|");
    Serial.println("| Seven Band Graphic Equalizer |");
    Serial.println("|------------------------------|");
    Serial.println("|     on an Arduino Shield     |");
    Serial.println("|------------------------------|");
    Serial.println("|      with Serial output      |");
    Serial.println("|------------------------------|");
    // wait
    delay(5000);
  }

void loop()
  {
// *** Reset here works but slighly better response without it
//    digitalWrite(ResetPin, HIGH);                          // reset band to 63 Hz
//    digitalWrite(ResetPin, LOW);

    for (int i = 0; i < 7; i++)                            // for loop to save values to array
      {
        // HIGH to LOW transition works best here
        digitalWrite(NextBand, HIGH);  //*** added 
        digitalWrite(NextBand, LOW);
        delayMicroseconds(22);                               // to allow the output to settle
//        Spectrum[i] = doMath(analogRead(AnalogIn));        // read actual value to array
        // read spectrum level and filter noise
        Spectrum[i] = constrain(analogRead(AnalogIn), filter, 1023);  //*** added
//        digitalWrite(NextBand, HIGH);  //*** moved up      // select next band (160Hz, 400Hz, 1000Hz, 2500Hz, 6250Hz, 16kHz)
        delayMicroseconds(3);  //*** probably not necessary
      }

    for (int i = 0; i < 7; i++)                            // for loop to print array to Serial
      {
        if (Spectrum[i] == filter )  //***  chg'd               // ignore values lower than 100 (you also can use doMath())
           {
            Serial.print("\t");
            Serial.print("0");
          }
        else
          {
            Serial.print("\t");
            Serial.print(Spectrum[i]);
          }
      }
    Serial.println();                                      // Serial new line
    //delay(500);                                          // this sketch prints really much data, you can slow down if you have to.
  }
/*  *** remove
int doMath(int analogvalue)                                // you can filter the analog data and do your own math
  {
    int result;
    result = (analogvalue-32)/10;
    return result;
  }  */

you might consider using the F() macro to save precious RAM e.g.

Serial.println( F("|______________________________|") );

Awesome! Thanks Dennis. I'll give that new code a shot. Before I do that, though, I have one more question.. I've been running it using the 5V pin of the Arduino (which is being powered by my laptop). Is that safe? Most people I've seen are powering both separately using a 5V 2A source for the chip. All I have at the house is a 5V 4A (and I'll shoot myself if I have to drive up to RadioShack again)..

Thanks! Chris

So with the new code I'm getting some results now! But.. something still isn't quite right. Here's the output if it's powered by the Arduino:

1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 1023 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Here's the output when I have a separate power source.. I have the DC jack's power going to my breadboard, ground going to the Arduino, and then the breadboard ground to the Arduino.

324 324 324 324 324 324 324 327 327 327 327 327 327 326 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 219 219 219 219 219 219 218 221 221 221 221 221 220 221 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 96 96 95 95 95 95 95 95 95 98 98 98 97 98 98 97

For power, I always use an external supply. Do your LEDs require ubber amps? I don’t trust the usb 5V and even unplug it after a download for serious testing.

I would check your audio in connection since I ran the same sketch on my MSGEQ7 and got different results.

Dennis

Hm... Ok, well, I swapped out for a different 3.5mm jack and the output still doesn't seem quite right. The output stays pretty much consistent across all the different columns. It's either the same number all the way across, or it'll be +-1.. Maybe the micro controller is fried? As far as I can tell they should all be different to represent the different spectrums..

So far I don't have it hooked up to any LEDs . I was just wanting to make sure it was working correctly before integrating it into my light setup.

Another interesting symptom.. If I watch the serial monitor run for around 2 minutes, the output slowly rises up to over 1000. After around 5 minutes it just prints out 1023 for all the lines..

I don't know what to tell you as the schematic you posted is correct for the MSGEQ7. And the program works on my analyzer. That only leaves the processor and your (I assume breadboard) circuit. The odds are that the problem is the EQ7 circuit so drag out a multimeter and check each connection.

Measure 5V on EQ7 pin 1, C4, R1. Power off and measure resistance (continuity) between all other connections.

I doubt if its the processor but you can use different analog and digital pins if you want to eliminate the possibility of a bad I/O port.

The only other suggestion I have is ... while testing, use a Function Generator program on your pc. The audio frequency and level will be constant and predictable. Music varies too much for troubleshooting. The program I use is FG Lite (Marchand Function Generator) and its free.

Dennis

Tested and I'm getting about 5.15v on all of those. I checked the other circuits and all of them showed some resistance (I think? Not really sure what to look for).. But anyways, I think the issue might be with the 33pF capacitor (or what I thought was a 33pF). I did some research and it looks like it may actually be a 330000pF capacitor (says 334 on it). So I can see how that would be an issue. I ordered a new 33pF one and we'll see what happens.

Thanks for all the help!

Any updates on this? I am having similar problems with the same chip.