0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atom Echo S3R、 I2S MIC で遊ぶ。 (M5Stack用PDMマイクユニット)

0
Posted at

Screenshot from 2026-04-23 20-09-35.png

Screenshot from 2026-04-23 20-12-16.png



//i2s_mic_m5nqnoh2_1

#include <driver/i2s.h>

#define I2S_NUM             I2S_NUM_0           // 0 or 1
#define I2S_SAMPLE_RATE     16000
#define I2S_BUFFER_SIZE     512
#define I2S_PIN_CLK         I2S_PIN_NO_CHANGE
//#define I2S_PIN_WS          33 //
#define I2S_PIN_WS          1 //

#define I2S_PIN_DOUT        I2S_PIN_NO_CHANGE
//#define I2S_PIN_DIN         32 //
#define I2S_PIN_DIN         2 //


int16_t i2s_sambles[I2S_BUFFER_SIZE];
void i2sMicInit() {
  i2s_config_t i2s_config = {
    .mode                 = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
    .sample_rate          = I2S_SAMPLE_RATE,
    .bits_per_sample      = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format       = I2S_CHANNEL_FMT_ALL_LEFT,
    .communication_format = I2S_COMM_FORMAT_I2S,
    .intr_alloc_flags     = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count        = 4,
    .dma_buf_len          = 256,
    .use_apll             = false,
    .tx_desc_auto_clear   = false,
    .fixed_mclk           = 0
  };
  i2s_pin_config_t pin_config = {
    .bck_io_num           = I2S_PIN_CLK,
    .ws_io_num            = I2S_PIN_WS,
    .data_out_num         = I2S_PIN_DOUT,
    .data_in_num          = I2S_PIN_DIN,
  };
  i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
  i2s_set_pin(I2S_NUM, &pin_config);
}
void setup() {
  Serial.begin(115200);
  delay(1000);

  i2sMicInit();
}

void loop() {
  size_t bytes_read;
  i2s_read(I2S_NUM, (void *)i2s_sambles, sizeof(i2s_sambles), &bytes_read, portMAX_DELAY);


  // Display only the first data
  Serial.printf("20000,%6d,-20000\n", i2s_sambles[0]);

//for(int i=0;i<I2S_BUFFER_SIZE;i++){
//  Serial.printf("20000,%6d,-20000\n", i2s_sambles[i]);
//}

}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?