Base image for Raspberry Pi 3 B+, speaker bonnet, I2S microphone and camera

I am moving a Raspberry Pi project to BalenaOS. A Raspberry Pi connects to a camera, a screen, and an ([Adafruit I2S 3W Stereo Speaker Bonnet for Raspberry Pi. All this works on a Raspberry Pi 3 B+, and used to work on balenablocks/audio until it moved to Alpine Linux. So I am looking for another base image that supports this hardware.

If possible, I would also like to include an Adafruit I2S MEMS Microphone Breakout, 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.

I would also like to remove the popping sound present at the beginning and end of playing an audio file, which the speaker bonnet tutorial solves with

an extra helper systemd script that will play quiet audio when the I2S peripheral isn’t in use. This removes popping when playback starts or stops. It uses a tiny amount of CPU time.

I tried those instructions on the balenablocks/audio image and still had the popping sound.

Finally I would also like to control the volume of the speaker bonnet. The speaker bonnet tutorial suggests rebooting twice, which I did, but alsamixer does not show a volume control when launching it from a shell on Balena Cloud.

I appreciate any suggestions of base images, projects, or hacks!

Hi @bulgy, sorry to hear about your troubles after the recent update to balenablocks/audio. Just to clarify, the whole setup did in fact work properly with previous versions of the audio block? If so, could you pin to a previous version?

Also, simply thinking out loud, instead of using the block, perhaps rolling your own container with the same functionality as the block - but using a balenalib/ubuntu or balenalib/debian base image would do the trick? Hope that helps get you started!

Thanks! Yes, I confirm that the setup did work with a previous version of the block, though now I can’t find which. Yes, pinning to a previous version or starting with balenalib/debian would give me again the ability to update the device. In either case, how could I include a microphone, remove the popping sound or control volume? Should I post each of these as its own topic?

Hi @bulgy, balenablocks/audio developer here :wave:

There is quite a lot to unpack here, I suggest we first tackle the issue of the audio block not working anymore for you. The move to alpine should obviously not break previous stuff so I’m interested in details. Can you expand on what you mean with it stopped working? Do you get any errors in the logs?

I can definitely build old versions of the audioblock for you to try (or you can even build them from GH repo) so we can also try and narrow down which version prompted this changes on your app, would that be useful?

Once we figure this out we can look at the rest, I think it would greatly change depending on wether or not you are using the audio block image.

@bulgy Did you ever get your base image reverted to a functional state? Or, as Tomas asked, can you provide some context and some logs as to what happened, what stopped working exactly? Thanks!

Thanks @tmigone and @dtischler. I will address each issue in a separate post.

Here’s what I mean by “stopped working”:

$ balena push <app-name>
[Info]     Starting build for <app-name>, user <user-name>
[Info]     Dashboard link: https://dashboard.balena-cloud.com/apps/.../devices
[Info]     Building on arm02
[Info]     Pulling previous images for caching purposes...
[Success]  Successfully pulled cache images
[main]     Step 1/18 : FROM balenablocks/audio:raspberrypi3
[main]      ---> e6c00128d96d
[main]     Step 2/18 : RUN install_packages xserver-xorg-core     xinit lxsession desktop-file-utils     raspberrypi-ui-mods rpd-icons     gtk2-engines-clearlookspix     matchbox-keyboard     python3     python3-pip     python3-picamera     iceweasel     xterm
[main]      ---> Running in df6f55cf9876
[main]     fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/armv7/APKINDEX.tar.gz
[main]     fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/armv7/APKINDEX.tar.gz
[main]     ERROR: unable to select packages:
[main]     
[main]       gtk2-engines-clearlookspix (no such package):
[main]         required by: world[gtk2-engines-clearlookspix]
...
[main]     The command '/bin/sh -c install_packages xserver-xorg-core     xinit lxsession desktop-file-utils     raspberrypi-ui-mods rpd-icons     gtk2-engines-clearlookspix     matchbox-keyboard     python3     python3-pip     python3-picamera     iceweasel     xterm' returned a non-zero code: 7
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c install_packages xserver-xorg-core     xinit lxsession desktop-file-utils     raspberrypi-ui-mods rpd-icons     gtk2-engines-clearlookspix     matchbox-keyboard     python3     python3-pip     python3-picamera     iceweasel     xterm' returned a non-zero code: 7
[Info]     Built on arm02
[Error]    Not deploying release.
Remote build failed

That is an issue with the move of Balena Blocks from Buster to Alpine.

Yes, I am able to pin to a specific release and make a functional version work. I still see the errors above, but I can move a new device to a specific release of the application.

@dtischler and @tmigone Building on a previous version of balenablocks works, see this reply

So I’m now ready to address the I2S microphone along with the bonnet, removing the popping sound, and controlling the volume of the bonnet. What do you think of putting each of these in its own thread?

@bulgy, yes I think it’s better to create a fresh thread for the I2S microphone so we keep things separated (if you haven’t already).

Regarding the popping/clipping sound, I took a look at the tutorial you linked. They way they solve it seems a bit hacky but it should work for the audio block too. Basically they install a service that continuously outputs a “silent” sound. Looking at the install script they provide here the command is: /usr/bin/aplay -D default -t raw -r 44100 -c 2 -f S16_LE /dev/zero &. You could add this to your start script, make sure you include the & so it runs in the background and doesn’t halt your main process, however this probably can’t be done from the audio block’s entry point as aplay will need the PuseAudio instance to be running, so you should look into running it from another service.

Another alternative you can try is disabling PulseAudio’s “suspend-on-idle” module. This module “Disconnects sinks and sources from their backend after a predetermined amount of idle time.”, I suspect this might be interfering in your case. To disable it check out the audio block’s script here, you’ll need to add a line to disable “module-suspend-on-idle”.

1 Like

Hey, did you have any luck tracking down your auto popping issues? Or if you opened a new forum thread already just link it here and we can close this one!

1 Like

The second option seemed easier and I tried it. This one would require several changes in the code and I am not yet familiar enough with Docker containers and services to do it.

I added:

pa_disable_module suspend-on-idle

to my entry.sh script. The code compiles and deploys, so it should work. I tested it on a jack 3.5 device and it plays sound. This jack 3.5 audio output did not have a popping sound in the first place, so I can’t say whether it works. I’ll test the removal of the popping sound next time I have access to the I2S device, which I don’t have with me at the moment.

I suggest we close this one and I’ll reopen it if I still have issues with the popping sound. I posted the I2S microphone thread here: I2S speaker and microphone on Rasbperry Pi . How about controlling the volume of the bonnet?