├── .github └── FUNDING.yml ├── README.md ├── i2s_mic_test └── i2s_mic_test.ino └── images └── whistling.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [atomic14] 4 | ko_fi: atomic14 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Simplest Test Code for an I2S Microphone on the ESP32 I can Imagine 2 | 3 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Z8Z734F5Y) 4 | 5 | I've got a lot of audio projects. And I've tried to make these all available on GitHub. 6 | 7 | You can see all my projects here: [atomic14](https://www.youtube.com/channel/UC4Otk-uDioJN0tg6s1QO9lw) - please take a look and subscribe if you like them! 8 | 9 | Quite a few of the issues I get on the projects seem to boil down to people having problems with their microphones. This is understandable - there's a lot to take in on some of the projects as they are pretty complicated. 10 | 11 | It can be hard to tell if the problem is with the microphone, the code, or something completely unrelated. 12 | 13 | Without actually recording and playing back the audio, it's hard to know what the problem is. 14 | 15 | It's easy if you have an amplifier and speaker - but that's just adding another failure point. Is it the microphone or the speaker that is the problem? 16 | 17 | We can play audio directly back via the ADC through headphones - but again, this is another failure point. 18 | 19 | I think the most minimal thing we can do is to use the serial plotter in Arduino. This should work for everyone without any issues and is a very simple test. 20 | 21 | Open this sketch up using the Arduino IDE and hit run. Now go to Tools->Serial Plotter. 22 | 23 | There's only a few lines of code that you will need to change: 24 | 25 | ```c++ 26 | #define I2S_MIC_SERIAL_CLOCK GPIO_NUM_26 27 | #define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_22 28 | #define I2S_MIC_SERIAL_DATA GPIO_NUM_21 29 | ``` 30 | 31 | # Wiring up the INMP441 32 | 33 | This is a popular cheap microphone with readily available breakout board 34 | |INMP441 | ESP32| Info| 35 | |---|---|---| 36 | |VDD|3v3|Power - DO NOT USE 5V!| 37 | |GND|GND|GND| 38 | |L/R|GND|Left channel or right channel| 39 | |WS|22|Left right clock| 40 | |SCK|26|Serial clock| 41 | |SD|21|Serial data| 42 | 43 | # Wiring up the ICS-43434 44 | 45 | This is a better microphone (IMHO) with a less popular breakout board that I sell... [Available Here](https://www.tindie.com/products/21519/) 46 | |ICS43434 | ESP32| Info| 47 | |---|---|---| 48 | |VDD|3v3|Power - DO NOT USE 5V!| 49 | |GND|GND|GND| 50 | |LR|GND|Left channel or right channel| 51 | |WS|22|Left right clock| 52 | |SCK|26|Serial clock| 53 | |SD|21|Serial data| 54 | 55 | Feel free to change the pins - but make sure you adjust the code to match. 56 | 57 | You should see a waveform that looks like this if you whistle (if you can't whistle - try screaming 😱). 58 | 59 | ![Whistling](./images/whistling.png) 60 | 61 | Once you've got your microphone up and running, here are some projects that you might enjoy: [Audio Project Playlist](https://www.youtube.com/playlist?list=PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD) 62 | -------------------------------------------------------------------------------- /i2s_mic_test/i2s_mic_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // you shouldn't need to change these settings 4 | #define SAMPLE_BUFFER_SIZE 512 5 | #define SAMPLE_RATE 8000 6 | // most microphones will probably default to left channel but you may need to tie the L/R pin low 7 | #define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT 8 | // either wire your microphone to the same pins or change these to match your wiring 9 | #define I2S_MIC_SERIAL_CLOCK GPIO_NUM_32 10 | #define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_25 11 | #define I2S_MIC_SERIAL_DATA GPIO_NUM_33 12 | 13 | // don't mess around with this 14 | i2s_config_t i2s_config = { 15 | .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), 16 | .sample_rate = SAMPLE_RATE, 17 | .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, 18 | .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, 19 | .communication_format = I2S_COMM_FORMAT_I2S, 20 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, 21 | .dma_buf_count = 4, 22 | .dma_buf_len = 1024, 23 | .use_apll = false, 24 | .tx_desc_auto_clear = false, 25 | .fixed_mclk = 0}; 26 | 27 | // and don't mess around with this 28 | i2s_pin_config_t i2s_mic_pins = { 29 | .bck_io_num = I2S_MIC_SERIAL_CLOCK, 30 | .ws_io_num = I2S_MIC_LEFT_RIGHT_CLOCK, 31 | .data_out_num = I2S_PIN_NO_CHANGE, 32 | .data_in_num = I2S_MIC_SERIAL_DATA}; 33 | 34 | void setup() 35 | { 36 | // we need serial output for the plotter 37 | Serial.begin(115200); 38 | // start up the I2S peripheral 39 | i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); 40 | i2s_set_pin(I2S_NUM_0, &i2s_mic_pins); 41 | } 42 | 43 | int32_t raw_samples[SAMPLE_BUFFER_SIZE]; 44 | void loop() 45 | { 46 | // read from the I2S device 47 | size_t bytes_read = 0; 48 | i2s_read(I2S_NUM_0, raw_samples, sizeof(int32_t) * SAMPLE_BUFFER_SIZE, &bytes_read, portMAX_DELAY); 49 | int samples_read = bytes_read / sizeof(int32_t); 50 | // dump the samples out to the serial channel. 51 | for (int i = 0; i < samples_read; i++) 52 | { 53 | Serial.printf("%ld\n", raw_samples[i]); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /images/whistling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomic14/esp32-i2s-mic-test/84207ccc59f8644355d5043d3ee956f981835530/images/whistling.png --------------------------------------------------------------------------------