Skip to content

PDMIn Bug on ESP32-S2 (NotImplementedError: PDMIn) #11055

@CrackXT

Description

@CrackXT

CircuitPython version and board name

Adafruit CircuitPython 9.2.2 on 2025-01-09; FeatherS2 with ESP32S2
Adafruit CircuitPython 9.2.9 on 2025-09-07; FeatherS2 with ESP32S2
Adafruit CircuitPython 10.1.4 on 2026-03-09; FeatherS2 with ESP32S2
Adafruit CircuitPython 10.2.1 on 2026-05-13; FeatherS2 with ESP32S2
Adafruit CircuitPython 10.3.0-alpha.2 on 2026-05-15; FeatherS2 with ESP32S2

Code/REPL

### Testcode from https://learn.adafruit.com/adafruit-pdm-microphone-breakout/circuitpython with Error -> NotImplementedError: PDMIn

# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import array
import math
import board
import audiobusio


# Remove DC bias before computing RMS.
def mean(values):
    return sum(values) / len(values)


def normalized_rms(values):
    minbuf = int(mean(values))
    samples_sum = sum(
        float(sample - minbuf) * (sample - minbuf)
        for sample in values
    )

    return math.sqrt(samples_sum / len(values))


# Main program
mic = audiobusio.PDMIn(board.D1, board.D12, sample_rate=16000, bit_depth=16)
samples = array.array('H', [0] * 160)


while True:
    mic.record(samples, len(samples))
    magnitude = normalized_rms(samples)
    print((magnitude,))
    time.sleep(0.1)

Behavior

Zurückverfolgung (jüngste Aufforderung zuletzt):
Datei "", Zeile 28, in
NotImplementedError: PDMIn

Description

I encountered an unexpected problem during a project involving a PDM microphone.

According to the changelog, PDMIn has been implemented and available for Espressif MCUs since CP 9.2.2. I could not find any exceptions regarding specific Espressif MCUs; however, there appears to be no support for the ESP32-S2.

The error does not occur with an ESP32-S3.

I modified the code (Where's my PDMIn?) from https://learn.adafruit.com/adafruit-pdm-microphone-breakout/circuitpython to indicate the lack of support. The original code example implies that PDMIn is supported because it lists all pin combinations despite the error.

If it is a hardware limitation, this should be clearly indicated on the page https://learn.adafruit.com/adafruit-pdm-microphone-breakout/circuitpython perhaps my extended code could be published there as an additional "safety measure."

If it is not a hardware limitation, please fix it if possible—thanks.

Additional information

mod. Testcode (Where's my PDMIn?)

import board
import audiobusio
from microcontroller import Pin

def is_hardware_PDM(clock, data):
try:
p = audiobusio.PDMIn(clock, data)
p.deinit()
return True
except ValueError:
return False
except RuntimeError:
raise

def get_unique_pins():
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
pins = [pin for pin in [
getattr(board, p) for p in dir(board) if p not in exclude]
if isinstance(pin, Pin)]
unique = []
for p in pins:
if p not in unique:
unique.append(p)
return unique

try:
for clock_pin in get_unique_pins():
for data_pin in get_unique_pins():
if clock_pin is data_pin:
continue
if is_hardware_PDM(clock_pin, data_pin):
print("Clock pin:", clock_pin, "\t Data pin:", data_pin)
except RuntimeError:
print("PDMIn is not supported on this MCU.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions