Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Microphone FFT Hardware Test Not Working

  1. #1
    Junior Member
    Join Date
    Jul 2022
    Posts
    8

    Microphone FFT Hardware Test Not Working

    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:

    Click image for larger version. 

Name:	Screen Shot 2022-08-01 at 3.28.00 PM.png 
Views:	9 
Size:	3.7 KB 
ID:	29082

    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();
      }
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,787
    It really should work.

    Can you show us photos of your wiring? Maybe there an issue we'll be able to see.

  3. #3
    Junior Member
    Join Date
    Jul 2022
    Posts
    8
    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.

    Click image for larger version. 

Name:	teensy4_audio_pins.jpeg 
Views:	1 
Size:	69.4 KB 
ID:	29085

    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.

    Click image for larger version. 

Name:	F4GK0IQHCB8U55R.jpeg 
Views:	5 
Size:	36.1 KB 
ID:	29086

    I tried running the FFT example with this setup and no luck.

  4. #4
    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);

  5. #5
    Junior Member
    Join Date
    Jul 2022
    Posts
    8
    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();
      }
    }

  6. #6
    Junior Member
    Join Date
    Jul 2022
    Posts
    8
    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();
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •