Hello everyone,
It's been 2 weeks I'm trying to configure the microphone on M5stickCplus 1.1
Here is the sample code I'm using
I believe that the module has a built-in microphone.
As output of this code, only 0 is displayed.
Can someone please help me out 🙏?
#include <M5StickCPlus.h>
#include <driver/i2s.h>
#define SAMPLE_RATE 16000
#define SAMPLES 256
void setup() {
M5.begin();
Serial.begin(115200);
// I2S config
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_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false,
};
i2s_pin_config_t pin_config = {
.bck_io_num = 0,
.ws_io_num = 34,
.data_out_num = I2S_PIN_NO_CHANGE,
.data_in_num = 32
};
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);
Serial.println("Mic test started...");
}
void loop() {
int16_t buffer[SAMPLES];
size_t bytesRead;
i2s_read(I2S_NUM_0, (char *)buffer, SAMPLES * sizeof(int16_t), &bytesRead, portMAX_DELAY);
// Print a few samples
for (int i = 0; i < 10; i++) {
Serial.println(buffer[i]);
}
delay(500);
}