I have set a sample code to record audio signal. One device is with my partner in USA and other is with me in India. Both device are M5 Core 2. We both get different Zero line for output. Our code is 100% same as same firmware is built and flash by me.
My Partner's output
My output

My I2S setting to record audio
esp_err_t err;
const i2s_port_t I2S_PORT = I2S_NUM_0;
// i2s config for reading from both m5stack mic
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
.sample_rate = 16000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,
.dma_buf_len = dmaBufCount,
};
// i2s pins
i2s_pin_config_t i2s_pins = {
.bck_io_num = GPIO_NUM_12,
.ws_io_num = GPIO_NUM_0,
.data_out_num = I2S_PIN_NO_CHANGE,
.data_in_num = GPIO_NUM_34};
This is in Loop of 2 milliseconds to record audio. (Sample rate 500Hz)
esp_err_t result = i2s_read(I2S_PORT, i2sData, 16, &bytesRead, 10);
if (result == ESP_OK && bytesRead >= 16)
{
for (int i = 0; i < bytesRead / 2; i += 2)
{
soundAvg += (i2sData[i] + i2sData[i + 1]) / 2;
}
soundAvg = soundAvg / 8;
AvgSound = soundAvg;
}
If my settings are incorrect. Can you please let me know what should be the optimum setting to record at 500Hz, we are capturing industrial noise along with vibrations being recorded in same loop from MPU6886.