2

I am deploying a Pi 4 on a wheelchair and require audio output to prompt the user. The Pi is headless (i.e. no monitor). On the bench, with a monitor, my code correctly sends the audio out the 3.5 jack to a powered amplifier. When I unplug the HDMI cable and reboot, the audio stops working. Any suggestions will be much appreciated.

I set the output to analog via the sound icon on the monitor. Could it bed that the Pi forgets the setting when no monitor is connected? Or, does the Pi look for HDMI before analog and hang? Or, do I need to set the sound level manually since the desktop is not working without the monitor? Any help will be greatly appreciated.

Thanks in advance. Rick

2

Try adding the following into config.txt and reboot the Pi.

hdmi_ignore_edid_audio=1
audio_pwm_mode=2

The first line tells the Pi to ignore whatever HDMI thinks it's capability is and use the on-board audio.

The second line tries to take out some hiss and noise - it may not work for your audio but worth trying.

Make sure that these are in a section that gets read as config.txt can have sections depending on model, serial number etc.

1
0

This answer may come too late for Mr. Foulds, but let me disgorge my research here.

It seems the canonical way to choose the audio output on the RPi is to use the raspi-config, which is an interactive menuing system. Like Mr. Foulds, I have a project where I would like the analog audio to be the default. You cannot use raspi-config at boot (unless you want to use something like expect, but please do not).

A look at the source code for raspi-config provides the answer:

https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config#L1968

All it does is configure the .asoundrc file for the current user (usually pi for RPis). Notice that what really changes is the 'card' property in the pcm.output and ctl.!default blocks. But how do we know which "card" is the analog output?

Use 'aplay -l | grep bcm2835'. That shows you all available cards.

Use your favorite unix pattern matching tool to extract the card number. Here's my example:

   aplay -l | grep bcm2835 | grep "Headphones" | perl -lane 'print substr($F[1],0,1)'

This will emit the card number of the "headphones" card.

Simply create the .asoundrc file with this card number at boot time. There is already a template for this file in the raspi-config source linked above. I would use that.

You can change this RC file at any time. When the linux sound system needs to route audio output, it appears to consult this file. No rebooting is needed. If you would like to read more about the linux sound architecture, here is the wiki:

https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture

I did a lot of web searches, but could not find this answer stated clearly. I hope this helps.

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .