You are on page 1of 42

Raspberry Pi 3:

Master Projects Guide


Table of Contents
Introduction
Chapter 1: Digital Picture Frame
Chapter 2: Portable NES Megaconsole
Chapter 3: Smart Mirror
Chapter 4: Infrared Remote
Chapter 5: Fun with Audio (Hi-Fi Audio Hub)
Chapter 6: Anonymous Router
Conclusion
© Copyright 2016 by DCB Web Trading Ltd ______ - All rights reserved.
The following book is reproduced below with the goal of providing information that is as
accurate and reliable as possible. Regardless, purchasing this book can be seen as consent to the
fact that both the publisher and the author of this book are in no way experts on the topics
discussed within and that any recommendations or suggestions that are made herein are for
entertainment purposes only. Professionals should be consulted as needed prior to undertaking
any of the action endorsed herein.

This declaration is deemed fair and valid by both the American Bar Association and the
Committee of Publishers Association and is legally binding throughout the United States.
Furthermore, the transmission, duplication or reproduction of any of the following work including
specific information will be considered an illegal act irrespective of if it is done electronically or
in print. This extends to creating a secondary or tertiary copy of the work or a recorded copy and
is only allowed with express written consent from the Publisher. All additional right reserved.

The information in the following pages is broadly considered to be a truthful and accurate account
of facts and as such any inattention, use or misuse of the information in question by the reader will
render any resulting actions solely under their purview. There are no scenarios in which the
publisher or the original author of this work can be in any fashion deemed liable for any hardship
or damages that may befall them after undertaking information described herein.
Additionally, the information in the following pages is intended only for informational purposes
and should thus be thought of as universal. As befitting its nature, it is presented without
assurance regarding its prolonged validity or interim quality. Trademarks that are mentioned are
done without written consent and can in no way be considered an endorsement from the trademark
holder.
Introduction
Congratulations on purchasing Raspberry Pi 3 and thank you for doing so.
The following chapters will discuss how to use the Raspberry Pi 3 to its full potential in tons of
engaging and super awesome projects that you can show off and which will take people’s breath
away.
This book isn’t going to detail how to set up and use Raspberry Pi - you can see my last book for
that information. Chapter 1 briefly skims over advanced operating system setup where before you
may have been doing it using NOOBS, but that’s all we cover related to general setup and usage.
It’s not going to teach you all about what Raspberry Pi is, either. If you’re here, you should know
exactly what the Raspberry Pi is. This book, rather, is going to help you as an intermediate or
advanced Raspberry Pi user in order to come up with some cool new ideas for projects that you
hadn’t before, and in order to get the juices flowing with some new technologies, you may have
yet to encounter. For the Pi hobbyist or the software tinkerer, this book is absolutely perfect.

The projects, for the most part, skim over some more complex details such as soldering in favor
of projects of a more mediary difficulty. Soldering goes into a whole other facet of hardware
engineering. This book contains mostly projects which are self-contained in and of the Pi’s core
functionalities, as well as some cool build projects which you can do as a frame for those core
functionalities. In other words, we aren’t going to be building some super complex Pi robots with
a million different sensors. However, we are going to be building some super cool things such as
smart mirrors and software-based infrared remotes, such that it should trigger a ton of ideas for
other things you can use these same concepts for. In other words, this book is meant to do two
things: serve as a catalyst for personal innovation, and get you working with some technologies
you may have had no clue existed.

This book also takes advantage of a lot of open source already-existing Pi projects and concepts.
If you’re an able programmer and hobbyist with spare time on your hands, you should absolutely
consider working with these projects in order to extend their core functionalities. Many of them
are modular and would also benefit from something as simple as designing new applications
using their API.
There are plenty of books on this subject on the market, thanks again for choosing this one! Every
effort was made to ensure it is full of as much useful information as possible, please enjoy!
Chapter 1: Digital Picture Frame
The first project that we’re going to jump into in this book is a digital picture frame. This
is rather self-explanatory. But this isn’t just going to be any picture frame. This picture frame is
going to pull pictures off of the internet and have them displayed in your frame. This specific
example is going to pull them from DeviantArt.
This will almost certainly make a super cool addition to your home and provide a nice
ambiance. Since it’s a Pi unit, you can also stream video and things like that to it. This project is
super simple, but it’s also super cool and super effective. Let’s look at how you make it.
Tools:
For this project you’re going to need the following:
- Raspberry Pi 3
- SD card, eight gigabytes works great
- Raspbian operating system, version Jessie as of the time of writing
- Win32DiskImager (for Windows computers), ApplePi Baker (for Mac
computers), Linux computers have built-in SD card OS writing compatibility
- LCD screen (I recommend getting the official Raspberry Pi display due to ease
of use/assembly)
- Picture frame
The first thing you’re going to do is get the system up and running. This is going to differ
based on what sort of operating system that you’re working off of. Bear in mind that for this
process, you really ought to have the LCD screen already set up with your Pi, so that you can test
the scripts as well as not have to reconfigure certain things later.
Windows
For Windows computers, you’re going to pop in your SD card and start up
Win32DiskImager. Your SD card will pop up on the side under your devices. What you’re going
to do is select that, then seek your ISO file and write it to your SD card. You may get a prompt
warning you that it will format all data on the SD card. This is true, but it’s nothing to worry
about. Be sure that you have any valuable data on your SD card backed up before you try to
perform this because it will be eviscerated to make room for the Raspberry Pi operating system.
Linux
The process for setting up a bootable SD card on a Linux system is a bit more arduous, but
the nice thing is that it is compatible right from the get-go and you don’t have to mess around with
arbitrary third-party programs. This would also work on Mac but there are simpler utilities to
make the entire process much easier on a Mac, so there’s not much reason to run this.
Also, extreme caution needs to be exercised when you’re using the dd command because
it has the potential to absolutely zero a hard-drive or hard-drive partition if used incorrectly.
Avoid this and use this method at your own risk. In other words, be careful.
First, you need to run the command df -h to see what devices are currently mounted
excluding your SD card.
Afterwards, pop in your SD card or SD card reader.
Then run df -h again. Look for the new device listed. The name will be something along
the lines of /dev/sdCardName/1. The ending, whether it be p1 or 1 or anything along those lines,
refers to a single partition. However, you’re overwriting the whole SD card, so you’re going to
truncate the name so that it’s just the /dev/SdCardName part.
Next, you need to unmount the SD card. This ensures that nothing can be read or written to
it while the operating system image is being transferred. To do this, you’re going to run:
umount /dev/sdCardName
In this instance, you of course replace “/dev/sdCardName” with whatever the name of
your SD card is. If your SD card showed up more than once in the output of the df command, you
need to unmount every partition.
After this, you need to write the operating system image to your SD. This is where we get
into the careful part of dd - if you insert the wrong device name, you’re going to erase all data on
your hard drive, which is super duper not a good deal at all.
In the terminal, you’re going to write the following command. Be certain that the input file
if= is the path to the image file, and the output file of= is the exact device name to which you’re
writing. Getting this wrong could mean the wiping of all of your data.
sudo dd bs=4M if=raspbian.img of=/dev/sdCardName/
This is going to take a bit. The dd command by default doesn’t show you your progress,
but don’t fear! Even if it seems frozen, it isn’t.
Anyway, at the end of the process, the SD card could be bigger than the original image,
and dd command will make a copy of the entire card. We need to truncate the new image to the
size of the original.
dd bs=4m if=dev/sdCardName/ of=sdCardCopy.img
truncate --reference raspbian.img sdCardCopy.img
diff -s sdCardCopy.img rabian.img
The two should be identical according to the diff command. After that, you need to run the
sync command to certify that everything is flushed and you can unmount the SD card. Then just
take out the SD card. You’re done. Woohoo!
macOS
This is much like Win32DiskImager in that it’s rather self-explanatory. Just pop in your
SD card, select your disk image, and go.
Anyway, once you’ve gotten all of that finished, you need to put the SD into your
Raspberry Pi and boot up.
The first thing that we want to do is set it so that we have the Raspberry Pi automatically
log in at boot. When you boot up Raspbian for the first time, you’re likely going to have a set-up
wizard. In this case, just go through it. When you get to the option that says “Start desktop at
boot”, set it to no. The Raspberry Pi will reboot and then ask that you log in. The username, by
default, is pi - the password is raspberry.
Anyway, in order to log in at boot, you need to change some internal settings. The first
thing we’re going to do is open Nano (our Terminal text editor) as an administrator and change
some settings. Run the following command:
sudo nano /etc/inittab
Then, scroll down until you find the line:
1:2345:respawn:/sbin/getty --noclear 38400 tty1
You just comment that out by adding a hash to the beginning of the line:
# 1:2345:respawn:/sbin/getty --noclear 38400 tty1
Then head to the line below that and modify it so it looks like this:
1:2345:respawn:/bin/login -f userName tty1 </dev/tty1 >/devtty1 2>&1
userName being whatever the login user name is. If you changed the default user name
from “pi” then use whatever user name you have designated.
Then reboot it by running sudo reboot and, if everything goes off without a hitch, it will
automatically log you in. Perfect!
Now, before we do anything else, we’re going to get our wireless connection working
from the command line. Raspberry Pi 3 has built-in wifi capabilities, which is fantastic and
simplifies this process a fair amount.
The principal thing to do here is to search for wireless networks, of course. We’re going
to do this by using the following command:
sudo iwlist wlan0 scan
This will turn up the ESSID, or the name of the network, as well as the authentication
version used. WPA and WPA2 are the most common, and should be what you’re using. In that
case, this guide will work just fine, and we’re only going to cover those in the scope of this book.
For WPA2 enterprise or WEP hex keys, you’re going to need to do a custom Google search.
Anyway, once we have our information figured out for sure, we’re going to open the wpa-
supplicant file in Nano. Here’s how we do that:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Then we seek down to the end of the file and add this:
network={
ssid=”networkName”
psk=”password”
}
Next, we exit to save the file and it should automatically connect in a matter of seconds. If
it doesn’t, you can restart it with sudo ifdown wlan0 followed by sudo ifup wlan0, or just reboot
the Pi altogether.
You can be sure that it connected by using ifconfig wlan0 - the inet addr field should have
an address beside it if you’re connected. If it doesn’t have that, then there may have been an error
in your configuration setup. Double check the ssid and password that you entered.
The next thing we have to do is install the Linux FrameBuffer Image Viewer, or fbi. This
is super simple.
sudo apt-get update
sudo apt-get install fbi
Now, after this, we need to make the scripts that actually do everything. The first thing we
need to do is create a new folder to store everything in. Let’s call it deviantArt.
mkdir deviantArt
Then navigate into it:
cd deviantArt
Now we’re going to create a new file, let’s call it getpics.
sudo nano getpics.sh
This is just going to be a bash file. In this bash file, you’re going to write the following:
rm *.jpg *.png

rm xx.*

wget -U ‘SomeUserAgent/1.0’ -O- ‘http://backend.deviart.com/rss.xml?q=special:dd’ 2> /dev/null |

grep -Po ‘http://[^.]+/.deviantart.com/art/[^”]+-\d+’ |

sed -r ‘s/.+-([0-9]+)/http:\/\/www.deviantart.com\/download\/\1\/xx/’ |

wget -U ‘SomeUserAgent/1.0’ -i-


FILELIST=~/deviantArt/*

totalCount=0

for f in $FILELIST

do

file -b $f

echo “Checking file number $count”

count = $(($count + 1))

if [ “$(file $f|grep JPEG)” ]; then

mv ${f} $(count%.*}.jpg

elif [ “$(file $f|grep PNG)” ]; then

mv ${f} $(count%.*}.png

elif [ “$(file $f|grep ASCII)” ]; then

echo “Skipping script file”

else

rm ${f}

fi

done

bash /home/pi/deviantArt/slide.sh

Afterwards, exit Nano and create a new file called slide.sh. Then, type the following:
fbi -noverbose -m resolution -a -t 10 /home/pi/deviantArt/*.jpg
/home/pic/deviantArt/*.png
Where screen resolution is the, well, resolution of your screen. Since you’re going to be
outputting this to a tiny little LCD screen, double-check to see what exactly your screen resolution
should be. In my case, it’d be For example, a 7” LCD display may be 800x480, in which case the
command would be:
fbi -noverbose -m 800x480 -a -t 10 [...]
Basically, you can find what you need on the box of your LCD display, or via a Google
search.
After this, you need to add whatever resolution to the system. If you’re using the
Raspberry Pi official display, this may not be necessary, but let’s go ahead and do it anyway to be
sure. If we took the aforementioned 800x480 display, what we’d do is this:
First, you enter the frame buffer modes file in Nano:
sudo nano /etc/fb.modes
Then we’d scroll to the end of the file and enter the following:
mode “800x480”
geometry 800 480 800 480 32
timings 0 0 0 0 0 0 0
accel true
rgba 8/16,8/8,8/0,0/0
endmode
You can adjust this to fit your display resolution and basically whatever your preferences
are.
Then, just like before, we exit Nano in order to save the file. We just have to make a script
to restart the computer. We do this like so:
First, we make the file:
sudo nano restart.sh
Then, once we’re in, we just type this:
sudo reboot
Then we exit to save once more. Now we have to make the script files executable.
sudo chmod +x getPics.sh
sudo chmod +x slides.sh
sudo chmod +x restart.sh
We’re going to have this set to reboot at midnight. We’re oging to do this through the
process cron, which is great for scheduling certain processes for certain times.
First, we go into the startup sequence within Nano:
sudo nano /etc/rc.local
Then, when the script is open, we’re going to add the following above “exit 0”.
/etc/init.d/cron start
bash /home/pi/deviantArt/getPics.sh
Then we exit to save again. What this will do is start the cron process and launch our
getPics script every single time the Raspberry Pi is booted up. Now, we just have to schedule the
unit to reboot at midnight. We do that by going into cron:
crontab -e
Then enter this:
@midnight /home/pi/deviantArt/restart.sh
Exit to save once more and then reboot. Everything should now be running system-side.
Now all we have to do is add our other components.
The process for this is relatively straightforward. Depending upon what type of picture
frame you have, the exact assembly is going to, of course, vary. I can say for certain that one thing
youŕe going to have to do is engineer a place for your Pi display behind the glass of your frame.
Fortunately, if you’re using the official Pi display, it’s pretty thin. Due to the variety of
different frame shapes and forms you could have, I’m going to leave the exact details of this to
you.
Chapter 2: Portable NES Megaconsole
Since Raspberry Pi’s inception, it’s been used by hobbyists everywhere to run all sorts of
video game emulators. So in that manner, this idea is nothing new. What makes this differ from
other general emulator projects, though, is the fact that this one is entirely self-contained and
portable. What’s more is that from the outside, it looks like little more than an NES.
Also, if you and your kid share a love of gaming - especially retro gaming - this can be a
super fun project to undertake.

What’s better is that it may be a self-contained unit, but you can use any USB joypad you
like with it, and play games spanning several eras - it may look like an ordinary NES on the
outside, but it packs so much power on the inside.
This project actually spawned from an old NES that quit working. It’s been sitting gutted
in my garage for years, waiting for an appropriate craft project to come along. At one point, it
clicked - the Raspberry Pi gives me a perfect chance to repurpose an old and invalid video game
console into a totally modern wonder.

Here’s what you’re going to need for this:

Tools:

- NES (broken is better, here)


- Hinges
- Sharpie
- Power drill with drill bits designed for plastic
- Raspberry Pi 3
- Display - I recommend either this 4” display or this 5” display. Which one you
opt for is up to you, but if you go with the latter, you’ll need to do more sanding.
- Sanding block (numerous grits)
- USB controller - Here’s a NES model and here’s a SNES model. The SNES
model is, of course, more practical, and if you get the NES model, you’re
basically limited to NES and Gameboy/Gameboy Color games. Don’t let that deter
you from the absolute mad style, though.
- Screwdriver
- SD card
- USB drive
- 3.5mm speaker system of some sort if your display doesn’t have sound - I
recommend that they’re flat so that they can fit in the bottom portion to provide a
counterweight to the top-heavy design. This isn’t necessary if you decide you’d
just like to use headphones for your sound needs.
- Heavy material of some sort, thick linen, recycled curtain, etc.

So the first thing you’re going to do, of course, is crack your NES open. You do this by
taking out the screws on the bottom until they’re all out. Then, you just take off the top. Super
duper easy.
Within the NES, you’re going to find a lot of components that you need to remove. These
are pretty straightforward, and you’re gutting it entirely, so just take everything out. I did leave the
power/reset button connectors and the controller jacks, though. They’re very aesthetically
pleasing and when the top is replaced, give it the appearance that it’s an actual NES. You can do
as you want, of course.

So, the next thing that you’re going to want to do is get to work on the Pi. With the NES
gutted, we can set it to the side as we work on the actual bulk of our software.
I’m not going to reiterate how to image disks for Raspberry Pi, if you need to remember
how to do that or any essentials like setting up wireless networks, then I recommend you head
back to chapter 1.

So with that in mind, we need to figure out exactly what image we want to use. The one
we’re going to use here is RetroPie. RetroPie actually sits on top of Raspbian in order to help you
play and emulate classic games.
As with all emulator guides, I’m going to make the legal disclaimer that for emulation to
be legal, you must own a physical copy of the original game that you’re emulating.

Anywho, with that said, let’s move on to how to install RetroPie. You’re going to install
Raspbian like before. Then, within Raspbian, we’re going to be sure we’re connected to either a
wireless network or we have an ethernet cable plugged up, and then we’re going to be executing
certain commands.

The first command we’re going to execute is checking our free disk space with df -h.
/dev/root is the main partition here.
Afterwards, we’re going to update the APT packages we can get.

sudo apt-get update && sudo apt-get upgrade


After this, we need to actually install the packages required for the RetroPie setup.

sudo apt-get install git lsb-release


After we’ve done that, we’re going to need to download the RetroPie setup script.

cd
git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git

Then we need to make the script executable and then, well, execute it.
cd RetroPie-Setup
chmod +x retropie_setup.sh
sudo ./retropie_setup.sh
I’m sure some of this looks familiar from the last chapter or previous work with
Linux/Raspberry Pi that you’ve done.

After this, you need to check to be sure that your locale is correct. The RetroPie install
deals with a variety of scripts in order to install all of the packages and libraries that are needed
for each emulator to run, and the installation thereof will likely not work if your system locale
settings aren’t correct. It’s easy to verify them. You just execute the locale command.

If any of the local settings aren’t set, then you need to set them. There’s a very easy way to
set this:
sudo update-locale LC_ALL=”locale”

Where the locale will be your locale. Your locale may be something like en_US.UTF-8.
Anyway, after you’ve verified your locales and set them if needed, we need to start
installing RetroPie. We can choose between a full install and a partial install. If you don’t want
all of the emulators that RetroPie has to offer, you should do the latter. Otherwise, just go for the
full install.

Full Install

For the full install, we’re going to just go to manage packages, then highlight quick install
and press enter. Certainly nothing too strenuous here. What this is going to do is install every
emulator that RetroPie has to offer. It will also create all of the directories for you to store your
ROMs in. If you follow the simple steps described thus far, all of the ROMs are going to be
stored in ~/RetroPie/roms.

Partial Install

This is a much lighter option than the full install and allows ya decent looking top ou to
install a much lighter proportion of emulators than you were going to otherwise. You get to
specifically select which ones that you want to be installed. It’s worth nothing that you need to
install the following core packages for RetroPie to function:
- RetroArch
- EmulationStation, which handles starting up all of your games that
you have set up, as well as sorting them
- RetroPie Menu
- Runcommand

Once you have those installed, you can pick whether you want to install the main,
optional, and experimental packages. This is where you’re going to be finding that you can install
and update any of the emulators that you want.
After this, we’re going to want to set it so that Emulation Station starts at boot. This is
super easy. In retropie, just go to Setup Script, then go to Configuration / Tools, before finally
arriving at the autostart menu. There will be a list of boot behaviors. Choose the first: “Start
Emulation Station at boot”. Now you have a Raspberry Pi system which will automatically boot
into Emulation Station, making it super easy to access your games from the get-go, not having to
bother with any peripherals beyond your controller.
Anyway, before we move on, we're going to talk about how to get the ROMs that you want
onto the Raspberry Pi. The most simple way to do this is via USB drive, so that’s precisely what
we’re going to cover right now.

The process is relatively simple. On a different computer, you need to download the
ROMs that you want. I’m not going to tell you where to get them, but a simple Google search
should certainly suffice.

Next, you put the drive in your computer. In order for this method to work appropriately,
you’ve got to format the drive to FAT32. Here’s how you do that on every major OS:

Windows
Plug in the drive. Go to the File Explorer and right-click the USB drive in the sidebar.
There will be an option in the drop down list to “Format…”, and you’re going to click that. A
little dialogue will pop up, and one of the options will be “File System” - set it to FAT32. Fill out
any appropriate fields such as drive name, click “Okay”, and you’re good to go.

Linux

The first thing you need to do is install Gparted. Run:

sudo apt-get install gparted

Then run it. Make sure your USB drive is plugged in before you do. Then find your drive
in the drop down menu in the upper right corner. Then you just create a partition on the drive if
there is none, and set it to the file system FAT32. If there are partitions, double check that it’s the
correct disk, delete/expand any partitions until there’s only one, then format it to FAT32.
Mac

Put the drive in your computer. Then go to Finder and search for Disk Utility. Open it.
On the sidebar, locate your flash drive and select it. Then click the “Erase” tab and select
“MS-DOS (FAT)” as the format and specify a name. Click the “Erase…” button, then click
“Erase” when the warning pops up. Momentarily, the flash drive will appear on your desktop.

Anyway, with all of that done and the drive formatted, you need to go to the drive and
create a folder called “retropie”.

Then all you do is put your USB drive in the Raspberry Pi. Wait for the drive to stop
blinking, and then take it out.
When you stick it into your primary computer again, you should see a ton of directories
within your retropie/roms folder. Add every ROM to its relevant folder, then throw it back in
your Raspberry Pi. From here, you just wait for it to finish setting up. When the drive once again
stops blinking, you just refresh the Emulation Station program by pressing F4. If all goes well,
you should be able to play your new games from your Raspberry Pi.
Right, so with that done, let’s get back to the more impressive and unique part of this:
making this work within the context of the NES.

So, with your NES taken apart, you’re going to notice that it has the perfect set-up to open
and close on a hinge. This is a great advantage to using specifically the NES: it has a super
simple design. It’s made out of a top and a bottom and everything relevant is sandwiched between
those parts. Once you take out the electronics, you have a lot of free space to do whatever it is
that you want to do, too.

Also, you may wish to superglue the cartridge lid closed. It could make tinkering with
everything easier. I opted to do exactly that.

Anyway, the first thing we’re going to do here is install our hinges. Hinges aren’t a hard
concept at all. Figure out mentally where you’re going to want the hinges and then make marks for
their screw holes wherever they may be. Take your drill and slowly drill a hole where those are.
Install the hinges. Very simple. Try opening and closing the NES to verify that all is in working
order. It should go off without a problem.
Now with that done, you’re going to start figuring out where you want your components to
be. Hopefully, you’ve been testing out all components as we go, having your LCD screen already
set up with your Raspberry Pi.

Firstly, you need to decide how much room you need. If your display is bigger than 6
inches wide by 4 inches tall, you’re going to have to sand down the inner grooves on the lid so
that your display is mounted strangely. This isn’t too terribly difficult, just a little time-consuming
and takes a little elbow grease. Grab your sanding block and work away at it until it’s level. Start
out at a lower grit then work your way up to a higher grit for a finer, less abrasive sand. Be super
careful here, because plastic gets sanded down extremely fast.
After that, you need to figure out where the screws go in your Raspberry Pi. In order to do
this, you may need to actually detach your display momentarily. Certainly, this isn’t the most
inconspicuous way to mount your Raspberry Pi, but it’s 1) the most secure and 2) the most
effective in this context. It gives a super clean “home brewed” feeling to the whole thing. Do the
same procedure as before, drill holes in the lid of the NES where the screws will go, and then
fasten a nut on the other side. Again, this is not necessarily inconspicuous, but nobody is going to
notice if you don’t specifically point it out or you’re showing the rig to them anyway. You could
maybe get away with a double-velcro solution but I would be worried about the security of such a
setup.
Anyway, once that’s all fashioned, you should have your Raspberry Pi secured to your lid.
Let’s check the security of the design. Throw in your linen in the bottom compartment. This will
serve you in two ways:
1) If your screws aren’t as secure as you thought they were, your Pi won’t be
damaged by a rough fall.
2) It will act as a counterweight when you decide to mount your LCD screen,
which will make the unit as a whole very top-heavy.

Try opening and closing it, just verify that everything is in working order. Now what you
want to do is plug in all necessary peripherals while your screen is still detached so that you
don’t have to fumble around under the monitor. Note that if your monitor mounts directly to your
Raspberry Pi via screws, then you’re going to need to unscrew your Pi first, since you can only
really have one set of screws going through the same screw holes.

But yes, plug in your speaker(s) if applicable, your controllers, your power cable(s), all
of that. Then when you’re ready, set up the screen on top of all of it. Go ahead and set up your
screws like you need.

There should be enough room that you can route the power cable out of the actual power
jack, but if not, you can just drill in the hole to make it even bigger or take out the rear A/V and
power section altogether. Since the micro USB power adapter is, well, micro, you likely can
route it through the existing A/V hole for a neat little power line with no extra drilling.
The real beauty of this too is that with the right LCD screen, you can actually directly
output your content to a bigger TV screen via HDMI. For example, the aforementioned 5” LCD
screen has this capability.

By the end of this project, you have a full-featured self-contained video game emulator
system, encased in a classic video game system -- arguably the most classic video game system.
Chapter 3: Smart Mirror
This is one of the more ambitious projects that a Raspberry Pi enthusiast can undertake.
With that said, it’s incredibly rewarding.
There are already two major iterations of the Raspberry Pi smart mirror that are
commonly used: MagicMirror2 and MirrorMirror. MagicMirror2 is technologically more
advanced than MirrorMirror, and more extensible and modular by its very nature. This is why
we’re going to undertake the MagicMirror2 instead of MirrorMirror - it may be technologically
more advanced, but it’s easy to set up and it’s easy to get working, and you have a lot more
options right off the bat.

The only reason I say that MagicMirror2 mirrors are more technologically advanced than
smart mirrors styled after MirrorMirror’s smart mirror is because they are based around having
an easily extensible API and they have a much more established community.
So what’s the concept underlying a smart mirror?

A smart mirror is basically what it sounds like: a mirror that incorporates technology. The
most immediate and cost effective way to do this is to have a display behind a two-way mirror.
The idea is that with a two-way mirror, also called an observational mirror, you can see the
sources of light on the other side of the mirror. You place a monitor on the other side of the two-
way mirror, optimally within the frame of the mirror (though a frame certainly isn’t necessarily
required and you don’t need one, despite the fact that your mirror may be a mess if you don’t
incorporate it.) Then, from the spectator side of the mirror, you can see whatever is on the
monitor on the other side of the two-way mirror.

For the most part - with DIY mirrors at least - instead of custom software, Raspberry Pi
smart mirrors usually load into a simple custom webpage in Chromium on boot. This allows a
great level of functionality to the setup in general because you can go in and handcode JavaScript.
Anything you can represent on a webpage, you can represent on your smart mirror.
The advent of the Raspberry Pi and other miniature hobbyist computers made this idea far
more approachable than it used to be. It used to be the stuff of dreams and, quite literally, of
fairytales. However, the fact that computers are now super small and contain so much power in
such little size means that they now can be used for such ambitious projects as the fabled magic
mirror.
Anyway, without further ado, let’s jump into this project.

Here’s what you’re going to need:


Tools:

- LED/LCD monitor with HDMI output


- It’s preferable that the electronics of the monitor be near the
middle rather than to the sides, to make it far easier to set up and
work with.
- Wood to make a frame. Or anything to make a frame out of, but wood is the most
accessible.
- Proper tools for woodworking (drill, screws, etc.)
- Raspberry Pi 3 (of course)
- Surge protector or other way to combine multiple outlets into one neat power
line
- Extension cord
- Two-way mirror
- MicroUSB to USB cable
- USB block power adapter
- SD card with Raspbian image

The general modus operandi for this kind of smart mirror is that the monitor and the two-
way mirror are the exact same size, but this isn’t necessarily required at all. It also doesn’t
necessarily have to be a monitor - you could do this with a flat-screen TV as well. This example
is going to look at how you’d use a computer monitor, though. The process would be pretty
similar.

So the first thing you’re going to do is get some measurements. You need to go crazy and
take the bezel/casing off of your monitor. Do you have to do this? No. But it does make the mirror
much slimmer and give you more room for the important electronics contained therein. Get the
combined width of your two-way mirror and your two-way mirror. Store this information
somewhere, because you’re going to need it later.

In the meantime, make sure your monitor and mirror are the same size. If they aren’t, get
the measures of the monitor and use a saw in order to cut the mirror flush to those measurements.
They should match up in size.

You have two routes here: you can make a super fancy frame, or you can make a
rudimentary frame and call it minimalism. I’m not much of a woodworker, so I opted for the latter.

What you’re going to do for a minimalist frame and case is just create a little wooden box,
basically, that will fit your monitor and mirror flushly. When I say little, I of course, don’t mean
little. It needs to be deep enough to fit your mirror, monitor and components with no issue,
alongside a mounting block behind them, two along the top and two along the bottom. This is what
you’re going to use that little measurement of your monitor and mirror for. The extra space
allotted by the mounting blocks will leave plenty of room for any extra components and wire
work that you need to do.
Anyway, after doing that, you need to create and attach a frame. This, of course, needs to
be much broader than your casing, but also much thinner. It needs to be able to hold in your
monitor and mirror from the front.
After you make the frame, you need to glue it to the front of your case along the edges.
For the record, you should likely drill a hole in the bottom edge of your casing so that you
can thread your power cable through it neatly.

At this point, you’ve got the basic structure to the mirror set up. You then need to flip it
over and get to work with some basic power stuff, as well as your Pi.

I’d recommend putting a case on your Raspberry Pi here, that way if something
catastrophic happens, you don’t have a motherboard swinging around commando style in the rear
of the mirror. After doing so, you need to set up your surge protector and tape it down to the back
of the monitor for purposes of cable management. We’re done with the Raspberry Pi for a few
moments while we test everything out monitor-wise, but keep it close - we’ll be using it here in
just a second.

Plug the appropriate power cable into your monitor and then plug that into the surge
protector as well. Plug the end of the surge protector into your extension cord and thread that
through your power cable drill hole. Plug that into the wall and press the little power button
which correlates on your monitor’s electronic circuit board in order to turn it on. Pretty much
every monitor has some default text even if it doesn’t have input. We’re going to just turn our
monitor on, turn it face up, and see if the default text shows through our one-way mirror. If all
goes well, you should see something along the lines of “No Input Detected” floating around or
stationary, the exact display depending of course on your monitor.
Now we’re going to turn it back down. We’ve gone over before how to boot up and install
Raspbian. You should, at this point, have an SD card with Raspbian on it. Go ahead and plunk that
into your Raspberry Pi unit. Lastly, plug in a keyboard and mouse peripheral, so that you’re not
just staring at a screen unable to do anything.

With that done, you’re now going to take the microUSB to USB power cable and plug it
into your Raspberry Pi. You’re going to feed this into a USB block power adapter and then plug
that into the surge protector or two-way power splitter.
Turn your mirror back up. You should see Raspberry Pi booting up. Go through
everything, but this time, be certain that you set it to boot into the graphical environment and not
the command line.
Once all of that is together, open the Terminal and do the same things we did earlier to
configure wireless networks.
Since this is just for a smart mirror set up, you have the option to remove all of the
packages you won’t be using. Run the following command:
sudo apt-get remove --purge idle3 java-common libreoffice* minecraft-pi python-
minecraftpi python3-minecraftpi wolfram-engine
This will clear up a pretty solid amount of space and leave your OS a lot more usable,
well, space.

Now it’s finally time to install MagicMirror2. What you’re going to do is go to the
Terminal again and type in the following command:

curl -sL
https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh | bash

This is the principal reason we decided to opt for MagicMirror2 over coding our own
shell and website: it’s so much easier to do. The underlying concept is the same, but
MagicMirror2 packages it so neatly and efficiently in an easy to use package.
After that, we’re going to rotate the screen, because currently it’s not at all oriented
correctly. So what we’re going to do is go into the config file:

sudo nano /boot/config.txt


Then we’re going to add the following text somewhere in the file. It doesn’t really matter
where:

display_rotate=1

Just like always, exit and save the file.

Now we’re also going to disable the screensaver and screen sleeping, so that way our
display is always active and we don’t have to fiddle with anything to turn it back on.

Type this into Terminal:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Add the following to the bottom:


@xset s noblank
@xset s off
@xset -dpms

Exit and save, like usual. The next location is this:


sudo nano /etc/lightdm/lightdm.conf

Now we’re going to find the section called “Seat Defaults” and seek the xserver-
command within it. Modify the line so that it looks like this:
xserver-command=X -s 0 -dpms

Exit and save again. There we go.


Now, we have to turn off the power saving feature that Raspberry Pi will automatically
enable. We have to turn it off for the wireless driver specifically, because if we don’t turn it off,
Raspberry Pi will shut it down since it’s not actively being used by anything. We want our mirror
to always have the latest updates, so we’re going to just disable this feature.
Back to Nano:

sudo nano /etc/network/interfaces

Then seek out the wlan0 section and add this below it:
wireless-power off
Reboot the Raspberry Pi using sudo reboot.

Now, the most basic features of our smart mirror are set up. Now, we have to create
config files for MagicMirror2.

We’re going to do this by navigating to the MagicMirror2 config folder:

cd MagicMirror/config

Then we’re going to run the following command:

cp config.js.sample config.js

This will create a configuration file for us. Now we can start it up and try it out.

cd $HOME/MagicMirror
npm start

The fact that MagicMirror2 is very modular opens up a ton of possibilities in regards to
the modules you can have set up.

So there you go. You now have a super impressive smart mirror that will blow away any
visitors to your house, get you up to speed in the morning, remind you of important events, give
you empty compliments, and many other things.
Plus, there are a lot of ways to build on top of these concepts. For example, you could
incorporate the open-source voice API Jasper so that the mirror responds to things that you say.
You could use a motion sensor so that the monitor and Raspberry Pi sleeps until you come around,
at which point they’ll boot up to life.
Chapter 4: Infrared Remote
This is inevitably one of those projects that you don’t need justification for undertaking.
This one is enjoyable simply because it’s, well, fun. Here’s the lowdown: there’s a new add-on
for the Raspberry Pi that can actually send and receive infrared signals. So this is actually pretty
sick. This means that with this add-on, once we set it up, we can actually use turn on a huge
number of devices from our host computer (or any number of things, really).
You could make a custom remote with only relevant buttons to you, or if you - like me -
usually watch TV with a laptop in your lap anyway, you could write a custom program which
would actually allow you to select which infrared device you wanted to communicate with and
send commands directly to it without bothering to keep up with any number of remotes. And in
today’s day and age, there are a lot of remotes.
But as I said, this is ultimately just a really fun tinkering project that opens up a lot of
possibilities as far as further development goes, and it’s just really cool and enjoyable.

It’s worth saying that the same hardware component which makes up the bulk of this
project, the MATRIX Creator, also has a flurry of other components built in. Among these is a
microphone array, allowing for one to set up voice command things similar to and including
Amazon Alexa, a temperature sensor, an ultraviolet sensor, a pressure sensor, an accelerometer, a
gyroscope, a magnetometer, and a humidity sensor.

In other words, this one component combines an absolutely massive number of different
sensors and components that you’d have to buy separately otherwise, which is super impressive.
That is to say that if you buy the MATRIX Creator, you’re also opening the door to a lot of
projects that go far beyond this infrared remote example.

With that said, this is most certainly our starting point to this whole thing, so let’s jump in.
For this specific project, here’s what we’re going to need:

Tools:
- MATRIX Creator
- Raspberry Pi 3
- 5 volt 2.0A power
- A device with infrared that’s supported by LIRC. (Most devices with infrared
are supported by LIRC.)
So basically, per usual, you have to have Raspbian installed in the first place for this all
to go properly. You can just boot into the graphical interface again instead of command line. A lot
of the time, that’s actually preferable. The only times it’s not is when you’re doing very intensive
processes and you need all of the processing power that you can get to go towards the processes
themselves and not trying to work around the resource intensive interfaces.
Once you have that installed, you need to install the software for the MATRIX Creator
specifically. To do this, you’ll need to run the following command:
echo “deb http://packages.matrix.one/matrix-creator/ ./” | sudo tee --append
/etc/apt/sources.list

Afterwards, update your package list, and then install the required packages.

sudo apt-get update


sudo apt-get install matrix-creator-init cmake g++ git
Then reboot the Raspberry Pi like always:

sudo reboot
After rebooting, everything will be clean and tidy and squared away for you to us as you
wish.

We talked earlier in the tools list about LIRC, but we didn’t say what that actually meant.
LIRC stands for Linux Infrared Remote Control. It is a package which allows you to decode and
send infrared signals from a great number of remote controls. Bear in mind this doesn’t mean
every remote control, but for the most part, you’ll be absolutely fine in regards to which remote
control you’re using.

You can test the MATRIX Creator to be sure that everything is in working order by simply
pressing a button on the remote. An LED on the add-on will blink every time you do.

It’s worth mentioning that we need to test everything that we have in order to ensure that
LIRC is working as intended.

What we’re going to do here is type the following:


sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0
After doing this, press some buttons while aiming at the sensor. You should see some
relevant feedback popup in the terminal referencing “pulse” and “space”. This means all is in
working order.

After that, we’re going to figure out how to record commands with LIRC. What we do in
order to do that is run the following command while in our user directory, which can be found at
(/home/pi):
irrecord -d /dev/lirc0 ~/nameOfController.conf

Then it’s going to prompt you with various different instructions. All you’re going to do
through this process is exactly what it tells you.
It’s going to ask you here and there for key names. When it does this, it’s imperative that
you use the predefined names. If you’re like me, you don’t always know the esoteric predefined
names that are set for every popular infrared remote, and hey, that’s okay. In order to get those
names, we can just open a new instance of Terminal and run the following command:
irrecord --list-namespace

By the end of this whole process, you’ll have generated a config file for a given remote.

After all of that, we have to now add this to our master remote control entry. “How do we
do that?” you may be asking. That’s a very pertinent question, friend. What we’re going to do is
open that config file that we just had, if it’s not already open, and copy everything from begin
remote to end remote.

Once you have that text copied, we’re going to go and edit the master config file. Type this
into Terminal in order to access this config file:
sudo nano /etc/lirc/lircd.conf

Swap out everything in the file with the text that you just copied from your config file just
now. Exit to save. You now have a working infrared remote hardware Frankenstein-type neato
invention contraption. You can do this for as many remotes as you’d like to.

If you decide you want to add more remotes to the master remote file, you absolutely can.
All you have to do is place the begin remote and end remote chunks consecutively, like so:

begin remote

name remote1
bits 16
[keymaps]
end remote
begin remote

name remote2
bits 16
[keymaps]
end remote
begin remote
name remote3
bits 16
[keymaps]
end remote
Once we’ve got all of that set up, we finally are at a point where we can use this for the
ultimate evil: sporadically turning off televisions other people are watching after nefariously and
covertly setting up the remotes to our Raspberry Pi. How do we do this? Relatively simple. We
just type the following command:
irsend SEND_ONCE deviceName NAME_OF_KEY_HERE

deviceName is whatever you named your device when you created the config file, and
whatever its name is in the master remote config file. The name of the key is the, y’know, name of
the key. For example, if in our config files, the key name for the power button on our Panasonic
remote was KEY_POWER, we could type:

irsend SEND_ONCE Panasonic KEY_POWER


And it would turn on/off the Panasonic TV, provided of course that there’s not an
interference between the MATRIX Creator and whatever infrared device we’re talking about. =
So there you go. That’s about as simple as we’re going to be able to make this whole
thing. You can incorporate these commands into bash scripts in order to, for example,
automatically turn on this or that peripheral when an event happens, like turning on a TV or
monitor when motion is detected or a certain face is recognized by facial recognition software.
All in all, there are a ton of possibilities for this specific technology.
Chapter 5: Fun with Audio
Alright, so in this chapter, we’re going to start talking about another concept: how can we
use this technology to improve our ability to relax at home? I mean, sure, video game consoles
and tinkering with remotes are super cool, but what can we actually do with Raspberry Pi where
it’s practical, out of sight, and makes it just a little bit easier to get by on the day-to-day?
I don’t know about you, but I like to relax with music. There’s little that’s more relaxing to
me than reclining and listening to an album after the daily stresses of life.

Hopefully, a lot of people will find this chapter useful, because music is one of the
primary tools through which the soul and the mind communicate for a great number of people.
People who both just enjoy listening to music to relax and who are genuine enthusiasts of high
fidelity audio will likely enjoy this chapter quite a bit.

What we’re going to talk about, first and foremost, is what we’re working with and what
we’re trying to accomplish here.

Basically, what we’re trying to do here is make a little device that will stream music from
our network (or from AirPlay). Bear in mind it can also stream on-board music with no issue if
you directly link a flash drive or a USB hard drive to it. However, if you do decide to opt for a
USB hard drive, be absolutely certain that it has its own built-in power supply. If it doesn’t, then
it will draw far more power than the Pi is able to put out. This could lead to data corruptions,
hardware failures, or you frying your Pi entirely. Those are things we really don’t want to happen,
obviously, so let’s just avoid that altogether.

The process for this all is relatively simple. There’s no soldering, there’s just a little
back-to-forth from computer to Pi and back at first, but it’s certainly not much of a hassle. The
great thing about this method is that it actually is relatively easy, but has a pretty mind-blowing
result.

In order to follow this project appropriately, you do not need some sort of high-end
amazing speaker system. No, not at all. All you need to have is some sort of speaker or audio set,
and a love for great-sounding music. There is no elitism here.
One more caveat before we jump into this all: you don’t have to buy a digital to analog
converter. However, it is recommended, because the onboard audio jacks for the Raspberry Pi
are very dicey at best. They are noisy, quiet, and all-around not the type of thing you want
clouding your music. So while you don’t necessarily need a digital to analog converter, I highly
recommend that you get one, if only because it makes the end-result of the process much, much
sweeter and more enjoyable. So to that end, we may as well say that yes, you need to buy a digital
to analog converter. But also to that end, it’s generally recommended to pair a digital to analog
converter with an amplifier. There are two main reasons for this: amplifiers usually have some
sort of on-board equalization that you can tamper with to make your music sound however you’d
like for it to, and certain higher-end headphones are naturally a bit quiet. This is intended to be a
feature rather than a bug in higher-end audio equipment, though. It’s ameliorated with an amplifier
setup typically.
So, with that said, let’s get going with all of this. Here’s what you need:

Tools:
- Source PC
- SD card, preferably fast and preferably bigger, with the RuneAudio image
installed to it. (you don’t need to get Raspbian this time.)
- Dedicated digital to analog converter (DAC)
- (optional) Amplifier
- (optional) Spotify Premium
This is a lot simpler than the former tutorials that we’ve covered in terms of what all you
need, and it’ll be a lot simpler comparatively than the one which follows, also.

So the first thing that we’re going to do is set up our peripherals. Plug in your ethernet
cable (given it’s a first time setup and all of that), as well as your DAC and sound source. Then
pop in your SD card and an HDMI connection. After that’s done, just plug in your power cable to
boot it up.

There’s not much to do in the way of specific set-up instructions; RuneAudio primarily
does the heavy lifting itself. We’re using the RuneAudio, then, for a lot of the same reason that we
used the MagicMirror2 setup package earlier: it’s simple and keeps us from having to do a lot of
the things we’d have to do otherwise, while giving us a nice, neat package with a lot of features
so our hands don’t have to get dirty at all. Once everything is set up, we’re going to want to move
back to our parent computer and try connecting to RuneAudio from a client. If you’re using
Windows, you’re going to want to type in http://runeaudio. If you’re using a different operating
system, such as macOS or Linux, you’re instead going to type http://runeaudio.local. If you can’t
find your Pi, we need to troubleshoot the problem. If you aren’t able to find the runeaudio rig, then
we’re going to try instead typing its address in directly. Remember that address that we just
specified? Type that in instead of http://runeaudio(.local). You should be directed to the
RuneAudio page. Super simple.

I know for sure that a lot of what I’m looking for here is that my set-up is wireless and as
clean and wire-free as possible. If you’d like to set it up to be wireless, what you do is click on
the Menu from the RuneUI and select Network from the drop-down menu. From here, you’re going
to click on WLAN0 and select your home wireless network from the list which you’re given. Set
the IP assignment to static, and type in an IP address. It needs to be in the format specified, but you
can put anything that you want in place of the xs:

192.168.1.xxx
When it asks for the netmask, what you’re going to do depends on what you’re connecting
to the RuneUI from.
If you’re connecting from Windows, you’re going to do the following:
- open up the command line (go to the Start menu, search for “cmd” or “cmd.exe”,
run it)
- Enter ipconfig /all
- Your subnet mask will be among the information listed. Use what it says.
If you’re connecting from Mac, it’s more like this:
- Go to System Preferences.
- Go to Network.
- Select your primary connection. Your subnet mask is most likely already listed. If
not, click Advanced… in the bottom right area of the window.
- Go to the TCP/IP tab. Your subnet mask will be listed here.

Lastly, if you’re connecting from Linux, it’s going to be a bit more like this:
- Open the Terminal.
- Type ifconfig. It’ll be listed in the information printed out to the screen.

Enter the submask and then confirm all of your settings. Your Raspberry Pi music rig is
now set up for wireless access.

Anyway, going forward: what we’re going to go ahead and do now, once we’ve got our
wireless connection and all of that setup, is move back to our computer if we’re not already on it.
I’ve only really done this on a Windows computer, and for this reason, I can only really divulge
how it would be done on a Windows computer. I’m not certain what the process would be for
Linux and Mac computers. With that said, I’m sure it’s relatively simple, and a quick Google
search would turn it up. What you’re searching for is how to establish NAS with your host
operating system and access it with RuneAudio. In fact, I’m sure it’d be relatively similar to the
Windows process! Anyhow, here’s how you go about the process on Windows:
First, go to the folder you want to share. You may have a music folder with your library in
it already. If so, great. You just need to go ahead and right-click that folder and click Properties.
After that, head to the Sharing tab and click the button which says Share…, after which a drop-
down list will appear. From this drop-down list, go ahead and choose “Everyone” and click the
Add… button. Set the permission level to be Read for the group “Everyone” and click the Share
button. After this, you’re going to find the network path. It will be directly listed under the file
name on the Sharing tab.
Once we’ve went ahead and established the shared folder, we need to turn off password
protection for shared folders. Go to the Network and Sharing Center by right-clicking on the
network listings in the taskbar and clicking “Open Network and Sharing Center”. Once we’re
here, we’re going to go to Advanced Sharing Settings, seek to the bottom of the page and expand
where it says “All Networks”. There will be an option here under the section called Password
protected sharing. Click the radio option to turn it off and then click the save changes button at
the bottom.

After this, we need to configure RuneAudio so that it sees and recognizes the shared
folder from Windows. We’re going to head to the RuneUI again, just like before. Then we’re
going to click Library, followed by Network mounts. Under source name, you can just whatever
name that you’d like to give this specific source. You can go to edit a network mount after the fact
if you decide you’d like to change this. Under fileshare protocol, we’re going to choose the
option SMB/CIFS - this is the option for Windows network shares. Under IP address, we enter
the address of the NAS. This can be found by heading to your router configuration page, logging
in with the relevant information, and then seeking out the list of connected computers. This is
normally under some sort of local network tab under the names DHCP table, DHCP client table,
or DHCP list. You’ll find a list of all the devices connected to the router, alongside their IP
addresses. Find your computer which is sharing the folder, and enter the IP address found
alongside it. Finally, under remote directory, just enter the folder name. This is case-sensitive.

We’ve now set up a network-shared folder with RuneAudio. As I said earlier, you can
also set up local drives for the Raspberry Pi to draw the library from. However, this is by now
means absolutely required and is actually a little superfluous. The nice thing about having a NAS
setup is that you can actually have the shared folder be on your main PC and actively update
without having to actively detach a drive from your Pi, add new music, and reattach it to the Pi. In
other words, this is mainly an ease-of-use concern.

By now, your rig is mostly set up. There are still some important things to do if you really
wanna scrape as much functionality as you possibly can out of this, though.

The first thing you can do, if you have a Spotify Premium account, is set the rig up so that
it can stream Spotify. This is relatively easily done.

To start off this whole process, what you’re going to do is head over the RuneUI page
again at http://runeaudio(.local). Then from there, you’re going to look for the menu in the top
right corner, click Settings, and then scroll down the page until you see “Features management.”
There will be a button to turn on Spotify features. Click it, then enter your Spotify username and
password. Remember that you have to have Spotify Premium for this, and if you don’t already
have a Spotify account then I highly recommend you get one. It offers high quality music streaming
of a gigantic music library at a pretty hard-to-beat price.

Anyway, you can now test this out by heading back to the Library page and selecting the
Spotify client. In the Playback source section, look for the Spotify option and click it. After this,
you’ll see your Spotify playlists. You can now add them to your queue and listen to them.
The next thing we’re going to do is set up AirPlay functionality. This isn’t required, but it
is a handy feature. What AirPlay functionality will do is allow for you to stream media from your
Apple devices - such as an iPhone, iPad, or Apple computer - straight to your Raspberry Pi rig.
You can also set up AirPlay streaming on a number of other devices as well, such as Android
phones or Windows computers, using third-party programs even if these devices don’t necessarily
have built-in AirPlay functionality.
You set up AirPlay functionality much the same way that you set up Spotify functionality.
You head to the RuneUI page and then find the settings page again. Right below where the Spotify
option was, there should likewise be an option for AirPlay. You’ll have to configure your
device’s AirPlay name, but that’s very easy to do. After you have it all setup, you can test it out!
Pull out your iPhone and start playing a song, then set your Raspberry Pi rig as the AirPlay
source. Note that you may have to select AirPlay as the Playback Source in order to use this
feature. This is especially useful is you have something like a house party or get-together going
on. Anybody with an iPhone can see and change the song by just going to RuneAudio while
connected to your wireless network! Super simple procedure.
The last major thing we’ll talk about is setting up a DLNA renderer on your Pi and
connecting to it from another device. We’re going to use a Windows PC again in this example.

Just like before, you’re going to go to the RuneUI and hit up the settings menu, this time
looking for the option that says DLNA and UPNP. UPNP and DLNA are both protocols for
streaming data over a network. DLNA is actually derived from UPNP and is specifically intended
for streaming media as opposed to anything else. We’re going to be setting up our RuneAudio rig
with DLNA specifically in this example.

Moving on, we’re going to go to the settings menu to the place where Spotify and AirPlay
were. Below both options, there should be a button to select and set up DLNA and UPNP. Click
it. You’ll set up the DLNA name of your device and then you’ll be pretty good to go on that front.

Now we need a way to send music to it. The simplest way is just to use a software called
Upplay. There are a few different reasons you should use Upplay as opposed to anything else:
- It’s super simple to use.
- It’s open-source, which means it’s secure.
- It’s free.
- It works on Windows and Linux, which makes it better-suited for
a general guide.

To get Upplay, you can just go to the website at www.lesbonscomptes.com/upplay/.


Download it and set it up. You can import your music to it and - this is the important part - select
your Raspberry Pi as the UPNP client. It should be relatively straightforward, from here, to
import your music and stream it to your Raspberry Pi. Like usual, you’re going to need to change
your playback source to DNLA/UPNP.
You may not want to enable all of these services though. The Raspberry Pi has a lot of
power, but there is the possibility that, if you have all of these running, you very well may ask a
bit too much of what your Raspberry Pi is fully capable of and experience stuttering or freezing in
your audio. Proceed with caution, as always.
Chapter 6: Anonymous Router

With the increasing amount of surveillance and constantly being linked to everything,
privacy is certainly a concern. Even if you’re not necessarily the tinfoil hat type, it’s still
worthwhile to browse anonymously, if only because if the conspiracy theorists are right and
there’s a secret race of lizard people controlling everything around us, you know you’re
somewhat untraceable.

That’s the point of this project. This project is going to turn your Raspberry Pi into an
anonymous router using the Tor service. What is Tor? Tor stands for The Onion Router. What it
does is basically mix the IP you’re connecting with into a melting pot of IPs and swap them all up,
so that it’s basically untraceable which one is yours. You can see how this works firsthand by
installing Tor on your private computer, and comparing your IP when not using Tor to the one you
have when you do use Tor. If you attempt to trace your IP, it should also come up in a completely
different location from you. Therein lies the beauty of a Raspberry Pi Tor router. This router is
one that you can take with you anywhere and browse anonymously without any extra steps. Any
and all server will be entirely anonymous.

The best part is that it’s relatively simple to use and set up, as well. There’s a fair amount
of software to install, but once you’ve got that all setup, it’s easy as Pi.

So what do we need for this?


Tools:

- Raspberry Pi 3
- Ethernet cable
- SD card with an image of Raspbian
- USB battery pack (like the ones used for portable phone chargers. In fact, that
will work. I recommend the one specifically made for Raspberry Pi by Adafruit.)
- MiniUSB to USB power connector
- USB power block (for home usage)

So let’s get going with all of this. Set up everything as we usually do. Go through the usual
process of setting up Raspbian, expanding the usable space, all of that. If you don’t remember or
skipped to this part from the table of contents, I advise you to refer to chapter 1 where I go into
great detail on how to install Raspbian.
After you have all of that setup, the first thing that we’re going to do is set up everything
relevant so that our Raspberry Pi can be a wireless access point. Open up the Terminal, because
we’re about to go crazy with some command line work.

We have to start with this process by getting software which will serve as the hostap, or
the host access point. First, we update the apt list:
sudo apt-get update
Afterwards, we download the relevant software for this purpose.

sudo apt-get install hostapd isc-dhcp-server


Once you’ve installed all of that, you need to go ahead and grab an iptables manager.
sudo apt-get install iptables-persistent

During the setup of our iptables manager, you’re going to run into two configuration
screens. Say yes to both of these. Now, we have to set up a dhcp server. We have to go into Nano
a couple times for this and edit a configuration file. Let’s go ahead and do that.

sudo nano /etc/dhcp/dhcpd.conf


Once we have our file open in Nano, ready to modify, we need to find the lines which say
the following:

option domain-name “example.org”;


option domain-name-servers ns1.example.org, ns2.example.org;

We need to comment them out, so throw a hash sign in front of both of those. Once that’s
done, we need to set this up as the official DHCP server on the network, so seek to the lines
which say the following:

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

Uncomment the line which says authoritative. Once you’ve done that, you need to seek
down to the bottom of the ile and enter the following lines:
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

After that, exit and save from Nano like always. Then you’re going to open and modify yet
another file. Type in the following:

sudo nano /etc/default/isc-dhcp-server


Once it’s open, head down to where it says INTERFACE=”” and modify it so that it
instead says INTERFACES=”wlan0” (provided that wlan0 is the name of your wireless adapter.
If you’re using the built-in Raspberry Pi 3 wireless adapter, it should be. If not, though, modify
your entry as necessary.)
Exit and save nano one more.

Next, we’re going to turn wlan0 off temporarily while as work with it.

sudo ifdown wlan0


This will shut down the wlan0 wireless adapter until we specify that it needs to be turned
back on. Anyway, the next thing that we’re going to do is change the wlan0 connection so that it
has a static IP and so that the connection is incoming rather than outgoing. This means editing even
more text files - how cool is that? The next thing that you’re going to do is run the following
command:
sudo nano /etc/network/interfaces

Find the line which says auto wlan0 and comment it out, along with every line which
comes afterwards.

Add the following lines after where it says allow-hotplug wlan 0:

iface wlan0 inet static


address 192.168.42.1
netmask 255.255.255.0

Exit to save once again.

Now, we have to assign a static address to our wireless interface:


sudo ifconfig wlan0 192.168.42.1

This will set our wireless interface’s address to be 192.168.42.1.


Once all of that is finished, we need to establish the details for our access point. We’re
going to set up an encrypted network so that only people who have the given password are able to
join.

We’re going to create a new file using Nano just as we did in the first chapter:
sudo nano /etc/hostapd/hostapd.conf
To which you’re going to add the following text:

interface=wlan0
#driver=nl80211
ssid=Pi_Access_Point
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=passwordGoesHere
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

Exit and save once more. Remember this file. If this happens to not work later, come back
and uncomment the driver=nl80211 line. Optimally, it needs to be commented out if you’re using
the Raspberry Pi 3 internal adapter. However, you may encounter an issue rarely and need to use
the nl80211 driver. Try it without first. Also, SSID can be whatever you want it to be. You could
even freak out the neighbors by naming it something really bizarre. wpa_passphrase is the
password for the network. Set this to whatever you like.

Now we have to specify to our hardware that this configuration file, well, even exists.
This is super important in allowing other devices to connect to our wireless network. We’ll be
once more using Nano:

sudo nano /etc/default/hostapd

Within this file, you’re going to look for the line which says #DAEMON_CONF=””.
You’re going to uncomment the line and put /etc/hostapd/hostapd.conf between the quotation
marks. It should look like this:

DAEMON_CONF=”/etc/hostapd/hostapd.conf”
Afterwards, exit and save the file. That’s all we have to change here. However, we do
have to edit another file in just the same way. Enter the following command:
sudo nano /etc/init.d/hostapd
Once you’re within the file, you need to find the DAEMON_CONF= line again and
modify as we just did. There aren’t supposed to be quotation marks on this one, so don’t add
them. It should look like this:

DAEMON_CONF=/etc/hostapd/hostapd.conf
What we’re going to do next is set up network address translation. Basically what
network address translation means is a protocol which allows several clients to connect to a
wireless network, and then send all the same data outbound with the same IP. In order to set this
up, we need to - you guessed it - edit even more text files.
Run the following command:

sudo nano /etc/sysct1.conf

Then seek down to the bottom of the file and add the following:
net.ipv4.ip_forward=1

Exit and save this file. This will make it so that it forwards through the Pi’s IP as soon as
you boot up the Pi. However, we can also activate this IP forwarding instantly by using the
following command:
sudo sh -c “echo l > /proc/sys/net/ipv4/ip_forward”

One all of that’s finished, we’re going to run the following commands using the IP table
manager program that we installed earlier. What these are going to do is do the network
translation from our wireless port, to which other devices will connect, to our ethernet port which
has our outbound internet activity.

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state
RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Once all of that’s finished, we need to set it up to be sure that this happens as soon as we
boot up the Pi by using the following command:

sudo sh -c “iptables-save > /etc/iptables/rules.v4”


Now we can test this out to be sure that everything is in working order. We can do this by
going ahead and running the following command in order to start up hostapd with the
configuration file that we created:

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf


It should go off without a hitch. If you get a warning or it fails to run entirely, go ahead and
remove the comment from the driver line that I was talking about earlier. I’ll save you a tad bit of
time going back and remind you that in order to access our configuration file, you type in the
following:
sudo nano /etc/hostapd/hostapd.conf/

With all of that done, if you didn’t get an error and instead got some normal feedback text,
then what you need to do next is check it with another computer that has a wireless connection or
a wireless device such as a smartphone. Go to wherever you can see the wireless networks which
are available for connection. If you see the SSID pop up for your Raspberry Pi, then your access
point has been successfully set up with no issue.
In order to test it out further, you can try connecting and disconnecting from the network
that you created. You should see some dialog pop up in the console of your Raspberry Pi which
shows that you connected and disconnected. Note that during this process, you won’t be able to
actually connect to the internet through the Ethernet connection just yet.

Now that we’ve tested everything, press Ctrl+C in order to exit the program and return to
the Terminal command line. Now that we have it all set up and we know that it works, we need to
set up our Pi as a daemon, or a tool which starts when the system boots up. Here’s how we do
that. First, we have to test the hostapd and the DHCP server as daemon services on our Pi to be
sure that there are no errors:

sudo service hostapd start


sudo service isc-dhcp-server start

If there are no errors (there shouldn’t be), then here’s how we set them to run upon boot:
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable

There we go. With those done, we have this set to start upon the Raspberry Pi’s boot.

Try once more to connect to the network with another computer. This time, let’s check that
DNS is in working order. From the command line of whatever computer you’re connecting from,
ping www.google.com. If it doesn’t work, there’s an issue with your dhcpd setup. If it works, then
fantastic. Your Pi is now a wireless router.

This is the most crucial step in this whole process of setting up a Tor router, and is sort of
a project in and of itself. There are a lot of possibilities when you’re setting up your Pi as a
throughway for wireless connections. You could set it up as a super strong firewall or any other
array of options.
Anyway, with that all done, let’s get to installing the Tor parts onto our Pi. Going back to
our Pi terminal, run the following commands in order to update our APT and install the Tor
services:

sudo apt-get update


sudo apt-get install tor

Once everything is installed, we’re going to edit our Tor configuration files in Nano.
sudo nano /etc/tor/torrc

Type the following text near the top of the file just below the FAQ segment:
Log notice file /var/log/tor/notices.log
VirtualAddrNetwork 10.192.0.0/10
AutomapHostsSuffixes .onion,.exit
AutomapHostsOnResolve 1
TransPort 9040
TransListenAddress 192.168.42.1
DNSPort 53
DNSListenAddress 192.168.42.1

Save and exit from Nano like always. The next thing that we’re going to do is modify our
IP tables so that incoming connections through the wlan0 interface will be sent through the Tor
software before anything else.

Those rules we just set up are actually irrelevant now and were just for testing purposes
because we of course want to take such an ambitious project one step at a time. We need to flush
the former rules, which we can do by way of the following command:

sudo iptables -F
sudo iptables -t nat -F

Now what we’re going to do is send all DNS data from our wireless interface to the
internal Tor DNS port:
sudo iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-
ports 53

Note that this is one line! Don’t arbitrarily put a line break or the command won’t work.

Afterwards, we’re going to send all TCP traffic from our wireless interface to the relevant
Tor port:

sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports


9040

Now we’re going to save this IP table over where the previous one was:
sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

After this, it’ll automatically be set up upon reboot. Your networking is now technically
being routed through Tor.

Next, start the Tor service:


sudo service tor start

We need to verify that it is indeed running and there aren’t any issues. We’re going to run
the following command, and if it doesn’t go over then you’ll be notified of a failure:
sudo service tor status
If everything goes swimmingly, then run the following so that it’s a daemon:

sudo update-rc.d tor enable


Now it’s time to test it. Go ahead and connect on your wireless device again using the
settings that we previously mentioned. Head to the relevant command line of whatever device
you’re using and certify that you’re connected to the Pi by pinging its IP:
192.168.42.1

After that, certify that the proxy is active. You can do this by heading to
https://whatismyipaddress.com, which will tell you your current IP and the place from which
you’re connecting. Tor should make this completely inaccurate and, in fact, if you refresh the
page, it should actually change.
This is the beauty of Tor routing services. You’re essentially completely anonymous for
99% of your web traffic. The vast majority of the anonymity which you shed after setting up an
onion routing proxy like Tor is that which you voluntary rid yourself of by using social media and
things of that nature. But for general purpose web searching, you’re for the most part protected.

So there you have it. You now have a portable proxy. You can take it essentially anywhere
with you and have it set up so that you can browse anonymously anywhere. You do this, of course,
by using our portable battery pack that we bought and plugging the USB end of the microUSB to
USB cord into it. Anywhere that you can get access to an ethernet cable, you can browse
anonymously. You can also use the USB block wall adapter so that you don’t have to bother with
a rechargeable battery pack at home.

This is a great project, chiefly because there are a huge number of ways which you can
expand upon it. For example, by connecting to your Pi on your host computer through SSH, you
can actually set up a middlebox that you can use anywhere, even at someplace like Starbucks.
You’d need another wireless adapter for this, which would be tuned to your host wireless
network via SSH terminal commands to the Raspberry Pi. After changing a few internal files,
your Pi would instead route information through the secondary wireless adapter rather than the
ethernet cable. I’d argue that you could actually very easily write a script in order to automate that
whole process and make it a super simple deal to set up, needing only the name of the primary
wi-fi network and any relevant information (passwords and such.)
Conclusion
Thank for making it through to the end of Raspberry Pi 3: Master Projects Guide, let’s hope it
was informative and able to provide you with all of the tools you need to achieve your goals
whatever they may be.

The next step is to go even further. You, of course, very well may make the projects contained in
this book. You may even modify them a little bit to make them your own. But what the world today
needs is more tinkerers. More people who engage with hardware and dream up solutions to the
things that they need instead of waiting on somebody to create and mass-market what they need
for them.
In the course of this book, I’ve opened you up to a lot of technologies, and there are more
technologies still. Consider, for example, the smart mirror that we worked on earlier: sure, it’s a
great idea in and of itself, but there are a lot of ways you could take it even further. You could use
the Amazon Alexa services in order to link voice recognition to your mirror. Raspberry Pis have
an official camera module, and there’s a plethora of facial recognition software out there, too.
Either one of these could be used in order to identify exactly who the end user is and send them
personal information that is tailored to them specifically. Right now, we’ve got a static smart
mirror, which in and of itself is pretty cool. But there are lots of “one step further”s with this kind
of thing; enough “one step further”s, in fact, to turn the “one step further” into a whole marathon.

The beauty of the Raspberry Pi, and indeed the reason that it’s sold millions of units, is because
it’s so extensible. When you use a Raspberry Pi, you’re in control of the hardware, and there’s
nowhere to go but up. The Raspberry Pi is little a mini computer, and in that comes a lot of
power. Anything that you can do with a computer and conventional hardware - which is
effectively anything you can think of - can be implemented using a Raspberry Pi. That’s the reason
that this technology is so cool, and that’s the reason that I’m so happy to be sharing it with you and
helping you to unlock your full potential.

If you’ve enjoyed working with the Raspberry Pi, you should absolutely look into other similar
technologies such as Arduino and the Intel Edison. Consider how you can pair them with Pi.
Another thing you could do is go to electronics stores like Radioshack and look at all their
electronic components. Since the sky’s the limit with the Raspberry Pi, given the know-how (and
the soldering ability), you can make any one of them work for any project you can dream up. Run
into a moisture sensor and water pump? Create a program that automatically waters your plants
for you. There’s literally so much that you can do with the Raspberry Pi that the impossibilities
are, quite literally, endless.

Finally, if you found this book useful in anyway, a review on Amazon is always appreciated!
Other Books by Timothy Short

Raspberry Pi 3: Beginner to Pro Guide


SQL: Beginner to Pro Guide
Linux: The Quick Start Beginners Guide

PowerShell: Beginner to Pro Guide

Blockchain: The Comprehensive Guide to Mastering the Hidden Economy


C++: Beginner to Pro Guide

WordPress: Beginner to Pro Guide

Shopify: Beginner to Pro Guide

Passive Income: The Ultimate Guide to Financial Freedom

Project Management: Beginner to Professional Manager and Respected Leader


Evernote: Made Simple: Master Time Management and Productivity

All available via www.amazon.com

You might also like