mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 02:43:42 +00:00
microphone: PDM MEMS microphone support using I2S interface
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Example using the i2s hardware interface on the Adafruit Circuit Playground Express
|
||||
// to read data from the onboard MEMS microphone.
|
||||
//
|
||||
// Uses ideas from the https://github.com/adafruit/Adafruit_CircuitPlayground repo.
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/microphone"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultSampleRate = 22000
|
||||
quantizeSteps = 64
|
||||
msForSPLSample = 50
|
||||
defaultSampleCountForSPL = (defaultSampleRate / 1000) * msForSPLSample
|
||||
)
|
||||
|
||||
func main() {
|
||||
machine.I2S0.Configure(machine.I2SConfig{
|
||||
Mode: machine.I2SModePDM,
|
||||
AudioFrequency: defaultSampleRate * quantizeSteps / 16,
|
||||
ClockSource: machine.I2SClockSourceExternal,
|
||||
Stereo: true,
|
||||
})
|
||||
|
||||
mic := microphone.New(machine.I2S0)
|
||||
mic.SampleCountForSPL = defaultSampleCountForSPL
|
||||
mic.Configure()
|
||||
|
||||
for {
|
||||
spl, maxval := mic.GetSoundPressure()
|
||||
println("C", spl, "max", maxval)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user