Pimoroni Pygame audio coming of of other places

I have the pimoroni line-out device and wrote my own python3 pygame application. I cannot get the audio to come out of the line-out device. I have plugged in a USB DAC and am able to get pygame to talk to the external USB device. I am updating the display and handling buttons and the applicatoin works great except that the audio comes out of the external USB device instead.

$ 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: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

in /usr/share/alsa/alsa.conf
defaults.ctl.card 1
defaults.pcm.card 1

and the audio comes out of the USB device. If I change the 1 to a 0 in alsa.conf and the audio still comes out of the USB device. Changing the /etc/asound.conf to have “1” makes audio come out of the USB device, setting to “0” audio comes out of nowhere.

pcm.!default {
type hw card 0
}

ctl.!default {
type hw card 0
}

I’m not sure what configuration I need to do to make the pimoroni DAC output.

Another data point. I installed mopidy on another SD card plugged the pimoroni line-out onto the new RPi. It came up and ran mopidy with spotify. Audio came out of the line-out. I ran my pygame program and it said no available audio device. So I expected that mopidy might be using it.

sudo /etc/init.d/mopidy stop

Run my program and it starts up but screen is black and pushing buttons where the sound would normally come out, no audio anywhere.

You need to configure the I2S audio to tell the Pi to use the DAC via GPIO.

From here, https://github.com/pimoroni/pirate-audio

You’ll need to add the following lines to /boot/config.txt to get audio up and running:

dtoverlay=hifiberry-dac
gpio=25=op,dh

Thanks for your quick response. I didn’t have the gpio line in /boot/config.txt. I did have the dtoverlay=hifiberry-dac

I added the

gpio=25=op,dh

to config.txt and rebooted. Tried my script again with no sound coming out of anywhere. So no change as far as I can tell.

Here is my alsa-info on the machine. I am not sure exactly what to expect in the following output. But thought it might be informative.

upload=true&script=true&cardinfo=
!!################################
!!ALSA Information Script v 0.4.64
!!################################

!!Script ran on: Wed Mar 25 21:42:18 UTC 2020

!!Linux Distribution
!!------------------

ID_LIKE=debian

!!DMI Information
!!---------------

Manufacturer:
Product Name:
Product Version:
Firmware Version:
Board Vendor:
Board Name:

!!ACPI Device Status Information
!!---------------

!!Kernel Information
!!------------------

Kernel release: 4.19.97-v7+
Operating System: GNU/Linux
Architecture: armv7l
Processor: unknown
SMP Enabled: Yes

!!ALSA Version
!!------------

Driver version: k4.19.97-v7+
Library version: 1.1.8
Utilities version: 1.1.8

!!Loaded ALSA modules
!!-------------------

snd_soc_rpi_simple_soundcard

!!Sound Servers on this system
!!----------------------------

No sound servers found.

!!Soundcards recognised by ALSA
!!-----------------------------

0 [sndrpihifiberry]: RPi-simple - snd_rpi_hifiberry_dac
snd_rpi_hifiberry_dac

!!PCI Soundcards installed in the system
!!--------------------------------------

!!Advanced information - PCI Vendor/Device/Subsystem ID’s
!!-------------------------------------------------------

!!Modprobe options (Sound related)
!!--------------------------------

snd_pcsp: index=-2
snd_usb_audio: index=-2
snd_atiixp_modem: index=-2
snd_intel8x0m: index=-2
snd_via82xx_modem: index=-2

!!Loaded sound module options
!!---------------------------

!!Module: snd_soc_rpi_simple_soundcard
* :

!!ALSA Device nodes
!!-----------------

crw-rw----+ 1 root audio 116, 0 Mar 25 14:36 /dev/snd/controlC0
crw-rw----+ 1 root audio 116, 16 Mar 25 14:36 /dev/snd/pcmC0D0p
crw-rw----+ 1 root audio 116, 1 Mar 25 14:36 /dev/snd/seq
crw-rw----+ 1 root audio 116, 33 Mar 25 14:36 /dev/snd/timer

/dev/snd/by-path:
total 0
drwxr-xr-x 2 root root 60 Mar 25 14:36 .
drwxr-xr-x 3 root root 140 Mar 25 14:36 …
lrwxrwxrwx 1 root root 12 Mar 25 14:36 platform-soc:sound -> …/controlC0

!!ALSA configuration files
!!------------------------

!!System wide config file (/etc/asound.conf)

pcm.!default {
type hw card 0
}

ctl.!default {
type hw card 0
}

!!Aplay/Arecord output
!!--------------------

APLAY

**** 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

ARECORD

**** List of CAPTURE Hardware Devices ****

!!Amixer output
!!-------------

!!-------Mixer controls for card 0 [sndrpihifiberry]:]

Card hw:0 ‘sndrpihifiberry’/‘snd_rpi_hifiberry_dac’
Mixer name : ‘’
Components : ‘’
Controls : 0
Simple ctrls : 0

!!Alsactl output
!!--------------

–startcollapse–
state.sndrpihifiberry {
control {
}
}
–endcollapse–

!!All Loaded Modules
!!------------------

Module
rfcomm
bnep
hci_uart
btbcm
serdev
bluetooth
ecdh_generic
fuse
8021q
garp
stp
llc
brcmfmac
brcmutil
spidev
sha256_generic
cfg80211
raspberrypi_hwmon
hwmon
rfkill
snd_soc_rpi_simple_soundcard
bcm2835_codec
bcm2835_v4l2
v4l2_mem2mem
v4l2_common
bcm2835_mmal_vchiq
videobuf2_vmalloc
videobuf2_dma_contig
videobuf2_memops
videobuf2_v4l2
i2c_bcm2835
videobuf2_common
spi_bcm2835
snd_soc_bcm2835_i2s
videodev
media
vc_sm_cma
snd_soc_pcm5102a
evdev
snd_soc_core
snd_compress
snd_pcm_dmaengine
snd_pcm
snd_timer
snd
uio_pdrv_genirq
uio
fixed
i2c_dev
ip_tables
x_tables
ipv6

!!ALSA/HDA dmesg
!!--------------

[ 5.058124] bcm2835-codec bcm2835-codec: Loaded V4L2 isp
[ 5.079053] snd-rpi-simple soc:sound: pcm5102a-hifi <-> 3f203000.i2s mapping ok
[ 5.182635] usb 1-1.1.3.4: new full-speed USB device number 10 using dwc_otg

To be honest, all that Alsa stuff is above my current skill level. I just went poking around the manual install instructions for the Pirate Audio and found what I posted above. Yours is a PCM5100A DAC chip if that helps.
I have a pHat Beat setup as a Pirate Radio. I just ran the Pimoroni one line installer and all was good to go. I wasn’t trying anything fancy.
Turning yours into a little game console is a really cool idea though and I hope you sort it out.

Did you install Full Raspbian or the Lite edition? Just curious, the full will show you what options you have by clicking the speaker icon in the tray. It should show the hifiberry as an output option. In the lite you have to launch something from command line to select the source, something like that.

EDIT:
What do you have connected to the Line OUT?
Earbuds should work Ok as is but you will need amplified speakers.