Sunteți pe pagina 1din 143

Raspberry Pi 4 Projects

Guide

How to Install the Full Windows 10 Operating


System, Set Up A VPN Server, Host a

Wordpress Site and Power Other Impressive


Projects with Raspberry Pi 4

Nelson Newman
Copyright 2019 © Nelson Newman

All rights reserved. This book is copyright and no part of it


may be reproduced, stored or transmitted, in any form or
means, without the prior written permission of the
copyright owner.

Printed in the United States of America.

Copyright 2019 © Nelson Newman


Contents
Introduction .....................................................................................1
Chapter 1: Running Raspbian For the First Time .................................3
Chapter 2: Get Started With the Chromium Web Browser .................9
Chapter 3: The Libreoffice Productivity Suite in Raspberry Pi 4 ........12
Chapter 4: Creating a Portable Security Box ......................................19
The Installation of Kali on Raspberry Pi .............................22
Installation of Hacking Tools ................................................23
Chapter 5: Installing Full Windows 10 on Raspberry Pi 4 ..................25
Running Windows 10 IoT Core on Raspberry Pi ................26
Installing Windows 10 Iot Core on Raspberry Pi ................................28
Preparation of your Raspberry Pi for IoT Core...................................30
Booting into the IoT core ........................................................36
How to Run the Powershell Remotely .................................39
Deploying your IoT applications ...........................................41
Chapter 6: The Raspberry Pi can function as a desktop PC ...............43
Chapter 7: Build Your Own Raspberry Pi Night Vision Camera..........53
Chapter 8: How to Build an Action Camera inside a Vintage Flash Unit
with Raspberry Pi 4 and Camera Module ..........................................62
Chapter 9: The Scratch 3 Desktop can now be installed and used for
Raspbian on your Raspberry Pi! .........................................................71
Chapter 10: Virtual Gaming with Raspberry Pi 4 ...............................78
Chapter 11: Setting up Raspberry Pi as a Vpn Server ........................87
How to find your Raspberry Pi ..............................................93
Static IP ........................................................................................96
Paranoia Level............................................................................98
Getting Connected To Pi .........................................................99
Access Granted ........................................................................ 103
Chapter 12: Hosting a WordPress Site on Raspberry Pi 4 .. 107
Chapter 13: started with the Camera Module................................. 113
Take Still Pictures With Python Code................................ 124
How To Change Image Settings And Add Image Effects127
Set the image exposure mode .............................................. 135
Introduction
The Raspberry Pi is one of the most sophisticated
technologies invented in recent years that have allowed
even beginners to explore a fully-fledged computing system
with much ease. Apart from creating a platform for
beginners to begin coding, it serves as a foundation for
more advanced programs and functions to thrive. Some
developers have been able to use Raspberry to create more
impressive devices for use in our homes and workplaces.

Some of these devices are quite complicated than others


and as a result, requires more guidance to get it started and
working, which is why this book has been written to
enlighten beginners and users generally on projects to
familiarize you with the optimal usage of this device.

This guide will enlighten you on the following:

 How to install the full Windows 10 operating system


on the Raspberry Pi 4
 How to Host a Wordpress Site on Raspberry Pi 4
 Getting the device set up as a VPN server.

1
 The creation of a portal to get your guest Wi-Fi-
powered.
 And many more.

This book will guide you through on how to make the best
use of your Raspberry Pi 4 device with major ideas that will
help you in getting the most of your Raspberry Pi 4 device.
The Raspbian is specifically designed to run on the
Raspberry Pi and this is based on Debian Linux. The
Raspberry Pi 4 has the Raspbian pre-installed on it and
ready to use as soon as it’s purchased.

The Raspbian is designed similarly to the traditional


windows, icons, menus and pointed principles (WIMP), as
a result, any Microsoft Windows or Apple macOS won’t
have a problem handling this OS. This book has been
written to put you through on how to get started with the
Raspbian.

Apart from creating a platform for beginners to begin


coding, Raspberry serves as a foundation for more
advanced programs and functions to thrive. Some
developers have been able to use Raspberry to create more
impressive devices for use in our homes and workplaces.
Some of these devices are quite complicated than others
2
and as a result, requires more guidance to get it started and
working, which is why this book has been written to
enlighten beginners and users generally on projects to
familiarize you with the optimal usage of this device.

Chapter 1: Running Raspbian For the


First Time
If you are running Raspbian for the first time, you will get
the Welcome Wizard. After which you can start working
on your Raspbian like getting to change some of its settings
otherwise referred to as the configuration to match up with
how and where you intend to be using your Raspberry Pi.

How to close the Wizard

 Click on the Cancel button to close the Welcome


Wizard.

3
 In a situation where you are using the wireless
network with your Raspberry Pi, mere clicking the
Cancel button might not result in the closing of the
Welcome Wizard; you might be required to answer
at least some first set of questions before the wizard
closes.
 After closing the Welcome Wizard, select the Next
button.
 After selecting the Next button, you will be
prompted with a drop-down box coming up in turns
which will require you to select your country,
language as well as time zone from the lists.
 You are required to click on the checkbox if you are
using the US-layout keyboard, to ensure that
Raspbian is making use of the correct keyboard
layout.
 Clicks on the “Use English language” checkbox to
select it, to make your desktop, as well as programs,
appear in English irrespective of the native language
of your country.
 Select “Next” when you are done.

4
 For security reasons, the next page that appears will
prompt you to alter the password for the “pi” user
from the default “raspberry.” You are advised to do
this to keep your device from intruders by using
your own password in the boxes as shown below.
 Click on the checkbox next to the “Hide
characters” option to show the passwords to help
you confirm what you type in and they must be the
same for both boxes.
 Select “Next” when you are done.

5
 You will be prompted to select your preferred Wi-Fi
network from the list on the next screen that comes
up.
 With the use of your mouse or keyboard, scroll
down the networks’ list and search for the name of
your network to select it and click Next afterward.
 In a situation where you are using a secured Wi-Fi
network, you will be required to produce the
password which is also referred to as the pre-shared
key. It is to be noted that you will normally find this
on the card with the router or go check below the
router itself.
 To get connected to the network, select Next and
you can select Skip in a situation whereby you are
not connecting to a wireless network.

6
Set up continues:

 The model of Raspberry Pi that has the built-in


wireless networking is the Raspberry Pi 3, Pi 4 as
well as the Pi Zero W families. A USB Wi-Fi adapter
will be required, if you want to use a different model
of the Raspberry Pi with a wireless network.
 You will be prompted to check and install updates
for Raspbian as well as other software for your
Raspberry Pi on the next screen. The regular update
of the Raspbian will help to get bugs fixed; the
addition of new features and the OS performance
will be improved as well.
 Select Next to get the updates installed or select
skip if you decide to skip the update process. It is to
be noted that Updates download can take some
minutes and as soon as it is done, you will be
prompted with a window saying “System is up to
date,” click the OK button after you see the
message.

7
 At the final screen of the Welcome message, wizard
will come up with just a few tasks to be done. It is to
be noted that changes made during the setup
process will get activated only after you must have
restarted your Raspberry Pi.
 Select the Reboot button to get your Raspberry Pi
restarted, if prompted to do so. After the restart, the
Welcome Wizard will not show up this time and
your Raspberry Pi will be ready for use.

8
Chapter 2: Get Started With the
Chromium Web Browser
1. Load the Chromium browser to start up with practicing
the use of your Raspberry Pi.
2. Go to the top left and click on the raspberry icon to
display the menu.
3. Select the internet category using your mouse pointer.
4. Select the Chromium web browser to get it loaded.

 The Chromium browser is a web browser that allows


you to visit websites, play video games and get to
interact with people far and wide on forums as well
as chat sites.
 You can start to use your Chromium by simply
maximizing its window to take up the screen.
9
 Go to the top right of the chromium window title
bar where you will find three icons. Select the
middle one denoted by an up-arrow icon. This will
help in maximizing the window such that it will fill
up the screen.
 Next to the maximize button to the left, is the
minimize button that helps in hiding a window
until you select it on the taskbar located at the top
screen to have it opened again.
 The icon to the right of the maximize button is the
close button, as the name implies, it will close the
window.

CLOSE AND SAVE

While most programs will warn you to save before closing


your work whenever you select the close button, some will
not warn you. So, it is advisable to make sure you save your
works before closing it.

To start exploring your chromium-browser:

i. Go to the address bar which is located at the top of


the Chromium window which is the big white bar having a
magnifying glass on the left-hand side.

10
ii. Type in a website address and tap the ENTER key on
your keyboard. This will load the website.
iii. Several tabs might come up at the top of the
window if you are loading chromium for the first time.
iv. To go to a different tab, select the tab in question.
v. Click on the cross icon which is located at the right-
hand edge of the tab you like to close, to get it closed.
vi. Click on the tab button located at the right of the
last tab on the list to open a new tab alternatively, you can
have the CTRL key on the keyboard held down and press
the “T” key before releasing your finger on the CTRL.
vii. As soon as you are done exploring your Chromium
web browser, click on the close button which is located at
the top right of the window.

11
Chapter 3: The Libreoffice
Productivity Suite in Raspberry Pi 4
Other examples of productivity suite are the Microsoft
Office and Google docs.

To explore more things about your Raspberry Pi 4:

 Click on the raspberry menu icon.


 Go to the Office and click on LibreOffice Writer
which will load up the word processor portion of
LibreOffice. LibreOffice is a popular productivity
suite.
 It is important to note that the LibreOffice may not
be installed on the Raspbian OS images by default;
you will, therefore, need the recommended software
tool to get it installed.

12
 Apart from the ability to write documents using a
word processor,
 LibreOffice can also be used in getting them
formatted by making use of options like font style,
color, add effects, size as well as inserting tables,
pictures, charts including other content. With the
use of the word processor, you can also check for
mistakes, getting spelling highlighted with red as
well as checking with grammar issues highlighted
with green.
 Get started by writing a paragraph as regards what
you have learned so far on the Raspberry Pi
including its software. Go to the top of the window
to experiment with different icons and see what
they can do, check to see if you can perform some
simple actions like enlarging your writing, changing
your color.
 Hover your mouse pointer over each icon will help
in displaying the tooltips to be sure of what they do.
 When you are done, click on the File menu and
select the Save option to get your work saved. You
will be prompted to give it a name and then click on
the Save button.

13
Apart from the LibreOffice Writer, other parts of the
LibreOffice productivity suite that can be found in the
office menu category just like the Writer include:

LibreOffice Base: This is a database tool used for getting


information stored and getting to look them up quickly as
well as analyzing them.

LibreOffice Calc: This is a spreadsheet tool used for


handling numbers as well as getting charts and graphs
designed.

LibreOffice Draw: This is an illustrative program tool that


is used for designing pictures as well as diagrams.

LibreOffice Impress: This is a presentation program that


is used for the creation of slides as well as running of
slideshows.

14
LibreOffice Math: This is a formula editor tool used for
creating mathematical formulae that are properly
formatted which are usable as well in other documents.

Apart from their availability in the Raspberry Pi, the


LibreOffice are also available in other computers as well as
operating systems. Therefore, you can get it downloaded
for free from libreoffice.org and install them on any
Microsoft Windows, Linux computer as well as your Apple
macOS if you have an interest in it.

You can close the LibreOffice by going to the top right


window and clicking on the close button.

GETTING HELP

In a situation where you become lost or overwhelmed by a


particular program, the getting help section is designed to
provide all the information you need to guide you through
everything you need to know.

RECOMMENDED SOFTWARE TOOL

Raspbian is preloaded with varieties of software and the


best of this software can be found in the Recommended
Software tool.

15
It is, however, important to note that an internet
connection will be required to make use of the
recommended software tool, therefore, you need to make
sure your Raspberry Pi is connected to the internet.

Once you have your Raspberry Pi connected to the


internet, you can then follow the simple steps to get access
list of compatible software packages:

i.Select the raspberry menu icon.

ii. Go to preferences.

iii. Select “Recommended software”.

iv. After loading, download information about available


software.

v. Once the download is complete, a list of compatible


software packages will be displayed.

vi. Go to the left pane to select a category to see the


software from that category.

vii. To see everything, you can simply click on All


Programs.

16
viii. If you have software with a tick next to it, then it
means it is already installed on your Raspberry Pi and if not
already installed, you can simply click on the checkbox
next to the software to get it marked for installing. It is to
be noted that you can install as many software as possible
all at once, if your microSD is not large enough, you might
not have enough space for installing them all so you might
need to check for that. You can also uninstall similarly.

ix. Once you are done with the selection of the software,
either to install or uninstall, select OK to begin the process.

x. Once the downloading and installing of any new


software are done, you will be prompted with a dialogue
box. Select OK to close the Recommended software tool.

17
Add/Remove software tool is an additional tool that can be
used for getting the software installed or uninstalled and
this tool is located at the same preference category of the
Raspbian menu. With this, you will get to select more
software all at once.

18
Chapter 4: Creating a Portable
Security Box

People that get paid to hack into security systems with the
penetration testers, as well as other security personnel
have been able to exploit the portability and accessibility of
the Raspberry Pi 4 in carrying out their different functions.
The fact that it is designed with a built-in Ethernet port,
lesser power requirements and also can run any Linux
software, makes it easy for integration with targeted
networks.

Security operatives make use of software called Kali which


is a Linux distro that is used for hacking tasks. The
Raspberry Pi particularly has Kali software built purposely
to be used with it and it’s relatively easy to install.

19
The Kali Linux on the Raspberry Pi comes in handy for
ethical hackers looking for more portability. Raspberry Pi 4
has been designed such that its usage requires less power
including having a small size built. Its size can be
compared as a credit card-sized computer such that when
combined with Kali Linux, you will derive a super-portable
network testing machine that can be carried anywhere.

It can be used on a laptop in cracking nearby Wi-Fi


passwords, testing for Bluetooth vulnerabilities, spoof
networks, and many other things. In a situation where you
want to avoid the installation of Kali Linux on your primary
computer, you can simply have a touch screen added.

Requirements Needed To Install the Kali


Linux

To get the installation of the Kali Linux started, you will


need the following:

 Raspberry Pi 2, 3, or 4
 Power supply
 HDMI cable
 A minimum of 8GB SD-Card
 Keyboard

20
 Mouse

Go to the Offensive Security download area, search and


download Kali Linux 2.0 image file for Raspberry Pi. It is
to be noted that there are other image files available so you
will need to scroll down to find the Raspberry Pi 2/3
download. Make sure you verify that you are installing the
genuine Kali version in a situation where you are using Kali
for security testing.

Once the download is completed, you will then need to get


the file extracted. But if your computer does not have the
right software to get the file extracted, download WinRAR
and get it installed for the extraction of the image file.
Once extraction has been completed, it is then ready to be
written on an SD-Card whose minimum size should be
8GB.

Nevertheless, it is advisable to use a card which is up to


16GB or 32GB because it gives room for more space to have
tools and apps downloaded and run. The next step is to
have the image file loaded into Win32 Disk Imager and
have it written to the correct drive and ensure that you
have picked the correct one because it will overwrite any
drive selected.
21
It is to be noted that a few minutes will be required to
write the package and once it is done, you will be
prompted with a message which states “Write Successful.”
And in case you don’t know, the Win32DiskImager is a
Window program used for saving and restoring images
from removable drives.

The Installation of Kali on Raspberry Pi


Kali will be ready for installation on the Raspberry Pi once
the image has been written to the SD-Card. All the needed
accessories can now be connected such as making use of
the HDMI cable in plugging the TV or monitor as well as
the addition of the keyboard and mouse for control.

Power up the Pi which will result in the bootup process


causing the screen to go blank a few times before boot up
is done. You will be prompted by a login page where you
will need to enter your username and password. By default,
the username and password are root and or respectively.

It is, however, advisable to change your login credentials


into something that guarantees more security, but you will
also need to change the SSH host keys because the Kali
22
image for the Raspberry Pi 4 also comes with a set of pre-
configured default keys. To change the SSH host keys, you
can employ the use of the commands below:

 root@kali:~ rm /etc/ssh/ssh_host_*
 root@kali:~ dpkg-reconfigure openssh-server
 root@kali:~ service ssh restart

Installation of Hacking Tools


Once you have been able to effectively install the Kali
Linux following all the instructions stated above, input the
command startx from the command line to make it boot
into the graphical desktop environment. The ARM-based
Kali images come with a bare minimum of tools that are
pre-installed by default.

Nevertheless, to get new ones installed, you can make use


of the Kali metapackages. There is the availability of
various metapackages that contains different groups of
tools to be used for specific purposes such as Wi-Fi analysis
or password cracking.

To have access to the full list of metapackages that are


available as well as all the tools that are included with the
default desktop image of Kali, install the “kali-linux-full.”
23
You can also get each available tool with the “kali-linux-
all” metapackage.

Depending on your needs, you can also decide to pick


specific metapackages. It is to be noted that all
metapackages are installed with the use of standard Linux
apt-get method. For instance, to have access to the
complete toolset, you can make use of the command apt-
get install kali-linux-all. After the installation of your
preferred tools with the default passwords changed, your
Kali will be ready for use.

After the full installation of Kali, apart from its usefulness


in security operations, it is also useful for playing around
with new tools without posing any risk of damage to your
primary machine, though you should ensure that you are
only hacking targets that have given you express
permission.

24
Chapter 5: Installing Full Windows
10 on Raspberry Pi 4
The Operating system of Microsoft can be installed on the
Raspberry Pi 3 Model B or B+ boards by making use of
windows on ARM installer (WoA) which is available on the
GitHub. The operating system previously used on the
Raspberry Pi devices is the Windows IoT core operating
systems but there is now an opportunity to have the full
Windows 10 OS installed.

The Windows on Arm installer is available on the GitHub


and do require bundled binaries and WoA core package for
use.

To install the full windows 10 on your Raspberry Pi 4, you


will require the following:

 A set of binaries and software which are all available


on the GitHub page.
 A Raspberry Pi 3B or B+
 A Windows 10 ARM64 image which can also be
found linked on the GitHub page.
 MicroSD card having at least 16GB storage space
with an A1 rating.

25
Running Windows 10 IoT Core on Raspberry Pi
If you want to have the full version of Windows including
the Windows 10 IoT core running on your Raspberry, you
can have a stripped version of the operating system up and
running on the microcomputer.

In the case of the Raspberry Pi Model B+, they don’t have


the required processing power to give room for the running
of the Windows 10 full version on them. They only have the
1GB RAM as well as a 1.4GHz ARM-based processor.

It is advisable to go for the Windows 10 IoT Core which is a


basic version of the operating system of Microsoft and it
also has an added advantage of being functional on less
powerful platforms. It gives you room to run a single UWP
app at a time because of its lightweight properties. A
license is not needed except you are commercializing your
creations and you will need a limited amount of
equipment.

1. First, you will need the Raspberry Pi 3, spare microSD


card including a separate Windows computer that has a
microSD card reader.

26
Other tools that will be needed include a text editor, Visual
studio, the SDKs add-ons including certificates.

2. The next thing is to set up the memory card for the


Raspberry Pi which you will be using.

3 Make use of the New out Of Box Software (NOOBS)


installer to make installation easier.

4. Get a bootable card created from a Windows PC or


Laptop afterward with the use of the IoT dashboard app of
Microsoft.

5. Make use of the Broadcom Raspberry Pi 2 & 3 or 4 option


as well as the OS build or Windows 10 IoT Core in setting
up your device.

6. Specify a password and choose a Wi-Fi network.

7. Install the operating system on the Raspberry Pi-


compatible memory card.

8. Get the card inserted into the Raspberry Pi. Once


inserted, your device should be ready to get booted up with
the latest version of the Windows IoT Core.

27
Installing Windows 10 Iot Core on
Raspberry Pi

Windows is constantly evolving its platforms and they are


not only focusing on the apps including their flashy
graphics, but they also have been able to extend their
evolutions to other and new platforms as well. With the
diminishing reign of the Windows phone as well as the
Windows 10 Mobile, this has allowed Microsoft to focus
more on their major products, improving more on the
desktop edition as well as giving room for new hardware in
more intelligent manners.

Now considering the Raspberry Pi which is not just a


conventional workstation with it's Pi 3 Model B+ having
just 1GB of RAM with 1.4GHz ARM-based processor, will
28
not be enough to run the full version of the Windows 10.
Windows have been able to improve in this area by coming
up with the Windows 10 IoT Core to get installed instead
due to its lightweight properties.

It is to be noted that the IoT core has a very limited


experience in which you can run on a single UWP app at a
time and it shouldn’t be seen as a desktop replacement. Its
basic installation has been made free and it’s a very
interesting app to try out, all you will need is to make
payment for the license in case you have a plan to get the
results distributed.

If you want to explore the app development world as well


as making much more optimal use of your Raspberry Pi,
having a good understanding of setting up the IoT
development platform. It is known for its low cost and
consumes lesser power as well. You will need the following
to integrate the IoT core:

 Raspberry Pi 3
 A spare microSD card
 Windows computer has a microSD card reader for
the installation media to be created

29
 Download Visual studio, text editor including
certificates, when you are ready to start with the
development of the applications.

Preparation of your Raspberry Pi for


IoT Core
The Windows 10 IoT Core has been made available for
different lightweight system on a chip device with the
ARM-based Raspberry Pi as well as DragonBoard
platforms. They have also been designed to run on Intel-
powered MinnowBoard.

In terms of cost and ease of use, the Pi comes in handy and


in a situation where you like to switch to other projects, Pi
is much more flexible supporting a range of both hardware
add-ons including applications.

30
In getting your Pi ready, you will need to set up your
microSD for the model of your Raspberry Pi.

It is to be noted that the Pi board doesn’t have a built-in


BIOS as you might think and the required code is read
directly from the microSD.

This is the reason cards can’t be switched directly between


Pi’s different model even between the closest of all the
models, the Pi 3 with the Pi 3 Model B+. You can now easily
set up the default Raspbian OS and Windows 10 IoT core
using the New Out Of Box Software (NOOBS).

You can also make use of Microsoft’s IoT dashboard app in


creating a bootable card with the use of a Windows PC or
laptop.

31
To download, click on the tab that reads “Download the
Windows 10 IoT Core Dashboard”

When asked if you want to run or save it, select Run.

You will be prompted with a request, select Yes to allow it


to make changes to your PC.

The IoT Dashboard

 When the Windows 10 IoT dashboard opens, it


shows a list of “My devices” which will be empty by
default.
 As soon as your Windows 10 IoT core starts running
on your Pi, it will enable you to get access to the
features remotely.
 Go to the sidebar and select “Set up a new device.”
 Sign in using your Microsoft account if you are not
logged in already. You will be prompted with a set
of options as shown below.

32
 The next step is to set your device to Broadcomm
Raspberry Pi 2 & 3 or 4
 Select your OS to build which should be Windows
10 IoT core. It is advisable to go for the latest version
which is 17763 at the time of writing this book.
 Specify a device name as well as the password. The
default name is minwinpc which is quite easy to
remember and you are advised to use a good
password and avoid using the same password you
used for the login for other services.
 Go to the right-hand side of the window where you
will find a list of Wi-Fi network connections.
 Select your preferred network on the list and it is to
be noted that your Raspberry Pi will automatically
get online at boot up.

33
 In case there is a change of location and you need
to boot up your Windows 10 IoT core in a different
location, there will always be a chance to choose an
SSID and provide it with the passphrase.
 Insert the SD card into your PC once this is done. It
is to be noted that the Raspberry Pi makes use of
MicroSD card while most laptops make use of only a
full-sized SD card slot. Therefore, it is advisable to
purchase a cheaper microSD adapter and make sure
you have everything that might be available on your
microSD card backed up in case you need to keep
the files because once the setup process is complete,
all files will be completely wiped out.
 Due to the same reason, once your card has been
inserted, make sure you properly check to make
sure it has been correctly selected by the IoT
dashboard as the installation destination.
 Both the name and capacity should be shown as
expected and to be sure of this, double click on the
dropdown menu and get all the options reviewed to
select the correct one.
 Accept the terms of the software license by ticking
the box and then select the Download and install

34
option afterward to get the process completed. The
latest build for your device will get downloaded by
the IoT dashboard. It is to be noted that this file is
large and as a result, it might take up to an hour to
download using home broadband.
 The image will be stored locally afterward and you
won’t have to get it downloaded again in case you
want to flush the microSD in the future.

After installation is complete, you might be faced with


situations where you will be prompted with the Dashboard
needing to format a different drive for it to be readable.
Once faced with this, take the following steps:

i. Cancel the message.

ii. Eject the SD card.

iii. Insert the SD card into your Raspberry Pi.

iv. Switch on the Power to boot into the Windows 10 IoT


core.

35
Booting into the IoT core
 Booting into the IoT core might take a little longer
showing the Windows logo or a blank screen at first
time booting.
 You will be asked to choose a Wi-Fi network that
can be skipped if you already chose a network
during the image creation.
 The next page after this will be the device overview.
The brief rundown about the spec of your hardware
will contain the IP address including other
information as shown below:

36
 Once you are booted into the Operating system, it is
advisable to check for any available updates.
 Go to the sidebar and click on the icon denoted by a
red person to get logged in to your Microsoft
account.
 Open the Settings by clicking on the cog icon.
 Select App Updates in the sidebar.
 Apart from the ability to use the Raspberry Pi as a
regular desktop PC, it can also be used for headless
operation due to its compact and low-power design
even with the exclusion of the monitor, mouse or
keyboard.
 Microsoft has also built the device such that it now
has a remote access feature in its IoT dashboard. To
make use of this functionality:
 Return to your personal computer.
 Go to the IoT dashboard sidebar and select “My
Devices.”
 Right-click on your Raspberry Pi and click on Open
in the Device Portal which will result in the opening
of your default browser which contains different
details about your IoT Core System.

37
 Use “Administrator” as the username while your
password should be the one you specified during the
setup process. In a situation where no password was
entered, make use of the default password which is
“p@ssw0rd”

In a situation where your Pi is not displayed under My


devices pane, check to make sure your connection is not
blocked by Windows. When this happens, you can do the
following:

 Search for “Allow an app through Windows


Firewall” in the start menu.
 Go to the firewall control panel.
 Scroll down the list of applications and ensure that
the WINDOWS10IOTCOREDASHBOARD.EXE is
selected for easy access to private networks.
 The device portal enables you to perform a different
kind of management tasks which includes:
 Changing your password.
 Setting the remote device time.
 Monitoring the performance and resource usage of
your Raspberry Pi.

38
 With the device portal, you can also get the
application deployed to the device.

How to get an application deployed to the device

i. Go to the sidebar and expand the Apps section.

ii. Click on the Apps manager option.

iii. To get a package uploaded from your desktop, select


“Choose file”

How to Run the Powershell Remotely


 You can remotely access the file system of Pi and
run commands on it directly by going through the
dashboard. Do this by following the instructions
below:
 Go to the IoT Dashboard’s My Devices and right-
click its entry.
 Select Launch PowerShell.
 Confirm that Windows can have changes made to
your PC.
 Input your login details which should navigate you
to the PowerShell prompt. This works similarly as if
you are typing directly into your Raspberry Pi.

39
If you have a problem initiating a connection, check to be
sure that the format of credentials is correct. The format
should be in the form: username prefixed by the IP address
of the Pi as well as a backslash for example here, we have
192.168.1.77\Administrator.

If this doesn’t work, then probably your Pi is not included


in the list of trusted devices. Then you will have to:

i. Quit the remote PowerShell session to get this fixed.

ii. Go to the windows search box where you are required to


type in PowerShell.

iii. Right-click on the search results and click on “Run as


Administrator.”

Input in “new start WinRM” and select return to ensure


that your Windows Remote Management is working fine.

40
Type in "Set-Item WSMAN:\localhost\Client\
TrustedHosts -Value 192.168.1.77" to replace "192.168.1.77"
using the address that was copied down from the screen of
your device overview.

Then your PowerShell session will be ready for launching


on your Pi and it is known to be very interactive as well.

Deploying your IoT applications


 It should be noted that IoT applications are not
installed in the same way as the normal Windows
apps and there is no SETUP.EXE file that can be
double-clicked on and most times, the target
systems won’t have a mouse and monitor included.
 If an application is developed using the IoT Core,
you will need to get it packaged into an image that
can be booted. It should also contain both your code
as well as the required operating system with device
driver files which can be flashed onto the microSD
for proper distribution.
 The card is designed to start up an IoT – ready
device like the Raspberry Pi or Arduino board and it
can also be used in launching a single application

41
that can be a machine controller, time-lapse camera,
voice assistant, etc.
 It is to be noted that if you are a fan of the IoT
development, the IoT Core distribution being
described in this book can only be used in creating
test images which are a major target for developers
that have an interest in prototyping new designs.
 There are also retail images that are compiled to be
used by consumers and they can be used on
corporate networks as well. They can also be
effectively secured to protect it from intruders.

 A core pro license can also be used in generating


them but this doesn’t leave out all the testing and
development that is required on a normal IoT Core
system and they can upgrade when it’s time for your
final media to be built.

42
Chapter 6: The Raspberry Pi can
function as a desktop PC
The Pi can be connected with an HDMI cable to
compatible display for use as a regular PC. Add power
supply, a keyboard and a mouse then you are good to go.
Add a microSD card for storage support.

From the Pi 3 onward, all Raspberry Pi models have inbuilt


Bluetooth and Wi-Fi. You can use USB dongles for this on
older models, check for compatibility at elinux.org’s
Raspberry Pi Hub. You can also use the Ethernet which is
available in all models except the Raspberry Pi zero.
Install the operating system of your choice, the Chromium
browser and the LibreOffice are preinstalled.

Everything You Require To Use Your Raspberry Pi


Like A Desktop PC!

Recently I lauded the Raspberry Pi on twitter and it


occurred to me that I should test my theory. If I set it up as
a PC, Can the Raspberry Pi really perform the obligations
of a school computer or that of a standard office PC?

43
Every computing work I do for one week will be on the
Raspberry Pi. I will do my writing and editing for the next
seven days on this little device set up as a traditional
computer.

This way, I will find out if the Raspberry Pi can perform


office tasks well enough to rival a traditional computer. So,
what are the parameters? What do you require in a
standard office PC?

 Internet connectivity
 Email
 Web browsing
 Word processing and spreadsheets
 Printing
 Collaboration

Raspbian Stretch as the operating system is called is


capable of every one of the listed features. If you want to
use a Pi as your office PC, all you need to do is set it up the
right way and the will to be productive.This may not work
for everybody as my workload includes:

 Check email
 Check Slack
44
 Editing work
 Writing
 Pitch emails
 Internet research
 Editing photos and screenshots

I often play music, sometimes I find a task on amazon and


that’s about it. So in my opinion the Pi can be used as an
office PC without disrupting your work.

Day 1: The Initial Set Up

To begin, I had to find a display, connect a mouse and


keyboard. I then connected the Pi to the Wi-Fi, this will be
my office for the week.

Now I have to pick a device, out of the 12 Raspberry Pi


devices, I decided on the Raspberry Pi 3 B+. The Pi 3B+
feature a 1.4GHz 64-bit quad-core ARM Cortex-A53 CPU,
1GB of RAM, 4 USB ports with inbuilt Wi-Fi and Bluetooth.

It has a microSD card slot so I will use an 8GB microSD


card as my main storage, I have a USB drive on standby in
case I need extra storage space.

45
My typical work week is five days, from Monday-Friday,
still I decided to set up the Pi beforehand. By Sunday
evening my workspace was ready, even I don’t want to
spend my Sunday night setting up computers.

Luckily, building my Pi computer didn’t take me up to 30


minutes.

Day 2: Using a Wireless Mouse

On Monday morning, the beginning of my trial week, I


fired up my Pi, I wanted to test the limits of my device. I
wanted to know if there will be any complications. What
could make the Pi lag? Most especially any apps to stay
away from?

I had a tough start due to a problem with my wireless


mouse. Every click and movement lagged by about half a
second slow, which was a distraction. Luckily I could solve
this with a minor edit in the /boot/cmdline.txt

All I had to do was scroll to the end of the line and added:

46
After saving, I exited (Ctrl + X, then follow the instructions
on-screen), I restarted my Pi. After restarting, now there is
no delay and my mouse works perfectly.

I was ready for challenges but after the initial problem,


everything else went smoothly. I installed a password
manager plugin to save time and it worked. All my editing
and browsing work were hitch free.

Day 3: Using Multiple Browser Tabs

Today, I perform harder tasks, writing and research.

Would this makeshift computer be up to the challenge?


Would it handle word processing and multiple browser
tabs?

47
And yes, it did.

I limited the number of open tabs to four or five at any


point. As my ongoing work is on Dropbox, I was anxious to
see if I could synchronize my device. As it turns out, I
didn’t have to worry. It went well, I had access to my files
and I worked on them with Office Online.

LibreOffice is okay but I didn’t want to lose work if it


doesn’t work out. WordPress editing on the Pi’s browser
was the same with that of my usual PC.

48
Day 4: Switching to the Laptop for Today

I didn’t want to spend a whole week working in the


confines of my office. Since my Raspberry Pi set up was a
desktop, I couldn’t bring it with me. I switched to my
laptop and continued my work at the local cafe.

Day 5: All Good Except for Keyboard Woes

Back to work using the Raspberry Pi. By now I have


realized that everything works fine. My only issue is with
the keyboard, I am having a hard time typing with it. Since
I used my laptop yesterday, I could really see the
difference.
The lesson here is actually for any computer project,
particularly on a desktop PC. Always select a comfortable,
usable keyboard.

Day 6: Image Editing Works Fine

49
This is the last day of my project and I had some articles to
submit. It dawned on me that this is the time for me to edit
some images. I started installing GIMP, I was nervous
before I realized it was available in the Raspberry
repository. Soon enough I began cropping and resizing as I
would on a traditional computer.

I am not saying the GIMP on a Pi is suitable for high end


photo editing. But it works smoothly for medium
resolution photos and graphics.

Day 7: What About Playing Games?

Retro gaming is incredible on the Raspberry Pi. To stream


your games on a bigger screen, connect the Pi to a TV
using the HDMI. This time, I decided to install DOSBox on
the Pi to revisit some of my favorite retro gaming
experience.

The Raspberry Pi: It an efficient Desktop PC!

After using the Raspberry Pi as my substitute desktop


computer for a week, I made a quick summary of my
experience.

50
1. When I logged into my Google account, auto-
installed extensions clashed with the Chromium
browser’s pre-installed extensions. I fixed this by
disabling the extra extensions.
2. Keep the number of open browser tabs to a
minimum.
3. The Raspberry Pi is not portable.
4. The Pi couldn’t cope with the Slack homepage. I use
Slack often, but the Pi can’t handle it. I tried the
Linux app version too but it didn’t work.
5. It is slow when downloading from the cloud.
6. Use the right keyboard and mouse to avoid issues.
7. On the Pi, I could edit quality images using the
GIMP.
In conclusion, most of these problems, won’t trouble the
average user. Since my work involves writing, editing and
photo editing, I must say I had a decent experience with
the Raspberry Pi.

Ultimately, this makes a solid fact about the


Raspberry Pi’s viability as a desktop PC.

Sure, there were some complications but whether in the


office or in school, a standard user can do all their

51
computing work on a Raspberry Pi. If you choose the right
mouse and keyboard, you won’t notice a difference
between a Pi and a traditional PC.

In a nutshell, I have proven that the Raspberry Pi can be


used as a low-budget Pc. It is not flawless but a Pi will do as
a short term desktop computer. It will serve until you find
a more appropriate computer.

So if you want a cheaper substitute for the desktop


computer, why not try a Raspberry Pi? Or you can try the
Samsung DeX? Since 2018, Samsung tablets and phones
have featured a hidden desktop mode in case you want to
use your android device like a traditional computer.

52
Chapter 7: Build Your Own
Raspberry Pi Night Vision Camera
To build a homemade night vision camera, you need a
Raspberry Pi Zero W, Pimoroni HyperPixel screen, and
Raspberry Pi IR Camera Module.

According to Dan, his Raspberry Pi night vision camera is


an homage to a childhood spent sneaking about the levels
of Splinter Cell. Sam fisher in his night vision goggles is an
iconic image. My fascination with the idea of seeing in the
dark motivated me to try building a portable hand-held
night vision device.

Running the Raspbian, the night vision camera features a


variety of functions, these include touchscreen controls
through the Pimoroni HyperPixel, real-time image and
video capture and covers a viewing distance of about two
to five metres.

53
Night Vision

A homemade night vision camera mash up built with the


Raspberry Pi Zero W, Pimoroni HyperPixel and an IR
camera.

It’s okay to FAIL

The FAIL (First Attempt In Learning) concept is a friend,


Dan mentions the problems he faced while building his
54
camera and how he solved them, this made the project
exciting. Every complication while building your digital
device is an opportunity in disguise.

Here is a guide to help you build your own device.

Night Vision

55
Building A Night Vision Device

My device includes an IR camera (infrared, this allows


taking photos and videos in the dark) the Pimoroni
HyperPixel 4.0 touchscreen and a Raspberry Pi Zero W.

I purchased an old handheld camera flash for 50p at a boot


fair. The flash casing later served as a harbor for the
hardware. The Pi zero fitted in comfortably with the
original components and enough space still remained for
the HyperPixel screen. The flash was portable and it has a
titling handle, so it possible to angle the device.
Features

 Can see in the dark (2m to 5m)


 4-inch LCD touchscreen
 GUI controls
 10-button control with various preview times
 Handy titling handle
 The swivel head allows you to move the camera for
optimum viewing angle.
 Capture real-time video saved to the camera
 Capture images and stills

56
A Note on Screen Rotation

Building this night vision camera in August 2019, I was


having problems with the HyperPixel 4.0 screen. I had to
rotate the screen and this was simple, it only requires an
edit in the config.txt file.

The main issue was that the ‘touch’ accuracy was off by 1
and 2 cms. I tired other operating systems; I had the same
issue with the new Buster OS. Finally, I downloaded an
older version of the Raspbian OS from:
http://downloads.raspberrypi.org/raspbian/images/

Software Install

With the Raspbian OS which had all the required software,


once the camera was connected, I was able to use it
immediately. I also had to install the guizero, this was easy.
Installing it through the terminal,

57
Using GUI Zero

To activate the IR camera making it record a video, capture


an image or display a preview, majority of the program
code uses the PiCamera Python library. What is being
captured by the camera is displayed as the preview and you
can extend or shorten the amount of time your night vision
camera is on by manipulating the length of a preview.

The program includes generating a function that controls


the camera preview, the example below shows that the
preview has been set to display for 10 seconds.

A button configured using the guizero is shown on the


HyperPixel screen. When you click this button, it initiates
the command.

58
Shutting down the Night Vision

The shutdown function and the guizero ‘options’ features


are combined, it is configured this way using the guizero.
This creates and displays a window that provides the user
options. Here you get the option to ‘shut down’ or ‘cancel’
the shutdown of the device.

The GUI

This 10 buttons and features are present in the GUI`

 A 10 second preview
 A 30 second preview
 A 60 second preview
 A 5 minute preview
 A 10 minute preview
59
 A 15 minute preview
 Take a photo
 Capture a 10s video clip
 Turn on the preview (no time limit)
 Close the night vision GUI and shut down.

The original colors of the buttons were grey which was too
bright for my stealth agenda, so I changed them to black
and green.

FAILING (First Attempt in Learning)

I enjoy the challenges I face during each project. When


option A falls through and you have to find another option
or you will have to choose another method. Now you have
to find a viable option.

60
3. Retrofit a Vintage Camera Flash with a Raspberry Pi
Camera Module

Alan Wang wanted to go against the trend of replacing old


analogue cameras with digital updates. So he retrofitted a
broken vintage camera flash with a Pi Zero W to make a
video-capturing action cam.

Alan craved a large hole in the body of a broken flash unit,


he fitted the Raspberry Pi Zero W, a camera module and
other elements in through this hole. He added a USB
power bank as the power source.

Whenever he presses the onboard touchpad, the retrofit


camera records 12 seconds of footage which is saved as an
MP4 file. Although Alan used a microSD card for storage, a
USB flash drive can also be attached.

61
Although the flash function of the unit was still broken,
this is a great case of upcycling old tech. it looks cool and
you can set it up alongside a Film camera to create some
comparison between the footage they produce. The image
above is an example of this.

Next is a breakdown of the design, and the code required


to operate the camera.

Chapter 8: How to Build an Action


Camera inside a Vintage Flash Unit
with Raspberry Pi 4 and Camera
Module

62
1. Purchase a camera flash,
2. Take it apart to remove the capacitor and circuit
board,
3. Now you have to find a way to fit the Raspberry Pi
inside it,
4. Cut a large hole in the side, put the Pi and the USB
OTG hub also, so you can access the Pi directly or
with your computer.
5. The Pi won’t fit without its protective case, so leave
it on. Cut a breadboard in half, add two LEDs and its
resistors to it, then insert the breadboard at the
back of the USB OTG hub.
6. Attach and strap a small power bank to the flash as
the power source
7. Anytime you use click on the touchpad, the camera
will record a 12 seconds video. The two LED lights
act as status indicators, for recording and standby.

63
The PiCamera library creates H.264 videos which are
converted to MP4 by MP4box. If a USB drive is connected,
the MP4 files are generated onto it. The system dive can
also serve this purpose if a USB drive is unavailable. This
device is similar to the action camera that can be installed
on hot or cold shoes of film cameras.

When done, the user needs to just remove the power


source and disconnect the USB drive to have access to the
files.

The Raspberry Pi operates a Raspbian Buster operating


system. Firstly, I tested it in GUI environment (with the
inbuilt Thoony), the GUI mode is very slow and very hot in
this mode, making it impractical. So I designed it to start
up in terminal mode, this is faster and power saving. I left
the SSH and the HDMI port untouched in case I have to
make modifications.

I used a 5-megapixel Pi mini camera that only records 30


fps videos at nothing more than 720p resolution. This is
due to inadequate memory space. I made a function to
automatically run the script on startup. This didn’t work
out but I later forced it to run by adding "sudo systemctl
start myscript.py" in.bashrc
64
It is possible to auto-run the script using via.bashrc but
then the LEDs didn’t light up the way I wanted or they
didn’t even light up at all, this is still a mystery to me. I also
tried the USB drive auto mount technique.

One of the issues was that you have to wait for several
minutes after taking the footage before extracting your files
or the last MP4 will be outputted as empty (0 byte). You
can compromise by shooting an extra video to ensure the
last one you wanted, won’t be generated as empty.

Also, when you attach a USB drive, the window indicates


that the USB drive is corrupt; this is caused by system
differences.

There is a risk of damaging the Raspberry Pi Zero’s Wi-Fi


antenna when building your device, attach a Wi-Fi adapter
to remedy this. You need the Wi-Fi to update system time.

In the trial run, I noticed the green LED is not bright


enough to be seen during the daytime.

65
66
67
68
69
70
Chapter 9: The Scratch 3 Desktop
can now be installed and used for
Raspbian on your Raspberry Pi!

Scratch 3

Since the Scratch 3’s release this January, the Scratch team
has been working with us to build an offline version for the
Raspbian OS. Compared to older versions the Scratch 3 has
improved interface and superior functionality. This feature
requires a better processor to run smoothly. With the Pi 4
running the latest version of the Raspbian, Buster, you are
guaranteed a comfortable experience using the Scratch 3
on your PC.

71
Which Raspberry Pi can I use?

To run the scratch 3, you need at least 1GB ram on your


device. The Pi 2, 3, 3B+ and the 1GB ram Pi 4 will run the
Scratch 3, albeit uncomfortably as the app may crash due
to lack of memory space if you are running other apps. The
2GB ram Pi 4 on the other hand will run the software
efficiently.

We hope to see improvements in the near future as the


Scratch team is working on minimizing the Scratch 3’s
memory requirements.

How to install Scratch 3

The Scratch 3 will only install on the Raspbian Buster.


First, update Raspbian!

 If you’ve yet to upgrade to Raspbian Buster, it is


better to install a new version of the Buster on your
microSD card than to upgrade to the latest version.
If you’re already using Raspbian Buster, you can update
your OS using this tutorial:

72
After updating your OS, the apt on the terminal or
Recommended Software app on the terminal may be used
to install Scratch 3.

How to Install Scratch 3 Through The


Recommended Software App
Enter the menu, tap Preferences > Recommended Software
then choose Scratch 3 and tap OK.

How to Install Scratch 3 Using The Terminal

In the terminal, open a window then type and run the


following commands:

73
What use is the Scratch 3 and Raspberry Pi?
Scratch 3 for the Raspberry Pi provides extensions that you
can use to control the GPIO pins and Sense Hat using
Scratch code.

GPIO extension

The new extension, the GIPO is different from that of the


Scratch 2, although users will be familiar with the layout
and functionality.

74
With the GPIO extension comes freedom to connect and
control a lot more electronic devices.

Simple Electronics Extension

It is easier to use the Simple Electronics extension than the


GPIO extension. In case you want to connect with
something simple, for example, a button controller for a
game or an LED. There will be more beginner-friendly
extensions for the Pi’s GPIO pins with the Simple
Electronics being the first arrival. Using the
implementation of gpiozero for python as a model, the
Simple Electronics extension makes it easier to use
electronic components: mostly LEDs and buttons for now.
In the model below, an LED is connected to GPIO pin 17
and a button is connected between pin 2 and GND to
control it.

75
Sense HAT Extension

The Sense HAT has been improved to optimize the new


features on Scratch 3, the newly updated version of the
extension also provides some new blocks you can use to:

 Sense tilting, shaking, and orientation


 Use the joystick
 Measure temperature, pressure, and humidity

76
 It displays patterns, text and characters on the LED
matrix.

Micro:Bit And LEGO Extensions

The Scratch 3 desktop will later sport some improvements,


this includes the micro:bit and LEGO extensions. This is
due to the Scratch link, a software that allows Scratch to
talk to a Bluetooth device is currently unavailable for a
Linux type OS like the Raspbian. We are making plans to
build a Raspbian version of the Scratch link but presently
we have no release date.

77
Chapter 10: Virtual Gaming with
Raspberry Pi 4
With the constant increase in mobile gaming and the rise
in virtual gaming, MMO games with streaming and
headsets for voice chatting is the new rave.

Years ago, this has already been predicted by experts.

But the rise in retro gaming is certainly unprecedented.


Nobody guessed that a single-board computer, the size of a
credit card would be this important in the explosion of
retro gaming. It is easy to build a retro gaming machine
with the versatile Raspberry Pi because it emulates several
collections of gaming platforms. To build one, you will
need information about the RetroPie ROMs, downloads,
and others.

Requirements for building a Raspberry Pi Gaming Center?


A lot of components are required to build a robust and
competent Raspberry Pi retro gaming machine. While
keeping the software in mind, let’s discuss the required
hardware.

 Raspberry Pi 4 board
 The Raspberry Pi
78
The Raspberry Pi has seen lots of iterations since its release
in 2012, each device more powerful and efficient than the
last one. Currently, there are two valid options.

1. Raspberry Pi 4 (our coverage): Features a 1.5GHz 64-bit


quad-core ARM Cortex-A72 system-on-a-chip (SOC) with
up to 4GB LPDDR RAM (shared with the GPU). Measures
3.370 × 2.224 inches (85.60 × 56.5 mm). Has 802.11b/g/n/ac
wireless networking and Bluetooth built in.

2. Raspberry Pi Zero (our guide): uses a 1GHz single-core


ARM1176JZF-S SOC with 512MB (shared with the GPU).
This more compact device is 2.56 × 1.18 inches (65 × 30
mm), and has a wireless variant, the Zero W.

The Pi 3B+ will do the job but the Pi 4 offers better


performance, so we advise you to choose this option.

Other Hardware and Cables

After getting your Pi, you will need a reliable SD card, an


HDMI cable, game controllers, a keyboard and mouse to
start with. A Raspberry Pi 4 with 1GB ram won’t set you
back for more than $40 but if you are building from
scratch, the full kit should be less than $100.

79
The Raspberry Pi with the enhanced 4GB ram will cost a lot
more. You can purchase a starter kit which contains
everything you need, except the mouse and keyboard.
After getting all the listed hardware, you have to find the
right emulators. It is best to install an emulation suite but
if you want to you can install the emulators individually.
The emulation suite contains many top emulators and can
be written on a SD card. You will find other unlisted
emulators preinstalled on the suite.

1. RetroPie

Possibly the most popular retro gaming software for the


Raspbian, it contains a large collection of emulators, via
the EmulationStation user interface. While several ported
games (computer games that run natively on the Raspberry
Pi) are bundled, the Emulators are available via the
RetroArch.

2. RecalBox

With over 40 emulators supported, including MAME and


over 30.000 titles. Also, using the EmulationStation user
interface and emulation support from RetroArch/libretro.

80
The cheat codes, a rewind tool, to undo mistakes and
screenshot features enhances the gaming experience on the
RecalBox.

Unlike RetroPie, the Recalbox is available only as a writable


microSD card image, it can’t be installed manually. Both
the RecalBox and RetroPie include the option to install
Kodi.

3. PiPlay

This is a compact alternative to RetroPie and RecalBox, it


features 12 emulated machines plus the ScummVM point-
and-click adventure game platform. It can be downloaded
and written on a disk or installed directly in the Pi through
GitHub. Lacking the lick user interface of the
EmulationStation, it is a more traditional, text-based
interface. It possesses stable emulation and good support
for controllers.

4. Lakka

Marketed as “a lightweight Linux distribution that


transforms a small computer into a full-blown emulation
console”, it also uses RetroArch.

81
With about 40 emulators and thousands of games
available, this is a competent alternative to RetroPie and
RecalBox.

You can upload game ROMs from a separate computer to


Lakka. You can also dual-boot Lakka with BerryBoot or
NOOBS, to run it alongside other Raspberry Pi operating
systems.

5. Pi Entertainment System (PES)

PES is an ArchLinus-based collection of emulators bundled


with RetroArch, with 18 hardware platforms including
MAME. Kodi is included and support for various game
controllers including the popular PS3 and PS4 control
pads.

PES also provides wireless network and network gaming to


retro platforms (except the N64) and it can be dual-booted
with BerryBoot.

6. Batocera

Available for all Raspberry Pi models, the Batocera is an


unusual retro gaming solution.

82
Batocera supports a host of gaming platforms; you just
have to plug your game controller to play.

With everything pre-installed and enabled, minimum


configuration is required. Some platforms are not available
on the Pi. Versions available for x86 devices supports a
larger selection of emulators.

Which Emulation Suite Should You Choose?

Out of the numerous options available, it can be hard to


choose one. If you want a system that will emulate
anything, then the RecalBox or RetroPie should be your
choice, they are very similar.

With so many emulation systems to choose from, you


might find your options a little overwhelming. Generally, if
you want a system that will emulate almost anything,
choose RecalBox or RetroPie. There’s very little difference
between them.

If you need a more specialized experience, choose one of


Batocera, PiPlay, Lakka, or PES.

83
Where to Get RetroPie ROM Downloads

You require ROMs to install games or applications on an


emulator. You need both game ROMs and BIO ROMs.
Although it is easy to overlook the need for BIO ROMs,
emulators can’t launch a game without them. The ROMs
for RetroPie are available legally and illegally.

Before, if the original belongs to you, you can legally use


the ROM, nowadays with peer to peer networking present
even on some standard download websites, this is a risky
practice.

Among the alternatives is the option to build your own


ROM. Although the hardware may vary depending on the
platform, they can still be found. For example, you can buy
a USB device Commodore 64 Datasette (cassette player) to
a computer. We are giving out this information with the
assumption that the ROM is strictly for personal use. Most
of the components can be found online.

How to Add ROMs to RetroPie and Other Suites

You have to copy ROMS to the correct directory on your


PI. Your best option is an FTP solution that supports SSH,
FileZilla is a good option.
84
Some emulation suites however, include a browser
interface so that you can upload the ROM from your
computer.

In gaming, the retro gaming suite you choose will include a


user-friendly library browser. You will only have to
navigate to the game with your controller to launch it.

Retro Controller Options: What Can You Use?

Several controllers are compatible with your Pi retro


gaming machine. Although wired controllers usually work
best, there are some well-regarded Bluetooth options.

Sony PlayStation 3 and 4 controllers can connect to


Raspberry Pi.

The Xbox One, Xbox 360, and PlayStation 3 and 4


controllers should all work. We have an article on how to
connect an Xbox One controller to Raspberry Pi, check it
for more information. Via an N64 emulator, a PS4
controller will work on your Raspberry Pi retro gaming rig.

If you want the retro feel, go for the old school joysticks
and console controllers with USB connectors. They are
available. I prefer to use a standard Raspberry Pi 3 case and

85
it’s not usually in the open. You may decide to use a retro
console-themed case and display it proudly. There are lots
of them available in various designs the mini SNES console
design for example.

You can also try 3D printing, Lots of retro style cases can be
found online as digital files, you just have to buy and
produce them. If you don’t have a 3D printer, there are
people who provide this service. You have to upload the
design and they want their payment upfront, they will ship
it to you. If you intend to build your own case, you can use
the slick design of a game for inspiration.

Retro gaming is becoming increasingly popular. A


Raspberry Pi and some hard work is all you need to build
these 7 amazing RetroPie game stations.

Maybe a retro gaming rig is the best application for a


Raspberry Pi. It’s straightforward to build with a library of
ROM to provide games for your pleasure.

86
Chapter 11: Setting up Raspberry Pi
as a Vpn Server
The function of the VPN is to help you in making your
online identity to protect your activity from being tracked
while browsing the internet or doing other things like
engaging in conversations. VPNs are famous for their use
in our regular computers and it is used in a similar way
when it comes to our micro-computer such as the
Raspberry Pi. Examples of VPN services that can be used
with the Raspberry Pi are Expressvpn, IPVanish, HideMy
Ass as well as the SaferVPN.

Fortunately, the Raspberry Pi can also be used as a VPN


server as well, by using it in the creation of a personal VPN
hotspot for protecting your identity information from
being leaked to any website that is opened via your
network.

Install a client on the Raspberry Pi and get connected with


the use of your router and your identity will get scrambled
before it hits the external network.

87
Set your Raspberry Pi up as a VPN server by taking the
following steps:

i. Install Raspbian to gain access to the command line.

ii. Install the VPN client to protect your identity by making


use of the PiVPN script. You are recommended to make
use of the OpenVPN as your VPN client.

A secured, as well as an encrypted connection, can be


created for your home network anywhere in the world by
plugging in a VPN server into your router. There are
several advantages attached to this, such as:

88
 Easy access to files on your NAS without endless
configurations or while the connection is being
encrypted.
 You will also get an option to make use of your
laptop on a public Wi-Fi hotspot without the risk of
any intruder accessing your transmitted data.
 It also gives you complete control over your data
having a rest of mind that all your data is safe.
 No special hardware is needed to get your VPN
working as well.

Installation of the VPN Servers

 For this guide, we will be using the PiVPN


OpenVPN installer that is not compatible with the
latest Raspbian stretch distro. Therefore, we will be
focusing on the use of the previous version called
Raspbian Jessie.
 Jessie was the most popularly used till July 2017 but
the PiVPN script is presently been updated to
support Raspbian stretch for its use.
 It is advisable to make use of the Raspbian Lite
version because it will be used on the Raspberry Pi

89
in the command-line mode. The Lite version does
not come with a graphical user interface.
 Get on your browser to get the 2017 file of raspbian-
jessie-lite.zip file and get the .img file in it extracted.

90
 Download and install the Win32 Disk Imager.

 Get your microSD card plugged into your card


reader and ensure that there is nothing you still
need on the card.

 Run the Win32 Disk Imager.


 You will be required to input in your administrator
password if you are logged in using the standard
Windows account.
 Go to the top at the right side of the white box and
click on the blue folder icon.
 Go to Raspbian Jessie Lite .img file that you
extracted and double click on it.
 It is, however, important to note that the file
browser might default to the download folder of the
administrator account instead of the current user. It
is therefore important to manually browse for the
right location.
 You will also need to check your microSD card if it
is the right one listed under Device and select
Write.
 Eject the microSD card once the process is done and
put it in the Raspberry Pi and boot up. You will

91
require a keyboard and monitor to be connected to
your Raspberry Pi through the internet will not be
required yet.
 Make use of the normal login to gain access by
making use of the username: pi; password:
raspberry.
 You can hide the Raspberry Pi in the corner that is
next to your router since it is just going to be used
as a server. It is advisable to set up your Pi to be
controlled remotely in the crustless mode. You will
need to enable Secure Shell (SSH) by typing in the
command sudo raspi-config to control in the
crustless mode.

Once set up, you should change the password immediately


to give you the sole access to the SSH, by taking the
following steps:

 Select Option 1 and input in your password twice to


alter it.
 Go to option 5 which is the interfacing options.
 Select P2 SSH.

92
 You will be prompted with a question saying
“Would you like the SSH server to be enabled?”
answer yes to this question.
 Once you select YES, Pi will confirm that your SSH
is on and select Finish afterward.
 Type in the command sudo shutdown now, to get
your Raspberry Pi shut down.
 Get your keyboard and monitor unplugged and get
the Raspberry Pi plugged into your router using the
Ethernet cable.

Now you will be able to control your Raspberry Pi remotely


without the use of the keyboard and monitor.

How to find your Raspberry Pi


 You will be required to turn your Raspberry Pi on
again after which you will need to give it a few
seconds to boot up. After which you can now find
the Raspberry Pi on your network.
 Make use of the Find Android app which lists every
device that is connected to your network and it is to
be noted that the Raspberry will be shown as
Raspberry on the list including the IP address.

93
 Go to Windows and make use of the IP scanner like
the Angry IP scanner for example. The Angry IP
scanner gets your Raspberry Pi listed as raspberry
pi.local located in the Hostname column.

 You will need to download and install the PuTTY


SSH client to get your Raspberry Pi connected.
 After this place, the IP address of your Raspberry Pi
in the Hostname box while you check to be sure
you’re SSH radio button is selected and finally select
Open.
 You will be prompted with a security message.
Check again to be sure the IP address of your

94
Raspberry Pi is the one you have at the top-left of
the PuTTY window and finally select YES to confirm
that you trust the device.

Now you will have access to log in using the username and
password of your Raspberry Pi including a command-line
used similarly to having the physical presence of your
Raspberry Pi. You should have the Linux updates
downloaded and installed by making use of the command
sudo apt-get update and sudo apt-get upgrade
afterward.

95
Then you can now install the OpenVPN through the PiVPN
installer by taking the following steps:

i. Type curl –L https://install.pivpn.io | bash to get the


installer started.

ii. Navigate to the installer by making use of the arrow


keys of the keyboard.

iii. Press the tab as well as the shift-tab in switching to the


YES/NO including the OK/Cancel option located at the
bottom of the different pages and back again. It is to be
noted that you might also need the use of a space bar in
selecting some options as well.

Static IP

You will need to set up a static IP address to notify your


router about the location of your Raspberry Pi on your
network so that this can be forwarded to incoming VPN
traffic. It is acceptable to keep using the IP address that is
currently being used by your Raspberry Pi but it is to be
noted that your router might not assign the same IP
address to a different device that is under your network
automatically.

96
To carry this out, if asked about using your current
network settings as your static address, you can click on
NO and change the last number of the address afterward.

For example with an IP address of 192.168.1.100, you can get


the 100, which is the last number here changed.

To ensure an address hasn’t been taken yet, you can make


use of the Angry IP scanner or Fing.

The IPv4 default gateways should already be set on the IP


address of your router and as a result, it will need no
adjustment. You can just do a proper check to ensure the
settings are correct and then select YES to continue.

You will need to follow the steps to choose which user’s


directory will be needed to store the configurations of your
OpenVPN:

i. The default “pi” will be the only one installed, so you will
have no other choice than to have it selected.

ii. You will be prompted by a piece of advice from the next


screen to enable unattended-upgrades for the Raspberry Pi
to get itself automatically updated using security patches.

97
The security patches are very useful for a machine which is
always connected to the internet having its network port
opened all the time.

iii. To enable the feature in the last step, select YES.

iv. You can now choose between using the TCP or UDP
protocols. It is more preferable to make use of the UDP
because they are faster, through the TCP also comes in
handy in certain situations.

v. Select “UDP” and click on the OK option.

vi. Let the port remains as the default (1194) and selects the
OK option. It is important to have the port number noted
somewhere and ensure the port is correctly displayed on
the screen.

Paranoia Level

 It is to be noted that you will be prompted with


three levels of encryption.
 For the PiVPN installer, you are recommended to
choose the 2,048-bit encryption which is regarded
as a good compromise considering security issues
and the time taken for the key to be generated. For

98
security, 4,096 come in handy and you will also be
given the option to download key components from
public key generation service for generation time to
be reduced.
 If the security is an important factor for you which
is otherwise referred to as the paranoid in terms of
the PiVPN installer, you can get your keys generated
from scratch. You can get this done on the
Raspberry Pi 3 in less than an hour.

 However, it is important to note that the PiVPN


installer does not give room for going back to alter a
setting that has already being made. Once you have
a setting such as the IP address wrong, you will need
to quit the installer again and then restart and this
will also involve you spending an extra hour on
generating of keys.

Getting Connected To Pi

 Apart from now having the keys for the encryption


of your connection, you should also understand how
users can get to connect to your Raspberry Pi.
Connection can be established for users in two
ways:
99
 The use of your external IP address.
 The use of dynamic DNS service.
 Making use of the external IP service is easier
because of its less involvement of your router but
for its downside, its IP address is not constant on
most of the residential broadband packages which
could make connecting to your VPN quite difficult
when you are not indoors.
 The dynamic DNS service will be useful for avoiding
the periodical change in IP address by giving you an
address such as pivpn.dynamicdns.com which will
automatically translate to the current external IP
address of your router.
 Once you enter the details into the settings of your
router, the DNS service will automatically get
updated by the router as soon as the external IP
address changes. This ensures that the address that
was chosen by you always translates into your home
connection’s external address.
 You will need to find out the dynamic DNS services
that are supported by the router by going into the
settings menu on the router. To access this, you will
need to sign up on the dynamic DNS service web

100
page and in case of some routers like the Netgear
D700; you can sign up directly from the interface.
 In a situation where your router does not support
dynamic DNS, you can sign up for a No-IP account
to compensate for this by making use of the
Windows application. This will automatically send
your external IP address to No-IP and for this to
work; you must make sure your computer is on.
 After you have completed the signup, you will be
given the option of selecting a hostname with
different domains and it will automatically fill in
your IP address. In a situation where your hostname
has already been taken, you will need to keep trying
different hostname or domain combinations until
you stumble on an available one.
 Then you should have your hostname listed at the
Hostname section of the No-IP dashboard with the
No Dynamic Update Detected underneath. Select
this option and you will be enlightened by the
wizard as regards setting up your DNS getting
updated on your router.
 Go to the PiVPN installer and select the Public IP or
an external IP address or choose the DNS entry if

101
you are making use of the dynamic DNS. In the case
you chose the DNS entry, you will be required to put
in your dynamic DNS Hostname and check properly
to be sure it is right before confirmation.
 For users connecting to your VPN, you will need to
be requested for the DNS Provider because it will be
needed in browsing the web through a VPN server
of the Raspberry Pi. The DNS server can view
whatever websites that must have been visited by
those connecting to your VPN as a result, you are
advised to build your DNS server if you need some
privacy.
 At the final stage, you will be required to “run pivpn
add to create the ovpn profiles,” however you will
need to have your Raspberry Pi rebooted first.
 Select the OK option to start rebooting.
 Forward the necessary port available on your router.
 Go to the settings of the router and get a port
forwarded to your Raspberry Pi to notify your router
where it will be sending the incoming VPN
connections irrespective if you decide to use an
external IP address which is connecting to your
Raspberry Pi VPN or using the dynamic DNS.

102
 You should visit the portforward.com for a
comprehensive router list. Stick to the use of the
default OpenVPN UDP port 1194.

 Ensure it is added to the IP address of your


Raspberry Pi while ensuring the UDP is selected and
not the TCP.

Access Granted

 Get logged back into your Raspberry Pi making use


of PuTTY.
 To ensure your Raspberry Pi is updated with the
latest security patches required, type the
commands: sudo-apt get updated then sudo apt-get
upgrade.
 For the users or clients that will be connecting to
your VPN, you will need to have their OpenVPN
profiles added.
 There will be a username and password allocated to
each user which will need to be used along with a
special file that was generated by you with the use of
PiVPN to get connected.
 To give a user or client access to your VPN, you will
need to type pivpn add and input in the username
103
and password for such a client. Once this is done,
.ovpn file will be generated and will be
automatically copied to /home/pi/ovpns. Any other
profiles that you intend adding can also be added.
To get profile removed type in pivpn revoke
followed by the profile name.
 Making use of the SFTP is the easiest way to copy
.ovpn files off the Raspberry Pi. To do this, you will
need an FTP client or WinSCP.
 You will need to download and install the WinSCP
and when you run it, a screen will be displayed
where you should ensure selecting the SFTP under
the File protocol.
 Go to the Hostname and enter the IP address of
your Raspberry Pi ensuring the port number is 22
and input in your username as well as password.
Select Login after inputting the required details.
Select YES to add the Host key of Raspberry Pi
added to the cache and avoid getting this warning
again.
 You will be navigated to /home/pi by default;
therefore you will need to browse the ovpns folder
after which you should get .ovpn copied to your PC.

104
 To get connected to your VPN, you will need the
combination of .ovpn file along with the correct
username and password. It is to be noted that the
client software will be needed for this.
 The next step is to download and install the
OpenVPN Installer.
 To copy .ovpn files to C:\Program
Files\OpenVPN\config. In a situation where you
intend sending these files to other people, it will be
a good idea to encrypt the files using the 7-Zip first
to have them secured. It is, however, important to
note that most email services will not allow you to
get an encrypted file sent over them as an
attachment so they will need to be hosted in a file
sharing service like Dropbox. After which you can
send a link to the Dropbox folder which contains
the encrypted file.
 It is also advisable to get the username including the
password sent separately from the 7-Zip encrypted
.ovpn file. You can preferably make use of an
encrypted platform like WhatsApp.
 To get the OpenVPN Gui loaded. Go to the System
Tray and right-click it.

105
 You will then be prompted with a list of OpenVPN
profiles that have been installed.
 Click on connect afterward for a secure connection
to your Raspberry Pi.
 Connection using a smartphone running in the
wireless hotspot mode is the easiest way to check if
your VPN is working from outside a home network.

106
Chapter 12: Hosting a WordPress Site
on Raspberry Pi 4
The hosting of your website on the Raspberry Pi 4 is a great
way of familiarizing yourself with the device. You will get
conversant with how to work with MySQL, Apache
software and PHP including the practical application of
working with Linux by running a Wordpress server.

Hosting a Wordpress on the Raspberry Pi 4 will also give


you access to your Wordpress website which can be used
to host your content.

To make your website a proper one, you will need to


register a domain name. Once this is done, you can display
your content such as CVs, creative portfolios, personal
blogs, etc.

To effectively start up your Wordpress on the Raspberry Pi


4, you will need to learn how to set up a LAMP stack on
your Raspberry Pi 4 and have it configured to work as a
web server. The LAMP stands for Linux, Apache, My
SQL, and PHP. Then you will need to get Wordpress
downloaded and installed as well as set up a basic website

107
that can be accessed on any device via the same network as
your Raspberry Pi 4.

Setting up an Apache web server

The Apache web server application is useful for installation


on Raspberry Pi 4 to let it serve web pages. Apache can
work on its own to serve HTML, files over HTTP and when
it is equipped with additional modules, it will effectively
serve dynamic web pages with the use of scripting
languages like PHP.

Installing Apache

i. Select Accessories to open a terminal window.

ii. Select Terminal from the menu.

iii.Type the command below into the terminal and select


Enter to install the apache2 package.

108
How to Test the Web Server

The Apache will by default put a test HTML file in the web
folder which can be viewed from your Raspberry Pi 4 or
another computer available on your network. To test the
web server, you are required to take the following steps:

i. On your Raspberry Pi 4, open the default web page of


Apache.

ii.Select the internet to open Chromium.

iii. From the menu, select the Chromium Web browser.

iv. Enter http://localhost into the address field.

109
v. You should be prompted with the page below, after step
iv., which shows that your Apache is up and running.

Once you have the Apache up and running, the webpage


can also be opened from any other computer available on
your network with the use of the IP address of your
Raspberry Pi 4 such as http://192.168.1.10.

You can type in hostname –I into the terminal window to


help detect the IP address of your Raspberry Pi 4 which is
useful in remotely accessing your device.

How to change the default web page

The default web page can be located at


/var/www/html/index.html and it depicts an HTML file on
the file system.

Go to the directory located in the terminal:

110
Details about each column:

 Permissions of the file or directory.


 The number of files the directory contains or simply
one if it has just a file.
 The owner of the file or directory.

111
 The groups that own the file or directory.
 The size of the file or directory.
 The date and time of the last modification.

The HTML directory, as well as the index.html, belongs to


the root user, therefore you will need to use the Sudo
command to get them edited:

The file can be edited using the leafpad:

In a situation where a change was made to the file, get it


saved and refresh the browser. All changes made will be
activated after the browser is refreshed.

Installing PHP

Whenever the server receives a request for a web page


through a web browser, the code that runs to show
everything that needs to be shown by the page is a
preprocessor called the PHP. It is also responsible for
sending the page to the browser. This preprocessor can
display different content under different circumstances.

112
PHP is a very useful language that has also been used for
huge projects like Wikipedia and Facebook.

Chapter 13: started with the Camera


Module

This tutorial is compiled to teach you how to connect the


Raspberry Pi Camera Module to your Raspberry Pi and take
pictures, record video, and apply image effects.

113
What you will need
Raspberry Pi computer with a Camera Module port
All the current Raspberry Pi models have a port for you to
connect the Camera Module.

Note: The Raspberry Pi Zero has a smaller port for the


Camera Module, so if you want to use a Pi Zero, make sure
you get the right Camera Module ribbon cable.

114
Raspberry Pi Camera Module

There are two versions of the Camera Module:

 The Standard version: This can only capture


images in normal lighting conditions.

 The Noir version: Although it has no infrared


filter, an infrared light source can be attached to
capture images in extremely low light.

115
Connecting the Camera Module

Ensure your Raspberry Pi is turned off.

1. Find the Camera Module port.

2. Open the port by carefully pulling up the edges of


the plastic clip.
3. Insert the Camera Module ribbon cable with the
panel facing downward.

4. Lock back the port by pushing the plastic clip back


in place.

116
 Boot the Raspberry Pi.
 Open the main menu, then under preferences select
the Raspberry Pi Configuration tool.

117
 Enter the Interfaces tab and make sure the camera
is enabled:
 Restart the Raspberry Pi.

118
How to Control the Camera

Module via the command line


By now, you have connected the Camera Module and the
software is enabled, use any of these two command tools,
raspistill or raspivid.

 Click the black monitor icon in the taskbar to open


a terminal window:

119
 Type the command in the image below to take stills
and save them on your desktop:
raspistill -o Desktop/image.jpg

 Click Enter to run the command.


If you run the command, a camera preview will display for
five seconds, then a still photo will be taken.

 Find your picture’s file icon on your desktop, then


double-click the icon to open your picture.

120
You can add more options to set the size and look of the
image the raspistill command takes.
 You can add -h to change the height of the image
and -w for the width:
raspistill -o Desktop/image-small.jpg -w 64

 Use the raspivid command below to record a video


with the Camera Module.
raspivid -o Desktop/video.h264

121
 The video.h264 file will be saved to your desktop,
double-click the file icon to play it with VLC Media
Player.

How To Control the Camera Module Using


Python Code

With the Python picamera, you can control the Camera


Module to make interesting projects.

 Open a Python 3 editing software, like the Thonny


Python IDE:

122
 Create and save the new file as camera.py.

Note: Ensure you don’t save the file as picamera.py.


 Type in the following code:
from picamera import PiCamera

from time import sleep

camera = PiCamera()

camera.start_preview()

sleep(5)

camera.stop_preview()

 Save, then launch the program. The camera preview


will display for five seconds.

Note: A display monitor has to be connected to the Pi for


this to work, you can’t see the camera preview if you use
remote access like SSH or VNC.
123
 Enter the following code to rotate your preview by
180 degrees, if it’s upside-down:
camera = PiCamera()

camera.rotation = 180

 To rotate the image, set rotation to any angle (90,


180 or 270). You can set rotation back to 0 degrees
to reset your image.
It’s easier to see any error in the program if you make the
preview a bit see-through.

 Set an alpha level to make the preview see-through:


camera.start_preview(alpha=200)

The alpha value can be set within 0 to 255.

Take Still Pictures With Python Code


After setting the commands, you can now capture images
with your Camera Module.

 Change the code to add a camera.capture() line:


camera.start_preview()

sleep(5)

camera.capture('/home/pi/Desktop/image.jpg')
124
camera.stop_preview()

Note: Set the sleep mode for at least two seconds, this
should be sufficient time for the camera sensors to register
lighting conditions.

 Launch the code.

The camera preview will display for five seconds,


then a still photo will be taken. The preview will
adjust the resolution while taking the picture.

The image will be saved to your desktop.

 Take five photos at once by adding a loop:


camera.start_preview()

for i in range(5):

sleep(5)

camera.capture('/home/pi/Desktop/image%s.jpg' %
i)

camera.stop_preview()

125
The variable i indicates the amount of times the loop has
run, from 0 to 4. Your photos will be saved as image0.jpg,
image1.jpg till it gets to image0.jpg.
Launch the code to take more pictures with your Camera
Module.
The camera will capture an image every five seconds,
stopping after the fifth photo.

 Check the five new images on the desktop.


Recording video with Python code

Now, let’s try videos.

 Change the code by removing capture() and


replacing it with start_recording() and
stop_recording()

Write it as shown in the image below:


camera.start_preview()

camera.start_recording('/home/pi/Desktop/video.h26
4')

sleep(5)

126
camera.stop_recording()

camera.stop_preview()

 Launch the code.

Your Raspberry Pi will display a 5 seconds preview,


recording the video before closing.

How To Change Image Settings And Add


Image Effects
The Python picamera software supports several effects
and configurations that you can use to edit how your
images look.
Note: Some settings will modify just the preview, some will
only modify your image and some can modify both.

Set The Image Resolution

Here is how to change the resolution of the image taken


by the Camera Module.
The default resolution for your image is set to your
monitor’s resolution. The maximum resolution for pictures
and videos are 2592×1944 and 1920×1080 respectively.

127
 Type the following command to set the maximum
resolution for your picture:
Note: You have to set the frame rate to 15 to enable
maximum resolution.
camera.resolution = (2592, 1944)

camera.framerate = 15

camera.start_preview()

sleep(5)

camera.capture('/home/pi/Desktop/max.jpg')

camera.stop_preview()

64×64 is the minimum resolution.


Change the resolution to 64×6 to take pictures at the
lowest resolution.

Add text to your image


Use the command annotate_text to add text to your
image.

 Write and launch the code to try it:


camera.start_preview()

camera.annotate_text = "Hello world!"

128
sleep(5)

camera.capture('/home/pi/Desktop/text.jpg')

camera.stop_preview()

Change the look of the added text

 Use the following command to change the size of


your text:
camera.annotate_text_size = 50

Although the default size is 32, you can change it to any


size within 6 to 160.
You can also change the color of your text.

 The first step is to add Color to your import line at


the beginning of the program:
from picamera import PiCamera, Color

 Change the code under the import line to the


following:
camera.start_preview()

camera.annotate_background = Color('blue')

camera.annotate_foreground = Color('yellow')

camera.annotate_text = " Hello world "


129
sleep(5)

camera.stop_preview()

Change the brightness of the preview

The default brightness is 50 but you can change it to any


value from 0 to 100.

 Launch the following code to try it:


camera.start_preview()

camera.brightness = 70

sleep(5)

camera.capture('/home/pi/Desktop/bright.jpg')

camera.stop_preview()

 The following code adjusts the brightness and adds


text that displays the current brightness level:
camera.start_preview()

for i in range(100):

camera.annotate_text = "Brightness: %s" % i

camera.brightness = i

130
sleep(0.1)

camera.stop_preview()

Change the contrast of the preview

You can change the contrast of your preview, just like you
changed the brightness.

 Run the following code to try this out:

camera.start_preview()

for i in range(100):

camera.annotate_text = "Contrast: %s" % i

camera.contrast = i

sleep(0.1)

camera.stop_preview()

Add cool image effects

You can apply any effect by using camera.image_effect.

The effect options include:


131
 none
 negative
 solarize

 sketch

 denoise

 emboss

 oilpaint

 hatch

 gpen

 pastel

 watercolor
 film

 blur

132
 saturation

 colorswap

 washedout

 posterise

 colorpoint

 colorbalance

 cartoon

 deinterlace1
 deinterlace2

The default is set to none.

 To try out any photo effect:


camera.start_preview()

camera.image_effect = 'colorswap'

sleep(5)
133
camera.capture('/home/pi/Desktop/colorswap.jpg')

camera.stop_preview()

 Launch this code to loop in all the image effects


using camera.IMAGE_EFFECTS:
camera.start_preview()

for effect in camera.IMAGE_EFFECTS:

camera.image_effect = effect

camera.annotate_text = "Effect: %s" % effect

sleep(5)

camera.stop_preview()

134
Set the image exposure mode

You can set the exposure by using


camera.exposure_mode.

These are the various exposure modes:

 off

 auto

 night

 nightpreview

 backlight
 spotlight
 sports
 snow

 beach

135
 verylong

 fixedfps

 antishake

 fireworks

Exposure is preset to auto.

 To choose any exposure mode and try it:


camera.start_preview()

camera.exposure_mode = 'beach'

sleep(5)

camera.capture('/home/pi/Desktop/beach.jpg')

camera.stop_preview()

 You can use camera.EXPOSURE_MODES to loop


over the various exposure modes.

136
Change the image’s white balance

You can preset the white balance using


camera.awb_mode.

The available white balance modes are:

 off
 auto
 sunlight
 cloudy
 shade
 tungsten
 fluorescent
 incandescent
 flash
 horizon
The white balance is preset to auto mode.

 To try out an auto white balance mode use this:


camera.start_preview()

camera.awb_mode = 'sunlight'

sleep(5)

137
camera.capture('/home/pi/Desktop/sunlight.jpg')

camera.stop_preview()

 You can use camera.AWB_MODES to loop over the


white balance modes.
What you will make
You can use a Raspberry Pi, Python and a Camera Module
to make stop motion animation videos or take pictures,
using a push button connected to the Pi’s GPIO pins as the
controller.
You can animate a LEGO tower, figures in a scene and
much more.

Conclusion

Thanks for taking out time to read through this guide. We


believe you have learnt a great deal from it. If you have,
please do leave a review on Amazon so we get to know
your thought.

Thanks

138

S-ar putea să vă placă și