├── HTB1CLnxSiLaK1RjSZFxq6ymPFXaM.jpg ├── README.md ├── s_Mic_Plot_TTGO.ino └── ICS43434.h /HTB1CLnxSiLaK1RjSZFxq6ymPFXaM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elshnkhll/ICS43434/HEAD/HTB1CLnxSiLaK1RjSZFxq6ymPFXaM.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ICS43434 2 | MEMS microphone Invensense ICS-43434 is connected to ESP32 via I2S bus. 3 | 4 | Specs: https://www.invensense.com/wp-content/uploads/2016/02/DS-000069-ICS-43434-v1.1.pdf 5 | 6 | Roku Remote Control: http://rokurc.com 7 | -------------------------------------------------------------------------------- /s_Mic_Plot_TTGO.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "driver/i2s.h" 3 | #include "ICS43434.h" 4 | 5 | 6 | void setup() 7 | { 8 | Serial.begin(115200); 9 | //Turn off WIFI to save power 10 | WiFi.mode(WIFI_OFF); 11 | 12 | Mic_Init(); 13 | delay(1000); 14 | } 15 | 16 | void loop(){ 17 | 18 | int32_t a = Mic_Get_Sample(); 19 | Serial.println( a, DEC ); 20 | yield(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ICS43434.h: -------------------------------------------------------------------------------- 1 | unsigned short int numOfBlanks = 500, smoothingReads = 3; 2 | 3 | i2s_config_t i2s_config = { 4 | mode: (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), 5 | sample_rate: 8000 * smoothingReads, 6 | bits_per_sample: I2S_BITS_PER_SAMPLE_32BIT, 7 | channel_format: I2S_CHANNEL_FMT_ONLY_RIGHT, 8 | communication_format: (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB), 9 | intr_alloc_flags: ESP_INTR_FLAG_LEVEL1, 10 | dma_buf_count: 8, 11 | dma_buf_len: 8 12 | }; 13 | 14 | i2s_pin_config_t pin_config = { 15 | .bck_io_num = 32, // BCK (SCK) - bit clock or serial clock 16 | .ws_io_num = 33, // LRCK (WS, FS) - left-right clock or word select or frame sync 17 | .data_out_num = I2S_PIN_NO_CHANGE, // DATA output - not used 18 | .data_in_num = 27 // DIN (SD) - serial data in (SDATA, SDIN, SDOUT, DACDAT, ADCDAT) 19 | }; 20 | 21 | const int i2s_num = 0; 22 | int retStat = 0; 23 | 24 | 25 | uint32_t sampleIn = 0; 26 | 27 | 28 | int32_t avgSampleIn = 0; 29 | 30 | 31 | void Mic_Init() { 32 | pinMode(27, INPUT); 33 | //Set up pin 21 and 25 as the BCK and LRCK pins 34 | pinMode(32, OUTPUT); 35 | pinMode(33, OUTPUT); 36 | //Init the i2s device 37 | i2s_driver_install((i2s_port_t)i2s_num, &i2s_config, 0, NULL); 38 | i2s_set_pin((i2s_port_t)i2s_num, &pin_config); 39 | i2s_start((i2s_port_t)i2s_num); 40 | 41 | Serial.print("\r\nBegin Level detect..."); 42 | Serial.print("\r\n\tRead 4000 samples to level out..."); 43 | 44 | //This pulls in a bunch of samples and does nothing, its just used to settle the mics output 45 | for (retStat = 0; retStat < numOfBlanks * 2; retStat++) { 46 | i2s_pop_sample((i2s_port_t)i2s_num, (char*)&sampleIn, portMAX_DELAY); 47 | delay(1); 48 | } 49 | 50 | } 51 | 52 | int32_t Mic_Get_Sample() { 53 | sampleIn = 0; 54 | avgSampleIn = 0; 55 | int16_t sampleIn16 = 0; 56 | //read in smoothingReads number of times and use the average 57 | for (retStat = 0; retStat < smoothingReads; retStat++) { 58 | i2s_pop_sample((i2s_port_t)i2s_num, (char*)&sampleIn, portMAX_DELAY); 59 | sampleIn >>= 8; 60 | sampleIn16 = sampleIn; 61 | avgSampleIn += sampleIn16; 62 | } 63 | 64 | sampleIn16 = round((float)avgSampleIn / smoothingReads); 65 | 66 | avgSampleIn = round( ((float)(sampleIn16 + 0x8000) / 0x8000 ) * 16000 ); 67 | 68 | return avgSampleIn; 69 | 70 | } 71 | --------------------------------------------------------------------------------