Setup Virtual Environment
If you are installing on the Bookworm version of Raspberry Pi OS or later, you will need to install your python modules in a virtual environment. You can find more information in the Python Virtual Environment Usage on Raspberry Pi guide. To Install and activate the virtual environment, use the following commands:
sudo apt install python3-venv python -m venv env --system-site-packages
To activate the virtual environment:
source env/bin/activate
Installer script
Luckily its quite easy to install support for I2S DACs on Raspbian.
Run the following from your Raspberry Pi with Internet connectivity:
sudo apt install -y wget wget https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/raw/main/i2samp.py sudo -E env PATH=$PATH python3 i2samp.py
We've added 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 (on a Pi Zero, 5%, on a Pi 2 or 3 its negligible). You don't need this on RetroPie because it never releases the I2S device, but it's great for Raspbian.
You will need to reboot once installed.
After rebooting, log back in and re-run the script again...It will ask you if you want to test the speaker. Say yes and listen for audio to come out of your speakers...
If it sounds really distorted, it could be the volume is too high. However, in order to have volume control appear in Raspbian desktop or Retropie you must reboot a second time after doing the speaker test, with sudo reboot
Once rebooted, try running alsamixer and use arrow keys to lower the volume, 50% is a good place to start.
If you're still having audio problems, try re-running the script and saying N (disable) the /dev/zero playback service
.
You can then go to the next page on testing and optimizing your setup. Skip the rest of this page on Detailed Installation if the script worked for you!
Detailed Install
If, for some reason, you can't just run the script and you want to go through the install by hand - here's all the steps!
Update /etc/modprobe.d (if it exists)
Log into your Pi and get into a serial console (either via a console cable, the TV console, RXVT, or what have you)
Edit the raspi blacklist with
sudo nano /etc/modprobe.d/raspi-blacklist.conf
If the file is empty, just skip this step
However, if you see the following lines:
blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804
Update the lines by putting a # before each line
Save by typing Control-X Y <return>
sudo nano /etc/modules
If the file is empty, just skip this step
However, if you see the following line:
snd_bcm2835
Put a # in front of it
and save with Control-X Y <return>
sudo nano /etc/asound.conf
This file ought to be blank!
Copy and paste the following text into the file
pcm.speakerbonnet { type hw card 0 } pcm.dmixer { type dmix ipc_key 1024 ipc_perm 0666 slave { pcm "speakerbonnet" period_time 0 period_size 1024 buffer_size 8192 rate 44100 channels 2 } } ctl.dmixer { type hw card 0 } pcm.softvol { type softvol slave.pcm "dmixer" control.name "PCM" control.card 0 } ctl.softvol { type hw card 0 } pcm.!default { type plug slave.pcm "softvol" }
Save the file as usual
For older versions of Raspberry Pi, edit /boot/config.txt instead.
sudo nano /boot/firmware/config.txt
And scroll down to the bottom. If you see a line that says: dtparam=audio=on
Disable it by putting a # in front.
Then add:
dtoverlay=max98357a
on the next line. Save the file and reboot your Pi with
sudo reboot
Text editor powered by tinymce.