Connecting the speaker

Perform the following steps to connect to speakers:

  1. Connect the USB sound card to your Raspberry Pi Zero and find out if the USB sound card enumerates using the lsusb command (on your Raspberry Pi Zero's command-line terminal):
USB sound card enumeration
  1. Cheap USB sound cards typically have an input terminal (to connect a microphone) and an output terminal (to connect a speaker). Both the terminals are standard 3.5 mm jacks. The input terminal is pink and typically marked with a microphone symbol. The output terminal is green and marked with a speaker symbol.
  2. Connect a speaker to the output terminal (green) of the USB sound card.
  3. On your Raspberry Pi Zero's command-line terminal, list all the audio sources connected to your Raspberry Pi Zero using the following command:
       aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835
ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835
ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Set [C-Media USB Headphone Set],
device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
  1. As shown in the aplay command's output, the sound card is listed as card 1. We need this information to set the USB sound card as the default audio source
  2. Open your sound configuration file from the command line as follows:
       nano ~/.asoundrc
  1. Make sure that the configuration file's source is set to card 1 (the soundcard):
       pcm.!default {
type hw
card 1
}

ctl.!default {
type hw
card 1
}

Save the configuration file (by pressing Ctrl X and press Y to confirm the name of the file. Press Enter to save the file. Refer to Chapter 11Tips and Tricks chapter for a detailed tutorial) and reboot your Raspberry Pi Zero.

  1. On reboot, test if the speaker works by downloading a wave file (Freesound.org has plenty of wave files). From the command-line terminal, play your file as follows:
       aplay test.wav

If everything is configured properly, you should be able to play audio using your USB sound card and speaker. If you are not able to play the audio, check the connections and make sure that your USB sound card is enumerated correctly and you have chosen the right audio source in the configuration file. In the next section, we will set up the microphone.