├── README.md └── esp32-i2s-sd.ino /README.md: -------------------------------------------------------------------------------- 1 | # ADMP441 MEMS I2S sample for ESP32 2 | 3 | ## Breakout Board 4 | 5 | Purchased from [OSHPark](https://oshpark.com/shared_projects/ypqAU3CH) via https://github.com/SamEA/ADMP441_Microphone.git 6 | 7 | ### BOM 8 | ![OSHPark](https://raw.githubusercontent.com/SamEA/ADMP441_Microphone/master/ADMP441%20Breakout%20Board%20Top.png) 9 | 10 | 1. R1 - 100kOhm 11 | 2. C1 - 100nF 12 | 3. U1 - ADMP441 MEMS desoldered from Amazon Dash 13 | 14 | ## ESP32 15 | 16 | |ADMP441|ESP32| 17 | |-------|-----| 18 | |WS |IO25 | 19 | |SD |IO22 | 20 | |SCK |IO26 | 21 | |VCC |3.3V | 22 | |GND |GND | 23 | 24 | Wire SD card to VSPI and CS=21 25 | 26 | ## Usage 27 | 28 | Dumps I2S PCM data to track.i2s on SD card. 29 | 30 | Run, 31 | 32 | ``` 33 | ffmpeg -f s32le -ar 16000 -ac 1 -i track.i2s track.wav 34 | ``` 35 | 36 | to convert to a WAV file. QED. 37 | -------------------------------------------------------------------------------- /esp32-i2s-sd.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static const int SD_CS = 21; 6 | static const int bytesToRead = 1024 * 1000; 7 | File f; 8 | 9 | void setup() 10 | { 11 | Serial.begin(115200); 12 | 13 | i2s_config_t i2s_config; 14 | i2s_config.mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_RX); 15 | i2s_config.sample_rate = 16000; 16 | i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT; 17 | i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT; 18 | i2s_config.communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB); 19 | i2s_config.dma_buf_count = 32; 20 | i2s_config.dma_buf_len = 32 * 2; 21 | i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; 22 | 23 | i2s_pin_config_t pin_config; 24 | pin_config.bck_io_num = 26; 25 | pin_config.ws_io_num = 25; 26 | pin_config.data_out_num = I2S_PIN_NO_CHANGE; 27 | pin_config.data_in_num = 22; 28 | 29 | i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL); 30 | i2s_set_pin(I2S_NUM_1, &pin_config); 31 | i2s_stop(I2S_NUM_1); 32 | 33 | i2s_start(I2S_NUM_1); 34 | 35 | SD.begin(SD_CS); 36 | f = SD.open("/track.i2s", FILE_WRITE); 37 | } 38 | 39 | void loop() 40 | { 41 | static int totalBytesRead = 0; 42 | if (totalBytesRead >= bytesToRead) { 43 | return; 44 | } 45 | uint8_t buf[64]; 46 | memset(buf, 0, 64); 47 | int bytes_read = 0; 48 | while(bytes_read == 0) { 49 | bytes_read = i2s_read_bytes(I2S_NUM_1, (char*) buf, 64, 0); 50 | } 51 | f.write(buf, 64); 52 | totalBytesRead += 64; 53 | if (totalBytesRead >= bytesToRead) { 54 | f.close(); 55 | Serial.println("DONE WRITING"); 56 | return; 57 | } 58 | } 59 | --------------------------------------------------------------------------------