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:

pi@raspberrypi:~ $ 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.


14 Comments

Vish · 2nd August 2023 at 15:14

This never worked for me 🙁 I tied with two purple color PCM5102A DACs from aliexpress and eBay ! None worked when connecting to my raspberry pi zero 2W as described !

I have used the steps as detailed in https://blog.himbeer.me/2018/12/27/how-to-connect-a-pcm5102-i2s-dac-to-your-raspberry-pi/ but it never worked for me !

It gives a red light saying power is connected! The moment the board is connect to an active computer speaker it starts making buzzing noise ! If I try to play any audio I only get noise ! Is there some soldering or bridging needs to be done on the board ? Please let me know if there are any special settings that needs to be enabled on this board

I tried the below :

1. Connect XSMT pin on dac board to 5v on Pi Zero 2W and Connect FMT pin on dac board to Gnd on Pi zero 2W

2. Connect XSMT pin on dac board to A3V3 pin on the dac board and Connect FMT pin on dac board to AGND on the dac board

3. Connect SCLK on dac board to raspberry Pi Zero 2W Gnd

I have the same result – Buzzing sound when connecting dac to an active speaker and when I start audio file I still get the same buzzing sound !

Looking for some suggestions and recommendations to understand what I might I have missed.

This is the board I used from Aliexpress and eBay –

https://www.ebay.co.uk/itm/204367400720

The solder pads on back of the baord look exactly like the pictures on ebay link above 4 sets of jumpers and each jumper having 3 pads ! I see some soldering for high / low but I highly suspect some thing needs to be changed on these jumpers !

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:

    pi@raspberrypi:~ $ 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