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 ModuleRaspberry Pi 3
VINPin 2 (5V)
GNDPin 6 (GND)
LCKPin 35
DINPin 40
BCKPin 12
SCKGND

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.


13 Comments

Bernd · 6th March 2023 at 04:46

Is there a solution for old Raspberry Pis with a 26 GPIO header? Mine doesn’t have pins 35 and 40.

    Bernd · 6th March 2023 at 04:55

    I found that my question was (kind of) answered on 14th May 2022. My Raspberry is rev 2 (I think; it has 512MB RAM) and not exactly the same as the rev1 board covered in the VolumeIO forum post, so that I will have to figure this out still.

Zvonimir · 19th September 2022 at 16:30

Hi,
Is this small I2S card also work on Volumio?
Regards,
Zvonimir

    Himbeer · 23rd October 2022 at 20:20

    Hello Zvonimir,
    yes, that should work! You only need to enable the I2S driver in the settings.
    Kind regards,
    Himbeer

Booster · 13th May 2022 at 21:31

Is this same possible with older Raspberry Pi A+/B P5 header?

serusko · 1st February 2022 at 21:00

hi, i did every step precisely and checked it twice but i see

card 0: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0

do you have any idea ?

i am using rpi zero

    Himbeer · 19th February 2022 at 12:29

    Hi, sorry for the late response. I tried with a Pi Zero W and the latest (bullseye) image of Raspberry Pi OS Lite and it still works fine for me:

    [email protected]:~ $ aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 [HifiBerry DAC HiFi pcm5102a-hifi-0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 1: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    Feel free to join my Discord or add me on Matrix if you still need help.

me · 28th April 2021 at 15:59

SCK can be connected to GND just by using the soldering-pad on the PCB

    Himbeer · 3rd June 2021 at 21:06

    Yes that will also work of course, thank you for adding that!

Raspberry Pi I2S Audio Interface – Simple DIY Electronic Music Projects · 21st November 2021 at 21:26

[…] How to connect a PCM5102 I2S DAC to your Raspberry Pi […]

Leave a Reply to Booster Cancel reply

%d bloggers like this: