RPi 5 Quad Stereo Sound with PCM5102A

Inspired by the news that HiFiBerry are releasing an 8-channel DAC board for the Raspberry Pi 5, but slightly disappointed they’ve sold out of their beta-test programme, coupled with the news that Rene has added 4-channel I2S support for circle, and seeing that the HiFiBerry dac8x is essentially four PCM5102A modules and a high quality audio path, I set out attempting to create a similar (albeit low quality) equivalent with four GY-PCM5102 modules.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

If you are new to single board computers, see the Getting Started pages.

Parts list

  • Raspberry Pi 5.
  • uSD card, HDMI, mouse, keyboard, etc to boot Raspberry Pi OS.
  • 4x GY-PCM5102A modules.
  • Breadboard and jumper wires.

The Circuit

The Raspberry Pi GPIO Pins are connected as follows:

Raspberry Pi 5GY-PCM5102A Modules
5VVCC – Modules 1-4
GNDGND and SCK – Modules 1-4
GPIO 18BCK – Modules 1-4
GPIO 19LCK – Modules 1-4
GPIO 21DIN – Module 1
GPIO 23DIN – Module 2
GPIO 25DIN – Module 3
GPIO 27DIN – Module 4

I eventually ended up using a small solderless breadboard to allow me to daisy-chain the power and common signals for the GY-PCM5102 modules.

Important: Recall that for these PCM5102 modules, there are solder jumpers that have to be setup on the back. More details here.

Raspberry Pi OS

Before connecting any of the GY-PCM5102A modules, I downloaded the latest 64-bit Raspberry Pi OS image and booted it up “as is” on my Pi 5 to make sure everything was working.

Then I installed any pending updates and rebooting to ensure everything was once again up and running.

It might be worth checking sound is working by firing up an Internet browser and watching a video or something. By default the sound will go over HDMI, so naturally you need a sound-capable HDMI device to support that.

At this point I shut it down again and connected up the four PCM5102 modules as per the diagram above then booted everything up again. The OS should boot correctly although at this point it will have no knowledge of the added boards.

Quad DAC Configuration

The basic principle is to use a device-tree overlay file to enable I2S audio and the four PCM5102 devices.

But the nice people at HiFiBerry have already done this with support from Raspberry Pi for their dac8x module, so actually all that is required is to edit the file /boot/firmware/config.txt and add the following line:

/boot/firmware/config.txt:

dtoverlay=hifiberry-dac8x

There is talk on the Internet about commenting out the audio=on parameter or enabling i2s=on, but I didn’t have to do either of these.

Then on reboot, there should be a new audio device “snd_rpi_hifiberry_dac8x” which can be selected.

At this point playing a video should output on the first PCM5102 device.

To test all 8 channels requires an application that can output audio on 8 channels. But for a simple test the “speaker-test” command can be used from the terminal:

kevin@pi5:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: sndrpihifiberry [snd_rpi_hifiberry_dac8x], device 0: HifiBerry DAC8x HiFi pcm5102a-hifi-0 [HifiBerry DAC8x HiFi pcm5102a-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0

kevin@pi5:~ $ speaker-test -t sine -f 440 -c 8 -D hw:2

speaker-test 1.2.8

Playback device is hw:2
Stream parameters are 48000Hz, S16_LE, 8 channels
Sine wave rate is 440.0000Hz
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 16 to 32768
Period size range from 8 to 256
Using max buffer size 32768
Periods = 4
was set period_size = 256
was set buffer_size = 32768
0 - Front Left
4 - Center
1 - Front Right
7 - Side Right
3 - Rear Right
2 - Rear Left
6 - Side Left
5 - LFE
Time per period = 23.295314
0 - Front Left
^C 4 - Center
1 - Front Right
7 - Side Right
3 - Rear Right
2 - Rear Left
6 - Side Left
5 - LFE
Time per period = 0.406018
kevin@pi5:~ $

The “aplay -l” command can be used to list all devices that ALSA knows about. In my case the pseudo hifiberry dac8x device is listed as “card 2”. This means I then need to use the device identifier “hw:2” for the speaker-test command.

The other parameters to speaker-test are as follows:

  • -t sine – output a sine wave rather than the default noise output.
  • -f 440 – set the sine wave frequency to 440Hz
  • -c 8 – use 8-channel sound output.
  • -D hw:2 – use the device “hw:2”

If all goes well, then playback on 0,1 (front left/front right) goes to PCM5102 module 1; 2,3 (rear left, rear right) goes to PCM5102 module 2; and so on.

Closing Thoughts

Now that I know the basic principles seem to work, I want to see what it would take to create a 8-channel audio output MiniDexed.

There is a PCB design for use with MiniDexed here: MiniDexed Quad DAC PCB Design.

Kevin

One thought on “RPi 5 Quad Stereo Sound with PCM5102A

  1. Great idea! I was thinking about the same thing, but I didn’t know how to connect everything, so I bought a DAC8x. One solution that came to mind and I want to test when I receive my ordered amplifier modules with balanced inputs is to use this setup as 4 balanced outputs by inverting the signal on every second channel.

    Like

Leave a comment