Random values from INMP441 when used with ESP32-DEV-38P board

Hello, I am having a similar issue to the one previously discussed here, where the INMP441 only gives random values not changing when sound is made. However, when I use the same code and connections with a different ESP32 devkit I do get normal results. The one which does not work is this one: https://www.tinytronics.nl/en/development-boards/microcontroller-boards/with-wi-fi/esp32-wifi-and-bluetooth-board-cp2102. The one which does work is this one: https://nl.rs-online.com/web/p/microcontroller-development-tools/2863991.

I am curious if anyone has any idea as to why one of them would not work.

1 Like

Read the pinned post re 'How to get the most from the forum'. It is not possible to answer your question; we have no useful info. Normally, we start with a photo of a hand-drawn wiring diagram. Label anything that isn't obvious, post links to sensor datasheets, etc., and, of course, all the code in code tags.

I'm curious as to why one does work

Sorry about that. For context, I am currently working on a project where I am making a sensor module where various thins are measured. These include temperature, dust, light and of course sound. I have made PCBs of both versions.

There are 2 versions. The older version (1.0) where the INMP441 works properly and the newer version (2.0) where it does not.

The electrical circuits between both versions are identical in regards to the microphone, however some other modules have been changed or removed. The use ESP32 devkit also changed between versions as explained in the original post.

Version 1.0:

Version 2.0:

The code I have used to get good results for version 1.0 is as following:

/*
  ESP32 I2S Microphone
*/

// Include I2S driver
#include <driver/i2s.h>
#include "soc/i2s_reg.h"
#include <Arduino.h>


// Connections to INMP441 I2S microphone
#define I2S_WS 25
#define I2S_SD 32
#define I2S_SCK 26
#define I2S_PORT I2S_NUM_0  
#define bufferCnt 10
#define bufferLen 1024
int16_t sBuffer[bufferLen];

void i2s_install() {
  const i2s_config_t i2s_config = {
    .mode                 = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
    .sample_rate          = 40000,
    .bits_per_sample      = i2s_bits_per_sample_t(16),
    .channel_format       = I2S_CHANNEL_FMT_ONLY_LEFT,
    .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags     = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count        = bufferCnt,
    .dma_buf_len          = bufferLen,
    .use_apll             = false,
    .mclk_multiple        = I2S_MCLK_MULTIPLE_384
  };

  i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}

void i2s_setpin() {
  const i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_SCK,
    .ws_io_num = I2S_WS,
    .data_out_num = -1,
    .data_in_num = I2S_SD
  };

  i2s_set_pin(I2S_PORT, &pin_config);
}

void setup() {

  Serial.begin(115200);

  i2s_install();
  i2s_setpin();
  i2s_start(I2S_PORT);
}

void loop() {
  size_t bytesIn = 0;

  esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen * sizeof(int16_t), &bytesIn, portMAX_DELAY);

  if (result == ESP_OK && bytesIn > 0) {
    long sum = 0;
    int sampleCount = bytesIn / sizeof(int16_t); 
    for (int i = 0; i < sampleCount; i++) {
      sum += (long)sBuffer[i] * (long)sBuffer[i]; 
    }
    double rms = sqrt(sum / (double)sampleCount);

    Serial.println(rms);
  }

  delay(100); 
}

In this version I only use 16 of the 24 bits that the microphone sends, but I have also had the code working using 32 bits and shifting it.

The issue is that the microphone in 2.0 does not print values that react with sound. The printed seem mostly random and do not respond to sound.

I am unsure if this issue is a hardware or software one. The electrical circuit is more or less identical to the previous one and I have measured using a multi meter that each pin does indeed have a voltage. I sadly don´t have access to an oscilloscope to verify that each pin really does work.

In electronics it's either identical or not.
If the problem is in the microphone part, reduce the code to just that and maybe even breadboard the PCB.