CircuitPython version and board name
Adafruit CircuitPython 7.2.0 on 2022-02-24; Adafruit QT Py RP2040 with rp2040
Code/REPL
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
# PDMIn(clock, data)
PDM_CLK = board.SCK
PDM_DAT = board.MISO
mic = audiobusio.PDMIn(PDM_CLK, PDM_DAT, sample_rate=16000, bit_depth=16)
samples = array.array('H', [0] * 160)
while True:
samples_recorded = mic.record(samples, len(samples))
magnitude = normalized_rms(samples)
print(samples_recorded, (magnitude,))
time.sleep(0.1)
Behavior
The values do not change as expected. A loud noise is made after pressing enter on the import and seeing print statements starting to show up:
Adafruit CircuitPython 7.2.0 on 2022-02-24; Adafruit QT Py RP2040 with rp2040
>>> import pdm_test
160 (32594.5,)
160 (31913.7,)
160 (32504.2,)
160 (31898.3,)
160 (32515.3,)
160 (31882.4,)
160 (32516.7,)
160 (31848.7,)
160 (32413.2,)
160 (31906.9,)
For reference, here is expected/working output when running 7.1.1 firmware:
Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit QT Py RP2040 with rp2040
>>> import pdm_test
160 (72.2027,)
160 (66.0032,)
160 (66.1652,)
160 (60.7902,)
160 (646.89,)
160 (7786.59,)
160 (1313.55,)
160 (185.272,)
160 (64.3999,)
160 (63.2283,)
160 (61.9871,)
Description
PDM mic not returning expected values.
Additional information
Here is the test setup:

This behavior is also seen running latest (10.0.3) firmware. The above output focusing on 7.2.0 was determined by testing older releases to find when the change was introduced.
This was also tested on a Feather M0 Express but the same behavior was not seen there. It worked as expected for latest (10.0.3) release.
CircuitPython version and board name
Code/REPL
Behavior
The values do not change as expected. A loud noise is made after pressing enter on the import and seeing print statements starting to show up:
For reference, here is expected/working output when running 7.1.1 firmware:
Description
PDM mic not returning expected values.
Additional information
Here is the test setup:

This behavior is also seen running latest (10.0.3) firmware. The above output focusing on 7.2.0 was determined by testing older releases to find when the change was introduced.
This was also tested on a Feather M0 Express but the same behavior was not seen there. It worked as expected for latest (10.0.3) release.