The Simplest Test Code for an I2S Microphone on the ESP32 I can Imagine

Overview

The Simplest Test Code for an I2S Microphone on the ESP32 I can Imagine

ko-fi

I've got a lot of audio projects. And I've tried to make these all available on GitHub.

You can see all my projects here: atomic14 - please take a look and subscribe if you like them!

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.

It can be hard to tell if the problem is with the microphone, the code, or something completely unrelated.

Without actually recording and playing back the audio, it's hard to know what the problem is.

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?

We can play audio directly back via the ADC through headphones - but again, this is another failure point.

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.

Open this sketch up using the Arduino IDE and hit run. Now go to Tools->Serial Plotter.

There's only a few lines of code that you will need to change:

#define I2S_MIC_SERIAL_CLOCK GPIO_NUM_26
#define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_22
#define I2S_MIC_SERIAL_DATA GPIO_NUM_21

Wiring up the INMP441

This is a popular cheap microphone with readily available breakout board

INMP441 ESP32 Info
VDD 3v3 Power - DO NOT USE 5V!
GND GND GND
L/R GND Left channel or right channel
WS 22 Left right clock
SCK 26 Serial clock
SD 21 Serial data

Wiring up the ICS-43434

This is a better microphone (IMHO) with a less popular breakout board that I sell... Available Here

ICS43434 ESP32 Info
VDD 3v3 Power - DO NOT USE 5V!
GND GND GND
LR GND Left channel or right channel
WS 22 Left right clock
SCK 26 Serial clock
SD 21 Serial data

Feel free to change the pins - but make sure you adjust the code to match.

You should see a waveform that looks like this if you whistle (if you can't whistle - try screaming 😱 ).

Whistling

Once you've got your microphone up and running, here are some projects that you might enjoy: Audio Project Playlist

You might also like...
AnalogWrite for ESP32 and ESP32-S2 with LEDC PWM. Includes PWM Phase Control, DAC and Smart GPIO resource management.
AnalogWrite for ESP32 and ESP32-S2 with LEDC PWM. Includes PWM Phase Control, DAC and Smart GPIO resource management.

analogWrite() ESP32 Installation Instructions This library was tested using using the ESP32 Arduino IDE Boards Manager installation method. Stable rel

ESP32 + GitHub Actions + Husarnet. A boilerplate project for ESP32 allowing in-field firmware update using GitHub Actions workflow.

esp32-internet-ota ESP32 + GitHub Actions + Husarnet. A boilerplate project for ESP32 allowing in-field firmware update using GitHub Actions workflow.

ESP32 software USB host through general IO pins. We can connect up to 4 USB-LS HID (keyboard mouse joystick) devices simultaneously.

esp32_usb_soft_host esp32 USB-LS pure software host thru general IO pins. Up to 4 HID devices simultaneously. board ~$3 :https://www.aliexpress.com/pr

An ESP32 system that can perform a Directory, Upload, Download, Delete, Rename and Stream Files in SPIFFS

ESP-File-Server An ESP32 system that can perform a Directory, Upload, Download, Delete, Rename and Stream Files in SPIFFS Using an ESP32 to handle fil

The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print.
The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print.

MqttPrint and MqttMonitor The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print. MqttPr

The okayest ESP32-S2 CAN development board
The okayest ESP32-S2 CAN development board

OkayCAN The okayest ESP32-S2 CAN development board Features Essentially an ESP32-S2 with a CAN transceiver and supporting components. Native USB suppo

A simple processor emulator written in c++ that can parse and execute x32 code. x32 is binary code made by me for this processor.

A SIMPLE PROCESSOR EMULATOR AND CODE EXECUTOR The Repository This is a fairly new project and is still heavy in development. If you find and bugs feel

Test suite for evaluating C code on 42 Basecamp
Test suite for evaluating C code on 42 Basecamp

Joãonette Test suite based on Moulinette, made by "Iniciativa João" ⛺️ Setup Clone this repo ( I suggest cloning to the root and calling it joaonette

A test of judging code using qemu

QEMU Judger Test This project was done abandoned 2 months ago, and I can't remember everything very well, so the steps here may be wrong. Setup First,

Comments
  • All Samples are -1

    All Samples are -1

    When I run the Code, all I see an the Serial Port are lots of -1 :-(

    The Code Works with the INMP441-Breakoutboard, but not with the ICS-43434.

    Have you any idea, on how to test the mic step by step?

    Thank you very much

    Sascha

    opened by Saschko2000 15
  • Unexpected output

    Unexpected output

    Hey! I have lillygo ttgo t-camera module with i2s mic. Initially I used https://github.com/atomic14/esp32_audio/tree/master/i2s_sampling project, configured pins and all worked fine. (from working code)

    // i2s config for reading from left channel of I2S
    i2s_config_t i2sMemsConfigLeftChannel = {
        .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
        .sample_rate = 32000,
        .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
        .communication_format =  I2S_COMM_FORMAT_I2S_LSB, //i2s_comm_format_t(I2S_COMM_FORMAT_I2S),
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
        .dma_buf_count = 4,
        .dma_buf_len = 1024,
        .use_apll = false,
        .tx_desc_auto_clear = false,
        .fixed_mclk = 0};
    
    // i2s pins
    i2s_pin_config_t i2sPins = {
        .bck_io_num = GPIO_NUM_26,
        .ws_io_num = GPIO_NUM_32,
        .data_out_num = I2S_PIN_NO_CHANGE,
        .data_in_num = GPIO_NUM_33};
    

    (recived raw file) Screenshot_288

    Next, i have tried this your project https://github.com/atomic14/diy-alexa. This is not working for me. I founded in issues, that you have recomended to check micro by this mic-test project. But when i'm using this mic-test code, I can only get this Screenshot_11 or only zeroes at all. I tried to copy i2s and pins config areas from working code, swap pins between each other, change sample rate, sample bit and buffer size. I founded only one different between codes: .communication_format = I2S_COMM_FORMAT_I2S_LSB, in working code .communication_format = I2S_COMM_FORMAT_I2S, in borken code I have replaced this line too. But nothing could not help. Have you any ideas?

    This is my full testing code

    #include <driver/i2s.h>
    
    // you shouldn't need to change these settings
    #define SAMPLE_BUFFER_SIZE 512
    #define SAMPLE_RATE 32000
    // most microphones will probably default to left channel but you may need to tie the L/R pin low
    #define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
    // either wire your microphone to the same pins or change these to match your wiring
    #define I2S_MIC_SERIAL_CLOCK GPIO_NUM_26
    #define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_32
    #define I2S_MIC_SERIAL_DATA GPIO_NUM_33
    
    // don't mess around with this
    i2s_config_t i2s_config = {
        .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
        .sample_rate = 32000,
        .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
        .communication_format =  I2S_COMM_FORMAT_I2S_LSB, //i2s_comm_format_t(I2S_COMM_FORMAT_I2S),
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
        .dma_buf_count = 4,
        .dma_buf_len = 1024,
        .use_apll = false,
        .tx_desc_auto_clear = false,
        .fixed_mclk = 0};
    
    // and don't mess around with this
    i2s_pin_config_t i2s_mic_pins = {
        .bck_io_num = GPIO_NUM_26,
        .ws_io_num = GPIO_NUM_32,
        .data_out_num = I2S_PIN_NO_CHANGE,
        .data_in_num = GPIO_NUM_33};
    
    void setup()
    {
      // we need serial output for the plotter
      Serial.begin(115200);
      // start up the I2S peripheral
      i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
      i2s_set_pin(I2S_NUM_0, &i2s_mic_pins);
    }
    
    int32_t raw_samples[SAMPLE_BUFFER_SIZE];
    void loop()
    {
      // read from the I2S device
      size_t bytes_read = 0;
      i2s_read(I2S_NUM_0, raw_samples, sizeof(int32_t) * SAMPLE_BUFFER_SIZE, &bytes_read, portMAX_DELAY);
      int samples_read = bytes_read / sizeof(int32_t);
      // dump the samples out to the serial channel.
      for (int i = 0; i < samples_read; i++)
      {
        Serial.printf("%ld\n", raw_samples[i]);
      }
    }
    
    opened by ValeraDanger 2
  • Problem for SPH0645LM4H

    Problem for SPH0645LM4H

    Mic Module : SPH0645LM4H Micro-controller ESP32.

    Problem : I get 1 as my output.

    Configurations (change in code) : #define SAMPLE_RATE 44100 // most microphones will probably default to left channel but you may need to tie the L/R pin low #define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT // either wire your microphone to the same pins or change these to match your wiring #define I2S_MIC_SERIAL_CLOCK GPIO_NUM_4 #define I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_0 #define I2S_MIC_SERIAL_DATA GPIO_NUM_5

    I have attached the logic analyzer png wherein data is being seen at the Din Pin of SPH0645Lm4H but the Esp32 is not able to read it.

    image

    Please help me if possible. I am stuck with this since 5 days now :(

    Thanks Anurag Paul

    opened by PaulAnurag 0
Owner
atomic14
atomic14
New version of the well known ESP32 Radio. Now optional I2S output!

ESP32Radio-V2 New version of the well known ESP32 Radio. Now optional I2S output! Compile time configuration in config.h. Do not forget to upload the

Ed Smallenburg 52 Nov 26, 2022
Simplest Apex Legends hack with overlay (DX9)

nullptr apex external [old version] | Автор Реализован на утечке - mhyprot ( кто не знает , это драйвер АС GENSHIN IMPACT ). Aimbot - mouse_event если

Basic 6 Nov 21, 2022
Teensy 4 I2S Audio Library

Teensy 4 I2S Library This is a no-nonsense I2S library for Teensy 4 and 4.1. It was derived from the I2S code in Paul Stoffregen's Teensy Audio Librar

Valdemar Erlingsson 8 Sep 26, 2022
Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. 🎤

pico-microphone Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. ?? Hardware RP2040 board Raspberry Pi Pico Microp

Sandeep Mistry 123 Nov 10, 2022
ESP32-Skid-Steer - Bruder Catepillar Skid Steer model converted to RC, controlled by an ESP32 with 2 analog joysticks and a receiver that is an ESP32 on the model.

ESP32-Skid-Steer Bruder Catepillar Skid Steer model converted to RC, controlled by an ESP32 with 2 analog joysticks and a receiver that is an ESP32 on

null 6 Oct 27, 2022
An embedded CAN bus sniffer which is able to monitor any of the vehicle internal CAN bus and perform some action by triggering new CAN messages.

An embedded CAN bus sniffer which is able to monitor any of the vehicle internal CAN bus and perform some action by triggering new CAN messages. In this way certain vehicle functionality can be triggered by responding to custom steering wheel button events, or use the vehicle virtual cockpit to display OBD-PIDs values instead of relying on an external display to present new information to the user

null 16 Nov 13, 2022
A test using a TTGO module (ESP32 + screen) which renders a 3d scene using pingo library

A simple 3D renderer tested and developed for the TTGO T-Display ESP32 board. The 3d renderer is: https://github.com/fededevi/pingo The 3D renderer is

fedevi 10 Nov 2, 2022
The Express LRS Handset project is first and foremost an experimental test bed for pushing the envelope with what can be done with the ELRS radio link

The Express LRS Handset project is first and foremost an experimental test bed for pushing the envelope with what can be done with the ELRS radio link

ExpressLRS 24 Oct 19, 2022
null 295 Nov 29, 2022
Allows for multiple SwitchBot buttons and curtains to be controlled via MQTT sent to ESP32. ESP32 will send BLE commands to switchbots and return MQTT responses to the broker. Also supports Meter/Temp Sensor

SwitchBot-MQTT-BLE-ESP32 Switchbot local control using ESP32. no switchbot hub used/required. works with any smarthub that supports MQTT https://githu

null 332 Nov 26, 2022