ESP32-S3 PDM Microphone
Posted: Thu Aug 21, 2025 3:36 pm
I'm trying to use a PDM microphone with the ESP32-S3 and arduino-esp32 library. I know I am reading microphone data (as it reacts to me blowing into the microphone), however I'm consistently getting negative values interspersed into the I2S output data. Has anyone got PDM working that can see where my error is..?
Why am I seeing negative values at all (should be gated by the I2S.available() check)? And why am I seeing more than -1 (it returns -1 if nothing..?)
Code:
Sample Output:
Why am I seeing negative values at all (should be gated by the I2S.available() check)? And why am I seeing more than -1 (it returns -1 if nothing..?)
Code:
Code: Select all
void setup() {
// setup 42 PDM clock and 41 PDM data pins
I2S.setPinsPdmRx(42, 41);
// start I2S at 16 kHz with 16-bits per sample
if (!I2S.begin(I2S_MODE_PDM_RX, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO)) {
Serial.println("Failed to initialize I2S!");
while (1); // do nothing
}
}
void loop() {
if (I2S.available() > 0) {
// Read data from microphone
int8_t sample = I2S.read(); // -1 if no data is available or an error occurred.
Serial.println(sample);
}
}Code: Select all
-17
-14
-11
-6
-3
4
9
14
20
23
28
29
30