As part of an air and noise pollution sensor project (Street Sense | Hackaday.io) I needed to support an I2S microphone using the ESP32 port. Using the ESP-IDF I implemented support for both I2S Master Rx and Tx . I spent a good deal of effort to bring the C code from a “just works hobbyist” quality to “industrialized” quality.
Exzellent – viel besser. Danke für den Fund! Bei MicroPython » Hardware API » I2S support findet sich die (experimentelle) generische Schnittstellenbeschreibung.
Historie
Hier die Entwicklungshistorie dieser Funktionalität für MicroPython auf ESP32:
from machine import I2S
from machine import Pin
bck_pin = Pin(14) # Bit clock output
ws_pin = Pin(13) # Word clock output
sdin_pin = Pin(12) # Serial data input
audio_in = I2S(I2S.NUM0, # create I2S peripheral to read audio
bck=bck_pin, ws=ws_pin, sdin=sdin_pin, # sample data from an Adafruit I2S MEMS
standard=I2S.PHILIPS, mode=I2S.MASTER_RX, # microphone breakout board,
dataformat=I2S.B32, # based on SPH0645LM4H device
channelformat=I2S.RIGHT_LEFT,
samplerate=16000,
dmacount=16,dmalen=256)
samples = bytearray(2048) # bytearray to receive audio samples
num_bytes_read = audio_in.readinto(samples) # read audio samples from microphone
# note: blocks until sample array is full
# - see optional timeout argument
# to configure maximum blocking duration
Sieht recht anständig aus. So wie hier ersichtlich in der Python Domäne super kompakt herausgeführt – standing on the shoulders of…
Gedanken
Wenn wir das – aus der Perspektive von Bee Observer betrachtet – nach Pycom MicroPython portiert bekämen, könnten wir mehrere Fliegen mit einer Klapy… [1][2][3].
So langsam sollten wir wirklich irgendwo eine Liste dieser Art von Edelsteinen anlegen, die wir auf diese Weise portieren wollen würden, sobald wir irgendwann soweit sind. ↩︎
Natürlich sollte das Vanilla/Genuine MicroPython genauso auf Pycom Geräten laufen, nur fehlt dann die essentielle Softwareunterstützung für die meisten Funkperipheriegeräte – es bleibt dann vermutlich nur WiFi übrig. ↩︎
Umgekehrt kommen für solche Versuche und der folgenden Anwendung in der Praxis natürlich haufenweise generische ESP32 breakouts in Frage. Wir freuen uns über positive Nachrichten, wenn hier jemand unter uns entsprechende Anstrengungen unternehmen sollte, sich dem Thema zu nähern. Auch Schadensberichte à la “dies und jenes funktioniert nicht” nehmen wir hier gerne im Logbuch auf. ↩︎
We haven’t actually tested this for real. However, the little example program didn’t crash the machine, which is at least something. @clemens and anyone interested: You might want to try this at home – thanks already!
Instructions
The ready-made firmware image [1] might make your life easier. The example programs [2] will have to be adjusted to use the Pycom-specific pin definition like bck_pin = Pin('P9') instead of e.g. bck_pin = Pin(32).
The following table describes the pins we use by default (Note that you can also use other pins for the same purpose).
I did not find any proofed pin definitions for the PyCom devices, so in case it is not working we may have a look at the ESP32 examples and used pins, eg. this and that.
So I will stay on the pins Andreas mentioned but in an other order due to better physically wiring:
Thanks for letting me know. Cheers! We might want to tell some people on the Pycom user forum accordingly [1].
When connecting the pins, there actually are design mistakes you would want to avoid. Regarding this, I collected the resources you referenced already and added some additional ones:
I have tested different pin combinations but sound does not get better. So I will try my Adafruit mic I have ordered a long time ago, same was used in the example and test this next (in case I will find it :-).
In the code is a comment
Testing was done with an INMP441 Microphone
but in the readme the Adafruit breakout is mentioned:
I have ordered some INMP441 mics also, really inexpensive, you can get it for 3-4 EUR at ebay. And in a nice form factor that will fit in a Lockenwickler
@clemens, @einsiedlerkrebs and me asked ourselves how processing the audio data would actually be done after ingesting it through the MicroPython I2S module. As Python will be too slow, data will have to be channeled through C-level implementations from the I2S driver to the analysis algorithm, most probably using DMA.