Adafruit PDM Microphone Circuit Python to Arduino

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ZBossTech
 
Posts: 1
Joined: Sat May 14, 2022 9:05 pm

Adafruit PDM Microphone Circuit Python to Arduino

Post by ZBossTech »

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)

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: Adafruit PDM Microphone Circuit Python to Arduino

Post by danhalbert »

We have an Arduino library, ZeroPDM, for this: https://learn.adafruit.com/adafruit-pdm ... iring-test. The library comes with some examples.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”