Library used to interface to the 7-band Graphic Equalizer Chip MSGEQ7, made by company Mixed Signal Integration

Dependents:   MSGEQ7_Hello_World LCD_Spectrum_Analyzer 4180_Lab4 MSGEQ7_Hello_World ... more

Notebook page detailing chip interfacing and library usage

The MSGEQ7 Library API

The MSGEQ7 library is very simple to use. In the class called 'MSGEQ7' there are 3 public functions and 2 arrays.

Descriptions of functions: MSGEQ7(PinName reset, PinName strobe, PinName analog) - Creates a MSGEQ7, taking 3 pin arguments specifying which Mbed pins are connected to the chip's reset, strobe, and analog out lines.

void readByte() - Interfaces with the MSGEQ7 chip and reads out all 7 frequency data values and stores the values in the byte array (in the form of an array of unsigned chars) called freqDataByte, of length 7. Each value stored ranges from 0 to 255, with 255 representing the maximum sound magnitude the MSGEQ7 chip can detect at that frequency.

void readInt(int max) - Interfaces with the MSGEQ7 chip and reads out all 7 frequency data values and stores the values in the integer array called freqDataInt, of length 7. Each reading will be scaled so that the stored data ranges from 0 to value 'max' specified by the user. This 'max' variable allows the user to scale the output of the chip to a useful range.

The user chooses between readByte() and readInt(int max) based on what form they want the data returned to them in. The user needs only to call one of those functions, not both.

Once the function readByte() or readInt(int max) has been executed, the frequency data from the MSGEQ7 chip is stored in a certain array, depending on which function was called.

readByte() stores data in freqDataByte[7], and readInt(int max) stores data in freqDataInt[7]. Both arrays are available as public data arrays in the MSGEQ7 class. For both arrays, the data at index = 0 is the value at frequency = 63Hz, and the data at the last position, index = 6 is the value at frequency = 16kHz.

See example program MSGEQ7_Hello_World for an example of basic API usage.


Example Programs

Import programMSGEQ7_Hello_World

Demonstration of MSGEQ7 library interfacing with MSGEQ7 7-band Graphic Equalizer Chip made by Mixed Signal Integration.

Import programLCD_Spectrum_Analyzer

This program gets 7-band frequency data from the MSGEQ7 library and displays a 7-band, 2-row bar graph on an LCD display using custom characters.

Committer:
chrisisthefish
Date:
Wed Oct 16 06:33:29 2013 +0000
Revision:
0:974a4855a7f8
Created MSGEQ7 Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chrisisthefish 0:974a4855a7f8 1 /*
chrisisthefish 0:974a4855a7f8 2 MSGEQ7 Library for interfacing to the MSGEQ7 Seven Band Grapic Equalizer chip made by Mixed Signal Integration
chrisisthefish 0:974a4855a7f8 3
chrisisthefish 0:974a4855a7f8 4 Chris Wilson
chrisisthefish 0:974a4855a7f8 5 twilson8@gatech.edu
chrisisthefish 0:974a4855a7f8 6 10/16/2013
chrisisthefish 0:974a4855a7f8 7 */
chrisisthefish 0:974a4855a7f8 8
chrisisthefish 0:974a4855a7f8 9 #include "MSGEQ7.h"
chrisisthefish 0:974a4855a7f8 10 #include "mbed.h"
chrisisthefish 0:974a4855a7f8 11
chrisisthefish 0:974a4855a7f8 12 MSGEQ7::MSGEQ7(PinName reset, PinName strobe, PinName analog):
chrisisthefish 0:974a4855a7f8 13 _reset(reset), _strobe(strobe), _analog(analog) {
chrisisthefish 0:974a4855a7f8 14
chrisisthefish 0:974a4855a7f8 15 // Initial condition of output enables
chrisisthefish 0:974a4855a7f8 16 _reset = 0;
chrisisthefish 0:974a4855a7f8 17 _strobe = 1;
chrisisthefish 0:974a4855a7f8 18 }
chrisisthefish 0:974a4855a7f8 19
chrisisthefish 0:974a4855a7f8 20 /* The user is given two choices as to what format the data is returned to them in:
chrisisthefish 0:974a4855a7f8 21 1. One byte - readByte
chrisisthefish 0:974a4855a7f8 22 2. Integer - readInt
chrisisthefish 0:974a4855a7f8 23 */
chrisisthefish 0:974a4855a7f8 24
chrisisthefish 0:974a4855a7f8 25 float MSGEQ7::read(){
chrisisthefish 0:974a4855a7f8 26 float reading = 0.0;
chrisisthefish 0:974a4855a7f8 27 _strobe = 0;
chrisisthefish 0:974a4855a7f8 28 wait_us(30); //Wait 30us for output to settle
chrisisthefish 0:974a4855a7f8 29 reading = _analog;
chrisisthefish 0:974a4855a7f8 30 _strobe = 1;
chrisisthefish 0:974a4855a7f8 31 return reading;
chrisisthefish 0:974a4855a7f8 32 }
chrisisthefish 0:974a4855a7f8 33
chrisisthefish 0:974a4855a7f8 34
chrisisthefish 0:974a4855a7f8 35 // readByte() reads the frequency values then stores them in unsigned char array freqDataByte,
chrisisthefish 0:974a4855a7f8 36 // with each frequency magnitude between 0 to 255
chrisisthefish 0:974a4855a7f8 37 void MSGEQ7::readByte() {
chrisisthefish 0:974a4855a7f8 38 _reset = 1;
chrisisthefish 0:974a4855a7f8 39 _reset = 0;
chrisisthefish 0:974a4855a7f8 40
chrisisthefish 0:974a4855a7f8 41 // Read all 7 frequency values and store them in the array
chrisisthefish 0:974a4855a7f8 42 for (int i = 0; i < 7; i++){
chrisisthefish 0:974a4855a7f8 43 freqDataByte[i] = char(read() * 255); //Mult by 255 to properly scale reading
chrisisthefish 0:974a4855a7f8 44 }
chrisisthefish 0:974a4855a7f8 45 }
chrisisthefish 0:974a4855a7f8 46
chrisisthefish 0:974a4855a7f8 47
chrisisthefish 0:974a4855a7f8 48 // readInt() reads the frequency values, then stores them in integer array freqDataInt,
chrisisthefish 0:974a4855a7f8 49 // with each frequency magnitude between 0 to a value 'max' specified by the user
chrisisthefish 0:974a4855a7f8 50 void MSGEQ7::readInt(int max) {
chrisisthefish 0:974a4855a7f8 51 _reset = 1;
chrisisthefish 0:974a4855a7f8 52 _reset = 0;
chrisisthefish 0:974a4855a7f8 53
chrisisthefish 0:974a4855a7f8 54 // Read all 7 frequency values and store them in the array
chrisisthefish 0:974a4855a7f8 55 for (int i = 0; i < 7; i++){
chrisisthefish 0:974a4855a7f8 56 freqDataInt[i] = int(read() * max); //Mult by 'max' to properly scale reading
chrisisthefish 0:974a4855a7f8 57 }
chrisisthefish 0:974a4855a7f8 58 }