Close

Proof of Concept

A project log for Audio Visualizer Hat

A hat to display audio frequencies.

AndyMacAndyMac 10/05/2015 at 02:330 Comments

The first circuit I built made full use of the analyzer chip. This EE Times article was very helpful during initial construction, and I used a lot of this code for early debugging.

Reading input directly from the chip proved the circuit worked and the microphone seems to be picking up sound at a reasonable difference.

I connected a single LED and mapped to one of the frequencies. When that frequency hits a threshold the LED lights. I don't know why, but that single light flashing along with the music (Spoon's "I Turn My Camera On") is funny to me. But overall the circuit works and most importantly it proved that there is no delay between reading the signal and outputting a signal.

The next step was ordering all of the parts and building out the circuit. The code i used is below. Significant credit to Max Maxfield.

/*
  Test #2 adds LEDs for visual representation
*/

// MSGEQ7 bands = 63Hz, 160Hz, 400Hz, 1,000Hz, 2,500Hz, 6,250Hz, 16,000Hz

int ctrlReset    = 2;                   // Digital pin 2 = signal to reset MSGEQ7s
int ctrlStrobe   = 3;                   // Digital pin 3 = signal to strobe (read data from) MSGEQ7s
int channelLeft  =  A0;                   // Analog pin 0 = spectrum data from left channel
//int channelRight =  1;                   // Analog pin 1 = spectrum data from right channel

int spectrumLeft[7];                     // Array to store 7 bands of spectrum data from left channel 
//int spectrumRight[7];                    // Array to store 7 bands of spectrum data from right channel

int Led4  =  4;                  //LED to light up and test 1 band

void setup()
{
  Serial.begin(9600);
  pinMode(ctrlReset,OUTPUT);             // Define reset as output
  pinMode(ctrlStrobe,OUTPUT);            // Define strobe as output
  pinMode(Led4,OUTPUT);
  digitalWrite(ctrlReset,LOW);           // Pull the reset signal low
  digitalWrite(ctrlStrobe,HIGH);         // Drive the strobe signal high
  digitalWrite(Led4,LOW);
}


void loop()
{
  readMSGEQ7();

  // Display values from the left channel on the serial monitor
  for (int i = 0; i < 7; i++)
  {
    if (spectrumLeft[i] < 100) Serial.print(" ");
    if (spectrumLeft[i] <  10) Serial.print(" ");
    Serial.print(spectrumLeft[i]);
    Serial.print(" ");
  }
  Serial.print("  ");

/*
  // Display values from the right channel on the serial monitor
  for (int i = 0; i < 7; i++)
  {
    if (spectrumRight[i] < 100) Serial.print(" ");
    if (spectrumRight[i] <  10) Serial.print(" ");
    Serial.print(spectrumRight[i]);
    Serial.print(" ");
  }
  */
  Serial.println();
  
  if (spectrumLeft[4] > 100)
    digitalWrite(Led4,HIGH);
  else
    digitalWrite(Led4,LOW);  
}


void readMSGEQ7()
// Read the seven spectrum bands from the MSGEQ7 chips
{
  digitalWrite(ctrlReset, HIGH);                     // Pulse the reset signal, which causes
  digitalWrite(ctrlReset, LOW);                      // the MSGEQ7s to latch the spectrum values
  delayMicroseconds(75);                             // Delay to meet minimum reset-to-strobe time

  for(int i=0; i <7; i++)                            // Cycle through the 7 spectrum bands
  {
    digitalWrite(ctrlStrobe,LOW);                    // Read current band (then increment to next band)
    delayMicroseconds(40);                           // Wait for outputs to settle

    spectrumLeft[i] = analogRead(channelLeft) / 4;   // Store current values from left & right channels 
//    spectrumRight[i] = analogRead(channelRight) / 4; // Divide 0-1023 by 4 to give 0-255
//Dividing by 4 is really for PWM output and I can probably eliminate that later

    digitalWrite(ctrlStrobe,HIGH);
    delayMicroseconds(40);                           // Delay to meet minimum strobe-to-strobe time
  }
}


/*
 * Copyright (c) 2014 Clive "Max" Maxfield
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

Discussions