Using the ESP32 with SPH0645 Micophone (I2S)

DaTebe
Posts: 1
Joined: Tue Mar 13, 2018 2:55 pm

Using the ESP32 with SPH0645 Micophone (I2S)

Postby DaTebe » Tue Mar 13, 2018 3:06 pm

Hello, everyone,

I have an ESP32 (Himalaya Matrix Core: https://eckstein-shop.de/HIMALAYA-Matri ... -DEV-Board). I would like to use the SPH0645 (https://learn.adafruit.com/adafruit-i2s ... t/overview) via I2S to measure the volume in the environment.
Unfortunately I'm totally lost, because the documentation is not really meaningful. I would like to do the exact same thing as described here with the Feather M0: https://learn.adafruit.com/adafruit-i2s ... g-and-test

Were do I need to start? Where are the I2S pins on my board? How to use the library in the example in my platform.io environment? Can I use the library with an ESP32?

You'll notice. I'm totally lost right now.

Any help would be really great!
Many thanks in advance!

mauro_bilo
Posts: 1
Joined: Fri May 04, 2018 12:16 am

Re: Using the ESP32 with SPH0645 Micophone (I2S)

Postby mauro_bilo » Fri May 04, 2018 7:48 pm

Did you made some progress? I'm totally lost too.
I'm using the Adafruit Feather Huzzah Esp32 with the I2S SPH0645 microphone, but I can't make it work.
Any ideas? Someone can give me a hand?

tschundler
Posts: 1
Joined: Mon Jun 24, 2019 5:08 am

Re: Using the ESP32 with SPH0645 Micophone (I2S)

Postby tschundler » Mon Jun 24, 2019 5:15 am

Maybe a little late, but since this thread showed up in search, the key information is in:
https://docs.espressif.com/projects/esp ... s/i2s.html
with important notes on the mic in the comments here:
https://hackaday.io/project/162059-stre ... microphone
also related:
https://www.esp32.com/viewtopic.php?f=13&t=1756

The resulting sketch is something like:

Code: Select all

#include "driver/i2s.h"
#include "soc/i2s_reg.h"

#define BUFLEN 256

static const i2s_port_t i2s_num = I2S_NUM_0; // i2s port number

static const i2s_config_t i2s_config = {
     .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
     .sample_rate = 22050,
     .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
     .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
     .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
     .intr_alloc_flags = 0, // default interrupt priority
     .dma_buf_count = 8,
     .dma_buf_len = 64,
     .use_apll = false
};

static const i2s_pin_config_t pin_config = {
    .bck_io_num = 26,
    .ws_io_num = 25,
    .data_out_num = I2S_PIN_NO_CHANGE,
    .data_in_num = 22
};

void setup() { 
   pinMode(22, INPUT);
   i2s_driver_install(i2s_num, &i2s_config, 0, NULL);   //install and start i2s driver
   REG_SET_BIT(  I2S_TIMING_REG(i2s_num),BIT(9));   /*  #include "soc/i2s_reg.h"   I2S_NUM -> 0 or 1*/
   REG_SET_BIT( I2S_CONF_REG(i2s_num), I2S_RX_MSB_SHIFT);
   i2s_set_pin(i2s_num, &pin_config);
}

int32_t audio_buf[BUFLEN];

void loop() {
    int bytes_read = i2s_read_bytes(i2s_num, audio_buf, sizeof(audio_buf), 0);
    // have fun with your data
}

Who is online

Users browsing this forum: No registered users and 107 guests