In Education, Random Stuff, Raspberry Pi

I’m in the process of setting up a retro arcade system using a Raspberry Pi 3. I’ll post updates on the build later but for now I’m working on getting the software and controller hardware configured before starting on the cabinet. This will be a fun addition to our home as we like to entertain and who doesn’t enjoy a good two-player game of PacMan? Plus, we had a lot of the hardware sitting unused in closets and what we didn’t have is relatively inexpensive.

While setting up USB sound on the Pi I found a lot of different solutions online and before long I had pieced together a house of cards on an SD card that worked. Later, while working on the controller setup, I made some bad edits and decided to start the whole project over from a fresh install. What a hassle it was to go back to a bunch of random sites to try and reproduce what I had done originally!

It turns out there is a super simple solution. If you want to just skip ahead to it, click here.

Background

The Pi is an amazing little device. In the past I’ve used them to create a whole-home audio system that allowed Airplay to individual rooms from iOS devices as well as control from the Logitech Squeezebox system that we used to stream audio throughout the home before everyone in the family had an iPhone and iPad. That experience taught me that audio from the 3.5mm jack on the Raspberry Pi leaves a lot to be desired. Fortunately, you can find inexpensive USB audio devices that output impressive audio quality from a number of suppliers online. I used the white ones from Adafruit available here for 5 bucks and have been very happy with them.

Ultimately I replaced all of the Pi’s in the audio system with Apple Airplay Expresses after Logitech pulled the plug on Squeezebox. So I have a bunch of Raspberry Pi’s and USB audio dongles looking for projects to go into! I want great sound in my arcade cabinet so naturally I’m using one of my USB audio dongles even though I opted to go with a brand new Raspberry Pi 3 for this project rather than use one of my old 2’s.

My Setup

There are a number of options available to use for the arcade software. I’ve been using RetroPie so far and will most likely stick with it for the final build. Other options like Lakka and Recalbox look really nice as well but I’m finding a lot more resources online regarding RetroPie setup. And if there is one thing about the Raspberry Pi, it’s setup-intensive no matter what. Prepare to get comfortable with the command line and learning some Linux commands. That being said, RetroPie makes setting up an arcade system insanely simple but I have struggled getting audio working as well as my dual retro arcade controllers (that will be covered in another post).

RetroPie uses Raspbian as the operating system. This is a version of Linux Debian optimized for the Raspberry Pi and audio is sent to the 3.5mm jack by default. There are loads of tutorials available online about how to setup a USB audio device as the default sound output but all of them that I have been able to find do not work on the latest version of Raspbian known as Jessie. In Debian 8 (Jessie), the developers made a change to how ALSA devices are configured so all the files that old tutorials talk about are no longer present so those old tutorials are no longer helpful.

I have been unable to find one comprehensive tutorial that tells how to do this simply, so here you go! In a nutshell: you need to tell Raspbian to use device number 1 as the default audio device and then name that device “PCM” so EmulationStation won’t show the annoying message “VolumeControl::init() – Failed to find mixer elements!” whenever you change games.

I’m going to assume that you can SSH into your Pi or have a keyboard connected so you can hit F4 in RetroPie and go to the command line. If you need to learn how to SSH, use your favorite search engine and search “how to ssh into raspberry pi” (without quotes, naturally).

NOTE: It appears that there are multiple ways to make this work. In my opinion, the below is clean and simple and easy to “undo” if you want to go back to a vanilla setup without burning a new SD image.

The All-in-One Solution

In all code below, “pi@retropie:~ $” is the command line prompt (you don’t type it). The instruction you type is to the right of that. Lines shown below that are what is output on my system after entering the command. Sorry if this is obvious, trying to make this post accessible to any skill level.

From command line, check to see what audio cards you have:

pi@retropie:~ $ cat /proc/asound/modules
0 snd_bcm2835
1 snd_usb_audio

As you can see, the 3.5mm jack “bcm2835” is device 0 and “snd_usb_audio” (the USB card) is device 1. Raspbian uses device 0 for audio output by default so we want to tell Raspbian to use device 1 as the default audio device instead.

To set the default card all we need to do is create a file named /etc/asound.conf by typing this:

pi@retropie:~ $ sudo nano /etc/asound.conf

This opens the built-in text editor “Nano” and creates a new file named asound.conf in folder /etc/ on your Pi’s SD card. (NOTE: The command “sudo” gives the user “pi” admin rights. If you are logged in as root you can omit sudo from the commands but then, you knew that didn’t you ;-).

Type the following into Nano to set the default audio to device 1 and then name that device “PCM” so you don’t get the annoying message “VolumeControl::init() – Failed to find mixer elements!” each time you enter and exit a game from the RetroPie front end:

pcm.card1 {
type hw card 1
}
ctl.card1 {
type hw card 1
}

pcm.!default card1

To exit nano and save the file press Ctr+X (hold Ctrl key down then press X key). Press Y at the prompt and then press “Enter” to save the file. You’ll then need to reboot your Pi:

pi@retropie:~ $ sudo reboot now

After rebooting you’ll want to go into the RetroPie setup menu and choose the “Audio” option so you can increase the volume of the USB audio device. Choose option #4 and then press F6 and choose the USB card, then use the arrow keys or joystick up to increase volume. I set mine at about 83%. Hit Escape to exit and go back to RetroPie.

That’s pretty simple and trust me, it’s way easier than a lot of the other solutions I found online. If you ever want to undo your changes, simply type the following at the command line:

pi@retropie:~ $ sudo rm /etc/asound.conf
pi@retropie:~ $ sudo reboot now

Thanks for reading and happy retro gaming!

David
Wolters Advertising principal David Alan Wolters is a brand & marketing specialist whose clients include Fortune 500 corporations, small to medium size businesses, and numerous startups. David arms leaders with a powerful, strategic brand positioning so they can grow their business with intention, clarity and focus.

Leave a Comment