I2S microphone records silence (ESP32 board)

Hi,

This is my first post here.

Question/Issue:
I am trying to record some sounds with the ESP32 and an I2S microphone connected to it, but recorded is silence.

Project ID:
shmonov-project-1

Context/Use case:
My hardware details:
Dev board: ESP32-DevKit-LiPo with ESP32-WROOM-32UE MCU.
Microphone: Adafruit I2S MEMS Microphone Breakout - SPH0645LM4H.
This is how it is wired:

      .bck_io_num = 26,   // BCKL → GPIO26
      .ws_io_num = 32,    // LRCL → GPIO32
      .data_in_num = 33   // DOUT → GPIO33

I use there very pins because this is exactly how the mike is hooked up in the officially supported ESP-EYE board.
When I test this microphone with the following setup:

const i2s_config_t i2s_config = {
      .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
      .sample_rate = 22050,
      .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // could only get it to work with 32bits
      .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
      .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
      .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
      .dma_buf_count = 4,
      .dma_buf_len = 8
  };

  // The pin config as per the setup
  const i2s_pin_config_t pin_config = {
      .bck_io_num = 26,   // BCKL
      .ws_io_num = 32,    // LRCL
      .data_out_num = -1, // not used (only for speakers)
      .data_in_num = 33   // DOUT
  };

— I can see in Serial plotter that the microphone works fine.
But it doesn’t work if .bits_per_sample is set to something other than I2S_BITS_PER_SAMPLE_32BIT.

Is there any way to make my SPH0645 microphone work with Edge Studio IDE?
Any suggestions are welcome.

Thank you,
Alexander Shmonov

Hi @shmonov,

What program are you using to plot the microphone output in the Serial plotter?

I would not expect another microphone (other than the one on the ESP-EYE) to work with the Edge Impulse firmware if you are using the CLI to capture data, as the comms would likely be different. If you’re set on using the SPH0645, you will likely need to write your own driver to capture samples to record (e.g. as .wav files) as well as performing inference (you might need to do a rolling window). I’ve got some demos here with other microphones…not sure if they’ll help: ei-keyword-spotting/embedded-demos at master · ShawnHymel/ei-keyword-spotting · GitHub

1 Like

@shawn_edgeimpulse , I did get an I2S microphone working with edge impulse. An INMP441 to be specific.

Alexander, try to change from the right channel to the left channel. I went crazy trying to figure out why it wasn’t working. Even if your mic is set to the right channel try the code with the left. So your code should look like this :

  const i2s_config_t i2s_config = {
  .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
  .sample_rate = 22050,
  .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // could only get it to work with 32bits
  .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
  .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
  .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
  .dma_buf_count = 4,
  .dma_buf_len = 8

};

Also, try setting your mic to the left channel if possible, and also try left or right in the code.

Good Luck

3 Likes