PlatformIO Community

ESP32 I2S stops working when building with arduino AND esp-idf framework

I have a simple code reading an i2s microphone on an esp32 written with Arduino. The code runs fine when I build with framework=arduino only.
As soon as I build with famework=arduino,esp-idf the i2s output is only zeros.
I have no issues with my code otherwise. Any ideas?

This works:

platform = espressif32
board = featheresp32
framework = arduino
build_flags =
-D ESP32
monitor_speed = 115200

I2S output only zeros:

platform = espressif32
board = featheresp32
framework = arduino, espidf
build_flags =
-D ESP32
monitor_speed = 115200
platform_packages =
framework-arduinoespressif32 @

This is the code I am running:

#include <stdio.h>
#include <Arduino.h>
#include “driver/i2s.h”
#include <soc/i2s_reg.h>
#define SAMPLE_RATE 8000
#define MIC_SAMPLES_BUF 250

void setup() {


i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 20,
.dma_buf_len = MIC_SAMPLES_BUF,
.use_apll = false,
.tx_desc_auto_clear = true,
.fixed_mclk = 0

const i2s_pin_config_t pin_config = {
.bck_io_num = 27, // BCKL
.ws_io_num = 13, // LRCL
.data_out_num = -1, // not used (only for speakers)
.data_in_num = 12 // DOUT

i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_1, &pin_config);

uint8_t i2sData[MIC_SAMPLES_BUF*4];
size_t bytes_read = 0;

void loop()
i2s_read(I2S_NUM_1, &i2sData, sizeof(i2sData), &bytes_read, portMAX_DELAY);
int32_t *samples = (int32_t *)i2sData;

found the error. platformio uses version 4.0 of esp-idf when combined with arduino, and for some reason left and right i2s channels are swapped in this version.

Hm no in the latest version we use 4.1 (see

Have you made sure to update your platforms (CLI -> pio platform update) to have “Espressif32 version 2.1.0”? Is the bug still present in the there-used ESP-IDF 4.1?

I have the same problem! I am using esp-idf framework. When I used framework versions under 2.0, I2s works fine, but when I update framework to version 2.1, it doesn’t. I use i2s to read from adc, I tried to read both, left and right channels but doesn’t work.

Did you found what the problem is?

You mean platform version and not framework? platform-espressfi32 version 2.0 runs on ESP-IDF v4.1. The newest 3.0 runs on ESP-IDF v4.2, even. Maybe the bug is not present there? Otherwise I’d recommend posting to

In sdk 3.0 the problem disappears

ESP32 I2S works fine with the latest PlatformIO and ESP-IDF v4.2.1.

Depending on which MEMS I2 microphone you are using, the left or right i2s channels may need to be switched.

In case M5Atom Echo, If I read M5Atom.h first and read driver/i2s later, I succeed compile.
That mean, Type A is NG, Type B is good.
Type A
#include <driver/i2s.h>
#include <M5Atom.h>

Type B
#include <M5Atom.h>
#include <driver/i2s.h>

Maybe, we must update first.