I am looking to have the ability to store/analyze audio using a Raspberry Pi Pico. I have found that electret microphones are a good option, since it only requires an ADC, which is already built-in to the Pico.
I am having trouble with finding resources for code/packages in Micropython and was wondering if this route is the way to go. I don't know much about this concept, but is there a package out there that can take the data captured from the ADC and turn it into something useable?
1 Answer 1
I've added one recently to a Pimoroni Galactic Unicorn which uses the Pi Pico W board. I've just written it up in Instructables: Adding a Microphone to Pi Pico W on Pimoroni Galactic Unicorn. That describes adding the SparkFun Sound Detector (essentially an amplified electret microphone) to the Pico on GPIO27. I'm working on a second article that describes the C++ code which continuously reads the ADC using DMA leaving it in two buffers where the program can then process the data.
In MicroPython you can't really get perfect audio from a microphone using simple ADC reads in a loop. You'd need to use the low-level stuff to use interrupts or DMA in the same style as C/C++ code to get jitter-free reads at a predictable, fixed rate. It may also be harder to write efficient code to process audio data in real-time in MicroPython although ulab library could be very helpful.
Additional Info
I've not used it but CircuitPython has analogbufio which is present on the RP2040 build for Pico. A hackspace article about this was covered by Adafruit Blog: Fast analogue input with Raspberry Pi Pico – HackSpace Magazine Issue 64.
My second article Instructables: Making a Guitar Tuner and Audio Spectrum Analyser Using the Pimoroni Galactic Unicorn
-
I have learned a lot more since I posted this, though I haven’t had much time to go back to this project. I did recently find a way to control DMA through micropython. Check out this blog.Gabe Morris– Gabe Morris2023年12月22日 20:18:42 +00:00Commented Dec 22, 2023 at 20:18
-
That looks very thorough. One thing to watch out for if you get tempted by RP2040 ring buffer feature is the need for alignment which does not appear to be possible in MicroPython. It could be hacked by making a bigger buffer and then using the part that of it that has "natural alignment". Discussed in forums.raspberrypi.com/viewtopic.php?p=1861895 and forums.raspberrypi.com/viewtopic.php?t=315841KevinJWalters– KevinJWalters2023年12月28日 16:27:50 +00:00Commented Dec 28, 2023 at 16:27
-
Code still needs some work and tidying but my efforts are now documented in instructables.com/… based on github.com/kevinjwalters/galactic-bluetooth-audio/releases/tag/…KevinJWalters– KevinJWalters2024年01月03日 16:07:26 +00:00Commented Jan 3, 2024 at 16:07