3

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

3 Answers 3

3

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
2

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.

2
  • Thanks a lot for the detail that rebooting is not needed. I had to restart the audio application, but that's fine. As the card numbering changes on every reboot, this way I can finally control output reliably. Commented Jun 3 at 9:25
  • Also, you might want to include where the .asoundrc lives. Commented Jun 3 at 9:25
0

Adding the following option to /boot/config.txt fixed my analog audio issues:

dtparam=audio=on

And after that my system seems to default to the 3.5mm headphone audio input regardless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.