Adafruit sph0645 with xiao rp2040 input

Hello everyone, I have recently bought i2s mic from adafruit and am trying to simply read the mic and output the readings to serial monitor. I am using I2SInput example from arduino example library. Here is my code:

#include <I2S.h>

I2S i2s(INPUT);

void setup() {
  Serial.begin(115200);

  i2s.setDATA(4);
  i2s.setBCLK(5); // Note: LRCLK = BCLK + 1
  i2s.setBitsPerSample(16);
  i2s.setFrequency(22050);
  // NOTE: The following values are known to work with the Adafruit microphone:
  // i2s.setBitsPerSample(32);
  // i2s.setFrequency(16000);
  i2s.begin();

  while (1) {
    int16_t l, r;
    i2s.read16(&l, &r);
    // NOTE: Adafruit microphone word size needs to match the BPS above.
    // int32_t l, r;
    // i2s.read32(&l, &r);
    Serial.printf("%d %d\r\n", l, r);
  }
}

void loop() {
  /* Nothing here */
}

I have wired mic and board as following:
GND->GND
3V3->3V
D4->DOUT
D5->BCLK
D6->LRCL

From serial monitor I am getting always zeros despite all the noise I am trying to produce. It looks like something does not work properly.
Can anyone tell me what I am doing wrong here? Thanks

Which controller are You using?

It is Xiao Seeed RP2040 and the mic is Adafruit SPH0645

I have no experience about that device.

Today I got XIAO ESP32S3 board and tried the same task with the same microphone output mic activity to serial plotter. I modified the wiring slightly so now LRCL is pinned to D0, BCLK to D4 and DOUT to D5. I am getting zeroes. I double checked the wiring still do not understand why I am getting zeroes. Anyone any idea? Here is the code:

#include <driver/i2s.h>

// I2S pin configuration
const int I2S_DOUT = 4; // Data Out from microphone to ESP32
const int I2S_BCLK = 5; // Bit Clock
const int I2S_LRC = 0;  // Left Right Clock

// I2S configuration
const i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX), // Receive, not transfer, cast to i2s_mode_t
    .sample_rate = 16000, // Sample rate
    .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // Could vary depending on your module
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // SPH0645 is a mono microphone
    .communication_format = I2S_COMM_FORMAT_I2S,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = 4,
    .dma_buf_len = 1024
};

// I2S pin configuration
const i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_BCLK,
    .ws_io_num = I2S_LRC,
    .data_out_num = I2S_PIN_NO_CHANGE,
    .data_in_num = I2S_DOUT
};

void setup() {
  // Start Serial
  Serial.begin(115200);

  // Configure I2S
  i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  i2s_set_pin(I2S_NUM_0, &pin_config);
}

void loop() {
  // Buffer for reading data
  uint32_t buffer[1024];
  size_t bytes_read;

  // Read data from I2S
  i2s_read(I2S_NUM_0, &buffer, sizeof(buffer), &bytes_read, portMAX_DELAY);

  // Process and output data
  for (int i = 0; i < bytes_read / 4; i++) {
    // Output the read data as an integer value
    Serial.println((int)buffer[i]);
  }
}

Get a low-cost logic analyzer and connect it to the I2S bus to monitor the signaling. There are many such devices available on Amazon and other sources. They connect to your PC via USB. There is very powerful free software (such as PulseView) available that will decode protocols like I2S and display what is happening on a bit-by-bit basis.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.