If for whatever reason, you need an analog audio output on your Raspi and the internal one sounds too bad for your taste, here’s how to connect one of those cheap I2S modules (Aliexpress) to your Pi.
Physical connection

DAC Module | Raspberry Pi 3 |
VIN | Pin 2 (5V) |
GND | Pin 6 (GND) |
LCK | Pin 35 |
DIN | Pin 40 |
BCK | Pin 12 |
SCK | GND |
The PCM5102 will generate SCK by itself, but it needs to know that it should do that, this is done by connecting SCK to GND. Otherwise your audio output will sound like a distorted, bass-boosted remix (one could, of course say, that this is a nice feature :D).
Refer to pinout.xyz if you aren’t sure about the Pi’s pin numbering.
Software setup
This guide explains it quite well, but I will summarise it here, in case something ever happens to that link.
Editing boot.txt
Run this command to open the file in a text editor:
sudo nano /boot/config.txt
You will need to change the following things:
Uncomment (remove the # before the line):
dtparam=i2s=on
Comment (add a # before the line):
#dtparam=audio=on
Append this to the end of the file:
dtoverlay=hifiberry-dac
Creating asound.conf
Run this command to open the file in a text editor:
sudo nano /etc/asound.conf
And paste the following:
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
Now reboot your Raspberry Pi
sudo reboot
Testing our changes
Use the command aplay -l
to list your audio devices, if your changes were successful, the output should look like this:
[email protected]:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
You can try playing a wav file using aplay filename.wav
or install mplayer to play other file types.
0 Comments