Go Down

Topic: Issues with MSGEQ7 (Read 1 time) previous topic - next topic

ArianaGrande

Aug 30, 2019, 10:10 pm Last Edit: Aug 30, 2019, 11:29 pm by ArianaGrande Reason: Added output screenshot
Hello, everyone. I know there are dozens of posts about the MSGEQ7 chip (and believe me, I've read them), but I've run into an issue that I still can't solve.

Purpose: to use the MSGEQ7 to analyze the spectrum of incoming music and output DC voltages proportional to the signal's spectrum. This will be used to control a strip of programmable LEDs.

Datasheet: here

Circuit: here. The circuit design is straight from page 4 of the datasheet. Music comes in from my phone/laptop through an aux cord into the jack. Left and Right channels are connected via two 22KΩ resistors in series with a 0.01uF capacitor (I've also tried using a 0.1uF cap). A 33pF cap combined with two 100KΩ series resistors (making 200KΩ) make the clock. Strobe and Reset are connected to digital pins on the Arduino Mega. The DC output is connected to pin A0 on the Arduino.

I only use ceramic capacitors.

Code:
This is just a test script to make sure the chip works. This isn't the code with the LED components. I've tried various test scripts found online by people who supposedly got it to work. I have two separate MSGEQ7 chips, and neither are working properly, so I doubt the issue is chip damage.

Code: [Select]
#define analogPin 0 //A0
#define strobePin 2 //strobe is attached to digital pin 2
#define resetPin 3 //reset is attached to digital pin 3
int spectrumValue[7]; // to hold a2d values

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

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

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

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

     Serial.print(" ");
     Serial.print(spectrumValue[i]);

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


Problem: The values I get in the serial monitor are all in the 100s. The output should range from 0-1023, scaling most likely linearly with the strength of the signal; i.e. if I play a 63Hz sine wave, the output of the 63Hz bandpass should be in the 900-1023 range. But whether I play music or specific tones (e.g. 400Hz, 2.5KHz), the output doesn't change at all. The output of every band remains in the 100-199 range.

Output: here. The output is now staying in the sub 100 range.

What have I done wrong?

Grumpy_Mike

Please read this:-
How to use this forum
Because your post is breaking the rules about posting images.
Image guide
image guide

You seem to have the circuit wrong on your bread board. There is a capacitor between pin 5 and ground. This will be shorting out your signal into the chip.

ArianaGrande

Thanks for the reply, Grumpy_Mike. When I read the rules they didn't say I had to embed the pictures into the post. I thought I could simply link them. Sorry about that.

With regards to the bread board circuit, the capacitor is actually between pin 6 and ground. The perspective was a bit wonky there. See here:


By the way, ignore the resistor in the bottom right. I should have removed it before taking the pictures. It's a 220Ω resistor for the LED data pin.

Grumpy_Mike

Quote
When I read the rules they didn't say I had to embed the pictures into the post.
8. You can add attachments

Well that bit looks fine but we can't see where the wires go to on the Arduino.

Also solderless bread board produces poor contacts so go through those for continuity with your meter. Also your components are all spread out which is not good for the high frequency bit around pin 8 and the decoupling capacitor on the chip. It should be as close to the pins as possible.

Do those resistor from pin 8 actually add up to 200K? Use your meter to check.

The other thing is that audio jack socket is it really making contact? The ones I have look like this on the top but do not fit into a 0.1" pitch hole spacing. Check continuity from the other end of a jack lead connected to it to the components on the resistors.

Quote
Music comes in from my phone/laptop through an aux cord into the jack.
While that might give you some reaction you often have to have a much bigger signal than this by using an op amp to give you a gain of at least 10.


ArianaGrande

#4
Aug 31, 2019, 06:57 am Last Edit: Aug 31, 2019, 07:19 pm by ArianaGrande Reason: Fixed attachments
Really great ideas, Mike! I'm using this headphone jack and tested its continuity to success. I also checked the resistors and they indeed add up to 200KΩ. I condensed the circuit a bit as well. Here are some updated pictures:





It still doesn't work properly. Now I get straight 0's. This is really strange.

This is actually my second version of this project. The first version was software-based, using the FFT library to do the spectrum analysis. It worked great except the Arduino was kinda slow. So I don't think it's a problem with the headphone jack itself, but it could be like you said, that for the MSGEQ7 I need an amplified audio signal. I'll try adding an amplifier and see if that works. At the very least, I won't have to have my phone at max volume for this to work. Can I use any ol' op-amp, or do I need ones with certain properties (e.g. one with low internal resistance)? I have an NE5532P on hand.

Grumpy_Mike

#5
Aug 31, 2019, 10:01 am Last Edit: Aug 31, 2019, 10:15 am by Grumpy_Mike
Quote
do I need ones with certain properties (e.g. one with low internal resistance)?
No you need a normal op-amp. Here is a circuit I used on a Raspberry Pi project so the back end A/D is not relevant for an Arduino and it is two channel but I think you can pick out the X10 front end amplifier.




P.S. your images don't work because that page is asking for permission to install cookes on the machine and the Aruino forum is not liking this. These links need to be pure links to an image which is something image hosting sites don't like doing. As many of us here don't like cluttering our machines with all sorts of tracking cookes we don't like going to these sorts of sites. This is why you are best saving the image as an attachment. Then when it is posted there is a link to the attachment, copy that, click modify post and click on the image icon and paste in the attachment's URL. Then it shows up in the body of your post.

ArianaGrande

#6
Sep 02, 2019, 11:06 pm Last Edit: Sep 02, 2019, 11:10 pm by ArianaGrande
Thanks for the help with the pictures. I got those fixed now.

I found a different op-amp, the OPA227P from TI (datasheet).

Here are two pictures of the new circuit. Sorry for the mess:





I only have the left channel connected, but I set my phone's audio to be mono and shifted the balance 100% to the left channel. Also, I have two electrolytic capacitors connected in parallel summing to 14.7µF (instead of 16µF) if that's okay.

Now I get 1s and 2s as my output for everything. Even playing a 400Hz tone does nothing. I don't have access to an oscilloscope at the moment (I will Wednesday) so I can check the sound then to make sure it's actually getting amplified.

Connecting the music directly to the MSGEQ7 without passing it through the 22KΩ resistor and 10nF cap actually generated some output though. It didn't seem perfect, but I got 1023 across all bands to the beat of the song. It's not an optimal solution by any means but it feels like a small success.

DVDdoug

Quote
I only have the left channel connected, but I set my phone's audio to be mono and shifted the balance 100% to the left channel.
Just make sure you don't have the left & right channels mixed-up!    That could explain why you're getting nothing.

Quote
Connecting the music directly to the MSGEQ7 without passing it through the 22KΩ resistor and 10nF cap actually generated some output though.
The resistors make a "safe" mixer for the left & right channels.   (You shouldn't "short" the left & right outputs together.)    If one channel is silent the signal will be cut in half.    With only one channel connected 22K in series will essentially do nothing because the MSGEQ7 has very-high input impedance.   If you're only using one channel of if you have separate MSGEQ7s for each channel you don't need the resistors.

ArianaGrande

I'm confident I had the right channel, but I double-checked just to be safe and got nothing with either channel connected :/

DVDdoug, you say I don't need the resistors if I have separate MSGEQ7s for each channel. Would I still need the 10nF capacitor? in Grumpy_Mike's schematic, he has separate MSGEQ7s but still uses 22KΩ resistors. Can someone explain to me the purpose?

DVDdoug

You should be able to leave out the resistor, but I'd recommend keeping the capacitor. 

ArianaGrande

#10
Sep 06, 2019, 09:30 pm Last Edit: Sep 06, 2019, 09:31 pm by ArianaGrande Reason: attachments
So I tested the circuit with an oscilloscope to see if the sound was properly going through the circuit and getting amplified. Despite the ratio of the resistors being 10:1, the voltage level was only amplified 3 or so times. So either my understanding of amplification is flawed (very possible), or I need a different op-amp. I tested the circuit using a 63Hz tone and a 400Hz tone. The pictures of the scope are below. I would have taken screenshots on the scope directly, but I forgot to bring a USB drive.





I disassembled my circuit and rebuilt it from the ground up, hoping to find any mistakes I made. This time, I just used a simple summing amplifier. The gain should still be 10. Unfortunately, it still doesn't work.

I'm gonna try this one more time with my NE5532P op-amp when I get my hands on it (it's made for audio applications), but if it doesn't work, I think I'm just gonna throw in the towel.

Grumpy_Mike

The output signal is severely clipped. This is a result of the operational amplifier you used not being able to get close enough to the its power supply rails. You should be able to see what how close you can get from the data sheet of the op-amp.

What you need is what is called a rail to rail op-amp, or close to rail to rail. Again looking at the data sheet will tell you. I tend to use a MCP602 which is a good compromise between cost and rail to rail performance. The closer to true rail to rail operation you get the more expensive the op amp gets. From its data sheet you see:-

Quote
Linear Output Voltage Swing VSS + 100, --VDD - 100mV   with RL =25kΩ to VL, AOL ≥100dB
Which means it will get to 0.1V short of the positive supply and 0.1V above the negative supply ( normally ground ) 

Go Up