Skip to content

MSGEQ7 Musicvisualization Library for Arduino

NicoHood edited this page May 5, 2016 · 1 revision

Extracted from the old Wordpress blog.

Please see the official readme for the most up to date information: https://github.com/NicoHood/MSGEQ7*

Want to visualize music very easy with the Arduino? Here you go! The MSGEQ7 is an IC for analyzing 7 different frequencys very easy: 63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25KHz, 16kHz

This articel provides the hardware setup, a look at the code and a premade library for easy use with a little led example. The code is based on two MSGEQ7 inputs, but you can also use a single one. Everyone can blink a led to your bassboxes!

The example code in this post is a bit outdated, but the github readme is the most up to date.

What you need (stereo):

  • Any kind of Arduino
  • A Breadboard & cables
  • 2x MSGEQ7 IC
  • 3,5mm audio jack (or any other audioinput)
  • Capacitor: 2x 10nF
  • Capacitor: 4x 100nF
  • Capacitor 2x 33pF
  • Resistor: 2x 200K Ohm
  • Resistor 1x 220 Ohm (for led)
  • Led or led strips

Setup for Stereo on Breadboard:

MSGEQ7_Schematic

(c) hand drawn schematic my nuewire.com

 

The code in detail:

The syntax is very easy. Create an instance of the class and use the read function to get the newest input. By default the library saves the last 5 readings and outputs an average of this. I would recommend you to read every 20 ms so you get the average over 100ms. That gave me good results for my visualization. You can also use raw mode, just set the public variable "mode" to 1. (might change this later).

Addition Informations:

The library is not that hard to understand. Have a look at the source and you will probably understand it. It was a bit difficult to get the right oder of setting Strobe/Reset High and low but this should work fine now. You do not need to reset the IC like other people did. This way everything works until you plug off any cable. Then you have to restart your program keep that in mind. The library outputs values from 0-255 (1byte). This was to save memory and also its a lot easier to deal with a whole byte rather than 10 bit information. You can easyly transfer these values to led strips or whatever you want to do. For only one MSGEQ7 IC just connect both channels together and only use one analog pin. I recomment to just set the left pin=right pin and only use one of the variables. Should be fine then. There is always an output from the IC at about 10. If you want to get this away use something similar than the map function.

Later on i will release another library for LED strip visualization but i still need some time for that due to other projects. Till now it looks amazing. Stay tuned and have a look at my blog.

And for those of you who want to see the implementation directly:

void MSGEQ7::read(){//write external variables
  //digitalWrite(_resetPin, HIGH); //resets the IC, optional
  //digitalWrite(_resetPin, LOW);
  for (int i = 0; i < 7; i++){  //63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25KHz, 16kHz
    digitalWrite(_strobePin, HIGH); //Prepare for next value
    digitalWrite(_strobePin, LOW); //Next value for the IC
    delayMicroseconds(36); // to allow the output to settle
    //read left pin,  range 0-255
    left[i] = _left[i][_countRead]= analogRead(_analogPinLeft) /4;
    //read right pin,  range 0-255
    right[i]=_right[i][_countRead]= analogRead(_analogPinRight)/4;

    if (mode==0){ //smoothing
      uint16_t avleft=0, avright=0; //resets average values
      for (int j=0; j<TOTALREADINGS;j++){//writing smoothed value from average
        avleft+=_left[i][j];
        avright+=_right[i][j];    
      }
      left[i]=avleft/TOTALREADINGS;
      right[i]=avright/TOTALREADINGS;
    }
  }

  _countRead++; //add counter+1 for next reading value
  if (_countRead==TOTALREADINGS) _countRead=0; //restart counter
}

Should be self explaining. The stuff around this is just minor. If you are crazy and want to use more than two MSGEQ7 it should be easy to add some more.

 

To be continued with led strip visualization...

 

Download & Links:

For any suggestions or feedback just leave a comment
Clone this wiki locally