Build A Raspberry Pi Media Player

Download as pdf or txt
Download as pdf or txt
You are on page 1of 66

BUILD A RASPBERRY PI

MEDIA PLAYER
Power up your TV and music system

FROM THE MAKERS OF THE OFFICIAL RASPBERRY PI MAGAZINE


EoN
Pi NAS

www.dbooks.org
WELCOME

WELCOME!
T
hank you for picking up this copy of Build a
Digital Media Player. This is an exciting Raspberry Pi
project that’s fun and functional.
Raspberry Pi is small computer that can be picked up
from just $15. Add some simple software, and a remote
control, and you will build a digital media box that puts
shop-bought solutions to shame.
For starters, it’s cheaper to make your own media
player, but more importantly, you have complete
freedom to play whatever you want. Play your own movie
files, music and photographs alongside streaming video
and music from the big services.
In this book, we have collected together some of the
best articles from The MagPi magazine written on this
hugely popular subject. We’ll show you how to build a
media centre, create a home server that stores all your
video files, make your own music system and all the best
kit and projects to look at.
Happy making and enjoy your personal media player.

Lucy Hattersley

FIND US ONLINE magpi.cc GET IN TOUCH magpi@raspberrypi.com

EDITORIAL DESIGN PUBLISHING


Editor: Lucy Hattersley Designers: Natalie Turner and Sara Parodi Publishing Director: Russell Barnes
Features Editor: Rob Zwetsloot Illustrator: Sam Alder russell@raspberrypi.com
Contributor: PJ Evans
MAGAZINE SUBSCRIPTIONS Advertising: Charlotte Milligan
DISTRIBUTION Unit 6, The Enterprise Centre, Kelvin Lane, charlotte.milligan@raspberrypi.com
Seymour Distribution Ltd Manor Royal, Crawley, West Sussex, Tel: +44 (0)7725 368887
2 East Poultry Ave, London, RH10 9PE | +44 (0)207 429 4000
EC1A 9PT | +44 (0)207 429 4000 magpi.cc/subscribe Director of Communications: Liz Upton
magpi@subscriptionhelpline.co.uk CEO: Eben Upton

This official product is published by Raspberry Pi Ltd., Maurice Wilkes Building, Cambridge, CB4 0DS. The publisher, editor
and contributors accept no responsibility in respect of any omissions or errors relating to goods, products or services referred
to or advertised in the magazine. Except where otherwise noted, content in this magazine is licensed under a Creative
Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).

Build a Raspberry Pi Media Player 3


Contents
Build the ultimate media centre

08 Set up your system


Build your system and install RetroPie
software for playing media
24
10 Configure Kodi
Set up the software for streaming video
Build the ultimate home server
files and attach a smart remote control

12 Essential add-ons 16 Assemble your equipment


06 Add streaming services such as Netflix,
Spotify and YouTube
Let’s build a revolutionary server that can sit
in the centre of our home

Build the 20 Sharing and storing files


Sharing and storing large files on your

ultimate
network equals lots of fun and productivity

24 Add sound and vision

media Turn your server into a media powerhouse


with Plex and Mopidy

centre 28 Enhance your network


Take control of your network with VPN and
Pi-hole software
12
32 Backup and UPS
Keep your data safe with an uninterruptable
power supply

28

06

4 Build a Raspberry Pi Media Player


www.dbooks.org
BUILD A RASPBERRY PI MEDIA PLAYER Contents

Build the ultimate music system

38 Get started with music


Create a digital jukebox using open-source
software 57
42  dd services: Spotify &
A
SoundCloud Reviews
Extend the capabilities of your music
system with Mopidy extensions
52 Argon One M.2
Add a super-fast M.2 SATA SSD to
46 Set up multi-room audio
Raspberry Pi 4
Fill your home with sound using a

38 multi-room setup 54 Flirc


This stylish metal case keeps Raspberry
Pi cool by acting as a giant heatsink

56  anoSound ONE
N
Hi-Fi DAC Case
The best of both worlds with a melding
of the excellent NanoSound DAC

57 Argon IR Remote
A sleek minimalist remote for your
Raspberry Pi media centre

58 LibreELEC 9.1
LibreELEC comes to Raspberry Pi 4 Is it
ready for prime time yet?

60 The 10 best media players


Here’s how to play music and video on
your Raspberry Pi

62 10 Amazing media player


projects
The best ways to groove, dance, chill, and
more using a Raspberry Pi
46
FEATURE

BU I L D T H E U LT I M AT E

MEDIA
CENTRE
Create the ultimate media box
using just a Raspberry Pi

R
aspberry Pi is capable of many things, and we’ve
built a lot of projects with one. Having several
Raspberry Pi computers performing similar
functions seemed a littler redundant to us, though,
which gave us a brainwave – what if we could combine
multiple uses into one amazing project?
Thus we decided to see how many media services we
could squeeze into just one Raspberry Pi 4. Luckily, the
majority of the tools are already available – you just
need to know how to combine them all. Get ready for
the perfected media experience.

06 Build the ultimate media centre


www.dbooks.org
FEATURE

Parts list
Everything you need to put together your ultimate media centre

REQUIRED OPTIONAL
Case (Argon One M.2)
£42 / $45 magpi.cc/argononem2

M.2 storage drive

Ethernet cable
Raspberry Pi 4
£34 / $35 magpi.cc/raspberrypi4

Official Raspberry Pi
4 power supply
£8 / $10 magpi.cc/psu4 Raspberry Pi
TV HAT
£20 magpi.cc/tvhat

Mini Remote Control


£5 / $6 magpi.cc/miniremote

Game controllers
Wireless
keyboard

HDMI cable

Removable
USB storage

16GB
microSD
Flirc USB card
£20 / $23 magpi.cc/flircusb

Build a Raspberry Pi Media Player 07


FEATURE

Set up your system


Build your media PC and install RetroPie

PUT IT TOGETHER manual that comes with the Argon One shows
you how to add the daughterboard to Raspberry Pi
Install RetroPie
01 We’re using RetroPie. This software allows
and then install it into the case with some screws.
Follow these instructions, and keep the power
you to emulate several game systems, as well as button pins in the default position.
installing Kodi under it for video and music. You’ll
need to burn your microSD card manually for this
– we advise using Raspberry Pi Imager (download
Hook it up
it from magpi.cc/imager). It’s easy to use: click
‘Choose OS’, select RetroPie, then choose the
03 For first-time setup, we recommend
‘RPI 4/400’ version for Raspberry 4 and 400. Then connecting a USB keyboard, along with having it
click ‘Choose SD card’, select your microSD card. connected to a monitor instead of a TV for comfort
Finally, click ‘Write’. – however, connecting it to your
selected TV is also fine. If you
also plan to use a wired game If you want
controller, connecting it now to add an M.2
Install Raspberry Pi SSD drive for
02 We’re using the Argon One M.2 case for a
is also a good idea. The last
thing to connect should be
increased internal
storage, do
few reasons – it’s secure, it keeps your Raspberry the power supply. so now!
Pi cool, it can use a Nanosound DAC if that’s your
thing, and it routes all the inputs to the rear of the
case. Because it has all these bells and whistles, it
INITIAL SETUP
does take an extra step to install. The instruction

First boot
01 With a power supply plugged in and
switched on, press the power button on the back
of the case to boot up your Raspberry Pi. RetroPie
will do some initial automated setup stuff, then
ask you to configure your games controller

Raspberry Pi Imager makes it easy to install Press the relevant buttons to configure your games
RetroPie – choose the RPi 4/400 version controller; hold any button to skip a function

08 Build the ultimate media centre


www.dbooks.org
FEATURE

For troubleshooting
and tips on specific
controllers,
especially for Sony,
Microsoft, and
Nintendo consoles,
look at the docs:
retropie.org.uk/
docs

Select the Configure WiFi option from the RetroPie menu and enter your network details

buttons. If you don’t have a controller connected


yet, you can press F4 on the keyboard to get to
the main menu. If you’ve run out of buttons to
Stream from Steam
assign, hold down any button and it will skip the RetroPie allows you to use Steam Link
software to stream games from a gaming
function. Keep doing this until you get to the end,
PC straight to your TV! To do this, go to the
and confirm ‘OK’ to finish.
RetroPie menu and then RetroPie Setup.
If you’re using a wired network and controllers, Go down to Manage Packages and choose
you can stop here! Just add ROMs over the Experimental Packages from it. In that list will
network or via a USB stick to play games! be ‘steamlink’ – install it and it will then appear
in the main games menu, ready for you to start streaming from a gaming
PC running Steam with Remote Play on.
Make sure you turn the
controller on just after
the reboot 03 Bluetooth controllers
Press F4 and you’ll open the command line.
From there, make sure Bluetooth is installed using
Wireless connection
02 If you don’t intend to use an Ethernet
the command:
Install Argon
connection, you can connect to your wireless sudo apt install pi-bluetooth ONE software
network in the RetroPie menu. Select ‘Configure
To install the fan
WiFi’ and it will open a text Type exit to return to the graphical interface. Go control to the
menu. Select ‘Connect to To to the menu and select Bluetooth Configuration. system, press
WiFi’ and choose your transfer Select Register and Connect Bluetooth Devices F4 to get to the
network from the list. ROMs over the while your Bluetooth controller is in pairing command line, and
network, go to enter the following:
Enter your password and mode, then select it from the screen and follow
\\RETROPIE in the
hit OK – you may need Windows File Explorer, or
the pairing instructions. Once connected, you
curl https://
to wait a moment or two, smb://retropie on Mac, may need to reboot your Raspberry Pi before download.argon40.
but it should then be and open up the configuring the buttons – make sure you turn the com/argon1.sh |
fully connected. roms folder controller on just after the reboot. bash

Build a Raspberry Pi Media Player 09


FEATURE

Configure Kodi
Go beyond games to stream your own media files over a network

Install Kodi
01 Kodi is our preferred media centre software
overscan issues. Find them in the settings menu,
and be sure to give the name of the system an
for watching video and playing music, and you can update if you want to as well so you can identify it
install it to RetroPie. Once again from the RetroPie on your network.
menu, go to RetroPie Setup and then Manage
Packages, Optional Packages. From there you’ll be
able to install Kodi – although it may take a while.
Add networked sources
Once installed, you’ll find it in the Ports menu as
an option after a reboot.
03 The easiest way to access media (videos,
music, or pictures) over your local network is
to add them as media sources. Head back to the
settings meny from the top of the interface. From
Setup Kodi
02 Kodi will be automatically set up after
there, go to File Manager and select Add Source.
You’ll be able to browse your available networked
installation, however you may want to change machines, or alternatively write in
some settings, especially if you’re experiencing the SMB route if you know it.

To go back
to RetroPie from
within Kodi, go to the
shutdown menu from
Kodi (top left) and
choose ‘exit’

10 Build the ultimate media centre


www.dbooks.org
FEATURE

With the
settings configured
for the app, you’ll also
be able to control Kodi
from your browser. Find
out more here:
magpi.cc/kodiweb

Using IR remotes
The Flirc USB dongle allows you to program specific
media commands into itself from another computer
before plugging it into a media centre. You may
need a USB extender so it’s visible, though!

The Argon ONE case does have an IR receiver, but


it seems to have a couple issues with working at
the moment. You can always try installing the IR
software with argonone-ir from the command line,
as there will likely be a future update for it.

The first time you start


Kodi, you’ll have to do
a basic setup

Smart device Watching TV


remotes With a Raspberry Pi TV HAT, you can watch and record TV using Kodi. You
can have it streaming TV via a different Raspberry Pi if you don’t have an
You can also control Kodi using Android and iOS aerial socket near your home theatre, or have it as a server and viewer
devices, and there’s an official app for it as well, from the same device. We have a full guide you can find here:
which you can find here: magpi.cc/kodiremote. magpi.cc/tvhatguide.

While it’s downloading to your desired device, The system uses Tvheadend to configure it all.
you’ll need to tell Kodi to allow you to use it. You’ll need to make sure you have a decent
From the Settings menu, go to Services and find amount of storage attached if you
the Control option. From this list, you want to turn plan to record TV.
the following options to ON: ‘Allow programs on
other systems to control Kodi’, ‘Allow control of
Kodi via HTTP’, and ‘Announce these services to
other systems’. A Raspberry
Pi TV HAT
Open the app and you should be able to select enables you
to watch and
the name you gave your Kodi setup from the list record digital
and immediately start controlling it. terrestrial TV

Build a Raspberry Pi Media Player 11


FEATURE

Essential add-ons
Get streaming services and TV running on Kodi for the full smart TV experience

Warning!
Unofficial Add-on
Check that Netflix
add-ons like this are
legal in your region.

Catch your
favourite Netflix
shows and movies
on Kodi using a
third-party source

INSTALL NETFLIX from repository’, where you’ll find an option for


CastagnaIT Repository for Kodi. Select it, then
Get the source
01 While Kodi doesn’t have an official Netflix
Video Add-ons, and you’ll see the Netflix add-on.
Go to install it, choosing the latest version, and say
add-on, you can easily add a third-party one OK to extra stuff that will be installed.
that allows easy access to the streaming service.
First of all, head to Settings and go to System.
Scroll down to Add-ons and turn ‘Unknown Go to install it, choosing
sources’ to on. Go back and head to the File
Manager – go to Add Source and enter the
the latest version, and say
following address:
OK to extra stuff
https://castagnait.github.io/repository.castagnait/
Using Netflix
Call it ‘netflix’ to make things easier.
03 You may need to add extra software for
Netflix if you’re having issues. Exit Kodi, and press
F4 in RetroPie to access the command line. Enter
the following:
Install the add-on
02 From the Settings menu, go to Add-ons sudo apt install python3-pip
and scroll down to ‘Install from zip file’. As pip3 install cryptodome
‘netflix’ is now a source, you can select that to find sudo apt install libnss3
a file called repository.castagnait-x.x.x.zip to
download. Go back to Add-ons and go to ‘Install Head back to Kodi and Netflix should launch.

12 Build the ultimate media centre


www.dbooks.org
FEATURE

Listen to your favourite tunes with an


unofficial Spotify add-on for Kodi

INSTALL SPOTIFY
Spotify source
01 There isn’t an official Spotify app on Kodi,
so you’ll need to install from a third-party source
like with the Netflix add-on, although this one
you’ll need to transfer from another computer.
Install YouTube
Head to magpi.cc/spotifykodi on a computer and Unlike Spotify and Netflix, this one is a bit
easier – a YouTube app is available in the
download the zip file from the link under ‘Install
standard Add-ons list for Kodi! From the
with repository’. If you’re able to transfer it to
Add-ons menu, go to Download, Video
your media PC over the internet, do so, or load it Add-ons, and scroll down to YouTube.
to a USB stick and plug it into the media box we’ve Install it from there and it will live in the
been building. Add-ons menu from now on. Like the
other apps, you’ll have to use the standard
Kodi interface to navigate it.

Install source and add-on


02 Like with Netflix, head to Settings, Add-
Configure and use Spotify
ons, and ‘Install from zip file’. Head to the folder
you downloaded it to, or go through the USB
03 Use the Configure option from the screen
storage you’re transferring it with to find the where you installed the Spotify app and enter your
zip file. Head to ‘Install from repository’ and go Spotify login details. Once that’s done, head back
to Marcelveldt’s BETA repository. Go to Music to the home screen and you’ll find Spotify under
Add-ons and then install the Spotify app from the Add-ons menu. Open it to start browsing and
there. If you’re having trouble installing, you may listening – once again, it will use the standard Kodi
need to disable the Netflix add-on and restart. interface instead of the usual Spotify one.

Build a Raspberry Pi Media Player 13


Contents BUILD THE ULTIMATE HOME SERVER

Build the ultimate


home server with
Raspberry Pi

Creating your own media server, media centre, HTPC, or whatever you
want to call the box under your TV has never been easier. We have a
comprehensive guide on how to create and optimise your perfect project.

16 Build the ultimate home 28 Ultimate home server:


server enhance your network
Centralise your files in this all-in-one Improve your home network with these
file server for all your media, and more tips and tricks

20 Ultimate home server: 32 Ultimate home server:


sharing and storing files Backup and UPS
Set-up local file sharing and increase Keep your media safe locally and
the storage on your home server backed up to the cloud

24 Ultimate home server:


add sound and vision
Install Plex ad Mopidy and enjoy your
media anywhere

14

www.dbooks.org
TUTORIAL

Ultimate home
Part 01

server: assemble
your equipment
Revolutionise your home network with shared storage, media serving,
network management, home automation and more. All in one tiny box!

PJ Evans
MAKER

PJ is a writer,
software engineer
and tinkerer. His
server has just told
him it’s time for
another coffee.

twitter.com/
mrpjevans

The rear of the case


organises all the
ports neatly and the
bridge connects the
M.2 drive to your
Raspberry Pi 4

R
aspberry Pi also makes a great home protecting your data, you’ll need at least 4GB for
server. Why do you need a home server? it to work effectively. Then consider what the
Well, there’s all kinds of uses: file sharing, server will be doing. Serving files doesn’t require
protecting your network from dodgy advertisers, much effort and is well within the capabilities of
controlling your smart devices; the list goes on. In Raspberry Pi Zero, and we strongly recommend a
this new series, we’ll build a home server with all wired network connection.
You’ll Need the bells and whistles to inspire you to create your
own ultimate build, with plenty of ideas and tips
> Raspberry Pi 4
along the way.
magpi.cc/
Choose a case
raspberrypi4
02 Our Raspberry Pi 4 needs a good home
> Argon One M.2 case
Choose the right model
magpi.cc/
argononem2
01 It’s probably no surprise that we’re using
if it’s going to be a server. There’s no shortage
of cases available and if you’re lucky enough
a Raspberry Pi 4 with 8GB RAM model for our to have a 3D printer, many more designs are
> 1TB M.2 SATA
ultimate server. It’s the most powerful Raspberry available for download. Have a think about storage
SSD drive
magpi.cc/ Pi. However, you can go for lower memory sizes requirements such as additional disks or access to
wdbluem2 and get similar performance. If you’re interested USB or GPIO connectors. We’ve chosen the Argon
in using advanced file systems like ZFS for One case. Not only is it beautiful, it also features

16 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

The Argon One is an attractive


and practical case for a server

Wired Ethernet reduces load


on your wireless network
helping speed and reliability

passive cooling (as well as a fan) and support for 3B, and Compute Modules 3+ and 4. However, you
M.2 storage devices. As a server is intended to be will need to update the bootloader on these devices.
running 24/7, make sure your choice of case is well See magpi.cc/bootloader for info and instructions.
ventilated and will be placed where it can ‘breathe’.

Argon assemble!
Top Tip
Choose storage 05
03 The standard application for a server is file
Now we have the computer, case and storage,
it’s time to put them together. The Argon One
USB drives
sharing: the ability for anyone in your household to comes with a comprehensive installation guide. Add If you’re going for
access a library of files. If you’re thinking of a media the expansion board to bring all the connections mass storage and
server, consider carefully what type of storage to use to the rear of the case, then mount in the case as fancy adding an
array of drives,
and how much you need. Movies, especially in high- instructed, using the supplied thermal pads to
don’t forget a
definition formats, eat up a lot of space but don’t get a good connection between the board and the powered USB
require fast storage to play back reliably. We’re heatsink. Install your M.2 SSD drive in the lower hub to avoid
making use of the Argon One’s M.2 interface to add part of the case, then screw the two halves together. undervolting –
1TB of fast SSD-based storage, but you may prefer The M.2 SSD device is connected to Raspberry Pi 4 this can damage
one or more USB SSD drives. Using a microSD card using an external USB-to-USB bridge. your data
and hardware.
is still an option, but slower and less reliable.

Prepare the operating systems


Update your bootloader 06
04 By default, a Raspberry Pi 4 and Raspberry
Preparing an M.2 SSD device is identical to
preparing an SD card, but connecting the M.2 device
Pi 400 will try to boot from the microSD card and may be tricky. Either purchase an inexpensive M.2
then from a USB attached drive. So you will not need to USB device or start with an existing Raspberry
to do any additional tweaks to get the M.2 drive Pi build and use Argon One M.2’s USB bridge to
working. USB boot is also available on most other connect it. Then use Raspberry Pi Imager to ‘burn’
Raspberry Pi models, including Raspberry Pi 2, 3A, a Raspberry Pi OS disk image onto the SSD device so

Build a Raspberry Pi Media Player 17


TUTORIAL

The aluminium case connects to the CPU and memory


using thermal paste to act as a giant heatsink

The Argon One’s it’s ready to boot. As this is a server, we don’t need network. If you didn’t do this, set up your hostname
clever expansion
board brings all the a graphical user interface, so we can keep things by running sudo raspi-config from a Terminal.
connectors to the lightweight. Using Raspberry Pi Imager, select You can also set up networking here if you need to.
back and converts the
HDMI ports to full-size Raspberry Pi OS Lite and check out the advanced Update everything with:
menu (CTRL/CMD+SHIFT+X) to set things like
hostname and networking before burning the sudo apt update && sudo apt -y full-upgrade
image to the card. We are naming our hostname
‘ultimate’ so it is easy to find on the network.

Boot from microSD


Top Tip 09 There is an argument to be made for still
Networking choices
07 Full-time servers are not normally connected
using a microSD card as the primary boot device.
This dedicates your M.2 SSD to data only. In the
Which M.2?
to your network over wireless LAN. Whilst wireless event of an operating system failure, your data
Be careful when is a great technology for end-users, servers crave can still be accessed by removing the SSD drive.
selecting your M.2 reliability and the best way of delivering that is a Likewise, if you need to increase your storage
SSD. The Argon wired Ethernet connection. We recommend placing capability, you avoid having to rebuild your
One supports your server close to your home broadband router operating system from scratch. If you want to take
SATA devices,
(or whichever device handles your network traffic). this approach, make sure your bootloader prioritises
not newer
NVMe types.
That way, the network is not trying to handle two the SD card (you can check in raspi-config >
wireless conversations: one between you and the Advanced Options > Bootloader Version). You will
router and another between the router and the you’ll need to partition and format the second USB
server. Wired will be much faster and reliable. If drive with an ext4 file system.
this isn’t an option, don’t worry: it’ll still work, but
larger files may be slow to transfer.

Fan and power button support


10 The Argon One case incorporates not only
Boot time
08 Let your server boot for the first time,
passive cooling but also has a fan for keeping our
Raspberry Pi 4B nice and cool. It’s not the quietest
making sure no microSD card is inserted. Even if but does support active control. To install this, enter
you configured it as headless, it’s worth plugging the following command in a Terminal:
a monitor in so you can check everything is OK. It
will quickly reboot to resize the file system and then curl https://download.argon40.com/argon1.
start up. We used the Advanced menu in Raspberry sh | bash
Pi Imager to set the hostname to ‘ultimate’, so with
a wired connection we can ping ‘ultimate.local’ This will download the drivers and install them
from another computer to confirm it’s on the automatically. The fan will now adjust its speed

18 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

We recommend placing
your server close to your
home broadband router
based on temperature. It will also allow the power
button to cleanly shut down after being pressed
for three seconds. To change these settings, run
argonone-config from the command line.

sudo usermod -a -G adm, dialout, cdrom, The lower part of the


case accepts an M.2
Access from other devices
11 Let’s go back to networking. Our server’s
sudo, audio, video, plugdev, games, users,
input, netdev, gpio, i2c, spi <name>
SSD for large
storage needs

hostname is ‘ultimate’, so using the ZeroConf DNS


system (aka mDNS), it should be on the network as You should now be able to log in as your new user.
‘ultimate.local’. To test this from another machine, You can create as many of these as you need.
run ping ultimate.local from the command line
and see if you get a response from the server. If
you get no response, check your network settings
Create and exchange SSH keys
on Raspberry Pi using sudo raspi-config. If using
wireless LAN, try a wired connection instead. You
13 A fast and secure way to log into your new
can also use utilities like Fing (fing.com) to see if server is SSH key exchange. If you anticipate lots
your server has acquired an IP address. (Note that of logging into your new server with SSH, this is an
versions of Windows prior to 10 do not natively essential step. If you’re using Windows, start by
support .local addresses.) installing the free OpenSSH client from Microsoft’s
instructions (magpi.cc/msopenssh).
From a command line, first generate your keypair
(if you don’t already have one):
Create a user
12 All Raspberry Pi operating systems start with ssh-keygen
a pre-installed user called ‘pi’. So we can share files
and manage permissions, it makes sense to create This stores a public and private key in your home
our own user accounts. To do this, open a Terminal directory under ~/.ssh.
as the ‘pi’ user and run this command: Copy your public key over to your server:

sudo adduser <name> ssh-copy-id <name>@ultimate.local

...where <name> is the username you would like ...where <name> is the username you created
(avoid spaces and special characters). It will ask previously. Now you can log into your server
you a few optional questions about your full name without a password using SSH:
and location. Finally, you can set a password
(be sensible!). ssh <name>@ultimate.local

To give the user ‘super user’ or ‘sudo’ rights: If your local username matches the server’s, you
don’t even need to include it or the ‘@’.
sudo adduser <name> sudo

To give the new user all the same permissions as the You’ve now got the basis for building a powerful
‘pi’ user: home server. In the following tutorial, we’ll move
on to the most useful aspect of any home server:
sudo usermod -a -G file sharing.

Build a Raspberry Pi Media Player 19


TUTORIAL

Ultimate home
Part 02

server: sharing
and storing files
Sharing and storing large files on your network equals lots
of fun and productivity without filling up your computer
PJ Evans

“H
MAKER

ave you got that file? Can you email it to available to us. It makes sense to choose a
PJ is a writer,
me?” “But it’s 10GB! It’s too big!” We’ve protocol that is supported by as many different
software engineer
and tinkerer. His all been there. If you’re in a house full of platforms as possible, such as Linux, Windows,
server needs to go data-hungry family members, or working in a small and macOS. The de facto standard is SMB (Server
on a diet. business where a single repository of information Message Block) and the software that implements
twitter.com/ would be enormously helpful, then a file-sharing SMB on Raspberry Pi OS is called Samba.
mrpjevans device (sometimes called ‘network-attached Installation is simple:
storage’ or NAS) is what you need. We’re going to
take the Argon M.2 Raspberry Pi server we have sudo apt -y update && sudo apt -y upgrade
built and add file sharing and increase disk capacity sudo apt install samba
so there’s plenty of room for all your stuff.
If you get asked a question about WINS, just
Choose the right model
Identify your drive
01 To create our ultimate file sharing device,
say no. After installation completes, you have a
running file server, but with nothing configured.
carefully before we need to install some file-sharing software.
removing and
creating partitions There are many different protocols and options

Prepare your sharing location


02 The next choice to make is where to store
the files that we wish to share on the network.
There’s no hard and fast rule on this. You can use
your user’s home directory or create a dedicated
area. We’re going to create a new directory under
/var, which is an area in the Linux file system
designated for files that will ‘vary’.

sudo mkdir /var/shared

We’re now going to allow any user to read and


write files in that area:

sudo chmod -R 777 /var/shared

Putting the ‘welcome mat’ down like this is


not considered best practice, but it serves our
purposes. For critical implementations, investigate
more granular read/write settings.

20 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

You’ll Need
Adding an external drive
> Raspberry Pi allows for massive storage Our operating system is stored
ultimate server
and easy upgrades on the hidden M.2 card
magpi.cc/108

> 4TB Western


Digital USB 3.0
external drive (or
similar) magpi.cc/
wdelements

> Powered USB hub


magpi.cc/usbhub

DOWNLOAD
THE FULL CODE:
magpi.cc/uhssmbconf

Configure Samba
03 We need to tell Samba to share our
Take care to indent the code correctly. These
lines set up the most basic kind of sharing. Save
new directory. All the sharing settings and the file and exit the editor (CTRL+X), then restart
configuration options are stored in the file Samba so the new configuration is picked up.
/etc/samba/smb.conf, so open that up in an editor:
sudo systemctl restart smbd
sudo nano /etc/samba/smb.conf

This is a large file, but don’t be put off: we’re just


going to add to the end of it. Add the text shown in smb.conf
the code listing for smb.conf.
> Language: Config / Bash

Getting connected 001.


002.
[Shared]
comment = Shared
003. path = /var/shared
004. read only = no
How you connect to remote servers varies by platform, but we’ll cover some 005. browsable = yes
common ones here.

• Raspberry Pi Desktop: Open the File Manager, click ‘Go’ in the menu bar, Configure your users
click ‘Network’, select ‘ULTIMATE’ (or whatever you named your server), 04 Security constraints mean Samba cannot
click the ‘Shared’ directory, and enter your credentials (leave the domain
as WORKGROUP). check your password when you connect. To
• macOS: Open Finder, click on ‘Network’ on the sidebar, select ‘ULTIMATE’ mitigate this, you can set an additional password
(or whatever you named your server), click ‘Connect As…’, then enter your for Samba access. This can be the same as your
username and Samba password. Click ‘Shared’. regular password for something different. To add
• Windows: Open File Explorer and right-click on ‘This PC’, then select ‘Add a your user account to Samba and set your access
network location’. You’ll go through a short wizard; when asked which server
password, just run the following command:
to connect to, enter \\ULTIMATE\Shared and enter your username and
Samba password.
sudo smbpasswd -a <user>

Build a Raspberry Pi Media Player 21


TUTORIAL

...Where <user> is your current username or any command (assuming your external drive’s logical
other username that needs Samba permissions. name is /dev/sdb): Top Tip
Enter your new password twice and you’re ready
to go. sudo fdisk /dev/sdb RAID

FDISK is a utility for managing your disk’s partitions Did you know you
- the areas where data can be stored. can use multiple
disks to provide
Get yourself connected
05 Samba is now ready for use. You can also
Now complete the following steps (note that
this will erase any data on the disk). Repeatedly
protection against
drive failure?
mount shared drives from the command line in enter ‘d’ followed by RETURN to delete any current RAID is a system
Raspberry Pi OS using smbmount, or connect to partitions until you get a ‘no partition’ error. Enter for keeping two
your Raspberry Pi from another computer on your ‘n’ followed by RETURN to create the new partition, or more drives in
network – see ‘Getting connected’. accepting all the defaults. Enter ‘w’ to write the constant sync, so if
one fails, the other
changes to the disk and exit
has your data!

Adding more storage Format the disk


06 Now you have a shared drive up and
09 Once a disk has been partitioned, it needs
running, you may want to load it up with videos, a file system. There are many to choose from, but
audio, and more. Soon you may need more space a popular choice in the Linux world (and therefore
than our M.2 drive provides. You may also wish Raspberry Pi OS) is ext4. To start, we need the
to consider separating data and the OS onto partition name. If you have a look in the device
different disks so it’s easier and safer to perform directory (ls /dev), you will see that sdb (our drive)
upgrades or expansions. Thankfully, the powerful has been joined by sdb1 (our partition). To format
USB 3.0 ports on Raspberry Pi 4 are perfect for the partition:
adding inexpensive larger external drives, such
as the whopping 4TB Western Digital drive we’ve sudo mkfs.ext4 /dev/sdb1
chosen. If you want to go for multiple drives, we
recommend a powered USB hub to make sure there This will probably take a few minutes to run based
are no ‘brown-outs’ that could cause lost data. on the size of the disk.

Identify the new drive Mount the disk


07 When you plug in a USB 3.0 external drive,
10 To access your fancy new drive, you need
Raspberry Pi OS will recognise it and add it as a to ‘mount’ it. This is Linux-speak for making the Windows supports
connections too, but
new device in the /dev directory. We need to find formatted partition available as a directory on the it’s a little tricker
the assigned name of the device. Typically it will
be /dev/sdb, but not always. We can check with
this command:

sudo fdisk -l

The output will show two physical devices, labelled


as ‘Disks’: your M.2 drive and the new external
drive. It should be easy to tell them apart by the size
and manufacturer name. Look for the ‘logical name’
of the external drive and make a note of it.

Partition the disk


08 To create a suitable file system, we first
need to partition the new disk. Run the following

22 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

smb.conf (part 2)
> Language: Config / Bash

001. [Huge]
002. comment = Huge
003. path = /mnt/huge
004. read only = no
005. browsable = yes

sudo nano /etc/fstab

Carefully append the following line:

DOWNLOAD UUID=c13507ef-190d-400d-9fc0-96f7cedea521
THE FULL CODE: /mnt/huge ext4 rw,user,auto 0 0
magpi.cc/uhssmbconf2
This is an example UUID: Make sure everything
after UUID= is the UUID of your new drive. Save and
reboot. Your drive should be automatically mounted.
Our server connected system. The first step is to create an ‘endpoint’: a
to an external drive
folder that will act as the gateway to the new disk.
The normal directory to use for this is ‘mnt’. To access your fancy
Top Tip sudo mkdir /mnt/huge new drive, you need to
Data danger! You don’t have to call it ‘huge’ – use any name you
‘mount’ it
like. You only have to do this once; the folder will
Using FDISK and
persist like any other.
MKFS can cause
data loss. Check
To mount the drive:
Share the disk
all your device
logical names are sudo mount -t ext4 /dev/sdb1 /mnt/huge
12 The final step is to let Samba know about our
correct and that new disk. Set the permissions and edit the Samba
there’s no data on That’s it. Any files written into that folder will be config file as we did earlier:
the disk that you
placed on our new disk. To unmount:
need to keep.
sudo chmod -R 777 /mnt/huge
sudo umount /mnt/huge sudo nano /etc/samba/smb.conf

At the bottom of the file, add a new line and add the
contents of the smb.conf (part 2) listing. Save the
file and exit (CTRL+X). You can now restart Samba
Automount on boot
11 The problem with the mount command is
to start the share without rebooting:

that it will not persist after a reboot. You can add sudo systemctl restart smbd
a mount command to something like rc.local, but
the best way to deal with this is to add the drive to Now try mapping from a remote device. All being
the file system table (fstab). This is a dangerous well, you now have a huge amount of storage at
step as a misconfigured fstab can make your your disposal.
Raspberry Pi unbootable. First, get the UUID of
your new drive. Run this command:
We’ve now got our server sharing files across your
sudo blkid network. So, what else can you do with an always-
on device? In the next tutorial we’ll look at one of
Find the line containing our new drive (/dev/sdb) the most popular applications: media streaming.
and copy the list of numbers and letters quoted in
UUID=“”. Now edit the table:

Build a Raspberry Pi Media Player 23


TUTORIAL

Ultimate home
Part 03

server: add sound


and vision
Turn your server into a media powerhouse with Plex and Mopidy

PJ Evans
MAKER

PJ is a writer,
software engineer,
and tinkerer. His
ambient music
collection has
been described
as “inspiring” (PJ
Create as many Plex provides a beautiful
Evans) and “just libraries as you like playback experience and
a load of random by dividing media won’t say a word about
noise” (Mrs Evans, into directories your musical taste
music teacher).

twitter.com/
mrpjevans

S
ound and vision is where we’re at for our on startup. Reboot and then issue this one simple
ultimate server project in this tutorial. Sure, command in the terminal:
serving files is all very well (see the previous
tutorial) but what about a decent media interface? df -h
Luckily we’re spoilt for choice. We’re going to add
two media serving solutions, Plex and Mopidy, to our The ‘df’ command is short for ‘disk free’ and
server. Plex is a great choice for playing back your shows you a summary of disk usage. If all is well,
media anywhere in the world and Mopidy can turn you’ll see the external drive (partition sdb1) mounted
your server into a jukebox as well as a multi-room to /mnt/huge (or whatever you decided to call the
audio streaming system. We’ll also look at how to mount point). If /mnt/huge does not appear in the
create your file structure and how to add content list, refer back to the previous tutorial and make sure
You’ll Need from different sources. Let’s hit the play button. the entry in /etc/fstab is correct.

> Raspberry Pi
ultimate server
magpi.cc/108
Check, check, and check again Set up your library
> Plex magpi.cc/plex 01 Before we plunge into the world of media
02 Media streaming tends to involve a lot of
> Mopidy streaming, let’s make sure your ultimate server is files. Before you find yourself in a mess, take some
magpi.cc/mopidy correctly configured as per the previous tutorial. time to consider how you would like to structure
We want to be sure our external drive is mounting all your media. How you do this is up to you, but

24 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

you want to get the best quality possible, consider


buying in FLAC format (no lossy compression)
The command from services such as HDTracks (hdtracks.com) or
df -h shows that the
Qobuz (qobuz.com).
external drive has
correctly mounted

when it comes to ripping CDs, many encoders such


Going to the movies
as abcde (A Better CD Encoder, magpi.cc/abcde)
will automatically rip to a given structure, so it can
04 Adding mainstream movies can be a bit
be helpful to plan this out now. See Figure 1 for challenging as there are no legal vendors of DRM-
an example of a well-laid-out file structure. Don’t free movies. However, you can use Plex’s own free
feel that you have to follow this – if you would streaming service to access content with a wide range
prefer more complex (or simple!) divisions, that’s of (sometimes cheesy) movies to watch, as well as

Top Tip completely up to you. video podcasts. You can also use plug-ins to access
all of YouTube. Of course, if you have a collection of
home movies, it’s a great way to get them up on the
Quickly copy big screen.
your media Add some sounds
03 Now we have lots of fast USB 3.0 space to
Moving a lot of
media files over play with, we can add some media that we’d like to
Let’s Plex!
the network can
be very time-
stream. This is a massive topic in itself, so we’ll just
give you some pointers here. You can now legally
05 We’re going to install Plex, one of the most
consuming. Luckily, buy MP3s from many sources such as Amazon and popular media streaming services available. It
our USB drive
Apple. These are free from DRM (Digital Rights supports a dizzying array of file formats for both
can be mounted
Management), meaning you can play them back on audio and video. Plus, clever built-in transcoding
onto the source
machine for super- your Raspberry Pi media system without issues. If systems mean it can compress on-the-fly to ensure
fast copying. the smoothest of playbacks. All with a very friendly,
Remember, the good-looking user interface. Installation takes a few
host operating Figure 1 steps, so follow the commands in the install_plex.sh
system will need listing to add Plex’s repository, update, and then
a driver that
install and configure Plex. Once complete, we can
can understand
ext4 partitions. check Plex is running using this command:

sudo systemctl status plexmediaserver

You should see that Plex is ‘loaded’ and ‘active


(running)’. Press Q to exit and you’re ready
to configure!

First-time Plexing
06 When we installed Plex, it started a web
server on port 32400. So all you need to do is open a
web browser on another machine (or the server itself
if you’ve installed a desktop) and go to:

http://ultimate.local:32400/web

Figure 1 Here’s an (Replace the server name if you didn’t use


example of a sensible ‘ultimate’ when setting it up in part 01 of this series.)
directory structure
for your media files. What you should see now is the Plex welcome
Remember to create
screen. Be patient: it can take a few seconds on
it on your external
mounted drive the first run. To get the best out of Plex, create a

Build a Raspberry Pi Media Player 25


TUTORIAL

free account as prompted using an authentication


provider such as Google or just your own
email address.

Initial setup
07 Plex will take you through a short wizard to
get things set up. Start by giving your Plex server
a name; we’ve chosen ‘ultimate’ to be consistent.
You can also opt for access to your Plex library from
anywhere on the internet. Plex will attempt to open
a port on our home router so you can access your
media from the plex.tv website. If you don’t want
to do this, ensure the checkbox is clear. Click ‘Next’
to start adding your libraries. One-by-one, select a
library ‘type’ (music, movies, etc.) when navigating
to the corresponding folder on your external drive;
e.g. for ‘Music’, use /mnt/huge/Media/Music.
Once Plex is installed,
Streaming to headless devices
10 One restriction of Plex is that it requires
you need to add
each directory and
specify what type of
a device with some kind of interface to work and media it contains
Library management
08 Plex will now start scanning your folders for
plays audio to that interface. If we wanted to play
audio on the ultimate server itself, or stream to
content. It will also access online databases to add another Raspberry Pi computer that is connected to
metadata to its library to make your collection as speakers, we need to use Mopidy, a purpose-built
complete as possible. Depending on the size of your audio streaming solution. Luckily, Plex and Mopidy
collection, this process will take anywhere between can live side-by-side and even share libraries. To
seconds and hours. It’s a background process though, install Mopidy and its user interface, Iris, follow the
so you can start using Plex right away as your media commands in the install_mopidy.sh listing. Once
appears. You’ll also notice that Plex will also offer complete, you can access the user interface here:
you online content – you can disable this if you wish
or sign up for a ‘Plex Pass’ for a lot more features. If http://ultimate.local:6680/iris/
you don’t like what Plex has ‘found’ for your media
types, you can always click the pen icon and edit the
metadata; Plex doesn’t always get it right.
install_plex.sh DOWNLOAD
THE FULL CODE:
> Language: Bash magpi.cc/installplexsh
Access it anywhere
09 One of the great things about Plex is the 001. #!/bin/sh
002.
availability of its client applications. Not only is there
003. # Plex's repository uses HTTPS as the transport, so we need to
a rock-solid web-based interface (which works great install support
on Raspberry Pi OS’s Chromium) but support for a 004. sudo apt update
wide range of devices including PlayStation, Xbox, 005. sudo apt install apt-transport-https ca-certificates curl
Apple TV, Amazon Fire devices – and for mobile, iOS 006.
007. # Get Plex's public key and add the Plex repo
and Android. If you created an account earlier, all you
008. curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt
have to do is install the app and log in. Your ultimate key add -
server will be detected and added. Now you can 009. echo deb https://downloads.plex.tv/repo/deb public main | sudo
access and stream your media collection from any tee /etc/apt/sources.list.d/plexmediaserver.list
location on the internet.
010. # Install the server
011. sudo apt update
012. sudo apt install plexmediaserver

26 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

Mopidy is an
alternative to Plex,
designed for
local playback
and streaming

Warning!
Adding media to Mopidy
The laws covering the
ripping of CDs, DVDs
11 In the previous step we installed the
Add the following at the end of the file:

and Blu-rays vary from ‘local’ plugin, which allows Mopidy to access local [local]
country to country.
The private copying of file systems for media. One restriction is that it can media_dir = /mnt/huge/Media/Music
copyrighted material only support a single directory. Start by editing the
is illegal in the United
Kingdom. Check what config file: Remember to change this path if you’re using a
you want to do is legal different naming system or structure. Save the file
before proceeding!
sudo nano /etc/mopidy/mopidy.conf (CTRL+X), and instruct Mopidy to scan the contents,
magpi.cc/ripping
then restart:

sudo mopidyctl local scan


install_mopidy.sh DOWNLOAD sudo systemctl restart mopidy
THE FULL CODE:
> Language: Bash magpi.cc/installmopidysh Reload Mopidy in your web browser and the media
should be available. Now you can play music using
001. #!/bin/sh your server as the audio source should you wish.
002.
003. # Add Mopidy repo and install Advanced Mopidy
004. wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key 12 Now you have Mopidy installed, you can
add -
005. sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https:// upgrade to a few special features. Mopidy supports
apt.mopidy.com/buster.list a wealth of plug-ins and one of the most popular is
006. sudo apt update mopidy-spotify, which, you guessed it, turns Mopidy
007. sudo apt install mopidy
into a Spotify client (although you need a premium
008. sudo adduser mopidy video
009. account for this). Also, you can install Snapcast
010. # Configure (be careful with this line!) to create a synced multi-room audio system for a
011. printf "[http]\nhostname = 0.0.0.0" | sudo tee -a /etc/mopidy/ fraction of the price of solutions such as Sonos. For
mopidy.conf more detail and tutorials on all of this, check out The
012.
MagPi issues #96, #97, and #98.
013. # Install user interface
014. sudo apt install python3-pip
015. sudo pip3 install Mopidy-Iris
016. sudo pip3 install Mopidy-Local In the fourth part of this tutorial series, we’re going
017. sudo sh -c 'echo "mopidy ALL=NOPASSWD: /usr/local/lib/
to look at how Raspberry Pi OS can be put to work
python3.7/dist-packages/mopidy_iris/system.sh" >> /etc/sudoers'
018. to make your network a better place. Access your
019. # Enable and start service files securely from anywhere in the world, protect
020. sudo systemctl enable mopidy yourself from tracking ads, and more.
021. sudo systemctl start mopidy

Build a Raspberry Pi Media Player 27


TUTORIAL

Ultimate home
Part 04

server: enhance
your network
Make your ultimate server a network genie with these apps

I
n the previous parts of this tutorial, we’ve forward. The easiest way to do this is to ask your
PJ Evans taken a Raspberry Pi 4 and turned it into a router to reserve an IP address for your ultimate
MAKER

file sharing, media streaming powerhouse. server. We recommend you look at doing this
PJ is a writer, Next we’re taking on your network. There are before proceeding. Sorry for the vagueness, but
software developer
so many ways to enhance your home (or office) every router does this differently.
and tinkerer. His
server has just told network that we can’t hope to fit them into a few
him it’s time for pages. However, these steps will point you in the
lunch. This might be right direction and hopefully inspire you to make
getting out of hand.
Home control the easy way
twitter.com/
your home network smarter, faster, and more
convenient to use. Follow along and we’ll automate
02 Want to automate your home? Fancy being
mrpjevans
your home, allow you to access your data securely able to control lights or check a home webcam
from anywhere in the world, and automatically from anywhere in the world? How about if that
protect you from nefarious websites. software cost you absolutely nothing? Home
Assistant is an incredible package that integrates
a wide range of inexpensive smart devices such as
Philips Hue, Ikea Trädfri, and many more. Best of
Settle on an address
01 A key aspect for any server is that you
all, it’s open enough that you can create your own
activities and integrate your own projects relatively
should know where it is. It seems obvious, but easily. Installation on an existing server requires
a typical home network will assign IP addresses a few steps, but a great guide has been written by
dynamically (a system known as DHCP) and the HA team – magpi.cc/hacore – that we have
there’s a fair chance they will change from time summarised here: magpi.cc/hasummary.
Home Assistant can
control hundreds to time. We normally get around this by using
of IoT devices
zero-config domain names like ‘.local’, but we’re
with customisable
dashboards like this going to need a set IP address for our server going
Getting started with
03 Home Assistant
The first time you run Home Assistant, it’ll take
a few minutes or so to get its act together as it
installs everything it needs. HA will also scan
your network for any existing devices you have.
Once running, you can access the dashboard at
http://ultimate.local:8123 (change the name if
you didn’t call your server ‘ultimate’). You may
be surprised to see what is already detected and
available. If not, there are hundreds of plug-ins
to extend HA’s capabilities. Home Assistant is a
massive topic, so you may want to have a read of
our tutorial in The MagPi #99 (magpi.cc/99).

28 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

The Home Assistant app


allows you to monitor and
control all kinds of IoT devices

Our ultimate server now hosts a whole


suite of network features in a tiny case

Add an MQTT broker


04 We will absolutely forgive you if this title
sudo apt install mosquitto mosquitto-clients
You’ll Need
sounds like gibberish. MQTT is a very simple This will install Mosquitto and make sure it’s
> Raspberry Pi
protocol for sending messages from device running as a service at all times. To test it’s
Ultimate Server as
to device. It is loved by the home automation working, open two Terminal windows and run built in the previous
community, so it’s no surprise it’s well supported these commands, one in each: tutorials
by Home Assistant. The principle is simple: any
device can publish its data (e.g. a temperature mosquitto_sub -t "test"
reading) to an MQTT ‘topic’ (a label to describe mosquitto_pub -m "message from mosquitto_pub
the data stream). Then, any other device can client" -t "test"
‘subscribe’ to the MQTT topic and receive updates
in real-time. It makes brewing your own sensors If all is working, you will see a window ‘talking’
or switches so much easier as you don’t have to to the other. Now anything that generates MQTT
know about the target. messages can connect with you and your Home
Assistant server. Just add the MQTT integration in
HA and you can create graphs, alerts, and more.

A key aspect for any server


is that you should know 06 Adding remote access
Previously, we’ve configured our server to
where it is stream audio and video and now we can switch
lights, check the living room, feed the cat, and
more. So, if you’re not home, how do you do
A nice kind of mosquito
05 One of the most popular MQTT brokers (a
this? Remote access to your home network is
not something to take lightly, as if you can get
server that receives and broadcasts MQTT events) access, what stops someone else? The answer is
is Mosquitto. Installation is very straightforward: PiVPN, a script that installs a VPN (virtual private

Build a Raspberry Pi Media Player 29


TUTORIAL

A virtual private network) that you can connect to securely from a port mapping. Your router needs to forward all
network such as
Wireguard creates a anywhere in the world. Previously PiVPN only traffic to port 51820 (default) over UDP to your
secure encrypted link supported OpenVPN, which can be difficult to server. How to do this varies from router to router,
to your home devices
from anywhere work with, but now the much simpler Wireguard so search for your particular router’s instructions.
protocol is supported. To create users that can access the network,
run this command:

Top Tip Installing Wireguard


pivpn add

07 For lots of information on PiVPN and Give a username when prompted and a config file
Building
your Home Wireguard, head over to The PiVPN Project at will be created. Copy that config file to the device
Assistant pivpn.io. To get started with installation, run the you want to use to access the network and import
setup following command from a Terminal: it using the free Wireguard client software. Now
you can access your home network from a laptop
The Home curl -L https://install.pivpn.io | bash or smartphone from anywhere in the world.
Assistant
community
maintains a list of The installer will take you through a series of
compatible smart questions. An important point is to ensure you
Add a web server
devices. These
either work ’out
have a static IP address as your router will need
to know where to find your Wireguard server.
09 The fun thing about web servers is they
of the box’ or with When asked what type of server to install, are actually very simple things. You can place
a free plug‑in:
answer ‘Wireguard’. Continue through the a text file in the home directory and the server
magpi.cc/
installer, accepting the default answers. If you will happily serve it anywhere in the world. If
haplugin
don’t have a static IP address for your router, you you would like to be able to access files through
may need to consider a dynamic DNS service such a web browser, you can combine Wireguard and a
as DynDNS (account.dyn.com) so you can easily web server to make access both easy and secure.
reach your Wireguard service. As an example, we’re going to configure access
to the media library we have previously created.
First, install a web server:

Using Wireguard
08 Before you can use Wireguard to get secure
sudo apt install apache2

remote access to your network, you need to allow After that single line, you would be able to access
the internet to ‘see’ it. This is done by creating a simple welcome page at http://ultimate.local.

30 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

Adding directories to
10 your web server
It has a maintained blacklist of DNS servers
that are for advertising and intercepts any such
What a web server can provide you with is only requests. To do this, Pi-hole must be your DNS
limited by imagination. Let’s get simple access server. Here things get complicated. For best
to our music and videos, which are stored in results, your new Pi-hole server should also
/mnt/huge/Media. Apache has a complex be your network DHCP server (the server that
configuration system, but we’re going to play a allocates IP addresses to your local devices). This
little UNIX trick to make things easier: a symbolic requires some additional setup and we recommend
link. This allows us to map one part of the file you have a read of The MagPi #104 (magpi.cc/104).
system to another, creating a kind of short cut.

sudo ln -s /mnt/huge/Media /var/www/html/


Careful with those ports
media
13 A final warning. In this tutorial we’ve
Now you should be able to go to http://ultimate. talked about opening ports to the internet using
local/media/ and browse your files. It isn’t your router’s port forwarding features. You may
pretty, but it’s a start! Now you can connect to be tempted to just directly open ports to the
your network securely and access files easily. various services we’ve installed so you can get
access wherever you are. One tip: don’t. The
reason that services such as Wireguard exist is
Pi-hole can protect your to ensure that bad actors can’t find any easy way
to access your stuff. Wireguard uses state-of-
entire network, even the-art encryption. So long as your config file
is not compromised, you’re more than likely
your smartphone completely safe. If you open your web server
to the planet, we guarantee you will have bots
sniffing around trying to find access within
minutes. VPN isn’t easy, but it’s worth the time.
Avoid the dodgy advertising
11 One of the most popular Raspberry
Pi applications is Pi-hole (pi-hole.net), a
clever system designed to ‘sink’ internet Well, we’ve now built a pretty impressive server.
advertisements, leaving your browser clear of File sharing, media streaming, remote access,
noise. While we strongly recommend supporting network protection, and home automation. In
your favourite sites by allowing adverts, many the next tutorial we will look at how to protect
sites contain ads that are not only scams, all this hard work, and your precious data, from Pi-hole is a network-
wide ad blocker
but can lead to tricking you into downloading unexpected loss. that’s effective and
malware that can compromise your data. easy to use
Pi-hole can protect your entire network, even
your smartphone. To install it, simply run this
command from a Terminal:

curl -sSL https://install.pi-hole.net | bash

The installer will ask several questions, but is


well-designed and you’re probably going to be
OK to answer every one with the default answer.

Starting off with Pi-hole


12 Pi-hole works by looking at DNS requests.
These are requests to servers that map domain
names such as raspberrypi.com to actual servers.

Build a Raspberry Pi Media Player 31


TUTORIAL

Ultimate home
Part 05

server: Backup
and UPS
Now you have the ultimate server, let’s keep your
data safe with an uninterruptable power supply
PJ Evans
MAKER

I
PJ is a writer, f you’ve been following our home server We’re going to cover the three key pillars of
software developer
tutorials over the past months, you should server management: Backup, Reliability, and
and tinkerer. He
keeps several clones now have a pretty sweet Raspberry Pi- Monitoring. Luckily, these are not hard to achieve,
of himself in storage powered server up and running, with file even for a home setup, and you never know: there
just in case. sharing, media streaming, remote access, may come a day when you’re really glad you took
twitter.com/ and more. In this final part of our Ultimate the time to protect your investment.
mrpjevans Server tutorial, we’re going to look at protecting
both your hard work and all that data you have
entrusted to our favourite little computer.
Don’t be that person
RAID systems,
01 When you’ve completed a project like this,
like this RAID 10
it’s tempting to stop now and enjoy the fruits of
configuration,
protect against disk your labour. Sadly, the annals of computer history
failure and service
interruption by are filled with stories of those who did not heed the
duplicating data over warnings and didn’t back up. It’s caused heartbreak
multiple disks
when families have lost their photo libraries
and bankruptcy when companies have lost their
precious customer data. Never trust your data to one
single source, no matter how much you’ve spent, or
the reputation of the supplier. Think carefully about
how to keep your data safe, not only from hardware
or software failure, but also theft and disaster.

Three is the magic number


02 There’s a long-held mantra amongst system
administrators known as the 3-2-1 rule. You need
three copies of your data, on at least two different
media types with one off-site. Only then does
your data safely ‘exist’. This principle protects you
against hardware failure and physical problems such
as fire. Although this sounds initially complicated
or at least a faff to set up, don’t worry. Modern tools
have made this easier than ever before. We can get
your data to a healthy backed-up state without too

32 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

A simple way to keep data safe is


to have a second copy ready to go

You can theoretically add up to 256 disk


drives, but don’t forget a powered USB hub
even with just two, or you risk data loss

You need three copies of accident, you’ll be holding a parade through the
You’ll Need
streets when you realise you’ve got that data safe
your data, on at least two and sound on the second drive. All you need to
> Raspberry Pi
do is set up a regular backup routine to copy the
different media types contents of your first drive to the second.
Ultimate Server
(The MagPi issue
#107 to #110)
much work. What needs to be done is twofold: make magpi.cc/issues

sure the data is available elsewhere and that if you > Uninterruptible
Quick and easy backup power supply
delete a file, you can get it back.
04 Assuming you’re adding an identical USB (optional)

drive to your server, make sure you’ve partitioned > Additional USB 3.0
and formatted the drive identically to the original. external hard disks
(optional)
A local drive for local data
03 Let’s start with a very simple way of
See tutorial part 1 for details on how to do this.
Next, do an initial backup to ensure everything is
backing up your data. We connected a 4TB drive OK. This may take some time, depending on how
to our ultimate server for all our lovely files. much data you have. If your first disk is mounted to
The easiest thing to do is to double it so we can /mnt/huge and your new disk is /mnt/backup, the
mirror that data. Adding a second 4TB drive may command would be:
sound expensive for little benefit, but when your
original drive fails or you delete a critical file by sudo rsync -av /mnt/huge /mnt/backup

Build a Raspberry Pi Media Player 33


TUTORIAL

There are many


Let’s go offsite
uninterruptible power
supply (UPS) models 05 A central principle of a good backup policy
available that provide
a small footprint and is that at least one copy is nowhere near you. This
adequate time for
is to protect against all those things we really don’t
a clean shutdown,
perfect for home use want to think about such as fire, flood, theft, or
other types of damage. A wide range of services
exist to securely store your data for you for a
reasonable fee. If the worst happens, a copy of all
your precious data will be available to retrieve.
Some even offer a hard-drive-by-post service.
There are too many services to cover here, but
some tried and tested solutions for Raspberry Pi OS
Top Tip include iDrive, Amazon S3, and BackBlaze B2.

Time Machine
Not only can you Introducing iDrive
back up your 06 If you want to keep things easy, we can
ultimate server, but
recommend iDrive (idrive.com) as a contender. Not
it can back up your
only do they offer very attractive first-year terms:
Mac as well. Make
your file shares they are one of the few off-site backup companies
Time Machine- to offer full Linux (i.e. Raspberry Pi OS) support.
compatible by Although you’ll need to do some navigation of
following these Rsync will only copy changes, so it’s faster after the command line, you can install the iDrive tools
instructions:
the initial backup. To run this on a regular basis, and create a destination and a backup-set in a
magpi.cc/
add it to crontab (a schedule of regular jobs): surprisingly short amount of time. If you have a
timemachinegit
lot of data, the first backup may take some time,
sudo nano /etc/crontab but iDrive can throttle the bandwidth used. Once
uploaded, a regular incremental backup keeps you
Add this line at the end: up to date. Best of all, deleted files and different
versions of files can be archived.
1 12 * * * root rsync -av /mnt/huge /mnt/
backup > /var/log/backup.txt 2>&1

Home Assistant
The amazing rclone
can monitor your
server and your UPS,
This will run the backup every night at one minute
past twelve. You can change it to any time or to be
07 There are many services available that
triggering alerts
when necessary as (in)frequent as you like. offer some form of ‘block’ or ‘bucket’ storage.
Most popular is Amazon S3, but there are a
growing number of contenders such as BackBlaze
B2, Box, or Digital Ocean Spaces. Working out
how to communicate with all these can be a
challenge, but luckily rClone (rclone.org) knows
how to talk to over 40 different services. Sign up
for the service you want, get your credentials,
and configure rClone using its menus. Although
trickier to configure than iDrive, this can be a
very cheap way of backing up in the long term.

Let’s get physical


08 In the modern age of the cloud, this may
seem like an unnecessary step, but hear us out.
How far you go with backup is dependent on how

34 Build the ultimate home server with Raspberry Pi


www.dbooks.org
TUTORIAL

valuable you perceive your data to be. Typically,


photographs fall into this category: memories
that are irreplaceable. This is where the ‘two
types of media’ rule can come into play. If you
absolutely need that extra peace of mind, consider
either burning the data to good-quality DVD or
Blu-ray ROMs or, as many photographers do,
never reusing an SD card and archiving them
as you go. Many banks offer a cheap safety-box
service where you can store physical media.

As for off-site data storage,


there really are no
practical limits

Please don’t interrupt


09 Now backups are sorted, let’s look at
making sure you don’t need them. One of the
Two heads are better than one Companies like
classic causes of data loss is a sudden power cut.
This is due to the operating system constantly
11 Server reliability can often turn into a
BackBlaze and iDrive
offer cheap off-site
backup services so
writing and reading its storage and sometimes rabbit hole: when do you stop? The principles of
you know your data
caching reads and writes in memory (known as high availability (HA) will keep a server running is safe
‘journaling’). An inopportune power cut can use no matter what. If you really need to keep things
file system corruption and the loss of data. An ticking along, you need to eradicate every single
uninterruptible power supply (UPS) is a battery point of failure, and that includes the server
that can keep your server going during a power cut. itself. In the last step, we removed a single hard
In the case of a Raspberry Pi computer, sometimes drive as a point of failure. Using the principle
for hours. Best of all, they can communicate with of load balancing, we can remove the server as
your server over USB and invoke a safe shutdown well. Software such as Varnish can split the load
when the battery gets low, protecting your data. between two or more Raspberry Pi servers and if
Good UPSs for home use start at around £80. one fails, everything keeps on working. Magic!

Top Tip
Redundancy is a good thing Let it grow Remote
10 Another aspect of good server management
12 Nothing we have discussed here prevents Monitoring
is availability. If you have all your cool data on the your server from growing in the future. Modern
If you want to
server, you want to make sure it can handle failure RAID systems such as Z2 allow you to increase
monitor your
and keep going. Although the two-drive system disk capacity with no downtime. Using load- server from afar
will prevent data loss, it’s going to be a pain to balancing software such as Varnish means and have exposed
reconfigure everything. For a truly robust system, you can add in more servers, or replace failed a web server
you need a redundant array of inexpensive disks hardware, without anyone noticing. You’re free to the internet,
(RAID). This is a file system that allows a number to add more software and features whenever you services such as
uptimerobot.com
of disks to operate as one and can tolerate at want. As for off-site data storage, there really
will alert you if
least one drive failure. You can then replace the are no practical limits. Any time you need to
they can
drive and have the data protected again with no boost your hardware, it’s possible to do it with no no longer reach
downtime at all. The ZFS file system is especially interruption, again and again, truly making it the your site.
good at this. ultimate server.

Build a Raspberry Pi Media Player 35


Contents BUILD THE ULTIMATE HOME MUSIC SYSTEM

Build the ultimate


Home Music System
with Raspberry Pi
Add a digital-to-analogue (DAC) board to Raspberry Pi for the
ultimate sound system.

38 Get started with music


Create a digital jukebox using
open-source software

42 Add services: Spotify


& SoundCloud
Extend the capabilities of your music
system with Modipy extensions

46 Set up multi-room audio


Fill your home with sound using a
multi-room setup

www.dbooks.org
TUTORIAL

Ultimate home
Part 01

music: get started


Want your own whole-house audio without the price tag? In this three-part
series, we create a digital jukebox using open-source software

T
he ability to play music throughout your powered by a single connector. You can also use
home, in perfect sync and controllable two power supplies if you prefer. Mount the DAC
PJ Evans from your phone, has been around HAT on the GPIO pins and secure. We used 20 mm
MAKER

for a few years now. Many solutions are 2.5M screws to secure the HAT to the computer
PJ is a writer, available, from simple Bluetooth speakers and screen controller standoffs. Connect the
software engineer,
to high-end systems like Sonos. Often the 5 V and GND pins for the touchscreen to their
and lover of open-
source software. It’s price can be off‑putting and there has been partners on the DAC HAT.
his turn to choose recent controversy over the closed nature of
the next track, thank these systems. Can we build a whole-house
you very much.
audio system using nothing but open-source
@mrpjevans Prepare Raspberry Pi OS
technology and our favourite little computer?
This month, we’ll start by building a dedicated
02 The case prevents access to the microSD
music-playback station that can produce card, so make sure you’ve got a basic setup of
audiophile-level sound and web-based control. Raspberry Pi OS before assembling everything. For
this project we’re going to be using Chromium,
so we need the ‘standard’ OS image with Desktop
(but we don’t need the Recommended Software
Hardware assembly
01 The JustBoom DAC (digital-to-analogue
version). Burn this image with your preferred
method and make sure you’re connected to the
converter) HAT provides high-quality audio network with SSH enabled, or hook up a mouse and
output for our project. It also blocks the GPIO keyboard if you prefer. Finally, as ever, make sure
header, which we need to power the touchscreen. you’re running the latest version of everything
Luckily, the HAT has a GPIO breakout, so we with sudo apt update && sudo apt upgrade.
soldered a two-pin header to the 5 V and GND
for the touchscreen so the whole system can be

Mount into the case


You’ll Need 03 The Raspberry Pi 4B case used here will not
accept the assembly with the DAC HAT. If you’re
> JustBoom DAC
HAT magpi.cc/ not using a HAT, you can skip this step. Otherwise,
justboomdac carefully remove the two wall-mounting screw
> Official Raspberry Pi holes and then line up the HAT with the top
7″ Touchscreen ventilation spacers and remove any that are
magpi.cc/touch blocking the two phono sockets and the 3.5 mm
> Touchscreen Case socket from sitting flush in the case. Measure twice
magpi.cc/touchcase and cut once! The plastic is soft, so it’s fairly easy
to do. Once the assembly is sitting comfortably in
> Active speakers, e.g. Iris is a touchscreen-friendly, web-based interface for
magpi.cc/r1000t4 the case, you can screw in the touchscreen and it
Mopidy. It supports add-ons for popular platforms such as
Spotify and Soundcloud should now sit up securely.

38 Build the ultimate home music system


www.dbooks.org
TUTORIAL

This project is very flexible. We’ve


gone with some nice 25W active
speakers, but you can use whatever
suits your needs and budget

The Iris interface works


exceptionally well with
the touchscreen set up
in kiosk mode

04 Enable DAC output Luckily, the required drivers are


No sound will come from the DAC HAT by
default. Luckily, the required drivers are already already installed and waiting to
installed and waiting to be enabled. From the
command line, run the following: be enabled
Install Mopidy
sudo nano /boot/config.txt
05 Mopidy is a headless music server. This Top Tip
Find the line that reads: means it has no user interface of its own, so we’ll
add one later. To install Mopidy, we need to add its New album
dtparam=audio=on repository to APT. Run the following commands blues
one-by-one:
New music not
Remove the line (or add a # to the front to
appearing? Go to
comment it out), then add these lines: wget -q -O - https://apt.mopidy.com/mopidy.
Settings and then
gpg | sudo apt-key add - click ‘Run Local
dtparam=audio=off sudo wget -q -O /etc/apt/sources.list.d/ Scan’. If tracks still
dtoverlay=justboom-dac mopidy.list https://apt.mopidy.com/buster.list don’t appear, click
lcd_rotate=2 sudo apt update ‘Reset Cache’ on
the same screen.

That last line flips the screen if you’ve found, as Now install Mopidy and set its user’s permissions:
we did, that the touchscreen display is now upside
down. Reboot your Raspberry Pi computer and sudo apt install mopidy
from the command line, test audio output: sudo adduser mopidy video

aplay /usr/share/sounds/alsa/Front_Center.wav Set Mopidy to run as a background service on boot:

You should hear a calm voice say ‘front centre’. sudo systemctl enable mopidy

Build a Raspberry Pi Media Player 39


TUTORIAL

Configure and test Mopidy


Top Tip 06 Before Mopidy can be run, we need to
sudo pip3 install Mopidy-Local
sudo sh -c 'echo "mopidy ALL=NOPASSWD:
configure a few things. The default settings /usr/local/lib/python3.7/dist-packages/
Keep it simple are sensible, but if you want to access the web mopidy_iris/system.sh" >> /etc/sudoers'
interface (once installed) from another device, sudo systemctl restart mopidy
Change things to we’ll need to allow that.
suit your budget.
This installs the Iris and Local modules, then
You can run
sudo nano /etc/mopidy/mopidy.conf gives Iris permission to run Mopidy commands
Mopidy on a full-
size Raspberry Pi as the superuser. Finally, we restart Mopidy to
with the built-in After the comments block, add this: pick up the changes. In a web browser, go to
headphone socket. http://<hostname>:6680/iris/ to see the interface.
[http]
hostname = 0.0.0.0

Just add music


[audio]
output = alsasink
08 Mopidy supports a wide range of formats,
including MP3 and FLAC. Whatever you decide to
Save the file with CTRL+X and then start Mopidy: use, create a space for your music and upload some
files there. You’ll find a Music folder already exists
sudo systemctl enable mopidy in your home directory. We need to tell Mopidy
where to look for your files. Edit the Mopidy
In a browser, go to http://<hostname>:6680/ configuration file:
(replace <hostname> with your Raspberry Pi’s
name – ‘raspberrypi.local’ by default). If you get a sudo nano /etc/mopidy/mopidy.conf
welcome page displayed, all is working well.
Add append the following:

[local]
Install the UI & file support
The DAC HAT
provides high-
07 Next, we’re going to install Iris, a user
media_dir = /home/pi/Music

resolution output interface, and support for playing music stored on Restart Mopidy to pick up the configuration
at line level. You
can swap this with the local system. Run these commands: changes and then initiate the first music scan:
an amplifier HAT
and use passive
speakers instead sudo pip3 install Mopidy-Iris sudo mopidyctl local scan

Now in Iris, you should be able to see your albums


appear. Try playing one!

We’ve modified the case and removed the back so


everything fits. The screen takes its 5 V feed from the
GPIO breakout on the DAC HAT

40 Build the ultimate home music system


www.dbooks.org
TUTORIAL

Kiosk mode
09 DOWNLOAD
To get Iris running on the touchscreen, we
can make Chromium run in ‘kiosk’ mode so that no
kiosk.sh THE FULL CODE:
other elements of Raspberry Pi OS Desktop can be
seen. The first step is to install ‘unclutter’, a handy > Language: Bash/Shell magpi.cc/iriskiosk
app for hiding the mouse pointer when not in use.
001. #!/bin/bash
sudo apt install unclutter 002. unclutter -idle 0.5 -root &
003. sed -i 's/"exited_cleanly":false/"exited_cleanly":true/'
Now we’ll create a script to launch Chromium with /home/pi/.config/chromium/Default/Preferences
all the correct settings: 004. sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/'
/home/pi/.config/chromium/Default/Preferences
nano ~/kiosk.sh 005. /usr/bin/chromium-browser --noerrdialogs
--disable-infobars --kiosk http://127.0.0.1:6680/iris &
Add the code shown in the listing. When run, this
will enable cursor hiding, prevent some Chromium
error messages from being displayed, and then @/home/pi/kiosk.sh
start Chromium in kiosk mode, going directly to
the Iris website in full-screen. Save the file and reboot your system. The desktop
will appear and then Iris will boot full-screen. Your
touchscreen music system is now ready for use. You
can control everything from either the touchscreen,
Implement the kiosk script
10 Before we can use the script, it needs to be
a web browser on any device, or your smartphone.

flagged as an executable:

Load up the music


chmod +x ~/kiosk.sh
12 If you want to add some audiophile-
Now try it out by running ~/kiosk.sh. If you’re grade music to your collection, you can use your
entering commands remotely via SSH, use this Raspberry Pi computer to rip CDs to FLAC, a
command instead: lossless compression system. The files are large,
but no music detail is lost. A very easy-to-use
DISPLAY=:0 ~/kiosk.sh ripper is ‘A Better CD Encoder’ aka ‘abcde’.

All being well, Iris should start full-screen and be sudo apt install abcde
controllable by touch. We recommend going into
settings and enabling ‘Wide scrollbars’ to make it Hook up a CD drive to the USB port, insert a CD,
easier to control with fingers. You can also choose and enter this:
between light and dark themes, the darker theme
being a little kinder on the eyes when used with abcde -o flac
the touchscreen.
Abcde will guide you through the whole process,
including automatically naming the tracks. Place
the resulting directory in your Music directory and
Run on boot
11 The final step for our music system is to
go to Settings in Iris to initiate a rescan.

make it run on boot and go straight into kiosk


mode. We’ll ask the Desktop itself to do this. Enter
the following in the command line: Mopidy, with a little help from its friends, can play
music from many different services, including
sudo nano /etc/xdg/lxsession/LXDE-pi/ Spotify. In the next tutorial, we’ll explore how.
autostart
We’d like to acknowledge PiMyLifeUp for their excellent
Add this line, including the ‘@’ sign: tutorial on kiosk mode: magpi.cc/pikiosk.

Build a Raspberry Pi Media Player 41


TUTORIAL

Ultimate home
Part 02

music: services
Extend the capabilities of your music system with
Mopidy extensions and access a world of audio

P
reviously, we built a standalone music
server using a DAC (digital-to-analogue
PJ Evans converter) HAT, Mopidy, Iris, and a
MAKER

Raspberry Pi touchscreen. All these things,


PJ is a writer, together with a pair of decent speakers, guarantee
software engineer
audio bliss for your home or workplace. Now we’re
and can’t decide
whether to arrange going to extend the capabilities of Mopidy using
his collection by its plug-in architecture. With a few commands,
genre, title, or year Mopidy can be extended to stream audio from a
of release.
wide range of online services, from giants like
@mrpjevans Spotify to the gargantuan collections of the
Listen to all your favourite podcasts directly from Mopidy and
Internet Archive. This month we’re looking at the discover new shows with the iTunes Podcast catalogue
best Mopidy extensions and how to install them.
album, and track name. They will also record that
information inside the file itself so servers like
Mopidy can display details about what’s playing.
Local library
01 Let’s start by looking again at our local
This is called tagging. Unfortunately, the online
services don’t always get it right, so if you find a
collection. Storing music locally allows you reliable tag is misnamed or contains mistakes, you can use
playback and complete control over how your Kid3 to set the tags yourself. To install from the
music is organised. The downside is storage costs, command line:
so before embarking on ripping all your CDs, have
Warning! a think about how you want to store them. Last sudo apt install kid3
Copyright month we discussed using abcde (A Better CD
Where you live may Encoder) to rip to FLAC, which produces large files This desktop app provides easy bulk retagging of
or may not allow the with no quality loss. You can also consider using files and can even import artwork.
copying of data from
a CD. Check here for Ogg Vorbis. This open-source codec does involve
more info:
quality loss, but produces much smaller files, and
magpi.cc/ripping
there’s every chance you won’t be able to tell the If you find a tag is
difference. To rip a CD to Ogg Vorbis:
misnamed, you can use
abcde -o ogg
Kid3 to set tags yourself
Figuring configuring
You’ll Need Tag, you’re it 03
02 Many CD rippers, abcde included, will use
In the following steps, we’ll be setting up a
number of online services to interface directly with
> Mopidy Music
Server online services to find information about your your Mopidy installation. In many cases, you’ll
magpi.cc/mopidy CD and automatically name files after the artist, need to make changes to the Mopidy config file,

42 Build the ultimate home music system


www.dbooks.org
TUTORIAL

Adding Spotify to your Mopidy


server gives you access to
literally millions of recordings

Iris’s clever interface allows


you to search across many
different services at once

so it’s worth explaining how it’s formatted. Each Cut and paste this into /etc/mopidy/mopidy.conf
extension is named ‘Mopidy-Extension’. In the and add your Spotify username and password. See Top Tip
config file located at /etc/mopidy/mopidy.conf, the code listing overleaf for an example.
Extension becomes [extension] and any relevant Now restart Mopidy: Lossless or
options go underneath that line in the form ‘key = lossy?
value’. For example: sudo systemctl restart mopidy
Lossless (FLAC)
compresses audio
[local] Go back to Iris and the world of Spotify is literally
with no loss of
media_dir = /home/pi/Music at your fingertips.
quality. Lossy
(Ogg Vorbis, MP3)
We’ve provided an example config file to help removes audio
make sure things are properly set up. information to
Radio waves produce smaller
05 How about adding radio stations to your file sizes.

Mopidy setup? There is easy and free access to


Spot on
04 Now your local collection is set up, let’s
thousands of radio stations streaming across the
planet, catering for all interests. We have the
move on to the first of our extensions. Spotify is an option of two extensions for playing radio: TuneIn
amazing collection of music. Wouldn’t it be great and RadioNet. The TuneIn extension provides
to be able to access not only Spotify’s archive but access not only to live stations, but also historical
also your playlists and tagged artists? If you’ve got a recordings and is more suited to the curious
Spotify Premium account, you can do just that. Start browser rather that just getting to your favourite
by installing the extension from the command line: station. RadioNet is a simpler but easier-to-
navigate service that allows you to create a list of
sudo apt install mopidy-spotify favourite stations. To install:

We now need to authorise Mopidy to use your sudo apt install mopidy-tunein
account by visiting magpi.cc/mpdyspotify. Once sudo pip3 install Mopidy-RadioNet
you’re authorised, a config file will be displayed. sudo systemctl restart mopidy

Build a Raspberry Pi Media Player 43


TUTORIAL

Casting out SoundCloud


Top Tip 06 If you prefer your radio programmes ‘on
08 SoundCloud is an excellent online showcase
demand’, you’re probably a fan of podcasts. You’ve of music and other forms of audio. As well as
Enabled or got two options for listening to your favourite providing a way for bands to sell direct to their
disabled? shows on Mopidy. If you like to subscribe direct to fans, it’s a platform for new and upcoming
podcast RSS feeds, then it’s as easy as this: material from unsigned musicians. You can browse
Every extension SoundCloud’s vast collection from Mopidy, but as
supports ‘enabled’ sudo pip3 install Mopidy-Podcast with Spotify, you need to have an account (it’s free
in its config. If you
sudo systemctl restart mopidy to join) and authorise your installation.
want to remove
something First, visit mopidy.com/ext/soundcloud and
temporarily, just To use it, you need to point to an OPML file (a list follow the instructions to authorise Mopidy.
add ‘enabled of podcast locations), as shown in the listing. Most Copy and paste the resulting config file, and add
= false’ to the podcast clients can generate this for you. If you it to /etc/mopidy/mopidy.conf. Now install the
extension’s block prefer to browse a huge catalogue of programming, SoundCloud extension:
in /etc/mopidy/
then additionally install the iTunes plug-in:
mopidy.conf.
sudo pip3 install Mopidy-SoundCloud
sudo pip3 install Mopidy-Podcast-iTunes sudo systemctl restart mopidy
sudo systemctl restart mopidy

Now you can use Browse to find your favourite You can browse
show and listen on demand.
SoundCloud’s vast
collection from Mopidy
SomaFM
07 YouTube
SomaFM was one of the early pioneers
of internet audio streaming. Working through
09 The ubiquitous YouTube contains countless
a donations model, it has expanded to over 30 hours of audio-specific content. Either listen to
channels, all with the theme of ambience but one of the many audio recordings uploaded or just
covering different genres from electronica to jazz. the soundtrack of a favourite video. Again, the
Often SomaFM makes for perfect background standard installation pattern applies:
music. To add SomaFM to Mopidy (you’ve probably
spotted a pattern emerging by now): sudo pip3 install Mopidy-YouTube
sudo systemctl restart mopidy
sudo pip3 install Mopidy-SomaFM
sudo systemctl restart mopidy One difference with this extension is the need to
specifically enable it in /etc/mopidy/mopidy.conf.
Make sure this is in the file or YouTube files will
not appear in search results:

[youtube]
enabled = true

Digging through the archives


10 The Internet Archive (archive.org) is one of
the crowning achievements of the internet. This
vast resource aims to preserve anything that can be
expressed in digital form. Unsurprisingly, its audio
collection is vast, containing thousands of hours
or public domain recordings, from vintage music
Add audio services, like Spotify, SomaFM, and YouTube for a fully-fledged
modern music system to public speeches, documentaries, and a massive

44 Build the ultimate home music system


www.dbooks.org
TUTORIAL

mopidy.conf DOWNLOAD
THE FULL CODE:
> Language: Config file magpi.cc/modipyconf

001. [http]
002. # Make sure the web interface can be accessed by the
Mopidy-Party lets your friends choose the music, which
local network
may or may not be a good thing 003. hostname = 0.0.0.0
004.
catalogue of Grateful Dead recordings! You can 005. [audio]
access all of these from your Mopidy system: 006. # Direct audio to the DAC, not HDMI
007. output = alsasink
sudo pip3 install Mopidy-InternetArchive 008.
sudo systemctl restart mopidy 009. # The File extension isn't of much use, so we can disable it
010. [file]
We recommend using the ‘Browse’ feature of 011. enabled = false
Iris to navigate this resource. Search results can 012.
be overwhelming! 013. # If enabled, this adds support for M3U playlists
014. [m3u]
015. enabled = false
016.
Party time, excellent! 017. # Location of local music
11 You now have access to a mind-boggling 018. [local]
array of music and audio. Time to celebrate. We’ve 019. media_dir = /home/pi/Music
been using Iris as our interface to Mopidy, but in 020.
fact you can install different interfaces and even 021. # Replace with the information given when you authorise
run them concurrently. If you’re having a few 022. # then add in you Spotify username and password
friends around, Mopidy-Party allows you to safely 023. [spotify]
give everyone access to your music collection from 024. username = <Spotify username>
their phones and add their picks to a playback 025. password = <Spotify password>
queue. Now, who put Showaddywaddy on? 026. client_id = <Client ID>
027. client_secret = <Client secret>
028.
029. # Getting to many results in TuneIn? Add this so you only
Make your own get stations.
12 Something missing from your collection? 030. [tunein]
Is there no access to the latest and greatest 031. filter = station
streaming service? If you’re handy with a bit of 032.
Python coding, then you’re free to make your own 033. # Once authorised, add the provided token here
Mopidy extensions and share them with users 034. [soundcloud]
all over the world. Not only have the Mopidy 035. auth_token = <Auth token>
developers provided detailed documentation at 036.
magpi.cc/mpdyext, they have also provided a 037. # Most extensions are enabled by default. You must
‘cookiecutter’ project at magpi.cc/mpdycookie explicitly enable YouTube.
which will get you up and running in no time. 038. [youtube]
Contributions to improve existing extensions are 039. enabled = true
also welcomed.

Build a Raspberry Pi Media Player 45


TUTORIAL

Ultimate home
Part 03

music: multi-room
You’ve built your music system and enhanced it with
streaming services, now let’s fill your home with sound

I
Going multi-room
n the previous two tutorials, we’ve built
and configured an all-singing, all-dancing,
01 Sure, playback from our Mopidy setup is
tricked-out music system using a Raspberry great, but you don’t want to be carrying that setup
PJ Evans
MAKER

Pi computer and Mopidy, the Python-based around the house. With Snapcast we can play music
extendable music server. We can listen to our anywhere in perfect sync, so you can wander around
PJ is a writer,
music in beautiful FLAC quality and stream from your home without interruption. This clever piece of
software engineer,
and now has a the worlds of Spotify, SoundCloud, and YouTube. open-source software sends out audio in ‘frames’,
house with too There’s one amazing feature that systems such as each one with a time code attached. Any device
many speakers. Sonos offer that we haven’t yet covered: multi- that’s part of the stream matches the frame’s time
@mrpjevans room audio. Not just playing music in different code to its own internal clock to ensure playback
rooms, but also playing in perfect sync. In this final happens at the same time, providing in-sync audio.
part, we’ll do just that and learn a few new Mopidy The only downside is a short delay in starting
tricks along the way. playback as everything syncs up.

You’ll Need
> Mopidy Music
System

> Hi-Berry DAC+Zero


magpi.cc/ Hiding inside are a Connect this box to an
hifiberrydaczero Raspberry Pi Zero W and amplifier or active speakers for
HiFiBerry DAC+ Zero digital- synchronous whole-house audio
> Case (optional)
magpi.cc/ to-analogue converter
hifiberrycase

46 Build the ultimate home music system


www.dbooks.org
TUTORIAL

Snap to it
02 Before we can add Snapcast clients, our
original Mopidy needs to become one itself, so it
can keep in sync with everything else. We start
by installing the Snapcast client and server on
the same machine (it’s effectively streaming to
itself). Enter the following on the command line to
download the client:

get https://github.com/badaix/
snapcast/releases/download/v0.20.0/
snapclient_0.20.0-1_armhf.deb
sudo dpkg -i snapclient_0.20.0-1_armhf.deb

If you get an error here, run this to fix it:

sudo apt -f install

This automated install sets everything up and will


restart the service on reboot.

The HiFiBerry DAC


Change… is an entry-level
Snappy service digital-to-analogue
03 We have the client running on your Mopidy [audio]
converter that
provides much higher
quality than the
system, but nothing to serve music. So, now install output = autoaudiosink
standard audio-out
the server: from a Raspberry Pi
…to (the second part on one line):
get https://github.com/badaix/
snapcast/releases/download/v0.20.0/ [audio]
snapclient_0.20.0-1_armhf.deb output = audioresample ! audioconvert !
sudo dpkg -i snapclient_0.20.0-1_armhf.deb audio/x-raw,rate=48000,channels=2,format=S16
LE ! wavenc ! filesink location=/tmp/snapfifo
This will also restart on boot. The client will
automatically find the server as its local. Now tell Now restart Mopidy:
Mopidy to send its audio stream to the Snapcast
server instead of the DAC. sudo systemctl restart mopidy

sudo nano /etc/mopidy/mopidy.conf

Set me up
04 Iris comes with full control over the Top Tip
Snapcast system. After restarting Mopidy, go to
Choose your
the Iris interface and into Settings. You’ll see a
DAC
Snapcast icon. Click on it and then click ‘Enable’.
You should see a ‘Connected’ message appear. There are a wide
There will also be a group which represents your range of digital
local Mopidy setup. Click the group to rename it to audio convertors
something memorable. Before proceeding further, out there catering
make sure that playback still works. It’ll take a for every budget,
from £12 to
second or two longer to start as Snapcast syncs
thousands –
up, but should otherwise be unaffected. If it works choose wisely.
The addition of this purpose-built case not only
protects your project, but also adds a bit of class well, your local Mopidy setup is complete.

Build a Raspberry Pi Media Player 47


TUTORIAL

Join the band


07 To get streaming working, we now repeat
the process for installing the Snapcast client.
Start by downloading and installing the client:

wget https://github.com/badaix/
snapcast/releases/download/v0.20.0/
snapclient_0.20.0-1_armhf.deb
sudo dpkg -i snapclient_0.20.0-1_armhf.deb

If you see errors at the end of the process


with the line ‘dependency problems – leaving
Just add clients
05 Your system is now in effect streaming to
unconfigured’, run the following command:

itself, which means it can play in sync with other sudo apt -f install
The case includes
access to the HDMI devices, so let’s add one. We’re using the HiFiBerry
and USB ports, so DAC+Zero, a great DAC for a small price. Start This will detect and install all the dependencies
you can connect a
touchscreen monitor by connecting the DAC to a Raspberry Pi Zero W, required and then finish configuration. Snapcast
and use it as a
Mopidy control centre
ideally using standoffs to ensure a secure fit. will be configured to automatically start on boot.
Install Raspberry Pi OS Lite on this device as we’re
You can use Iris on
any web device going to be running it headless. Using raspi-config,
to control which make sure you’ve configured WiFi and set a
group is listening to
which stream suitable hostname. Now update everything to the
latest version using:

sudo apt -y update && sudo apt -y full-upgrade

Make some noise


06 To enable the DAC+ Zero, obtain command-
line access to your Raspberry Pi Zero W (using SSH
Configure and test
or connect up a monitor and keyboard) and edit the
main configuration file:
08 The Snapcast client is now running, but
we need to tell it where the server is. Edit the
sudo nano /boot/config.txt configuration file:

Near the end of the file, find the line reading: sudo nano /etc/default/snapclient

dtparam=audio=on Find the line that reads SNAPCLIENT_OPTS="" and


add your Mopidy server hostname as follows:
Delete it (or comment out with a #) and add:
SNAPCLIENT_OPTS="--host jukebox.local"
dtoverlay=hifiberry-dac
Replace ‘jukebox.local’ with whatever you named
Save (CTRL+X) and reboot your computer. Once back your server. Save and exit, then restart the client:
up, connect the phono sockets on the DAC to an
Warning! Copyright amplifier and test the output: sudo systemctl restart snapclient

Where you live may


or may not allow the aplay /usr/share/sounds/alsa/Front_Center.wav In a web browser, open up Iris on your main server
copying of data from and go to Settings, then click on Snapcast. You
a CD. Check here for
more info: If everything is working well, a nice person will say should see a new group (something like ‘Group 8ec’);
magpi.cc/ripping “front centre”. that’s your device. You can rename it if you wish.

48 Build the ultimate home music system


www.dbooks.org
TUTORIAL

Play, tweak, repeat


09 Now try playing something from Mopidy
with your new client hooked up to an amplifier
or active speaker. Everything should be in sync.
If not, you can adjust latency under your group
settings to fine-tune the playback. At the bottom
of the screen, you can click the speaker icon to
control which devices are playing and set their
individual volume levels.
You can add as many Snapcast clients as you
like. It’s a great use for an older Raspberry Pi and
you don’t have to use a DAC, you can just use the
standard audio/video jack to an active speaker.
We built another client using Pimoroni’s Speaker
Multistream!
pHAT and a battery for portable tunes.
11 The final step is to configure Snapcast to
If your home audio
setup features coax
or S/PDIF digital
enable Shairport Sync as a stream. Open up the interfaces, this
Snapcast configuration file as follows: JustBoom adapter is
perfect and can be
set up identically to
sudo nano /etc/snapserver.conf the DAC+ Zero

You can have a lot of


fun with Snapcast.
In the section starting [stream] you’ll see an entry We’ve used a
starting [stream] =. Directly under there, add the Pimoroni Speaker
pHAT here for
following line: the ultimate in
portable tunes

stream = airplay:///shairport-sync?name=
Airplay&devicename=Jukebox

Add some Apple


10 Snapcast supports multiple streams,
(You can change the names to anything you like.)
Now restart everything:
allowing clients to switch between them. We can
add Apple AirPlay 2 support as a Snapcast stream sudo systemctl restart snapserver.service
that runs alongside Mopidy. We can’t just install sudo systemctl restart mopidy.service
a package, though: we have to build and install
Shairport Sync with the following commands: In Iris, go to the Snapcast settings and change the
default stream to AirPlay. You can now push audio
cd from iOS devices and Macs to your music system or
sudo apt install build-essential git any other Snapcast client.
xmltoman autoconf automake libtool libpopt-
dev libconfig-dev libasound2-dev avahi-daemon
libavahi-client-dev libssl-dev libsoxr-dev
Going further
Top Tip
git clone https://github.com/mikebrady/
12 If you’ve played along and built this
DAC’s not
shairport-sync.git setup, you now have a pretty sweet audio player
for me
setup. The great thing about this project is the
autoreconf -fi wider range of budgets and platforms for which If you’re on a tight
it caters. You can reuse older hardware, upcycle budget, you don’t
./configure --with-stdout --with-avahi speakers, and turn just about anything with a need a DAC at
--with-ssl=openssl --with-metadata processor into a streaming client. You can also get all. The 3.5 mm
AV jack found on
HATs with pure digital S/PDIF or coaxial output so
most Raspberry
make you can use an amplifier’s DAC if you prefer. How Pi computers
about using a USB audio capture device to stream will suffice for
sudo make install audio around the house from your record player? smaller projects.
As ever, it’s over to you.

Build a Raspberry Pi Media Player 49


Contents REVIEWS

Reviews
When it comes to hardware and software, it can be tricky to figure
out what the best item for the job is. Let us show you some of the
best Raspberry Pi accessories that will help improve your
media centre project.

52 Argon ONE M.2 58 10 Amazing Raspberry Pi


The ultimate case for any media media players
server project Play something on your Raspberry Pi
with these excellent bis of software
54 NanoSound One Hi-Fi
DAC Case 60 10 Amazing Media
The ultimate case, now with incredible Player Projects
audio output Go beyond a basic media server and
make something amazing
55 Argon IR Remote
Control your media centre with this
handy remote

56 Ultimate home server:


Backup and UPS
Keep your media safe locally and
backed up to the cloud

50 Build a Raspberry Pi Media Player 2022

www.dbooks.org
REVIEW

Argon ONE M.2


Argon 40 magpi.cc/argononem2 £43 / $45
SPECS

DRIVE TYPE: Add a super-fast M.2 SATA SSD to Raspberry Pi 4 along with dual full-sized
M.2 SATA SSD
with Key-B or
Key-B&M
HDMI sockets, a power button, and fan cooling. By Lucy Hattersley
DISPLAY

T
PORTS: he Argon ONE M.2 case for Raspberry Pi 4 The aluminium alloy lid acts as a heatsink and
Dual full-size has been on the radar for many Raspberry a 30 mm fan provides active cooling. The fan
HDMI
Pi power users. We’re glad to report that is controlled via a script provided by Argon 40.
FEATURES: your anticipation has not gone unrewarded. Default settings start at 10% power when the CPU
UASP support, The marquee addition here is support for an temperature is at 55ºC, increasing to 55% at 60ºC,
power M.2 SATA SSD drive (the blade drives commonly and 100% at 65ºC.
management,
found in laptops). This sits snugly in a bottom
active and
passive cooling compartment and is connected to Raspberry Pi Putting it together
using the USB 3.0 connection (via a U-shaped Your M.2 SATA SSD clips into the lower part of
adapter). It features UASP (USB Attached SCSI the case and is held in place with a single screw.
Protocol) support to increase performance. The two halves are then screwed together and a
In the spirit of things, we tested it with a U-shaped USB adapter is used to bridge the lower
Raspberry Pi 4 8GB RAM and Raspberry Pi OS (64- part of the case the port on the upper part.
bit, magpi.cc/64bit). It’s an ingenious solution, but you lose a USB 3.0
An internal board repositions the ports to socket in the final build. More importantly, the
the rear, and converts the micro-HDMI ports of microSD card socket is sealed inside the case,
Raspberry Pi 4 to two full-sized HDMI sockets. requiring disassembly to access it.
GPIO remains accessible via a removable flap with Raspberry Pi EEPROM recently provided USB
a pin guide printed to the side. boot support in the default ‘critical’ firmware,

Gnome Disk Utility


benchmarking the
rootfs partition of
our SSD

52 Argon ONE M.2


www.dbooks.org
REVIEW

and a recent update (still currently in beta but due


soon) improves USB boot performance.
Once booted into Raspberry Pi OS, we installed
Imager and used that to flash a clean install of
Raspberry Pi OS (64-bit) onto the SSD drive.
Remove the USB thumb drive and Raspberry Pi
boots straight from the SSD.

Benchmarking the Argon M.2


We used a Samsung 850 EVO SSD supplied
by our friends at Custom PC magazine The two halves of the
case connect together
(magpi.cc/custompc) and installed Gnome Raspberry Pi remained cool under stress, maxing with a U-shaped USB
Disks for its benchmarking test. out at 53ºC – not even high enough for the fan 3.0 connector bridging
the M.2 SSD SATA drive
The M.2 did not disappoint, with an average to kick in, with the passive case doing all the to Raspberry Pi 4
read rate of 367.1MB/s compared to 45MB/s for our cooling. We took our Raspberry Pi clock speed up to
microSD card. That’s an 800% speed increase. 1800MHz (magpi.cc/overclock) and, after leaving
Raspberry Pi to recover, ran the test again. This

You get unrestrained time the board got a little more stressed, maxing
out at 73ºC – enough for the Argon fan to kick in
performance with an at 100% speed, but below the critical 80ºC point
where Raspberry Pi OS begins to throttle back the
overclocked Raspberry Pi 4 CPU speed.
So at all times you get unrestrained performance
coupled with an ultra-fast with an overclocked Raspberry Pi 4 coupled with an
ultra-fast SSD storage solution. If that’s not nifty,
SSD storage solution we don’t know what is.
We did also install Ubuntu, but we could not Verdict
Overjoyed with our SSD throughput rate, we set install the scripts for the fan in this case (as it
about testing CPU speed and thermal performance depends on GPIO Zero, magpi.cc/gpiozero), so the If you want to
take Raspberry
(the two are related as Raspberry Pi OS throttles fan was on permanently. Raspberry Pi OS remains
Pi 4 performance
performance if the CPU temperature exceeds 80°C). our preferred operating system at any rate. as far as it can
We performed a similar test to the one Gareth We spent a delightful couple of days knocking go, this is the
Halfacree uses when thermal-testing Raspberry Pi together the scripts for testing in Visual Studio way to do it.

10
boards (magpi.cc/thermaltesting). We ran stress- Code and creating graphs of the results in
ng and glxgears for ten minutes while monitoring LibreOffice, all while doing browser research and

/10
CPU speed and temperature recordings, followed writing up the results. Our Argon ONE M.2 build
by a five-minute cool-down period. remained a joy to use throughout.

Build a Raspberry Pi Media Player 53


REVIEW

aluminium case topped and tailed with soft-touch plastic

Flirc Raspberry Pi 4
Flirc £16 / $16
SPECS

DIMENSIONS:
66×91×25 mm Stylish and clever case with a body that becomes
CASE: a heat sink. By Lucy Hattersley
Aluminium

W
housing
e see a lot of cases here at The MagPi, Flirc claims that this is “the most beautifully
FEATURES: but the Flirc Raspberry Pi 4 case came crafted Raspberry Pi 4 case” and it’s not a wholly
Built-in
recommended to us via Raspberry Pi’s unwarranted claim. It certainly has a sense of
heat sink
engineering team, so we had to take a look. style. Everything is neatly constructed from high-
The Flirc Raspberry Pi 4 case comes in two quality materials and there’s considerable charm
halves: the bottom is a soft-touch plastic shell, to the heat sink. The microSD card slot is easily
and the top half is milled aluminium coated with accessible, and a small cut-out on the enclosure
more soft-touch. The result is a stylish and lovely- enables the LEDs to shine through.
to-hold case made from solid metal.
Here’s where things get clever: inside the case On the box
is a protruding heat sink that reaches down to One downside to the sealed approach is that the
Raspberry Pi 4’s CPU. This turns the whole of the GPIO pins are hidden away inside the case. Unlike
aluminium case into a giant heat sink, cooling
down your Raspberry Pi 4. to provide access to the pins.
Inside the pack is a square thermal pad (similar To Flirc’s credit, it has addressed this issue via a
in substance to Blu Tack). You use this to squidge small gap on the underneath of the Flirc Raspberry
the Raspberry Pi to the heat sink. Putting together Pi 4 case, which could be used with a breakout I/O
Warning!
the case is ludicrously simple: you simply drop a cable. But it’s an ungainly addition to such a lovely
Using stress should only Raspberry Pi in the bottom half, attach the thermal looking case.
be done for short periods.
Watch your Raspberry Pi
paste, squidge down the lid, and use four screws to If you plan to use Raspberry Pi as a desktop
and restart afterwards. hold everything together.

54 magpi.cc Flirc Raspberry Pi 4


www.dbooks.org
REVIEW

However, for many of us, GPIO pins are the very


essence of Raspberry Pi.
We’re going to experiment
Under pressure
some more with overclocking,
We stress-tested a Raspberry Pi 4 board on its own which makes this a fun case
vs a Raspberry Pi 4 inside the Flirc case to see what
temperatures it reported.
We used stress (apt install stress) and Next, we put a Raspberry Pi into the Flirc The case cunningly
doubles as a heat
the following script from Core Electronics Raspberry Pi 4 case and ran the same test. This sink, enabling you to
(magpi.cc/7Q0oX3) to test our Raspberry Pi 4 time it idled at a mere 28 run your Raspberry
Pi 4 more coolly
while measuring temperature: stress test took it up to a mere 46 °C. (and overclock to
faster speeds)
Because this is comfortably below the threshold,
while true; do vcgencmd measure_clock arm; it opens up a world of overclocking (something
vcgencmd measure_temp; sleep 10; done& stress that has been reintroduced on Raspberry Pi 4 –
-c 4 -t 300s see magpi.cc/sED3id).
We took the CPU clock speed up to 1.75GHz. The
This puts all four cores of Raspberry Pi 4 under overclocked Raspberry Pi (inside the Flirc case)
stress. For each test, we left the Raspberry Pi to run idled at 41
test took it up to 67 °C. Again, comfortably within
Verdict
a threshold. We also played around with CPU clock We love the style
Unsurprisingly, the Raspberry Pi with no heat speeds up to 2.0GHz, which idled at 48 °C and of the Flirc case,
sink attached quickly went up to 79 °C and hovered maxed out at 69 °C. and its heat sink
opens up a world
at that level for the rest of the test, nudging up We’re going to experiment some more with
of overclocking.
against (but not pushing over) the level where overclocking, which makes this a fun case. If only the GPIO
Raspbian starts to throttle the CPU. pins remained
accessible. If that’s
not a deal-breaker
for you, though,
then this is a great

8
case to get.

/10
Flirc Raspberry Pi 4 magpi.cc 55
REVIEW

NanoSound ONE
Hi-Fi DAC Case
Nanomesher magpi.cc/nanosound1 £59 / $80
SPECS

Combine the best of both worlds with a melding of the excellent NanoSound CHIP:
Texas
DACs and the Argon ONE case. Rob Zwetsloot grabs his listenin’ ears Instruments
PCM5122

SAMPLE

I
t’s no secret that we’re big fans of the The whole process is very quick, and we were RATE:
Argon ONE cases – they’re fantastic for able to experience some excellent sounds from the 192 kHz
keeping your Raspberry Pi cool, they look DAC part in no time, which uses the same tech as
RESOLUTION:
great, and they have neat features like GPIO pins the NanoSound DAC 2. You’re paying a little bit
24-bit
under a magnetic lid and all the ports rearranged of a premium for the DAC and case together (only
to the rear. We’re also a fan of the NanoSound about $5), but you are getting a custom version SIGNAL-TO-
DACs, so we were quite intrigued when we found of one of our favourite cases – so it’s definitely NOISE RATIO:
out about a melding of the two into one product: worth it. 112 dB

NanoSound ONE. AUDIO


OUTPUT:
You have your choice of RCA

bottom part for the case Control it with a


smartphone remote or
On paper it’s a simple change – the board the included remote

attached to the roof of the case that provides a fan


and heatsink is replaced with one that provides
a DAC and heatsink. Because of this, the ports
on the rear are slightly changed, going from two
HDMI ports and a 3.5 mm jack to one micro HDMI
port and two RCA jacks.
This does mean you’re losing the active cooling.
However, passive cooling of the heatsink (which is
the entire case) is definitely good enough.

Snug fit Verdict


Installing a Raspberry Pi 4 is simple – you add the
little breakout board that plugs into HDMI 0 and A great case with
the 3.5 mm jack on Raspberry Pi, and then connect great sound at a
the GPIO pins with the GPIO header on the top of reasonable price.
This could be
the case. The breakout board is a bit of a snug fit,
the one for folks
so don’t be worried if it looks like it’s not quite who need the
spaced out correctly. It is! best audio out of
You have your choice of bottom part for the case. a media centre.

9
The standard piece just encloses the whole thing
and provides an SD card port, while there’s also

/10
the M.2 SSD storage bay option which we reviewed
last month.

54 NanoSound ONE Hi-Fi DAC Case


www.dbooks.org
REVIEW

Argon IR Remote
Argon40 magpi.cc/argonir £9 / $10

Looking for a sleek minimalist remote for your Raspberry Pi media centre?
PJ Evans sits back on his sofa and gets clicking

U
sing a Raspberry Pi 4 as a media centre reasonable £9 is a minimalist, slim remote with
SPECS
makes for a brilliant way to access just enough to make controlling Kodi a breeze.
your favourite sounds and movies. Add Basic directional control, selection, volume, and
DIMENSIONS: Argon40’s sleek ONE case and it looks as good, if standard navigation work alongside a power button
150 mm × 35 mm not better, as any other set-top box. There’s even that works out-of-the box with any Raspberry Pi 4,
× 10 mm
mature software in the form of the LibreELEC regardless of operating system. It’s light too, at
POWER: operating system and Kodi media centre app. All just 65 g with two AAA batteries.
2 × AAA batteries
that’s missing is an easy way to control the action.
COMMUNICATION: The eagle-eyed may have noticed the ONE case’s More than media
Infrared circuitry includes an IR sensor, and now Argon40 If media centres are not your thing, or you have
HARDWARE has made the companion Argon IR infrared remote other epic plans for a remote control, Argon40
COMPATIBILITY: control available. provides software that allows you to assign any
Argon ONE & Thankfully, Argon40 has been watching key press to a button using the standard LIRC
EON cases
other tech design teams rather than those of library with ease, making the addition of IR remote
SOFTWARE most modern TVs. What you get for your very control to your project easier than ever before. In
COMPATIBILITY: our tests, this worked flawlessly. However, we did
LibreELEC or
have some issues configuring Kodi due to some
Raspberry Pi OS
missing steps in the supplied instructions. Once
resolved, the remote performed admirably from
across the room.

A minimalist, slim remote


with just enough to make
Verdict controlling Kodi a breeze
Although the
setup instructions
could be
improved, Argon40
has delivered a
sleek, simple, and
reasonably priced
IR remote, both
for Raspberry Pi
media centres
and homebrew
projects.

9 /10 The lack of extraneous buttons and a small form factor make the
Argon IR comfortable to hold and use
You’ll need an Argon ONE case (or the forthcoming
EON) to use the Argon IR

Build a Raspberry Pi Media Player 57


REVIEW

LibreELEC 9.1 Beta


LibreELEC libreelec.tv Free
SPECS

KODI VERSION:
18.3 ‘Leia’
LibreELEC comes to Raspberry Pi 4. Rob Zwetsloot
COMPATIBILITY:
tests it out to see if it’s ready for prime time yet
All Raspberry Pi
versions

INSTALLATION:
Graphical wizard
or burnable
image

IMAGE SIZE:
129MB

4K works fine for now,


but will get better

Y
ou could easily argue that Raspberry Pi was
already the perfect media PC – why get
excited for a Raspberry Pi 4-compatible
version of LibreELEC/Kodi, then? One of the many
improvements to Raspberry Pi 4 was the inclusion
of hardware H.265 decoding – also known as HEVC.
This means it can support 10-bit colour, as well as
the 4K output of the new Raspberry Pi 4.

Verdict And we can say right off the bat that with H.265
encoded media, it’s noticeable immediately. Colour
tearing and glitches are completely gone, with The video game part has a way to go
LibreELEC 9.x
media running at full speed without it seeming to
still needs some
work upstream.
struggle. 4K works fine as well – not great, just fine some extensive testing with the three versions,
However, the – at 30Hz. playback was the exact same, even with the
beta is well worth most demanding bit rates. The UI, however, was
jumping on board Size matters? noticeably just a little bit more responsive on
if you have a That’s not the only reason we decided to do a quick the higher gigabyte models. Just the slightest
Raspberry Pi 4 and
re-review of LibreELEC, though – there’s also the bit, though – nothing to splurge on. At the very
the need to use
question of what version of Raspberry Pi 4 do you least, the 1GB model is a bit better than previous

9
the extra power.
need. Could you save $20 and get the 1GB version Raspberry Pi computers, in our experience.
over the 4GB, or is there a difference? So, to recap: you don’t even need to buy the best

/10
Yes, there is a difference, but no it’s not worth version of Raspberry Pi 4 to get the major benefits
the $20 (for this purpose) in our opinion. After of the hardware redesign. That’s a huge win.

58 LibreELEC 9.1 Beta


www.dbooks.org
REVIEW

10 Best:
Raspberry Pi
media players
Here’s how to play music and
video on your Raspberry Pi

R
aspberry Pi has been used to play video and
music since the very first board landed in
the hands of an enthusiast. Its use as a media
platform is legendary, and for good reason. Want to
Plex
take advantage of Raspberry Pi’s media powers? Here
are ten excellent ways… Ultimate media library
Need a tiny media server that will stream to all your devices that support Plex?
Using Raspberry Pi you can create the ultimate streaming media server, with
VLC Media Player the tiniest footprint in both physical space and on your electricity bill.

plex.tv
All-purpose player
VLC seems to be able to play just about
anything you throw at it, while still
having a very small install size. It also
Pi MusicBox
has great streaming abilities, and can
receive web streams and network Music streaming software
streams as well. It also has a GUI.
Another excellent streaming solution for your home. As well as being able to
magpi.cc/qsXYHH connect to your local music collection, it connects well to online services such
as Spotify and SoundCloud.

pimusicbox.com

MPlayer
The legend
MPlayer is still adored by many long-term Linux
and open-source software users, and for good
reason: it’s great. You’ll probably have to compile it
from source to get a version you prefer, though.

mplayerhq.hu

60 10 Best: Raspberry Pi media players


www.dbooks.org
REVIEW

KODI
Kodi is software used in many
home-theatre PCs and other kinds
of media PCs. You can install
it on Raspbian on Raspberry

OSMC Pi; however, we find it works a


lot better if you’re using it on a
dedicated media device, especially
Raspberry Pi HTPC in conjunction with operating
A Kodi alternative for people who like slightly more modern user interfaces. systems that make use of it.
It has a special installer that can get a Raspberry Pi microSD card set up in
minutes, and it also supports streaming to other devices.

osmc.tv

Chromium
Web browser streaming
Using the default Raspberry Pi OS
browser, you can access a world
of content online from various
video sources like YouTube,
as well as stuff on your home
network with the right add-ons.
RuneAudio chromium.org

In-home music system


LibreELEC
RuneAudio is a complete home hi-fi The purest Kodi
system, connecting to local network
storage and internet streams. It can Our favourite Kodi-based OS gives you the pure, familiar, highly
be controlled by multiple clients if run customisable Kodi experience. It can play just about anything you
headless, and plays music perfectly can throw at it, including a lot of video games now.
through a DAC. It’s also open-source.
libreelec.tv
runeaudio.com

OMXPlayer
Volumio
Command-line
All-in-one audio player
Volumio wants you This is great for having
to have everything media play when you
connected to one turn a Raspberry Pi on,
device, and has or to control it from an
created a system to SSH-connected remote
allow you to do that. computer. It makes use of
Not only can you store minimal resources, while
music on it, you can also being hardware-
stream music from accelerated for great
other places to it. picture quality.

volumio.org magpi.cc/ABdFRJ

Build a Raspberry Pi Media Player 61


REVIEW

10 Amazing:
Media Lunchbox Arcade Game

player Lunch-time fun


There are many great and cool video game projects, but this portable arcade

projects
machine disguised as a lunchbox is still one of our favourites. Playing it at home
or at work on your break seems like the perfect fit for it.

magpi.cc/lunchbox

iPod Classic Spotify


The best ways to groove, dance,
music player
chill, and more using a Raspberry Pi
Upcycled classic

Y
ou can use Raspberry Pi to play all kinds of The clicky wheel iPod is a very important
media thanks to its small but mighty system- device in the history of portable media
on-a-chip. We’ve seen people use Raspberry players. So of course, Guy here ripped one
Pi to create incredible and inventive projects involving apart and upgraded it with a Raspberry Pi
Zero W and Spotify.
media – here are some of the very best.

magpi.cc/ipodspotify
Big and Smart Raspberry Pi
Picture Frame
Digital photo supremacy
With a spare monitor, a nice frame, and a Raspberry Pi loaded with
photos or connected to a cloud service, you can easily have a nice,
ever-changing series of pictures displayed on your wall.

magpi.cc/bigframe

BOSEBerry Pi
A 2010 throwback
The iPod docks of yore are remembered fondly by many and are still available
in a lot of hotel rooms. The form factor (and used price) really appealed to
maker David Hunt, who turn one into an internet radio box.

magpi.cc/boseberrypi

62 10 Amazing: Media player projects


www.dbooks.org
REVIEW

Atomic TV Vintage television


Digital to analogue
Custom-built nostalgia
Portable TVs were the coolest thing in the eighties and nineties.
Atompunk is a style that takes inspiration from American ideas of the future However, for obvious smartphone-related reasons, they have
from the 1940s and 1950s. This retro-future aesthetic has been perfectly fallen out of favour. This 1975 portable TV has been upcycled by
captured in Atomic TV, with bezels and curves and switches to match. It’s made the great Martin Mander to use a Raspberry Pi and a TV HAT for
from scratch as well and wouldn’t look out of place in the Carousel of Progress. portable digital telly. Nostalgic.

magpi.cc/atomictv magpi.cc/vintagetv

PiVidBox
Simple solution
This basic media player just requires
you to plug in an SD card or USB stick
with various media on it. It uses old
storage that would otherwise never
get used, and each has a curated
selection of content, labelled to make
sure you know what’s on it.

magpi.cc/pividbox Vinyl emulator


RFID records
Using Sonos and Spotify and some very lovely, RFID-enabled
cards to represent records, you too can experience the joy of
physical media. There are even cassette tape cases for specific
functions like play and pause or for specific playlists. Very nice.

magpi.cc/vinylemulator

Retro gaming
NES frame
Lo-Fi Orchestra
Video game art
Impractical yet cool
Pixel art and old game cover art
Using a whole host of microcontrollers and microcomputers – including have their place in pop culture, as
Raspberry Pi – Kevin, aka DIY Electro Music, has managed to recreate a lo-fi does modding the NES. Combine
version of Gustav Holst’s The Planets suite. He’s making his way through the them and you have this framed
suite, but Jupiter is one of our favourites. NES cartridge cycling through art.

magpi.cc/lofiorchestra magpi.cc/nesframe

Build a Raspberry Pi Media Player 63


SUBSCRIPTION

SUBSCRIBE TODAY
FOR JUST £10
Get 3 issues + FREE Pico W
Subscriber Benefits
FREE Delivery
Get it fast and for FREE

Exclusive Offers
Great gifts, offers, and discounts

Great Savings
Save up to 35% compared to stores

Subscribe for £10


Free Pico W
3 issues of The MagPi
Free delivery to your door
£10 (UK only)

+
Subscribe for 12 Months
Free Pico W
12 issues of The MagPi
Free delivery to your door
£55 (UK) £90 (USA)
£80 (EU) £90 (Rest of World)

Subscribe by phone: 01293 312193


Subscribe online: magpi.cc/subscribe
Email: magpi@subscriptionhelpline.co.uk
Subscribe for £10 is a UK-only offer. The subscription will renew at £30 every six months unless cancelled. A free Pico W is included
with a 12-month subscription in USA, Europe and Rest of World. (No Raspberry Pi Pico W with £5 Rolling Monthly Subscription).

64 magpi.cc
www.dbooks.org
SUBSCRIPTION

SUBSCRIBE TODAY AND GET A


FREE Raspberry Pi Pico W
Subscribe in print
today and get a FREE
development board WORTH

A brand new
RP2040-based
$6
Raspberry Pi Pico W
development board

Learn to code with


electronics and build
your own projects

Make your own


home automation
projects, handheld
consoles, tiny
robots, and much, This is a limited
offer. Not included
much more with renewals. Offer
subject to change or
withdrawal at any time.

Buy now: magpi.cc/subscribe

SUBSCRIBE
on app stores

magpi.cc 65
THANK YOU FOR READING!
Build a Raspberry Pi
Media Player!
Raspberry Pi is a small, clever,
British-built computer that’s packed
with potential. Made using the same
technology you find in a smartphone,
Want more articles and guides about
all the things you can make with
Raspberry Pi?

Read The MagPi, the Official


Raspberry Pi magazine

Sign up to our newsletter and get a free PDF


delivered to your inbox:
magpi.cc

Get a free Raspberry Pi computer with a


twelve-month print subscription:
magpi.cc/subscribe

Buy the magazine in print, and get books from


us and the rest of Raspberry Pi Press at
store.rpipress.cc

raspberrypi.com
www.dbooks.org

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy