Microphone FFT Hardware Test Not Working

trevtt

Member
Hi everyone,

I've recently bought a SPH0645LM4H from Adafruit, and am running the SPH0645 hardware test example file (code below). I am using a teensy 4.1 and have the pins connected using jumper wires as follows:

SEL: GND
LRCL: 20
DOUT: 8
BCLK: 21
GND: GND
3V: 3.3V

These is the configuration from this post. When I run the file, this is the output I get:

Screen Shot 2022-08-01 at 3.28.00 PM.png

Any ideas?
Code below:

Code:
/* SPH0645 MEMS Microphone Test (Adafruit product #3421)
 *
 * Forum thread with connection details and other info:
 * https://forum.pjrc.com/threads/60599?p=238070&viewfull=1#post238070
 */


#include <Audio.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=180,111
AudioFilterStateVariable filter1;        //xy=325,101
AudioAmplifier           amp1;           //xy=470,93
AudioAnalyzeFFT1024      fft1024_1;      //xy=616,102
AudioConnection          patchCord1(i2s1, 0, filter1, 0);
AudioConnection          patchCord2(filter1, 2, amp1, 0);
AudioConnection          patchCord3(amp1, fft1024_1);
// GUItool: end automatically generated code

void setup() {
  AudioMemory(50);
  filter1.frequency(30); // filter out DC & extremely low frequencies
  amp1.gain(8.5);        // amplify sign to useful range
}

void loop() {
  if (fft1024_1.available()) {
    // each time new FFT data is available
    // print 20 bins to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (int i = 0; i < 20; i++) {
      float n = fft1024_1.read(i);
      if (n >= 0.001) {
        Serial.print(n, 3);
        Serial.print(" ");
      } else {
        Serial.print("  --  "); // don't print "0.000"
      }
    }
    Serial.println();
  }
}
 
Hi Paul,

Thanks for taking the time. I'm at work right now so I don't have any photos of the setup. However, it is really simple so I believe I can describe it accurately. I have soldered a Teensy 4.1 to a rev d audio shield using some header pins. I have only soldered the pins that the audio shield uses, according to the diagram below found on the PJRC website.

teensy4_audio_pins.jpeg

I then soldered an electret microphone to the MIC & GND pins on the audio shield. I soldered the pins according to the diagram below, with the traces to the case connected to the GND terminal on the shield.

F4GK0IQHCB8U55R.jpeg

I tried running the FFT example with this setup and no luck.
 
I have used this sequence to "hear" the audio signal

Code:
AudioInputAnalog         adc1;  
AudioOutputI2S           i2s1;

This is the configuration sequence that has worked in the FFT analyzer (if something is missing in the configuration I am all ears):

Code:
AudioInputAnalog         adc1; 
AudioOutputI2S           i2s1;  
AudioAnalyzeFFT1024      fft1024_2;
AudioConnection          patchCord3(adc1, fft1024_2);

Try to raise the resolution in the Setup by:
Code:
analogReadResolution(12);

Before
Code:
AudioMemory(50);
 
As per TFTLCDCyg's suggestion, I've tried the code below (I am pasting the whole program for transparency). Now my output is:
FFT: 0.07 0.04 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Code:
// FFT Test
//
// Compute a 1024 point Fast Fourier Transform (spectrum analysis)
// on audio connected to the Left Line-In pin.  By changing code,
// a synthetic sine wave can be input instead.
//
// The first 40 (of 512) frequency analysis bins are printed to
// the Arduino Serial Monitor.  Viewing the raw data can help you
// understand how the FFT works and what results to expect when
// using the data to control LEDs, motors, or other fun things!
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

//const int myInput = AUDIO_INPUT_LINEIN;
const int myInput = AUDIO_INPUT_MIC;

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputAnalog         adc1; 
AudioOutputI2S           i2s1;  
AudioAnalyzeFFT1024      myFFT;
AudioConnection          patchCord3(adc1, myFFT);
//AudioConnection patchCord1(sinewave, 0, myFFT, 0);

AudioControlSGTL5000 audioShield;

void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  analogReadResolution(12);
  AudioMemory(12);

  // Enable the audio shield and set the output volume.
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(2);

  // Configure the window algorithm to use
  myFFT.windowFunction(AudioWindowHanning1024);
  //myFFT.windowFunction(NULL);
}

void loop() {
  float n;
  int i;

  if (myFFT.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (i=0; i<40; i++) {
      n = myFFT.read(i);
      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00"
      }
    }
    Serial.println();
  }
}
 
As per TFTLCDCyg's suggestion, I've tried the code below (I am pasting the whole program for transparency. Now my output is:
FFT: 0.07 0.04 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Code:
// FFT Test
//
// Compute a 1024 point Fast Fourier Transform (spectrum analysis)
// on audio connected to the Left Line-In pin.  By changing code,
// a synthetic sine wave can be input instead.
//
// The first 40 (of 512) frequency analysis bins are printed to
// the Arduino Serial Monitor.  Viewing the raw data can help you
// understand how the FFT works and what results to expect when
// using the data to control LEDs, motors, or other fun things!
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

//const int myInput = AUDIO_INPUT_LINEIN;
const int myInput = AUDIO_INPUT_MIC;

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputAnalog         adc1; 
AudioOutputI2S           i2s1;  
AudioAnalyzeFFT1024      myFFT;
AudioConnection          patchCord3(adc1, myFFT);
//AudioConnection patchCord1(sinewave, 0, myFFT, 0);

AudioControlSGTL5000 audioShield;

void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  analogReadResolution(12);
  AudioMemory(12);

  // Enable the audio shield and set the output volume.
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(2);

  // Configure the window algorithm to use
  myFFT.windowFunction(AudioWindowHanning1024);
  //myFFT.windowFunction(NULL);
}

void loop() {
  float n;
  int i;

  if (myFFT.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (i=0; i<40; i++) {
      n = myFFT.read(i);
      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00"
      }
    }
    Serial.println();
  }
}
 
Back
Top