Spectrum Shield Hookup Guide (v2)

Pages
Contributors: Toni_K, santaimpersonator
Favorited Favorite 0

Introduction

Update: This tutorial is an updated version of the original hookup guide (retired) to make use of the Serial Plotter feature of the Arduino IDE, reduce the setup complexity in the examples, and update some of the format of the content. For users looking for the original tutorial, use the following link: retired version.

Have you ever wanted to have your project react to music? Then this is the product for you! The Spectrum Shield provides your Arduino board with the capability of measuring a stereo audio input across 7 frequency bands. By reading the amplitude of each band with the ADC of your Arduino board, the users can control how attached devices respond to the audio input.

SparkFun Spectrum Shield

SparkFun Spectrum Shield

DEV-13116
$28.95
15

Materials Required

To follow along with this tutorial, we recommend the following items.

SparkFun RedBoard Qwiic

SparkFun RedBoard Qwiic

DEV-15123
$21.50
20
Arduino Stackable Header Kit - R3

Arduino Stackable Header Kit - R3

PRT-11417
$1.75
12
USB Micro-B Cable - 6"

USB Micro-B Cable - 6"

CAB-13244
$2.10
3
Audio Cable TRRS - 1ft

Audio Cable TRRS - 1ft

CAB-14163
$1.60

Required Tools

Some assembly is required for this product. You will need a soldering iron, solder, and/or general soldering accessories to solder on headers to your Spectrum Shield.

Solder Lead Free - 15-gram Tube

Solder Lead Free - 15-gram Tube

TOL-09163
$3.95
4
Soldering Iron - 30W (US, 110V)

Soldering Iron - 30W (US, 110V)

TOL-09507
$10.95
7

Click the button above to toggle a list of accessories that are available from our catalog.

Additional Accessories

Below is a sample selection of our other headers and soldering tools in our catalog that you may be interested in. For a full selection of our available Headers or Soldering Tools, click on the associated link.

Extended GPIO Female Header - 2x20 Pin (16mm/7.30mm)

Extended GPIO Female Header - 2x20 Pin (16mm/7.30mm)

PRT-16763
$2.25
Extended GPIO Female Header - 2x20 Pin (13.5mm/9.80mm)

Extended GPIO Female Header - 2x20 Pin (13.5mm/9.80mm)

PRT-16764
$2.25
Arduino Nano Stackable Header Kit

Arduino Nano Stackable Header Kit

PRT-16279
$1.75
Female Headers

Female Headers

PRT-00115
$1.75
8
Hot Plate Preheater - MHP50-B5 (Brass)

Hot Plate Preheater - MHP50-B5 (Brass)

TOL-26588
$119.95
PINECIL Soldering Iron Kit

PINECIL Soldering Iron Kit

KIT-24063
$69.95
3

iFixit FixHub - Power Series Portable Soldering Station

TOL-27147
Insulated Silicone Soldering Mat

Insulated Silicone Soldering Mat

TOL-14672
$10.95
10

Suggested Reading

We recommend you be familiar with these resources before continuing on with this hookup guide.

How to Solder: Through-Hole Soldering

This tutorial covers everything you need to know about through-hole soldering.

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

Connector Basics

Connectors are a major source of confusion for people just beginning electronics. The number of different options, terms, and names of connectors can make selecting one, or finding the one you need, daunting. This article will help you get a jump on the world of connectors.

Analog to Digital Conversion

The world is analog. Use analog to digital conversion to help digital devices interpret the world.

What is an Arduino?

What is this 'Arduino' thing anyway? This tutorials dives into what an Arduino is and along with Arduino projects and widgets.

Installing Arduino IDE

A step-by-step guide to installing and testing the Arduino software on Windows, Mac, and Linux.

Integrated Circuits

An introduction to integrated circuits (ICs). Electronics' ubiquitous black chips. Includes a focus on the variety of IC packages.

Analog vs. Digital

This tutorial covers the concept of analog and digital signals, as they relate to electronics.

Hardware Overview

Audio Connections

Audio Jacks

The Spectrum Shield contains two stereo audio jacks on the board. The first audio jack, is the input jack (labeled Input). This allows users to input audio from any device -- such as an MP3 player, or cellular phone -- using a basic audio cable. This connection does not have to be used, as there is another option for adding audio input, at the "Audio In" headers, described below.

Audio Jacks

The second audio jack is the audio output, labeled Output. This jack allows you to pass the audio back out to a speaker or other audio system, while the sound levels are being processed by the Spectrum Analyzer ICs. (*Technically, both audio jacks and the audio header are all tied together and can be used as either an input or output.)

Audio In Header

For some projects, you may not be piping audio from a pre-processed source such as a cell phone. For users who want to use things like a MEMS Mic Breakout or the Sound Detector as an audio source, there are three header pins that provide an alternative connection method to your shield.

Audio In Headers

These pins are as follows:

  • L = Left Audio Input
  • G = Ground Audio Input
  • R = Right Audio Input

With both the left and right inputs, you can use stereo devices on these headers. The signals also passes through to the Input and Output audio jacks.

MSGEQ7 ICs

The real power of this shield comes from the two MSGEQ7 ICs on the board. These are CMOS chips, which are seven band graphic equalizers.

MSGEQ7 ICs

Upon receiving an audio signal in, these ICs split the the spectrum into seven bands, splitting it at the following frequencies:

  • 63Hz
  • 160Hz
  • 400Hz
  • 1kHz
  • 2.5kHz
  • 6.25kHz
  • 16kHZ

For the visual learners, here's the frequency graph from the MSGEQ7 datasheet:

Frequency_Graph

Once the spectrum has been split into these ranges, each band is peak detected and multiplexed. The DC output is a representation of the amplitude of each frequency band. Using the strobe and reset pins on the ICs allows the user to select the DC peak output.

Shield Connections

There are 4 main pins that the Arduino/RedBoard or other microcontroller connect to the Spectrum Shield.

Analog Pins - There are two analog pins connected to the MSGEQ7 ICs. A0 is the DC analog output from the first IC for the left audio channel, while A1 is the DC analog output from the second, right audio channel.

Analog Pin Connections

Control Pins - The control pins connect to the Strobe and Reset pins on the MSGEQ7; D4 and D5, respectively. In order to enable the Strobe pin, you must pull the Reset pin LOW. To reset the entire multiplexer, pull the Reset pin HIGH.

Strobe and Reset Pins

The Strobe pin, once activated, cycles through each of the channels. After the initial pulse, it starts at 63Hz, pulses each channel until 16kHz, and then repeats, starting back at 63Hz. The DC output for each channel will follow the Strobe pulse.

Remember: The reset line for the MSGEQ7 IC is not the same as the Reset push button that resets the entire system (RedBoard + Shield).

Reset Button

The reset button allows you to reset your Arduino/RedBoard while the shield is inserted. Holding the reset button will pull the reset pin of the ATMega328 (or other microcontroller) low, allowing a system reset. This will restart any sketches currently running on the microcontroller.

Reset Button

Hardware Assembly

Solder Headers

As with any shield, the first step is to choose a header type. We recommend the stackable headers if you need to stack on other shields; otherwise, the (straight) male headers are the simplest to work with. Feel free to choose any connection method you prefer, but remember that his shield uses the Arduino Uno R3 form factor or footprint when selecting your headers.


How to Solder: Through-Hole Soldering

September 19, 2013

This tutorial covers everything you need to know about through-hole soldering.

Arduino Shields v2

April 20, 2020

An update to our classic Arduino Shields Tutorial! All things Arduino shields. What they are and how to assemble them.

You will need to solder the headers to the shield, so make sure you have all the appropriate supplies before you begin. If you aren't sure how to solder on the headers to the shield, please check out our How to Solder and Arduino Shield tutorials (also linked above).

Once completed, connect the shield to your microcontroller; if you are using Arduino Uno or SparkFun RedBoard, stack the shield on top.

Connect Audio System

In the following example, we will be using your computer as the audio source. Plug one end of the audio cable into the audio jack on your computer and the other end into the Input jack on the Spectrum Shield. Feel free to use the Output jack on the Spectrum shield to pass the audio out to a speaker or set of headphones.

Note: You may need to turn up the volume to meet the threshold for the IC to respond to the audio input. This volume may be above your tolerance for "comfortable listening". If this is the case, try using a speaker with an adjustable volume knob to lower the volume to a more reasonable level.

Connecting to the Computer

The last thing you will need to do is attach the microcontroller to the computer (with a USB cable). If you have done everything correctly, it should resemble the image below.

Hardware Assembly
RedBoard with Spectrum Shield attached to a computer.

Arduino Example Code

Note: This tutorial assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

Serial Plotter Example

Now that you have your hardware all hooked up, it's time to analyze some audio signals. Below, we will walk through the SparkFun_Spectrum_Shield_Serial_Plotter_Demo.ino sketch. To begin, download that sketch from the GitHub Repository, and upload it to your Arduino. (*The .zip folder must be extracted and the file for the sketch is located in the Spectrum_Shield > Firmware > SparkFun_Spectrum_Serial_Plotter_Demo folder.)

Code Overview

The start of the demo code defines the pins functionality. The Spectrum Shield pin connections to the microcontroller must be defined.

language:c
//Declare Spectrum Shield pin connections
#define STROBE 4
#define RESET 5
#define DC_One A0
#define DC_Two A1

//Define spectrum variables
int freq_amp;
int Frequencies_One[7];
int Frequencies_Two[7];
int i;

Note that we declare two arrays Frequencies_One[] and Frequencies_Two[]; these will be used to store the output of the seven frequency bands from the MSGEQ7 ICs. (*The freq_amp and i variables are counters used for iterations in the code and carry minimal significance.)

In the setup loop, the shield pins must also be declared as OUTPUTs for the STROBE and RESET pins so we can control the shield using the RedBoard. The DC analog pins are each declared as an INPUT in the code, because the RedBoard will be reading data in from these pins. Once the pins are declared, control pins (STROBE and RESET) are set to a LOW condition/output. A delay is added for the settings to take effect, then the serial output is initialized to a 9600 bps bard rate.

language:c
/********************Setup Loop*************************/
void setup() {
  //Set spectrum Shield pin configurations
  pinMode(STROBE, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(DC_One, INPUT);
  pinMode(DC_Two, INPUT);

  //Initialize Spectrum Analyzers
  digitalWrite(STROBE, LOW);
  digitalWrite(RESET, LOW);
  delay(5);

  Serial.begin(9600);
}

For the main section of the sketch, we loop through two user-defined functions. Read_Frequenices() and Graph_Frequencies() tell the RedBoard to read the frequencies coming off the Spectrum Shield, and serial print out the analog values, respectively.

language:c
/****************Main Function Loop***************************/
void loop() {

  Read_Frequencies();
  Graph_Frequencies();
  delay(50);

}

The Read_Frequencies() function is defined next in the code. When called, the function initializes/resets the ICs by cycling the RESET pin as described earlier in the Control Pins section. Then, the function steps through each frequency band on the Spectrum Shield using the STROBE pin, reads the DC analog outputs, and stores the values into the predefined frequency arrays.

language:c
/*************Pull frquencies from Spectrum Shield****************/
void Read_Frequencies() {
  digitalWrite(RESET, HIGH);
  delayMicroseconds(200);
  digitalWrite(RESET, LOW);
  delayMicroseconds(200);

  //Read frequencies for each band
  for (freq_amp = 0; freq_amp < 7; freq_amp++)
  {
    digitalWrite(STROBE, HIGH);
    delayMicroseconds(50);
    digitalWrite(STROBE, LOW);
    delayMicroseconds(50);

    Frequencies_One[freq_amp] = analogRead(DC_One);
    Frequencies_Two[freq_amp] = analogRead(DC_Two);
  }
}

The data is retrieved through the Graph_Frequencies() function. With this function, the RedBoard returns the analog value for the frequencies being read by the Spectrum Shield through the serial port.

language:c
/*****************Print Out Band Values for Serial Plotter*****************/
void Graph_Frequencies() {
  for (i = 0; i < 7; i++)
  {
//    Serial.print(Frequencies_One[i]);
//    Serial.print(" ");
//    Serial.print(Frequencies_Two[i]);
//    Serial.print(" ");
    Serial.print( (Frequencies_One[i] + Frequencies_Two[i]) / 2 );
    Serial.print("    ");
  }
  Serial.println();
}

Code Operation

With the sketch uploaded to your board, you are now able to analyze the different frequency bands of your audio input. Pull, up the Serial Monitor and set the baud rate to 9600. Then, using your computer play an audio sample. You should see the numbers in the columns of the Serial Monitor change with the audio.

Note: The "strength" and quality of the audio output from your computer is dependent on the sound card/chip use by your computer. Users may need to change their audio/speaker settings; as a baseline, I recommend turning up the audio on your computer to about 65% as a starting point.

Below, are some audio samples that users can use to test the Spectrum Shield:

Try playing the Youtube video and using the Serial Plotter of the Arduino IDE. You should see a response curve similar to the one below. Notice how the shapes resemble the figure from the datasheet in the Hardware Overview section.

Serial Plotter

Additional Examples

There are plenty of projects out there using the Spectrum Shield, so do a bit of searching if you need some more inspiration! Additionally, you can refer to the original tutorial, which provides other examples including one from Bliptronics, the collaborator on the Spectrum Shield, which works with the Spectrum Shield and an LED matrix.

Resources and Going Further

For more information, check out the resources below:

Also worth checking out is this edition of Engineering Roundtable, which details how to use the Spectrum Shield to control fire!