Go Down

Topic: MSGEQ7 Spectrum Analyzer 16kHz issue (Read 837 times) previous topic - next topic

rednecklawrence

Hello peoples! I am trying to interface an MSGEQ7 spectrum analyzer to an Arduino, and getting the results to show up on an 8x8 led matrix using an MAX7219 LED controller. So ive sorta got it working. However on my Graphic equalizer, the 16kHz band does not really respond or change when the rest of the bands change with the music as expected. It displays this behavior with 2 different codes, one with and one without the MSGEQ7 library (https://github.com/NicoHood/MSGEQ7), the other being my own code.

Library Code:
#include "LedControl.h"
#include "MSGEQ7.h"
#define pinAnalogLeft A0
#define pinReset 8
#define pinStrobe 9
#define MSGEQ7_INTERVAL ReadsPerSecond(50)
#define MSGEQ7_SMOOTH false

CMSGEQ7<MSGEQ7_SMOOTH, pinReset, pinStrobe, pinAnalogLeft> MSGEQ7;
LedControl lc = LedControl(12, 11, 10, 1);
int levels [9] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0, 8);
  lc.clearDisplay(0);
  MSGEQ7.begin();
  MSGEQ7.reset();
  Serial.begin(115200);
}

void loop() {
  MSGEQ7.reset();
  bool newReading = MSGEQ7.read(MSGEQ7_INTERVAL);
  for (int i = 0; i < 7; i++) {
    //bool newReading = MSGEQ7.read(MSGEQ7_INTERVAL);
    uint8_t val = MSGEQ7.get(i);
    Serial.println(MSGEQ7.get(6));
    if(val >= 255){
      val = 255;
    }
    uint8_t l = map(val,0,255,0,9);
    lc.setRow(0, i+1, levels[l]);
    lc.setRow(0,0, levels[map(MSGEQ7.getVolume(),0,255,0,9)]);

  }
}


My Code (with LedControl library):
#include "LedControl.h"
LedControl lc = LedControl(12, 11, 10, 1);
int levels [9] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
int Rset = 8;
int Strobe = 9;
int In = A0;
void setup() {
  lc.shutdown(0, false);
  lc.setIntensity(0, 8);
  lc.clearDisplay(0);
  pinMode(Rset, OUTPUT);
  pinMode(Strobe, OUTPUT);
  pinMode(In, INPUT);
  Serial.begin(115200);
}

void loop() {
  digitalWrite(Rset, HIGH);
  delayMicroseconds(200);
  digitalWrite(Rset, LOW);
  delayMicroseconds(200);
  for (int i = 0; i < 7; i++) {
    digitalWrite(Strobe, HIGH);
    delay(1);
    digitalWrite(Strobe, LOW);
    delay(1);
    lc.setRow(0, i, levels[map(analogRead(In), 0, 1023, 0, 9)]);

   
  }
}

The 16kHz will either always read a constant 10-12 on the first code(when using the library), or 30-50 with an occasional spike to the 100's (when reading analogRead)

Now I suspect a bad chip, because I got 5 of them at the same time, same ebay seller, and the other 4 don't really work properly at all in the same circuit. One of them does nothing, Others just fill all the bars to 100%, or a few bars at constantly 100%.

I hope I made some sense!


Go Up