This is an MSGEQ7 Arduino Tutorial and in it, we’re going to explore connecting the seven band graphic equalizer chip to an Arduino UNO R3 and start to get some measurable responses back. For those that have the MSGEQ7 Breakout Board, this is a great way to get started in understanding how to interface the chip with your own projects.

Setup

For this tutorial, you’ll need the MSGEQ7 Breakout Board, an Arduino UNO R3, some jumper wire, and some audio source connected with a normal headphone style cable, but that’s pretty much it. You’ll also want to download a copy of the datasheet for reference as well: Mixed Signal Integration MSGEQ7.

The hook up for this doesn’t really merit a schematic, since the breakout board only means you have to hookup five pins, but for the sake of completeness, the schematic looks like this…

MSGEQ7 Breakout Board Schematic
MSGEQ7 Breakout Board Schematic

Like I said, not much to it. Here it is all hooked up.

MSGEQ7 Connections
MSGEQ7 Connections

MSGEQ7 Functionality

The graphic equalizer chip manages the process of sampling and measuring the audio frequencies you provide it automatically. The trick is getting the timing of your code down correctly to accurately reset the chip, and to manage the steps necessary to move through the frequency measurements.

The chip starts by taking the input and running it through a bandpass filter, eliminating all the frequencies except for the particular frequency band assigned to that filter, in the case of the first sample, all frequencies are eliminated except 63Hz. This remaining signal is passed through a peak detector to determine the strength in that frequency. The measurement of that signal strength is presented as a voltage on the out pin between 0V and supply voltage, which in our case is 5V (also the recommended voltage in the datasheet). In order to move from one frequency measurement to the next, you pulse the strobe pin low.

A reset sequence is required at a minimum prior to the first attempted read. Reset moves the multiplexing system, the internal guts of the MSGEQ7 that manage moving through the frequencies, to the beginning, 63Hz. From that point forward, the chip is supposed to cycle through all the readings in turn as you pulse in strobe signals, and when it gets to the last one 16kHz, it will roll back to 63Hz on the next strobe and start over.

The timing diagram published in the official datasheet looks like it was photocopied about 84 times before it wound up in the PDF, so I’ve recreated it here in hopefully cleaner form…

MSGEQ7 Timing Diagram
MSGEQ7 Timing Diagram

The first important thing to note from the timing diagram, is that all the values are presented as minimums. That means we don’t have to worry about getting super fine down to the microsecond with our strobe or reset, we can just use delays to keep it easy. We do have to be a little careful, because even thought digitalWrite is considered a very slow manipulation of the state of a general purpose IO pin (GPIO), it still has a pulse width of only 5us, which is well below the minimum of everything there except the Reset pulse width. The other thing to note is the sequence that must be established in order to correctly begin the reset, and what state everything needs to be in during the sequence.

I do want to make one last thing clear, in case you’re not familiar with reading timing diagrams: you have control over the reset and strobe pins, the diagram of the output signal is only indicating what’s happening on the output, not that you should raise the pin voltage high!


Programming Your Arduino

Well, let’s make this thing do something!

First our declarations…

It doesn’t get much easier than that. All we do is specify that we’re connecting the strobe to digital 7, reset to digital 8 and the output to analog 5. At the bottom, we’re creating an array seven values wide that we’ll use to hold the readings from the analog pin. Now let’s get it setup…


Again, nothing terribly dramatic in here. First, we start the Serial interface. Next, we establish our pin modes: output for reset and strobe and input for the analog pin. Then we create the beginning state for the pins, just like it shows on the datasheet… everything low. Finally, we run carefully through the reset sequence to move the multiplexor into the position for the first frequency value. The only real difference between this and the datasheet timing diagram, is that I don’t raise the strobe pin while reset is high… it wouldn’t serve any purpose since the reset pin prevents the strobe from meaning anything. We delay 1ms with the reset high, well in excess of the minimum 100ns shown on the timing diagram, then we drop it low, raise strobe high, and delay 1ms again, this makes sure we are above the minimum reset to strobe delay of 72us.


Everything is appropriately initialized, so it’s time to harvest some data.

We have seven chunks of data to retrieve, so we’re going to do some FOR looping. In the first loop, we bring strobe low, then wait 100us to accommodate the output settling time. With the output settled, we read the voltage at the analog pin and write it into the array at position “i”.

Let’s take a quick look at the output settling time specification in detail. If we look at the signal on an oscilloscope, you can see why they have that requirement…

MSGEQ7 Output Settling Time
MSGEQ7 Output Settling Time

The grid is 5us per division on the x-axis, and at the top, you can see the yellow line, which represents the strobe signal. The blue line is the output value. When the strobe goes low, that tells the MSGEQ7 to output the voltage representing the frequency strength and there’s a very clear ramp the voltage takes to go from no signal to full signal. I ran this test at least a dozen times, and not once did I ever see a ramp time greater than 20us, so that 36us value includes a bit of slop in it, I imagine. Even watching the scope with a live signal that I know was jumping around from low to max back and forth, it never exceed 20us, so the datasheet is very conservative. I have no problem with that.

Once we’ve grabbed our analog value, we bring strobe high, and delay 100us again, this time to accommodate the strobe to strobe delay. Basically, the period of the signal must be at least 72us, or said differently, there must be 72us in between the falling edges of the strobe signal. I don’t think it’s stated anywhere in the datasheet, but it would seem to me that this delay is the length of time necessary for the multiplexor to move to the next bandpass filter, for the peak detector to do its thing and then get the voltage ready for being sent to the output.

The final act, is to quickly spit out our values to the serial monitor. I want to caution you, that when you get ready to ditch the serial monitor and move to making LEDs dance, you’ll want to comment out all your serial debug code. As an example, this little chunk of code that displays the seven frequency values in the serial monitor introduces a 40ms delay into our code. That’s approaching visual territory when talking about persistence of vision. However, for our purposes here, it’s fine to be able to see the values streaming up the serial monitor page.


Here is the code all in one piece…

Previous Post
MSGEQ7 Breakout Board Kit Assembly
Next Post
MSGEQ7 Arduino Tutorial 02: MSGEQ7 Decay Rate
You might also like
Menu