Introduction: A Multi-Room Audio System (MRAS) Using a Home Cinema That Can Be Controlled Via the Network

At home we have a wiring installation for speakers to be used by a multi-room audio system. A total of 5 wire pairs are available, with 3 of them going to the 3 bedrooms and the remaining two going to a room hosting the living area and dining table. All cables terminate to the entrance of the house behind a chest of drawers and were never utilized.

The goal was to install a multi-room audio system that will be reasonable priced and could be controlled by a mobile phone. In detail the main goals of the project were:

  • Use all available wiring (5 speakers in total)
  • 2 floorstanding speakers and 3 wall mounted speakers
  • Send a single audio channel (mono) to all speakers, as stereo -or any other format- is not suitable in multi-room environments
  • Be able to utilize all the speakers
  • Be able to select the speakers that will output sound
  • Play sound stored locally or from the Internet (like e-radios or Youtube)
  • Control the entire system from a browser (on/off, volume control, music source, speaker selection etc)

The most cost effective solution to achieve this was to buy a Home Cinema having 5 speakers (plus a sub-woofer) and use Raspberry Pi 3 to achieve all the automation required. The total cost was about 450 Euros.

In the above photos you can see the screenshots of MRAS taken from a mobile phone browser:

  1. The first photo is the home screen with the most common controls and grouping of speakers
  2. The second is used to individually control the speakers
  3. Next we have the available IR commands that you can send to the Home Cinema
  4. The fourth controls the media playlist (using mpd and mpc)
  5. Then we have the ability to add Youtube links in the current playlist (using youtube-dl)
  6. Finally, we have a simple status page with the CPU temperature and the total time that the system is up

Step 1: Billing of Materials

1x Sony Home Cinema 5.1 BDV-E4100

1x Raspberry Pi 3 (with case as the electronics are sensitive)

1x Micro SD 8 GB

1x mini breadboard

2x 5V 4 Channel Relay Shield

8x NPN transistors (2N2222A)

1x IR Led Transmitter 5mm 940nm (100mW)

1x IR Receiver 38kHz (TSOP38238)

2x 5V power supply (2.5A for the Raspberry and 1.5A for the relays)

1x power cable (for controlling power to the Home Cinema)

1x SparkFun microB USB Breakout

1x 3.5mm Jack to 2 x RCA Phono Stereo Audio Cable

Screws and anchors for hanging the speakers

Jumper wires (M-M, F-F, M-F)

Breadboard jumper wires

Step 2: Setting Up the Software

We first need to install the Raspbian operating system. Please follow the instructions to install NOOBS on your MicroSD card and from there Raspbian, using the following links:

https://www.raspberrypi.org/downloads/noobs/

https://www.raspberrypi.org/learning/software-guide/

Once installed we will need to perform some basic configuration. Open a terminal and run:

sudo apt-get update
sudo apt-get dist-upgrade -y
sudo raspi-config

On the “Boot Options” select the first option “Console”. This will avoid starting a Window Manager and save a lot of system resources.

Using the same terminal window, lets connect the Raspberry to our wireless network and set a static IP in order to be able to locate it easily (use pico text editor if you are not familiar with vi):

sudo vi /etc/network/interfaces

delete any lines mentioning wlan0 and add the following:

allow-hotplug wlan0
iface wlan0 inet static
	address 192.168.1.100
	netmask 255.255.255.0
	gateway 192.168.1.1
	wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Where 192.168.1.100 will be the IP of the Raspberry machine and 192.168.1.1 is the IP of our internet gateway (router).

Next edit the wireless configuration file:

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

The file must have the following contents:

country=GR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
	ssid="Wireless name"
	psk="Wireless key"
}

Where country must match your country code (in my case GR) and Wireless name and Wireless key must be your wireless SSID and password (pre-shared key) respectively.

Next we need to install all additional software. Again in the terminal run:

sudo apt-get install apache2 php5 libapache2-mod-php5 mpd mpc lirc -y

and wait for the installation to complete.

Now we will install youtube-dl in order to be able to play music from Youtube:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

We will also install composer (a PHP package manager):

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=bin --filename=composer

Finally we will install wiringPi to control the GPIOs of Raspberry:

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd gpio/
sudo cp gpio /usr/local/bin/
sudo chown root:root /usr/local/bin/gpio
sudo chmod 4755 /usr/local/bin/gpio

We are done, reboot the system:

sudo reboot

and check that you can SSH to it remotely using its static IP (in my case 192.168.1.100):

ssh pi@192.168.1.100

Step 3: Setting Up IR Communication Using LIRC

A major goal of the project was to remotely control everything and also consume as little power as possible, so having the Home Cinema always on was not an option. Using an IR receiver we can learn the IR commands from the remote control and using an IR LED we can send them on demand from the Raspberry. The commands that we have to record (with the help of LIRC) are the following:

  1. Power on or off: KEY_POWER
  2. Increase the volume: KEY_VOLUMEUP
  3. Decrease the volume: KEY_VOLUMEDOWN
  4. Select the input source: KEY_SELECT
  5. Mute the volume: KEY_MUTE

Please follow the instructions to install both the IR receiver and IR LED on Raspberry and record the IR commands using the following link:

http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/

I did not use the pull-down 10K resistor. Also after learning the remote control using irrecord please edit your lircd.conf and use your Home Cinema name as the name for the remote control:

begin remote
	name  SONY-BDV-E4100
...

While learning the Sony BDV E4100 remote control I had to do a lot of tests and the reason was that some remote control commands are 15 bits in length while others 20 bits. But the above commands that will be used by the system all had the same length, so after a few tests I was able to successfully control my Home Cinema.

You can now remove the IR receiver and cabling, since we will not be using it any more.

If you want to dive deeper in IR communication details consider reading:

https://learn.sparkfun.com/tutorials/ir-communication

http://www.sbprojects.com/knowledge/ir/index.php

Step 4: Configuring the Home Cinema

Before beginning the wiring of the entire system be sure to perform the following:

  • Connect the Home Cinema and the speakers to a TV and walk through the settings in order to be sure that everything is configured as expected and the firmware is up to date.
  • Select the AUDIO input source (or AUX), connect your phone and play some music. Make sure that all speakers output sound. If not, change your configuration and select that the speakers are not in a surround setup, but they are all placed on the front.
  • Also adjust the balance of each speaker to make sure that all output at the same volume (dB).

If you want to use a different Home Cinema follow all the instructions and after finishing all the steps review the status.json.back file available under /var/www/html/api. This file contains the GPIO ports that are used, the speaker grouping, the IR commands to control the Home Cinema and the time it takes for the system to power off and on in seconds. After making the necessary changes copy this file over status.json and fix the permissions. Please note that if you are going to be using a different speaker grouping or perform major alterations you may need to also modify the Javascript (JS) of the MRAS User Interface (UI). The JS code is located in theme_foot.inc.

Step 5: Wiring Up Everything

Please use the diagram provided to connect all components. Since the diagram is very detailed I will not provide step by step instructions, but instead provide some notes:

  • We will be using the 5V and 1.5Amps power supply to power the relay boards through the breadboard. I did not want to cut wires, so I used the SparkFun microB USB breakout. You can also view the actual picture of my setup.
  • I taped the IR LED opposite to the Home Cinema on top of the Raspberry power supply. Again check the provided photo.
  • To avoid cutting the power cable of the Home Cinema you can use an external power cable that will go through the relay in order to cut off power to the Home Cinema and consume less power when the system is not used.
  • The green terminals represent the back of the Home Cinema where all the speakers are connected.
  • We will be using the following GPIO ports from Raspberry (wirringPi numbering): 3.3V, GND, 0, 1, 2, 3 (or BMC 22 for controlling the IR), 6, 12, 13 and 23. Ports 0, 1, 2, 6, 12 and 13 are used to control the speakers, while port 23 is used to control the Home Cinema power.
  • We connected the GND from Raspberry (black cable) to the ground of the breadboard in order to have a common reference.
  • Do not forget to connect the audio jack to Raspberry and the RCA connectors to the Home Cinema.

For more information on relay boards you can read the following:

https://arduino-info.wikispaces.com/RelayIsolation

Step 6: Hardware Ready

The entire system is hosted inside a drawer that is empty, so only the speakers are visible. Review the photos of the final installation.

All speaker cables are well hidden, besides the floorstanding speaker near the dining table. In order to be able to disconnect and connect the speaker on demand I used an old USB extension cable and heat shrink tubing. You can view the final result on the photo.

Step 7: Setting Up MRAS

Download the code and configure the software:

cd /var/www
sudo chown pi:pi -R html/
cd html
git clone https://github.com/poursal/mras .
cd api
sudo chown pi:www-data status.json
chmod 664 status.json
composer install

Next we need to configure apache:

sudo a2enmod rewrite
sudo vi /etc/apache2/sites-enabled/000-default.conf

And inside VirtualHost add/update the Directory element:

<Directory /var/www/html>
	Options Indexes FollowSymLinks MultiViews
	AllowOverride FileInfo
	Order allow,deny
	allow from all
</Directory>

Once you are done execute:

sudo systemctl restart apache2

On each Raspberry reboot we need to reset a few configuration items (mpd and GPIO). Please edit the rc.local file (sudo vi /etc/rc.local) and add the following lines:

# Init GPIO
php /var/www/html/api/init.php

# Clear playlist
/usr/bin/mpc clear

# Disable power management on wlan0
iwconfig wlan0 power off

Configure alsa to copy both input channels to each output channel. Create a file under /etc/ with name asound.conf and contents:

pcm.card0 {
	type hw
	card 0
}
ctl.card0 {
	type hw
	card 0
}
pcm.monocard {
	slave.pcm card0
	slave.channels 2
	# type plug
	type route
	ttable {
		#Copy both input channels to output channel 0 (Left).
		0.0 1
		1.0 1
		#Copy both input channels to output channel 1 (Right).
		0.1 1
		1.1 1
	}
}
ctl.monocard {
	type hw
	card 0
}
pcm.!default monocard	

Reboot to apply the changes (sudo reboot). Download the provided MP3 (see below) and play it using mpd in order to verify that you can hear both left and right channels from all speakers.

cd /var/lib/mpd/music
sudo chown mpd:pi .
sudo chmod 775 .

After uploading the file in the music directory and renaming it to stereo.mp3 execute:

mpc update
mpc add "stereo.mp3"
mpc repeat
mpc play

Now navigate to all rooms and make sure that you can hear both channels.

Execute the alsamixer command and set the output at 90%.

Since working with files on the MRAS UI will not be that efficient the system is working with playlists. Please upload your MP3s to the music directory and execute: mpc update. Afterwards add files in the current playlist and once you are done save the playlist providing a name:

mpc clear
mpc add "Hits/90s"
# more mpc add commands if needed
mpc save "All hits"

And we are done. Using your desktop or mobile browser visit:

http://192.168.1.100

and you will be able to access the MRAS UI and all the provided functionality.

Step 8: Future Work

No system is complete. Here is a list of future work:

  1. The software first mutes the Home Cinema, it then enables/disables the speaker using a relay and un-mutes the Home Cinema. The muting is performed in order to protect the Home Cinema outputs from damage, but I am not sure if this is required.

  2. Better UI handling of the power on/off functions of the Home Cinema and some improvements on the backend. For details review the code.

  3. The current system is capable of controlling multiple outputs, but is not able to select multiple inputs. Also it is not capable of sending different inputs on different outputs. Of course this will require a complete redesign and different hardware.
Amps and Speakers Contest 2016

Participated in the
Amps and Speakers Contest 2016

IoT Builders Contest

Participated in the
IoT Builders Contest

Circuits Contest 2016

Participated in the
Circuits Contest 2016