HiFiBerry MiniAmp

The HiFiBerry MiniAmp is a very small audio sound card: 1/8 × 1/4 × 1/32 in (??? I don't think these dimensions are correct)

It is the perfect size for a Smart Doorbell except for the screw in header block, which needs to be removed.

The HiFiBerry MiniAmp only outputs 3W of power. So, it remains to be seen if the volume is loud enough.

Parts:

  • Raspberry Pi Zero running Raspberry Pi OS (aka raspbian)

  • HiFiBerry MiniAmp

  • Male-to-male and Male-to-female Jumper cables

  • Breadboard

  • Soldering iron, solder, etc

  • 2x Speakers

Step 1. Shut down the Raspberry Pi

Open a terminal window and login

Shutdown the Raspberry Pi

$ sudo shutdown now

or

$ sudo shutdown -h 0

Wait for the lights to stop blinking

Remove the micro USB power supply from the Raspberry Pi

When prototyping, I like to connect everything to a breadboard rather than mounting one card on top of the other. So, do either Step 2a or Step 2b.

Step 2a. Mount the HiBerry MiniAmp

Do either this step or the next one.

Mount the HiBerry MiniAmp on top of the Raspberry Pi

Go to Step 3

Step 2b. Connect the HiBerry MiniAmp

Do either this step or the previous one.

Connect the HiFiBerry MiniAmp to a breadboard and/or to a Raspberry Pi Zero using female/male and male/male jumper cables. The HiFiBerry MiniAmp uses either 8 or 9 pins. I am going to play it safe and use 9 pins

The required pins for the HiFiBerry MiniAmp are as follows:

Power Supply Pins:

Pin 1: 3.3V

Pin 2: 5V

Pin 6: ground

I2C Audio:

Pin 12 (GPIO 18, PCM_CLK): I2C-BCLK

Pin 35 (GPIO 19): I2C-SYNC

Pin 38 (GPIO 20): PCM

Pin 40 (GPIO 21): I2C-DATA

Direct Control of Amplifier:

Pin 36 (GPIO 16): MUTE (PAM8403)

Pin 37 (GPIO 26): SHDN (PAM8403)

Step 3. Connect Speakers

It doesn't matter if + goes to left or right, but both speakers must be hooked up the same way. See image.

You can use HiFiBerry MiniAmp with just one speaker. Again, it doesn't matter if the right or left jack is used.

Step 4. Install Required Software

alsamixer is installed with Raspberry Pi OS (raspbian).

To install mpd and mpc and get the service running, execute following commands:

$ sudo apt-get install mpd mpc -y

$ sudo service mpd stop

$ sudo chmod -R g+w /var/lib/mpd

$ sudo chmod -R g+w /var/run/mpd

$ sudo service mpd start

Step 5. Configure raspbian to work with HiBerry MiniAmp

Edit config.txt

$ sudo nano /boot/config.txt

and comment out the line

# dtparam=audio=off

and at the end of the file add the lines

# HiFiBerry MiniAmp

dtoverlay=hifiberry-dac

CTRL-o, ENTER, CTRL-x to save and exit the editor

and then reboot:

$ sudo reboot

Step 6. Configure mpd and mpc to work with HiBerry MiniAmp

Edit mpd.conf

$ sudo nano /etc/mpd.conf

and make the following changes:

audio_output {

type "alsa"

# name "My ALSA Device"

name "sysdefault:CARD=sndrpihifiberry"

mixer_type "software"

Step 7. Copy doorbell sounds from MacBook to Raspberry Pi

On a Mac,

  • open terminal window and navigate to the directory with doorbell sounds, which should be either .m4a or mp3

    • navigate to finder window 2 (cd /Users/.../Desktop/...)

    • Copy all the doorbell files to your raspberry pi using the command:

scp * pi@♣hostname♣.local:home/pi/.

Step 8. Check if things work

I have a doorbell sound called dingdong.

mpc insert "file:///home/pi/dingdong.mp3"

mpc play

mpc stop

Appendix: Various Commands

$ aplay -l # lists the playback hardware

**** List of PLAYBACK Hardware Devices ****

card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 [HifiBerry DAC HiFi pcm5102a-hifi-0]

Subdevices: 1/1

Subdevice #0: subdevice #0

$ mpc outputs # shows if the output is enabled

Output 1 (sysdefault:CARD=sndrpihifiberry) is enabled

$ mpc listall # list all doorbell sounds

$ mpc del 1 # delete doorbell sound #1 in playlist

$ mpc volume 80% # change the volume to 80%

$ cat /var/log/mpd/mpd.log # check for errors and then fix them

References:

mpc man page