MSGEQ7 Chip Problems

Hi there,

I have recently purchased two MSGEQ7 chips in order to create an LED light show. After wiring everything up as shown by Skoba and running code from a very similar project, I noticed that I was getting stagnant lights. Looking into the problem a bit further, I decided to test the MSGEQ7s with the test code that Skoba includes on his post. The code is as follows:

int analogPin = 0; // read from multiplexer using analog input 0
int strobePin = 2; // strobe is attached to digital pin 2
int resetPin = 3; // reset is attached to digital pin 3
int spectrumValue[7]; // to hold a2d values

void setup()
{
 Serial.begin(9600);
 pinMode(analogPin, INPUT);
 pinMode(strobePin, OUTPUT);
 pinMode(resetPin, OUTPUT);
 analogReference(DEFAULT);

 digitalWrite(resetPin, LOW);
 digitalWrite(strobePin, HIGH);

 Serial.println("MSGEQ7 test by J Skoba");
}

void loop()
{
 digitalWrite(resetPin, HIGH);
 digitalWrite(resetPin, LOW);

 for (int i = 0; i < 7; i++)
 {
 digitalWrite(strobePin, LOW);
 delayMicroseconds(30); // to allow the output to settle
 spectrumValue[i] = analogRead(analogPin);

 // comment out/remove the serial stuff to go faster
 // - its just here for show
 if (spectrumValue[i] < 10)
 {
 Serial.print(" ");
 Serial.print(spectrumValue[i]);
 }
 else if (spectrumValue[i] < 100 )
 {
 Serial.print(" ");
 Serial.print(spectrumValue[i]);
 }
 else
 {
 Serial.print(" ");
 Serial.print(spectrumValue[i]);
 }

 digitalWrite(strobePin, HIGH);
 }
 Serial.println();
}

When I run the code, I was expecting to see values under 100, as it is demonstrated by Skoba. Unfortunately, each band was being output at its max value (1023), even at zero volume. The image is shown here:

I do not know what I might be doing wrong, and would really appreciate any advice on how to troubleshoot this issue.

Thanks for all the help in advance!
~Lights

would really appreciate any advice on how to troubleshoot this issue

Well the standard way is to post the code and the schematic of what you are trying along with a focused photograph.

What test equipment do you have. You would normally need an oscilloscope to confirm that you have an input signal of the correct amplitude, and all the individual pins look like they have the same voltage on them.

Did you get them from a reputable source? There are some that actually have nothing inside floating around from the far east.

Grumpy_Mike:
Well the standard way is to post the code and the schematic of what you are trying along with a focused photograph.

Hey Grumpy_Mike,

First of all, thanks for looking into my post, I really appreciate it. Unfortunately, I don’t own a program that allows me to make a clean schematic, but I followed the schematic given by Sparkfun on their Spectrum Shield, in conjunction with the inputs and outputs given by the product’s datasheet (Page #3). It seems as if the schematic given by Sparkfun didn’t correlate with the actual pins on the datasheet. The end result looks like this (this is only 1 of the 2 chips, but both are wired exactly the same).

On the other hand, I am almost certain that my code is written correctly, because it’s picking up the output of the MSGEQ7s, but since they are constantly maxed out, the LEDs are only outputting the max color scheme. Here is the code:

#include <Adafruit_NeoPixel.h>

String colorPick = "GreenYellowRed";

const byte analogL = 0;   // - - - - - - - - - - - - - - - - - left channel analog data from shield
const byte analogR = 1;   // - - - - - - - - - - - - - - - - - right channel analog data from shield
const byte strobePin = 4;   // - - - - - - - - - - - - - - - - - data strobe for shield
const byte resetPin = 7;   // - - - - - - - - - - - - - - - - - reset strobe for shield
const byte dataPin = 8;   // - - - - - - - - - - - - - - - - - data pin for Neopixels
const byte numband = 10;  // - - - - - - - - - - - - - - - - - number of LEDs for each freq band
const byte numTop = 0;   // - - - - - - - - - - - - - - - - - number of LEDs to have top color
const int noise[] = {900, 900, 900, 900, 900, 900, 900}; // - - - - - - - - set this to magnitude of noise from shield
const float gain[] = {5, 5, 5, 5, 5, 5, 5}; // - gain for each band

Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, dataPin, NEO_GRB + NEO_KHZ800);

enum audio {
  MONO,
  RIGHT,
  LEFT };

int spectrumReadR;  //R magnitude from shield
int spectrumReadL;  //L magnitude from shield
int magL = 0;        //the magnitude of a freq band
int magR = 0;        //the magnitude of a freq band
int numONL = 0;      //the number of LEDs on in a freq band
int numONR = 0;      //the number of LEDs on in a freq band
float fl_magL = 0.0; //floating point mag after noise removal and scaling
float fl_magR = 0.0; //floating point mag after noise removal and scaling

int peakArray[7];

byte
  peak = 0,
  dotCount = 0;

void setup() {
  Serial.begin(9600);
  pinMode(resetPin, OUTPUT);
  pinMode(strobePin, OUTPUT);
  pinMode(dataPin, OUTPUT);
 
  strip.begin(); //begin strip communication
  strip.show(); //set strip blank

//Init spectrum analyzer
  digitalWrite(resetPin,HIGH);
    delayMicroseconds(5);
  digitalWrite(strobePin,HIGH);
    delayMicroseconds(50);              // strobe PW > 18 usec min
  digitalWrite(strobePin,LOW);
    delayMicroseconds(50);              //reset PW > 100 usec min
  digitalWrite(resetPin,LOW);
    delayMicroseconds(5);              
  digitalWrite(strobePin,HIGH);
    delayMicroseconds(100);             // allow reset to strobe falling > 72 usec min
}


void loop() {
  for(byte band = 0; band < 7; band++) {
    digitalWrite(strobePin, LOW); //set analyzer to low to read
    delayMicroseconds(40);
   
    spectrumReadR = analogRead(analogR); //read right audio
    spectrumReadL = analogRead(analogL); //read left audio
   
    digitalWrite(strobePin, HIGH); //set analyzer back to high
   
    magL = max(0, (spectrumReadL - noise[band])); //creates magnitude of frequency
    magR = max(0, (spectrumReadR - noise[band])); //creates magnitude of frequency
    fl_magL = gain[band] * float(magL); //adjusts magnitude for gain
    fl_magR = gain[band] * float(magR); //adjusts magnitude for gain
    numONL = map(fl_magL, 0, 1024, 0, numband+1); //maps magnitude to number of active pixels
    numONR = map(fl_magR, 0, 1024, 0, numband+1); //maps magnitude to number of active pixels
 
    anyBand(band);

    Serial.print(fl_magL);
    Serial.println();
   
    //Serial.print(band);
    //Serial.println(peakArray[band]);
    if(peakArray[band]==0) strip.setPixelColor(peakArray[band] + numband*(band), strip.Color(0,0,0));
    else strip.setPixelColor(peakArray[band] + numband*(band), strip.Color(255,0,0));
  }
  strip.setBrightness(20);
  strip.show();
 
}


void readBand(byte band) {
  for(byte band = 0; band < 7; band++) {
    digitalWrite(strobePin, LOW); //set analyzer to low to read
    delayMicroseconds(40);
   
    spectrumReadR = analogRead(analogR); //read right audio
    spectrumReadL = analogRead(analogL); //read left audio
   
    digitalWrite(strobePin, HIGH); //set analyzer back to high

    magL = max(0, (spectrumReadL - noise[band])); //creates magnitude of frequency
    magR = max(0, (spectrumReadR - noise[band])); //creates magnitude of frequency
    fl_magL = gain[band] * float(magL); //adjusts magnitude for gain
    fl_magR = gain[band] * float(magR); //adjusts magnitude for gain
    numONL = map(fl_magL, 0, 1024, 0, numband+1); //maps magnitude to number of active pixels
    numONR = map(fl_magR, 0, 1024, 0, numband+1); //maps magnitude to number of active pixels
 
    anyBand(band);
  }
}
 
void anyBand(byte band) {
  for(byte i = 0; i < numband; i++){
    if(i < (numONL - numTop)){
      strip.setPixelColor(i + numband*(band), Wheel(map(i,0,numband,20,83))); //main wheel colors
    }
    else if(i >= numONL){
      strip.setPixelColor(i + numband*(band), strip.Color(0,0,0)); //unused colors on wheel
    }
  }


  for(byte i = 0; i < numband; i++){
    if(i < (numONR - numTop - 1)){
      strip.setPixelColor(149 - i - numband*(band), Wheel(map(i,0,numband-1,20,83))); //main wheel colors
    }
    else if(i >= numONR){
      strip.setPixelColor(149 - i - numband*(band), strip.Color(0,0,0)); //unused colors on wheel
    }
  }
}

uint32_t Wheel(byte WheelPos) {
  if(colorPick == "GreenYellowRed") {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
  else if(colorPick == "PinkPurpleBlue") {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  else if(colorPick == "GreenTealBlue") {
    return strip.Color(0, 255 - WheelPos * 3, WheelPos * 3);
  }
}

Personally, I don’t own any equipment such as an oscilloscope at my house, but I can get access to one in the coming week. I am not sure how to use it in this specific situation, however. Same deal with a DMM. While I have taken an intro to circuit design course at my university, I am not personally an EE. I’m reaching the edge of my knowledge with this project and this last issue has run me into a wall. If you need any more information to help me solve this problem, I will be right on it.

Unfortunately, I don't own a program that allows me to make a clean schematic,

You own a pen and paper. Just draw your schematic and take a photograph of it. You attach photographs not post links to off site stuff.

Please read this:- How to use this forum

Now that photograph does show the chip is not powered correctly, there seems to be nothing connected to the ground ( pin 2 ). I stopped looking after that. Also you can not see all the wires and where they go on that photograph. The ones you miss out are just as important than those that you show.

It seems as if the schematic given by Sparkfun didn't correlate with the actual pins on the datasheet.

The schematic given by SparkFun did not contain ANY pin numbers on ANY chips so you can't say they don't correlate. On a schematic the physical position of a pin on a symbol has ( or should have ) no relationship to its pin number. Pin numbers must always be given on a schematic, which is why we as what you have done.

On the other hand, I am almost certain that my code is written correctly, because it's picking up the output of the MSGEQ7s,

No you can not say that in any way at all. The fact that you are getting a maximum signal is in no way indicative of anything working code nor hardware.

Personally, I don't own any equipment such as an oscilloscope at my house, but I can get access to one in the coming week. I am not sure how to use it in this specific situation

You would use the scope my looking first at the power rails actually on the chip. Then look at the audio input and see the waveform is the right size. Then look at the clock in pin, can you see it oscillating? Next look at the strobe and reset pins, can you see the pulse from the Arduino on the chip's pins? You will need the scope to be triggered on an edge to see the signal, or write a sketch that sends those pulses often enough to see. Finally look at the signal on the output of the chip can you see any signal there, a vaying voltage level.

Here is one quick check you can do...

Disconnect the MSGEQ7s from the Arduino's analog inputs. Ground the Arduino inputs and you should read all zeros. Connect the inputs to 5V and you should read 1023.

If the readings still remain constantly 1023 you have a software problem. (That may not be your only problem.)

If the readings change, that does NOT prove your software is 100% correct, but it shows your software is "doing something".

Grumpy_Mike,

My apologies for not properly formatting my post, but from here on out I will try to post correctly.

Grumpy_Mike: You own a pen and paper. Just draw your schematic and take a photograph of it. You attach photographs not post links to off site stuff.

Here is an Imgur album of a couple photos that I have taken (they are too large to fit as attachments), one being a sketch of the diagram that I followed with labeled pins (VCC being the 5V pin of the Arduino). The other three are different angles of my circuit. I apologize for the jumbled mess that it is, but that's the cleanest way that I could wire the board with the cables that I own.

Grumpy_Mike: Now that photograph does show the chip is not powered correctly, there seems to be nothing connected to the ground ( pin 2 ). I stopped looking after that.

To follow the schematic that I provided, pin 2 goes through a 0.1 microFarad capacitor to ground. Since I am following the schematic as closely as possible, I figured this was the correct way to wire the chip (please correct me if this is wrong).

As for the oscilloscope measurements, I will look into that as soon as I can.

DVDdoug,

DVDdoug: Disconnect the MSGEQ7s from the Arduino's analog inputs. Ground the Arduino inputs and you should read all zeros. Connect the inputs to 5V and you should read 1023.

Thanks for the tip, I will certainly try this out when I get the chance.

To follow the schematic that I provided, pin 2 goes through a 0.1 microFarad capacitor to ground. Since I am following the schematic as closely as possible, I figured this was the correct way to wire the chip (please correct me if this is wrong).

It is wrong. You have pin 2 and pin 6 mixed up. It is pin 6 that is connected to the capacitor and pin 2 that should be connected to the ground.

The capacitor on pin 5 is shown as 1nF (1000pF) and it should be 10nF (0.01uF).

So the schematic you are working from is wrong. No point in checking the pictures as what you are working from is wrong. When in doubt always follow the data sheet.

Grumpy_Mike: So the schematic you are working from is wrong. No point in checking the pictures as what you are working from is wrong. When in doubt always follow the data sheet.

That's frustrating, but okay. I'll make that change as soon as I can get my hands on a 10nF capacitor. Thank you so much for the advice, and I will let you know if that solves the problem.

Grumpy_Mike: It is wrong. You have pin 2 and pin 6 mixed up. It is pin 6 that is connected to the capacitor and pin 2 that should be connected to the ground.

The capacitor on pin 5 is shown as 1nF (1000pF) and it should be 10nF (0.01uF).

I want to thank you for pointing out this issue! I made the change and everything fell into place. After altering the code a tiny bit, the LEDs are displaying exactly what I was hoping for.

Thanks again ~Lights