Hello,
I have been using my PDM microphone breakout with a SAMD21 Feather via Circuit Python and it works great. The first program in this guide (https://learn.adafruit.com/adafruit-pdm ... cuitpython) outputs the sound intensity coming from the microphone.
However, I now need to use this microphone with the Arduino IDE for a project that requires other libraries outside of Circuit Python, so I will still need to be able to output the sound intensity but using the Arduino IDE. On the same guide above, there is a program for the Arduino IDE, however it only outputs an analog value that is a wave and not the same as a sound intensity value.
Is it possible to convert the code shown here to work for the Arduino IDE, or is there a better option? Thanks
/////////////////////////// Code begins here
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.TX, 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)
Adafruit PDM Microphone Circuit Python to Arduino
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- ZBossTech
- Posts: 1
- Joined: Sat May 14, 2022 9:05 pm
- danhalbert
- Posts: 4649
- Joined: Tue Aug 08, 2017 12:37 pm
Re: Adafruit PDM Microphone Circuit Python to Arduino
We have an Arduino library, ZeroPDM, for this: https://learn.adafruit.com/adafruit-pdm ... iring-test. The library comes with some examples.
Please be positive and constructive with your questions and comments.