• Stars
    star
    155
  • Rank 240,864 (Top 5 %)
  • Language
    C++
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library for Musicvisualization with MSGEQ7

MSGEQ7 Library 1.2.2 + Board v1.0

Header

The MSGEQ7 library provides an interface to an arbitrary number of MSGEQ7 chips, to convert analog voltage output from the chips to digital data. The data is of values from 0 to 255 (8 bits). Output from each chip, which is input to the library, is referred to in the documentation for this library as a "channel".

The MSGEQ7 is an IC designed to analyze sound (actually, any signal of varying voltages; in the case of sound or music, a signal as from a microphone). The chip measures aspects of input in seven frequency bands, and can provide output related to one (at a time) of these bands as an analog DC voltage signal. The frequency bands the chip analyzes are centered on: 63, 160, 400, 1K, 2.5K, 6.25K, and 16K Hertz.

This repository also includes source information for a Breakout Board with two MSGEQ7 chips. In a case of using two channels of output from a breakout board, referring to one channel as "mono" and two channels as "stereo" makes sense.

Buy Me A Coffee

Features

  • IDE 1.6.x with every Arduino compatibly
  • Sparkfun Spectrum Shield compatible
  • Reads 1-n MSGEQ7 sensors
  • Compact and fast implementation
  • More compact and flexible 8 bit resolution
  • Optional 10 bit resolution
  • Value smoothing
  • Tools to reduce noise
  • A Breakout Board.

Examples included:

  • Led: blinks led, shows basic usage
  • Serial: shows spectrum via serial and how to use more channels
  • FastLED: blinks led strip with different frequencies. Shows how to use different syntax. Uses FastLED library

Table of Contents

  1. Hardware
  1. Software
  1. Contact
  2. Version History
  3. License and Copyright

Hardware

Breadboard

To use the MSGEQ7 you first need a few other parts and connect them properly. Make sure the 33pF capacitor and the 200k Ohm resistor are precise. Otherwise the frequencies may be off. See the data sheet for more information.

Additionally this repository also contains a full instruction of how to build your own MSGEQ7 Breakout Board.

Required parts (stereo):
  • 2x MSGEQ7 IC
  • 1x Audio Jack 3.5mm (or any other audio input)
  • 2x 10nF Capacitor
  • 4x 100nF Capacitor
  • 2x 33pF Capacitor
  • 2x 200k Ohm Resistor
  • Led or Led strips
  • 1x 220 Ohm Resistor (for Led)

Breadboard Setup

This would be an example breadboard setup for the Led example.

Schematic

Breadboard Setup

Breakout Board

The MSGEQ7 Breakout Board lets you easily hook up an audio source or microphone to your microcontroller. You may also use a 2nd audio output to pass the audio signal to music boxes again. You can solder a 6 or 8 pin header to the board and connect it to a breadboard for example. It is fully open source so you can create a copy for yourself or modify it.

board

Features:
  • Stereo music analyze
  • Audio input via 3.5mm Jack
  • Additional audio output
  • Additional audio in/output via pin header
  • Mounting holes
  • Breadboard compatible
  • Easy to solder (DIP parts)
  • Open Source Hardware
Required parts:
  • 1x Breakout Board
  • 2x MSGEQ7 IC
  • 2x Audio Jack 3.5mm
  • 8 Pin Header Male
  • 2x IC Socket 8 Pins (optional)
  • 2x 10nF Capacitor
  • 4x 100nF Capacitor
  • 2x 33pF Capacitor
  • 2x 200k Ohm Resistor

pcb

Files:

You can find all needed files in the board folder. Click view raw to download the PDF files.

Schematic

Schematic

PCB

PCB

Soldering the board

You need to cut off the area around the audio jack a bit first to fit them better. A knife will work best here. After this just solder all components, starting with the capacitors and resistors to the IC sockets, the audio jacks and pin header. Any beginner can do this, no SMD component is used.

audio_jacks

Software

Library Installation

Install the library as you are used to. More information can be found here.

API Documentation

For a very fast library example see the MSGEQ7_LED example.

Create MSGEQ7 Object

Every CMSGEQ7 instance needs pins passed via template to optimize the code.

The reset and strobe pin can be any digital pin on the board. Those are connected to each MSGEQ7 IC in parallel. You can input as many analog pins as you have MSGEQ7 ICs. For example only use a single IC for mono mode, 2 for stereo or more for surround.

If you want to smooth the readings with the last reading pass 0-255 as first argument. 0 Will disable smoothing, 255 will take 100% of the previous value. 191-223 is suggested if smoothing is desired.

Function Prototype:

template <uint8_t smooth, uint8_t resetPin, uint8_t strobePin
          uint8_t firstAnalogPin, uint8_t ...analogPins>
class CMSGEQ7;

Examples:

// Single MSGEQ7 IC, Smoothing enabled (75%)
CMSGEQ7<191, 6, 4, A0> MSGEQ7;

// Two MSGEQ7 ICs (stereo), Smoothing disabled (0%)
CMSGEQ7<0, 6, 4, A0, A1> MSGEQ7;

Initialize MSGEQ7 ICs

Do whatever is required to initialize the ICs and resets it.

Function Prototype:

void begin(void);

Example:

void setup() {
  // This will set the ICs ready for reading
  MSGEQ7.begin();
}

Read MSGEQ7 ICs

Basic read function. Reads all channels and saves value inside the buffer. You can access the buffer with the get() function. Up to 400FPS (on 16MHz) are possible with 2 channels from what I've measured.

To automatically read every X seconds you may also use the 2nd function. Used together with the ReadsPerSecond(f) makro you can simply pass an FPS interval to the reading function. The return value tells you if a new reading was made.

Function Prototypes:

bool read(void);
bool read(const uint32_t interval);

Examples:

#define MSGEQ7_INTERVAL ReadsPerSecond(50)

void loop() {
  // Analyze MSGEQ7 ICs now. Will always return true.
  bool newReading = MSGEQ7.read();

  // Analyze without delay every interval
  bool newReading = MSGEQ7.read(MSGEQ7_INTERVAL);
}

Reset MSGEQ7 ICs

Resets ICs, so they start reading at 0 again. Normally this is not required since it is done in the read() function.

Function Prototype:

void reset(void);

Example:

void loop() {
  // Reset the IC frequently, otherwise it will get out of sync after a while
  MSGEQ7.reset();
}

Get MSGEQ7 ICs Frequency

Returns the data of the selected frequency and channel. By default this returns an uint8_t value, for 10bit resolution uint16_t. Frequency values should be 0-6 where 0 is the lowest frequency (Bass) and 6 the highest.

Depending on how many analog pins you have attached you can select the channel here (0-n). You can also leave out the channel variable to get an average value of all channels.

The output only ranges from 0-255 to save memory and use it easier. You won't lose much information anyways. If you still want to use 10bit mode see makros

The IC has a standard noise at about 10-19. You should keep that in mind. Have a look at the Map Noise function to get rid of this.

Function Prototypes:

MSGEQ7_data_t get(const uint8_t frequency, const uint8_t channel);
MSGEQ7_data_t get(const uint8_t frequency);

Examples:

void loop() {
  // Read bass frequency (of all channels)
  uint8_t input = MSGEQ7.get(MSGEQ7_BASS);

  // Read mid frequency (of channel 0)
  uint8_t input = MSGEQ7.get(MSGEQ7_MID, 0);
}

Get MSGEQ7 ICs Volume

Returns the overall volume of all frequencies of a channel. By default this returns an uint8_t value, for 10bit resolution uint16_t. The volume however is not that useful actually.

Depending on how many analog pins you have attached you can select the channel here (0-n). You can also leave out the channel variable to get an average volume of all channels.

Function Prototypes:

MSGEQ7_data_t getVolume(uint8_t channel);
MSGEQ7_data_t getVolume(void);

Examples:

void loop() {
  // Read volume (of all channels)
  uint8_t input = MSGEQ7.getVolume();

  // Read volume (of channel 0)
  uint8_t input = MSGEQ7.getVolume(0);
}

Terminate Reading MSGEQ7 ICs

Sets pins to input again to safely remove connections. This is normally not required.

Function Prototype:

void begin(void);

Example:

void setup() {
  // This will set the ICs pin to input again
  MSGEQ7.end();
}

Map Noise

Normally when using MSGEQ7 you get a background noise of around 15-19 (8bit mode) even if no music is played. To get rid of this you can use the mapNoise() function to get rid of this. This macro can be used to remap the input.

You can leave out the last 4 arguments, they will be replaced with default values. See makros for more information. For 10 bit resolution the function uses uint16_t and 1023 as default maximum value.

Function Prototype:

inline MSGEQ7_data_t mapNoise(MSGEQ7_data_t x,
                              MSGEQ7_data_t in_min = MSGEQ7_IN_MIN,
                              MSGEQ7_data_t in_max = MSGEQ7_IN_MAX,
                              MSGEQ7_data_t out_min = MSGEQ7_OUT_MIN,
                              MSGEQ7_data_t out_max = MSGEQ7_OUT_MAX);

Example:

void loop() {
  // Remove noise from input
  input = mapNoise(input);
}

Makros

Inside MSGEQ7.h some predefined makros are used to make code writing simpler. You can optionally also enable 10 bit reading mode (0-1024) if you like to. For most up to date definitions see MSGEQ7.h source file.

// Software version
#define MSGEQ7_VERSION 121

// Use (optional) full 10 bit analog readings for MSGEQ7
//#define MSGEQ7_10BIT

// FPS makro
#define ReadsPerSecond(f) (1000000UL / (f))

// Basic frequencies definitions (0-6 valid, 7 channels)
#define MSGEQ7_0 0
#define MSGEQ7_1 1
#define MSGEQ7_2 2
#define MSGEQ7_3 3
#define MSGEQ7_4 4
#define MSGEQ7_5 5
#define MSGEQ7_6 6
#define MSGEQ7_BASS 0
#define MSGEQ7_LOW 0
#define MSGEQ7_MID 3
#define MSGEQ7_HIGH 5

// Resolution dependant settings
#ifdef MSGEQ7_10BIT
typedef uint16_t MSGEQ7_data_t;
#define MSGEQ7_IN_MIN 20
#define MSGEQ7_IN_MAX 1023
#define MSGEQ7_OUT_MIN 0
#define MSGEQ7_OUT_MAX 1023
#else
typedef uint8_t MSGEQ7_data_t;
#define MSGEQ7_IN_MIN 20
#define MSGEQ7_IN_MAX 255
#define MSGEQ7_OUT_MIN 0
#define MSGEQ7_OUT_MAX 255
#endif

Contact

Contact information can be found here:

www.nicohood.de

Version History

1.2.2 Release (16.04.2016)
* Fixed mapNoise() example and keyword #4

1.2.1 Release (05.03.2016)
* Added 1.6.x library schema
* Added board pictures
* Fix reading the wrong frequency over time
* Smooth from 0-255 now
* Fix compiler warnings
* Renamed map function, moved outside the main class
* Improved documentation

1.2 Release (23.04.2015)
* Added breakout board files v1.0
* Optimized performance
* Variable number of ICs readable
* Added optional 10bit resolution
* Added more functions/tools
* Improved examples
* Added MSGEQ7_VERSION definition
* Added library.properties

1.1 Release (10.07.2014)
* Changed syntax
* Optimized performance
* Added more examples

1.0 Release (13.04.2014)
* Added general functionality

License and Copyright

If you use this library for any cool project let me know!

Copyright (c) 2014-2016 NicoHood

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
AUTHORS OR COPYRIGHT HOLDERS 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.

More Repositories

1

HID

Bring enhanced HID functions to your Arduino!
C
2,154
star
2

HoodLoader2

16u2 Bootloader to reprogram 16u2 + 328/2560 with Arduino IDE
C
736
star
3

Nintendo

Use Nintendo Controllers with Arduino
HTML
284
star
4

PinChangeInterrupt

A simple & compact PinChangeInterrupt library for Arduino
C
281
star
5

NicoHood.github.io

www.nicohood.de
CSS
173
star
6

IRLremote

Lightweight Infrared library for Arduino
C++
158
star
7

guestwlan

Easy & Secure Guest WLAN setup with QR code GUI and photodiashow.
Shell
142
star
8

GPGit

A shell script that automates the process of signing Git sources via GPG
Python
93
star
9

Hoodloader

Advanced HID Firmware for Arduino Uno/Mega
C++
40
star
10

arc-icon-theme

[New upstream] Icon theme for Arc-Theme
Shell
29
star
11

AnalogTouch

AnalogTouch library for Arduino
C
28
star
12

Arduino-IDE-for-Raspberry

Raspbian compatible Arduino IDE package
15
star
13

SecureLoader

AVR USB HID Bootloader that protects against malicious firmware upgrades
C
13
star
14

NicoHoodProtocol

Simple 1 byte Pipe Protocol
C++
11
star
15

RCLSwitch

Compact Version of RC Switch for sending only
C++
7
star
16

Arduino-Lego-Case

A Lego Case for Arduino Uno
6
star
17

grav-plugin-matomo

Integrates Matomo analytics into Grav CMS
PHP
6
star
18

SerialProtocol

A Protocol for Arduino - Raspberry Pi communication
C++
6
star
19

avr

Clean, modular and optimized avr libraries compatible with DMBS
C
6
star
20

archlinux

Scripts and tools for the daily usage of Arch Linux.
Shell
5
star
21

HelloWorld

simple example for c/c++ compiling
C++
3
star
22

ShutdownButton

Simple C Program to shut your Pi down with GPIOs
C++
3
star
23

IRC

Makes your Arduino an IRC Chat Client or Bot
C++
3
star
24

AVR-Development-Environment-Script

Compiles the latest AVR tools such as avr-gcc, avr-libc, avrdude and more
Shell
3
star
25

grav-plugin-geocoding

Converts addresses into geographic coordinates
PHP
3
star
26

LSD

Linux Security Database tracks the GPG usage by GNU/Linux projects
Python
1
star
27

Arch-Scripts

Shell
1
star
28

test

1
star
29

Visualizer

Led Visualizations for FastLED
C++
1
star
30

grav-plugin-seo

PHP
1
star