I2S speaker and microphone on Rasbperry Pi

A Raspberry Pi 3 B+ connects to an Adafruit speaker bonnet (Adafruit I2S 3W Stereo Speaker Bonnet for Raspberry Pi). The code is similar to Balena Sound, which I adjusted to keep Raspbian Buster (see Base image for Raspberry Pi 3 B+, speaker bonnet, I2S microphone and camera ).

I would like to include an I2S microphone (Adafruit I2S MEMS Microphone Breakout - SPH0645LM4H), which I did not include in the Raspberry Pi because it used the same pins as the speaker and I could not find in the code of either the microphone or the speaker how to change the pin numbers.

Is it possible to include both an I2S speaker and an I2S microphone on a Raspberry Pi?

Hi

If I understand correctly - you aren’t using balenaSound or balenaOS - is that correct?

Hello!

Yes, I am using balenaOS and code from BalenaSound before the move from Buster to Alpine.

Hi Bulgy, I did a bit of research and it seems like in theory it’s possible to use both at the same time however the setup is a bit convoluted and might require you adding extra components such as pullup resistors or shorting module pins. Just to be clear, it’s not possible to change the pins as there is only one I2S interface. The “solution” that’s proposed is “hacking” the interface to use one channel for input and the other for output. Results I’ve seen are mixed, presumably it depends on the microphone/speaker modules that you are using. This threads seem like a good start: Adafruit customer service forums • View topic - Two I2S channels for Raspberry Pi Zero and gpio - I2S Recording combined with I2S Playback - Raspberry Pi Stack Exchange

With regards to balenaOS, it shouldn’t be a problem or any different than setting this up on another OS.

Thank you @tmigone, that answers my question. The StackExchange thread says that:

Please note that using the aplay.service which constantly sends audio to the audio output will break the microphone.

A previous thread (Base image for Raspberry Pi 3 B+, speaker bonnet, I2S microphone and camera - #17 by tmigone) mentioned aplay as a way to avoid the popping sound on the I2S speakers. So I don’t think I can use the I2S microphone, the I2S speaker, and have no popping sound all at the same time.

One solution for the time being is to use the I2S microphone, which records sound in digital format, and use the audio jack for sound output.