Close

INMP441 readout on RP2040

A project log for Ethernet microphone with PoE (active or passive)

Single MEMS microphone with audio over UDP, using only RP2040 and INMP441 and just 3 resistors! (and an RJ45, plus some more for active PoE)

biemsterbiemster 10/25/2022 at 15:224 Comments

So I have chosen the arduino-pico environment for this project. SPI is quite straightforward to work with, but keep in mind that the LRCLK (=WS) has to go on pin BCLK +1 due to limitations on the PIO in arduino-pico.

The SPI is setup like this:

#include <I2S.h>

I2S i2s(INPUT);
int32_t l, r, sample;

void setup() {
  pinMode(1, OUTPUT); // L/R
  digitalWrite(1, LOW); // LOW=LEFT, HIGH=RIGHT
  
  i2s.setDATA(29);
  i2s.setBCLK(3); // LRCLK = +1
  i2s.setBitsPerSample(24);
  i2s.begin(16000);
}

and after this can be read out:

void loop() {
  i2s.read32(&l, &r);
  sample = l ? l : r;
  Serial.printf("%.6x\n", sample);
}

This will output 3byte 24bit samples on the UART, which can be played back on a Linux machine using the following commands:

$ cat /dev/ttyACM0 | xxd -r -p | aplay -r16000 -c1 -fS24_3BE

The call to xxd turns the hexadecimal samples into raw bytes.

This code and the pin diagram is available in https://github.com/biemster/arduino-pico-serialmic

Discussions

louis.croisez wrote 04/13/2023 at 17:49 point

I am newbye concerning the Rpi-Pico 2040 board, so I have no advice concerning your switch to C-SDK. I suppose that you have very good reasons.

On the other hand, speaking about the sample rate, I think that the limiting point is the sensitivity of the INMP441 mic, which does not allow to get up to 20kHz bandwidth. I found another microphone which seems to be able to give samples in such freq range: 

ICS-43434

  Are you sure? yes | no

biemster wrote 05/03/2023 at 21:54 point

The switch to C-SDK was because the ethernet lib uses it. I'll probably agree with you that the INMP441 is a bit underspeced when I look into it, but that's the one I had on hand and came cheap..

  Are you sure? yes | no

louis.croisez wrote 04/13/2023 at 09:32 point

Thank you for this project.
The sample rate is configured to 16KHz. Could the pico accept a 48KHz sample rate ?

  Are you sure? yes | no

biemster wrote 04/13/2023 at 16:11 point

I don't see why not, and I kind of remember trying this as well (but not sure).

Keep in mind though that I have seem to swapped to C-SDK code instead of arduino-pico, as I noticed in https://github.com/biemster/pico-ethermic.

This project got stalled a bit since I did not get the PIO ethernet to work yet.

  Are you sure? yes | no