This project was originally based on the “Build your own Concrete Bluetooth Speaker (how-to)” YouTube video by DIY Perks. From there a few different paths were explored and ultimately a 2.1 system was conceived.

Portability was sacrificed and the concrete form slated to become a standalone subwoofer for the system. As for the electronics and mid/high-range speakers, custom 3D-printed enclosures were designed.

Overview

This project is based on the popular Raspberry Pi ARM-based computer. The model and auxillary components required are outlined below:

  • Raspberry Pi Zero W
  • HiFiBerry DAC+ 2.6. (Digital-to-Audio-Converter)
  • Dayton Audio RS75T 8 Ohm full-range speakers
  • Adafruit class D audio amplifier build around the MAX9744 chip
  • Power supply providing 5V and 12V
  • 5-Pin rotary encoder for volume and playback control
  • 3D printed enclosures for full range speakers

Software requirements

The software required to build this project is broken down into quite a few parts

  1. Raspberry Pi Operating System
    • Headless WiFi and SSH connectivity
    • Security and hardening
    • Soundcard installation
  2. DAC drivers for high quality audio output
  3. Bluetooth drivers for additional wireless connectivity options
  4. Linux command line setup for audio streaming connectivity
  5. Python3 development environment
    • Global volume control
    • VLC playback control

For ease of installation, I’ve provided all software used in the Downloads section at the bottom to prevent any configuration issues between future updates of the software. The original maintainer links are, however, still provided for those that prefer the latest releases.

Operating system, connectivity and security software installation

An official light Rasbian OS build (obtained from the official Raspberry Pi homepage) was chosen as this will be a standalone and headless installation.

The Raspberry Pi foundation seems to have recently developped their own USB installation tool. The older guides recommended, if I recall correctly, Balena Etcher.

The installation of Rasbian is very straightforward and streamlined into 3 steps:

  1. Download the USB SD card imager program
  2. Download a Rasbian OS build as a .zip file
  3. Prepare and flash the OS onto your micro SD card using the imager application

Following this, you should eject and re-insert your newly minted SD card.

Enabling SSH and headless WiFi

One newly accessible partition should appear in your drive listings named “Boot”. Here you must create two files as follows:

  1. ssh - Without any extension or content. This will enable the ssh server with default settings on your Raspbian OS
  2. wpa_supplicant.conf - Make sure to fill the file with your relevant WiFi network details
network={
ssid="Complete WiFi Network Name"
psk="WiFi-network-password"
key_mgmt=WPA-PSK
}

That’s all there is to it!

To access your Raspberry Pi over your local network, you will need to find the LAN address that was assigned to your Pi by your router. Logging into the administrative interface of your router will allow you to see all LAN ip address allocations.

Accessing your Pi:

  1. Download, for example, an SSH client like Putty
    • Use the default Raspbian OS settings
User: pi
Password: raspberry
Port: 22
Address: **Your Raspberry Pi's LAN ip**

Security

Once you first log into your Raspberry Pi, run the standard Raspberry Pi config script with sudo raspi-config to create a new password and disable unecessary system functions (camera interface, etc). The original guide goes through each option in great detail.

Hardening

A detailed guide can be found in a dedicated post on the matter.

Soundcard installation

The sound utility that setup is based on is ALSA

It should be included with the Raspbian OS distribution but running the following may install any missing dependencies

sudo apt-get install alsa-utils

DAC driver setup

In order to properly route audio through the HiFiBerry DAC+, the appropriate overlay drivers must be configured. The default audio overlay must be disabled and the correct one chosen. Raspbian OS has build-in support for this DAC out-of-the-box.

Configuration changes are done on config.txt on the Boot partition. Raspbian OS mounts this at /boot. Based on the original HiFiBerry general setup, the DAC+ 2.6 instructions are:

  • Remove the existing audio configuration
    • Comment out the dtparam=audio-on line
    • Add dtoverlay-hifiberry-dacplus

Since the alsa-utils package features will be used, a few things must to be added to ALSA’s configuration. For a more detailed look at ALSA utilities, the following blog post by SC Phillips goes into great details.

Create /etc/asound.conf with the following contents:

pcm.!default {
  type hw card 0
}
ctl.!default {
  type hw card 0
}

For general documentation see the HiFiBerry pages or this page for a web-based datasheet.

Bluetooth connectivity setup

bluealsa

The Bluetooth portion is not as straighforward to implement as some of the other steps. Each device must be paired, trusted and an appropriate audio sink enabled to pass audio to the predefined sound card.

In order to pass audio through Bluetooth to ALSA the following needs to be set up and configured:

sudo apt-get install bluealsa

Configuration now requires an additional parameter to be added to the bluealsa.service configuration

sudo nano /lib/systemd/system/bluealsa.service

The ExecStart=... line should be changed to ExecStart=/usr/bin/bluealsa -p a2dp-sink to pass on the -p flag and paramter. A reboot is required.

The bluealsa outline was made with the help of a Scrible.net post on the matter. The bluealsa interface has a GitHub development page for further details.

Bluetooth connections

To successfully connect an audio source to the Raspberry Pi, the standard bluetoothctl command line interface is used. Note that sudo privileges are required to access the Bluetooth radio.

sudo bluetoothctl

To clarify any of the following commands, issue help at the bluetoothctl prompt.

  1. Enable Bluetooth on the Pi
    • power on
  2. Enable pairing agent and turn on discovery mode
    • default-agent
    • discoverable on
  3. Place your audio device in pairing mode and turn on the Pi’s scanning mode
    • scan on
    • Make a note of your audio device’s MAC address
    • scan off
  4. Pair your two devices making sure to accept prompts for passcode confirmation on both devices (if applicable)
    • pair xx:xx:xx:xx:xx:xx
  5. Trust your newly added device for future connections
    • trust xx:xx:xx:xx:xx:xx
  6. Connect your audio device to the Raspberry Pi
    • connect xx:xx:xx:xx:xx:xx
  7. Quit the Bluetooth manager
    • quit or exit

Although a new device is successfully paired, trusted and connected, audio will not be passed through to ALSA unless you explicitly enable it per MAC address

bluealsa-aplay xx:xx:xx:xx:xx:xx

Audio will be passed along to ALSA as long as that command runs. Note that you may run this command without an existing connection (ie. at startup)

Mplayer Setup

A well-known linux application for streaming audio from the terminal is mplayer. For the official documentation, follow this link

Install on your Raspberry Pi with sudo apt-get install mplayer.

Listening to a stream is as straightforward as passing the stream url to mplayer:

myplayer http://stream.com

However, depending on the stream bitrate, you should define and pass on a cache parameter to cache loaded streams.

mplayer -cache 8192 -prefer-ipv4 http://stream.com

Note: The optional iPv4 flag ensures compatibility with more local network configurations.

Python environment and control scripts

The volume control uses a rotary encoder (like this one) and a python script to interpret movement and modify the volume through ALSA. Volume and interface controls will use the GPIO pins of the Raspberry Pi and, by means of Python scripts, control our parameters on the Raspberry Pi.

The principal requirements are Python3, the pip package manager for Python3 and the Raspberry Pi GPIO python packages. Install using the following:

sudo apt-get install python3

The script was forked from a gist by Andrew Dupont on GitHub and the GPIO pins defined. Modifications will be made to allow digital control of the audio amplifier board.

In order to successfully connect your rotary encoder to the Pi, browse the excellent ..[C]omprehensive GPIO Pinout guide for the Raspberry Pi. Make note that the numbering can be relative to the physical RPi header or the system-on-chip pinout. Either is fine as long as it is consistentily used and appropriately defined in the python script.

Downloads

Other setups by others include this project by Nico Kaiser on GitHub. It offers install scripts to install and setup the various components.