I just realised I didn't explain the audio amplifier of my alarm clock introduced in the wiring post. Silly me ... Anyway, as you may have seen from the wiring in my previous port, I'm using the I2S pins to get the audio from the GPIO header and amplify it. I2S (or Inter-IC Sound) is a digital sound protocol, meant to pass audio data around between integrated circuits. Getting audio from the I2S pins requires some configuration to not use the onboard stereo jack output.

 

Hardware

 

To amplify the audio, I'm using a small 3W amplifier breakout board from Adafruit. It takes the digital audio signal as an input, converts it to analog and amplifies it, outputting straight to a speaker.

 

It connects to the Pi's GPIO as follows:

Screen Shot 2016-08-16 at 19.33.21.png

 

The little board costs about $6, making it a cheap and compact solution for projects like this one. The gain can be adjusted as well using the gain pin and resistors of different values, but leaving it disconnected works just as well, resulting in 9dB gain. Other possible values are 3dB, 6dB, 12dB and 15dB.

 

Software

 

I already did some reconfiguration of the audio when I added my USB microphone for voice control. Mainly to configure a different card for the default capture and playback devices. In my original tests, I was using a powered speaker connected to the stereo output jack of the Pi. Now, the Pi needs to be told to use the I2S audio rather than the stereo jack.

 

Before

 

Using "aplay -l" and "arecord -l" we can list the current playout and recording devices. The situation is as follows:

 

pi@piclock:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: 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 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

pi@piclock:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

Device Tree Overlay

 

A device tree is the description of the hardware in a system. And lucky for me, the device tree of the HiFiBerry DAC can be reused for this little amplifier board, making the configuration extremely easy. In the Pi's config file, the audio device tree parameter needs to be commented out and the hifiberry-dac overlay needs to be enabled.

 

pi@piclock:~ $ sudo nano /boot/config.txt

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on
dtoverlay=hifiberry-dac

 

A reboot is required to apply the changes:

 

pi@piclock:~ $ sudo reboot

 

After

 

After the reboot, using the same commands we used before applying the device tree overlay, it is possible to see the change has successfully been applied:

 

pi@piclock:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

pi@piclock:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

The playback device has changed, the capture device hasn't. Exactly what was needed.

 

Test

 

Now, what's the best way to test the new audio config than by turning on the radio using voice control?

 

 


arrow_prev.png

 


Navigate to the next or previous post using the arrows.

arrow_next.png