Teensy 4.0 I2S (no Audio Shield) + 4 MEMS microphones - working only 2

Status
Not open for further replies.

GurKin

Member
Hi people,
I am working on my first project with sound localisation feature (with azimuth and distance calculation) and stuck on peak detection of the I2S2 part of T4 while I2S1 working great (all mics are INMP441).
When I connected all 4 mics and declare both I2S1 and I2S2 I am receiving no one mic are working with next plotting
5764b0cb9dc80a2aa5bb757a168636a3.png

As soon as I am removing(commenting) declaring of one of I2S1 or I2S2 audio input I am receiving perfectly working but only for 2 mics, that connected to I2S1 (but no matter which one I am turning off!)
9dca1859eb800e01f16fd62fe52aa2be.png

What I am doing wrong?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

/*
 SD -> pin 8 (in1)/pin 5 (in2)
 L/R -> GND/VCC (left/right channel)
 WS -> pin 20 (LRCLK1)/pin 3 (LRCLK2)
 SCK -> pin21 (BCLK1)/pin 4 (BCLK2)
 */

AudioInputI2S            i2s1; 
AudioInputI2S            i2s2;

AudioAnalyzePeak         peak_L1;
AudioAnalyzePeak         peak_R1;
AudioAnalyzePeak         peak_L2;
AudioAnalyzePeak         peak_R2;

AudioConnection          patchCord1(i2s1, 0, peak_L1, 0); //connect the Left mic to the Left peak detector
AudioConnection          patchCord2(i2s1, 1, peak_R1, 0); //connect the Right mic to the Right peak detector


AudioConnection          patchCord3(i2s2, 0, peak_L2, 0);//connect the Left mic to the Left peak detector
AudioConnection          patchCord4(i2s2, 1, peak_R2, 0);//connect the Right mic to the Right peak detector



void setup() {
  Serial.begin(9600);
  AudioMemory(70);


  
}

elapsedMillis fps;
void loop() {
  if (fps > 5) {
      fps = 0;
      float LeftPeak1 = peak_L1.read();//Return is from 0.0 to 1.0.
      float RightPeak1 = peak_R1.read();//Return is from 0.0 to 1.0.
    
      float LeftPeak2 = peak_L2.read();//Return is from 0.0 to 1.0.
      float RightPeak2 = peak_R2.read();//Return is from 0.0 to 1.0.
      

  Serial.print("L1: "); Serial.print(LeftPeak1 * 3000.0); Serial.print("  ");
  Serial.print("R1: "); Serial.print(-RightPeak1 * 3000.0); Serial.print("  ");
  Serial.print("L2: "); Serial.print(LeftPeak2 * 3000.0); Serial.print("  ");
  Serial.print("R2: "); Serial.print(-RightPeak2 * 3000.0); Serial.print("  ");
  
  Serial.println("");


  }
}
 
I guess you could also use RX_DATA1 pin to input data using only single I2S interface, but then you had to enable the input pin and increase the frame size, and the audio library doesn't know anything about that as it expects only two channels, not four interleaved. Maybe that's what the AudioInputI2SQuad is supposed to do anyway when it's been implemented, and then also AudioInputI2SHex and AudioInputI2SOct variations are possible, though it would maybe be better if there were some generic implementation using some fancy constructor type parameter or plain number parameter giving the number of channels (AudioInputI2S(4) for an example, or AudioInputI2S(8CH) if you are using the types, enums or whatever).
 
Status
Not open for further replies.
Back
Top