Sunteți pe pagina 1din 169

Raspberry Pi 4 Beginner’s

Guide

The Beginner’s Guide to Master Raspberry Pi 4 as your


new PC and Build Amazing Projects

Graham O. Wilson
Copyright 2019 © Graham O. Wilson
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 © Graham O. Wilson
Contents
Introduction .............................................................................. 1
Chapter 1: Getting Started With Raspberry Pi 4 ....................... 2
Guided Tour of the Raspberry Pi .......................................... 4
Chapter 2: Discover the Items Essential for Setting up A
Raspberry Pi 4 ....................................................................... 17
Setting up The Software ..................................................... 30
Chapter 3:Using your Raspberry Pi ....................................... 35
The Chromium Web Browser ............................................. 43
The File Manager ............................................................... 46
The Raspberry Pi Configuration tool ................................... 58
Chapter 4: Programming with Scratch.................................... 64
Introducing the Scratch 2 interface ..................................... 65
Looping the Loop................................................................ 74
Chapter 5: Project 1--Astronaut Reaction Timer ....................... 1
Chapter 6: Project 2--Synchronized Swimming ........................ 7
Chapter 7: Project 3--Archery Game ........................................ 1
Chapter 8: PROGRAMMING WITH PYTHON .......................... 5
Introducing the Thonny Python IDE ...................................... 6
Your First Python Program: Hello, World! ............................. 8
Chapter 9: Project 1: Turtle Snowflakes ................................. 14
Chapter 10: Physical Computing with Raspberry Pi ............... 26
Introduction to GPIO header ............................................... 26
Chapter 11: Your first Physical Computing Program: Hello,
LED!....................................................................................... 37
Chapter 12: LED Control in Python ........................................ 41
Chapter 13: Using a Breadboard ............................................ 43
Chapter 14: Reading a Button ............................................... 45
Reading a button in Python ................................................ 46
Chapter 15: Make Some Noise: Controlling a Buzzer ............ 49
Controlling a buzzer in Python ........................................... 50
Chapter 16: Python Project 2 Quick Reaction Game ............. 52
Chapter 17: Virtual Gaming with Raspberry Pi 4 .................... 58
Introduction

In our opinion, you will certainly adore the Raspberry Pi 4.


Ultra-small, affordable, even cheaper than most video
games, you can use the Pi to build robots, learn coding and
create all sorts of exciting projects. It is capable of
performing any task a computer can, including activities
such as browsing the internet, listening to music, watching
movies and playing games, and much more.

The Pi is not just an average modern computer, it gives you


access to the inner workings of a computer. You get a
chance to build your very own PC, to connect the circuits
and wires to the board pins. The Pi was originally designed
to teach young people programing in languages like
Scratch and Python, and the official OS includes every
major programming language.
The Pi sparks interest in computer science and technology,
drawing the new generation into the ever important and
enlarging field of programming. Age doesn’t matter,
anyone can make interesting projects with the Pi: literary

1
anything from internet-connected weather stations to retro
games.
This book will guide you if you plan to use your Raspberry
Pi to build robots, gaming consoles and various other
projects. Shall we?

Chapter 1: Getting Started With


Raspberry Pi 4
The difference between the Raspberry Pi and your average
smartphone, laptop or desktop is the Pi being built on a
single printed circuit board, making it a single-board
computer. This is responsible for the Raspberry Pi's small
size, just like most single-board computers.
The size of the of the Pi 4 doesn’t affect its power; It will
perform the same tasks as any bigger and more power-
hungry computer, maybe a little slower but it gets the job
done.
The desire to make global computer education more
accessible birthed the Raspberry Pi family. The founders
had no idea it would be this popular when they created the
nonprofit Raspberry Pi Foundation.

2
In 2012, only a few thousand were built and they sold out
quickly, and since then, millions more have been sold all
over the globe.
People are now using the Raspberry Pi in their offices, data
entry centers, classrooms, factories, homes, spacefaring
balloons and self-piloting boats. The original Raspberry Pi
was called Model B and various models have since been
released after it, with each new model comes improved
specifications and specific features for specific use-case.
The Raspberry Pi Zero model for example, is a much
smaller (in size) and less power consuming version of the
Raspberry Pi, features that were dropped to achieve this,
includes the wired network port and the multiple USB
ports.

All models of the Raspberry Pi are compatible, so the


software written for one will work for the others. So
compatible that even the original pre-launch Model B
prototype will run the latest version of the Raspberry Pi
OS. It will probably be slower but it will still run.

The latest version and most powerful version of the Pi, the
Raspberry Pi 4 Model B is the ultimate focus of this book,

3
so you will be provided with enough information about it.
This information can also be applied to other Raspberry Pi
models, so it will be useful to anyone using a different
model of the Raspberry Pi.

Guided Tour of the Raspberry Pi

The Raspberry Pi displays all of its feature, component and


port in plain view, unlike a traditional computer which
covers its inner workings with a case, but you can also get a
case for your Pi to provide extra protection. You will learn a
lot from the Raspberry Pi, it allows you to see the various
parts of a computer, their functions and how and where to
plug in the extra components (called peripherals).
The Raspberry Pi 4 Model B (as seen from above) is shown
in the figure below. Turn the raspberry Pi to view it the
way it is displayed in the image (if you intend to use this
book) to avoid confusion when you want to use
components such as GPIO header.

4
The Raspberry Pi 4 Model B
The Raspberry Pi’s small board may look like a lot is
crammed into it, but it is actually easy to understand, and
we are going to start with the components, the inner
workings responsible for its capabilities.

5
The Raspberry Pi’s Components
Much like the setup of any other computer, the Raspberry
Pi comprises different components, and they all contribute
to its functionality. On the top side of the board, check the
metal cap just above the center point for probably the most
important of these components: the system-on-chip (SoC).

System-on-chip is a great name for the silicon chip you will


find under the metal cover. The silicon chip is an
integrated circuit which contains most of the Pi’s system.
The contents include the central processing unit, known as
the brain of a computer and the graphics processing unit
(GPU), which handles visuals.
The brain also needs a memory, so right beside the system-
on-chip is a chip, in the form of a small, black plastic
square. This chip is the Pi’s random access memory (RAM).
When working on the Raspberry Pi, your work will be held

6
on the RAM until you save it, then it will be written to the
microSD card.
The Ram and microSD card work together as the Raspberry
Pi’s volatile and non-volatile memory respectively. The ram
as the volatile memory will lose its contents, when you turn
of your Raspberry Pi, while the microSD card, the non-
volatile memory will retain its contents.

There is another metal cap at the top right of the board,


this houses the radio which allows the Raspberry Pi to
communicate wirelessly with other devices. The radio acts
as two important components: a Wi-Fi radio, which allows
the Pi to connect to computer networks; and a Bluetooth
radio, which allows the Pi to connect to peripherals such as
a mouse and send or receive data from nearby smart
devices like smartphones and sensors.

7
To the bottom edge of the board just behind the middle set
of USB ports is another black plastic-covered chip. This
chip is the USB controller, which runs the four USB ports.
You will find a smaller chip next to it called the network
controller; it runs the Pi’s Ethernet network port.

Then to the upper-left part of the board, just above the


USB Type-C power connector, is the last black chip,
smaller than the others, it is called the power management
integrated circuit (PMIC) and it is responsible for turning
the power that enters through the micro USB port into the
power that runs the Raspberry Pi.

8
And if all of these seem confusing, don’t lose sleep over it,
because using a Raspberry Pi doesn’t require you to know
all of its components and their location on the board.

The Raspberry Pi’s Ports


You will find various ports on the Raspberry Pi, among
these are the four Universal Serial Bus (USB) ports located
to the middle and right-hand side of the bottom edge, of
the board. You can connect USB-supported peripherals to
your Pi through these ports; examples include mice,
Keyboards, flash drives and digital cameras. There are
technically two types of USB ports: the ones with black
interior are USB 2.0 ports, based on version 2 of the
Universal Serial Bus standards: while the ones with blue
interior are the faster USB 3.0 ports based on the newer
version three.

9
The Raspberry Pi’s USB ports
By the right of the USB ports is the Ethernet port which is
also called the network port. With this port, you can
connect the Pi to a wired computer network through a
cable called the RJ45 connector. Pay close attention to the
Ethernet port and you will discover two light-emitting
diodes (LEDs) at is bottom; these are status LEDs that
indicate when the connection is working.

Above the Ethernet port, on the left-side edge of the Pi,


you will find a 3.5 mm audio-visual (AV) Called the
headphone jack, connect it to your headphone although
you will get a better performance if you use amplified

10
speakers. Rather than to just provide you with audio, the
3.5 mm audio-visual (AV) has a hidden extra feature; it
carries a video signal that you can connect to projectors,
TVs, and any other display that supports a composite video
signal. You will need a tip-ring-ring-sleeve (TRRS) adapter,
a cable specially designed for this function.

Look directly above the 3.5 mm AV jack, you will find a


weird-looking connector that has a plastic flap which can
be pulled; that is the camera connector or you can call it
the Camera Serial Interface (CSI). This allows you to use a
specially built Raspberry Pi Camera Module.

11
Look above this, still on the left-side edge, you will find the
micro High Definition Multimedia Interface (micro-HDMI)
ports, they are smaller versions of the same connectors on
Televisions, game consoles and set-top boxes. True to its
name, it carries both audio and video signals, hence the
term multimedia while the high definition comes from the
high quality of the signals. You can use these ports to
connect the Raspberry Pi to display devices such as
computer monitors, TVs or projectors. You have the option
to connect to at most, two devices at the same time.

Just above the HDMI ports, you will find USB Type-C
power port, this is used to connect the Pi to a power
source. You will notice that the USB Type-C power is
present in smartphones, tablets and other portable devices.

12
It is better if you use the official Raspberry Pi USB Type-C
Power Supply to power your Pi, but you can get by with a
standard smartphone charger.

Check the upper edge of the Raspberry Pi’s board and you
will find another weird-looking connector; you’d mistake it
for the camera connector if you don’t look closer. It is the
exact opposite of the camera connector, instead, it is a
display connector also known as Display Serial Interface
(DSI). It is designed to be used with the Raspberry Pi
Touch Display.

13
To the right edge of the board, there are 40 metal pins,
divided into two rows with 20 pins each. It is the GPIO
(general-purpose input/output) header; the Raspberry Pi
uses it to transmit signals to additional hardware, such as
LEDs, buttons, joysticks, temperature sensors, pulse rate
monitors and other similar hardware.
Below the header, just to the right, you will find a smaller
header with just four pins: you can use this to connect the
Power over Ethernet (PoE). The PoE is an additional power
option that allows the Raspberry Pi to be powered from a
network connection, instead of the USB Type-C port.

14
The last port on the Raspberry Pi can’t be seen from the
top of the board. Turn it over and you will see a microSD
card connector, located at the opposite side of the display
connector. This is where you'll insert the Pi’s storage: The
microSD card inserted here will house all the operating
system that runs the Raspberry Pi, all installed software
and all saved files.

The Raspberry Pi’s Peripherals


The Raspberry is like a desktop computer, it can’t do
anything on its own. To us the Raspberry Pi, you have to
connect it to peripherals: with bare minimum of; a
microSD card for storage; a display monitor or TV; a
keyboard and mouse to give instructions; and a power
source, 5 volt (5 V) USB Type-C power supply rated at 3
amps (3 A) or better. This pretty much gets you a fully
functional PC. More information on how to connect the

15
peripherals to your Pi will be provided in Chapter 2,
Getting started with your Raspberry Pi. There are a lot
more peripherals you can connect to your Raspberry Pi.

The Raspberry Pi Foundation produces official accessories


such as: the Raspberry Pi case, offers protection for your
device without hindering access to the various ports and
the Camera Module. The Raspberry Pi Camera Module; the
Physical computing with the Sense HAT; and the
Raspberry Pi Touch Display all this can be connected to
the display port for a video display and a tablet-style
touchscreen interface.
There are various accessories by third parties, from kits you
can use to turn a Raspberry Pi into a laptop or tablet, to
add-ons that allow the Pi to understand your speech, even
reply you vocally.
These assortment of Peripherals, promise exciting
possibilities but before you buy any one, remember one has
to learn to walk before you can run. Meaning you should
first understand how to use the basic peripherals before
taking on the more complex ones.

16
Chapter 2: Discover the Items
Essential for Setting up A Raspberry
Pi 4
Discover the items essential for setting up a Raspberry Pi
and learn how to connect them. The Raspberry Pi may
seem like any other computer because it requires various
external components known as peripherals, but it was
design for as fast and easy a set-up as imaginable. So if you
are intimidated just because the bare circuit board of a
Raspberry Pi looks different from encase, closed-off
computers, don’t be.
If you follow information on this book, you should be
running a Raspberry Pi in under ten minutes. If you got
this book from a Raspberry Pi Starter Kit, it means you
already have most of what you need to run the raspberry
Pi: just get a display monitor or a TV with HDMI
17
connection, this is the same connector used in Blu-ray
players, set-top boxes and gaming consoles. If you don’t
possess a Raspberry Pi Starter Kit, you are going to need
the following in addition to the Raspberry Pi 4 Model B:

USB Power Supply

– A 5 V power supply rated at 3 amps (3 A) and with a USB


Type-C connector. This is the Official Raspberry Pi Power
Supply and it is the one recommended, because it will be
able to cope with a Raspberry Pi’s fast varying power
demands.
microSD card with NOOBs

The microSD card is the permanent storage of a Raspberry


Pi; every software you install, every file you save, even the
operating system will be saved on it. We recommend a
minimum of 16GB, but an 8GB microSD card is
18
manageable. Get a card that has the bare circuit board
(NOOBS) pre-installed on it and this will save you time.
If you are using a blank microSD card, you will find
information on how to install NOOBs on a blank card in
Appendix A.

USB Keyboard and Mouse

You can’t control a Raspberry Pi without a keyboard and


mouse. Pretty much any wireless or wired with a USB
connector keyboard and mouse are supported by the
Raspberry Pi. Beware of some ‘gaming’ style keyboard with
colorful lights as they might draw too much power, and
therefore prove themselves unreliable.
Micro-HDMI cable

19
This is required to transfer sound and images from the
Raspberry to a display monitor or TV. The end with the
micro-HDMI connector is to be connected to the
Raspberry Pi, while the other end, the one with the full-size
HDMI connector is to be connected to the display. You can
also use a micro-HDMI to HDMI adaptor with the
standard, full-size HDMI cable.
If your monitor doesn’t have an HDMI socket, get a micro-
HDMI to DVI-D, Display Port, or VGA adapters. If you are
connecting to an older TV with composite video or have a
SCART socket, get a 3.5mm tip-ring-ring-sleeve (TRRS)
audio/video cable.
You can safely use a Raspberry Pi without a case, just don’t
place it on a metal surface, because metal conducts
electricity and can cause the Pi to short-circuit. Altogether,
you might be better off with a case: you will find the
Official Raspberry Pi Case in the Starter Kit, you can also
purchase cases produced by third parties, available at
stockists.
If you intend to use a Raspberry Pi on a wired network
instead of a wireless network (Wi-Fi), you are going to
need a network cable to connect the Pi to your network
router or switch.

20
Using the Raspberry Pi’s inbuilt wireless radio doesn’t
require a cable but you need to know the name and
password or passphrase of your wireless network.

Setting up the hardware

You have to start by unboxing the Raspberry PI, right?


Remember that although the Raspberry Pi is a strong piece
of hardware, it can still be damaged so try to protect it by
holding the board by its edges, instead of on the flat side
and make sure you are careful around the raised metal
pins. If these pins should bend, you are looking at a best
case scenario of difficulty plugging add-ons boards and
extra hardware, and worst case scenario, it can cause the Pi
to short-circuit, therefore damaging it.

Assembling the Case


If you want to use a case on your Raspberry Pi, then you
should probably do this before anything else. If you want to
use the Official Raspberry Pi Case, split the case into its
two individual parts: the red base and its white lid.

21
1. Pick up the case’s base and hold it in a way that the
elevated end is to your left while the lower end is to the
right.

2. Make sure there is no peripheral (not even the


microSD card) in the Raspberry Pi. Hold the Pi by the
USD and Ethernet ports, at a slight angle, then slot
the connectors (USB Type-C, 2 × micro-HDMI, and
3.5 mm) into their holes in the side of the case, now
lower the other side to sit the Pi flat in the base.

22
3. Take the white lid, you will see two clips on the left
side, place them into the matching holes on the left
side of the base, just above the microSD card slot.
Adjust until they are in place, then push down the
right side (above the USB ports) until you a click is
heard.

Connecting the microSD card


You have to install a storage into the Raspberry Pi, so when
you want to insert a microSD card, turn over the Raspberry
Pi (now in a case if you are using one). You will find the
microSD card slot labeled by the side of your Pi, insert the
card into it. It will only enter one way, so it should slide in
without resistance.

23
The card should slide into the connector, then stop
without any click.

For Raspberry Pi 3 of 4, anytime you want to remove the


microSD card, just grip it by the protruding end and pull it
out, gently. Older Raspberry Pi models require you to
gently push the card in first to unlock it.

Connecting a Keyboard and Mouse


You can connect the USB cable of your keyboard to any
one of the four USB ports (2.0 or 3.0) on the Pi. The Official
Raspberry Pi Keyboard has a USB on the back for you to

24
plug your mouse, but if you are not using this keyboard,
you can connect the mouse to another one of the Pi’s USB
port.

The USB connectors of either the mouse or keyboard


should slide in easily, if there is any resistance it means you
are doing something wrong. Ensure the USB connector is
the right way up.
Note:

Connecting a Display
The smaller end of the micro-HDMI cable should be
connected to your Raspberry Pi, specifically to the micro-
HDMI port closest to the USB Type-C port, then the other
end should be connected to your display device.
25
In case your display has more than one HDMI port, you
will find the port number next to the port, then switch the
input of your display to the one you connected the Pi to.
But is case there is no number by the HDMI port, just
switch between the available inputs until you find the right
one.

Note:
TV Connection
You can still use the Raspberry Pi with a display monitor or
TV that don’t have HDMI connector. Purchase a adapter
cable from any electronics stockist and use it to convert the
micro-HDMI port of your Raspberry Pi to DVI-D, DVI-D,
DisplayPort, or VGA that you can use for older computer
monitors; all you have to do is connect the adapter cable to

26
the micro-HDMI port of your Raspberry Pi, then you can
use a suitable cable to connect the adapter cable to your
display monitor.
In case you want to use a TV that only has composite
video or SCART input, then it’d be ideal for you to get a
3.5 mm tip-ring-ring-sleeve (TRRS).

Connecting A Network Cable


(Optional)
If you want to use a wired network on the Raspberry Pi,
you need a network cable also called an Ethernet cable to
make the connection. With the plastic clip facing
downwards, plug the Ethernet cable into the Ethernet port
of your Raspberry Pi, until you hear a click. And whenever
you want to remove the cable, squeeze the plastic chip into
the plug and gently pull it out.

27
Connect the other end of the Ethernet cable to a port on
your network hub, do this, the same way you connected
the cable to your Pi.
Connecting a Power Supply
The last step in setting up your Raspberry Pi should be
connecting it to a power supply, only do this when you are
ready for the software installation: because the Raspberry
Pi doesn’t have a power switch, it will turn on immediately
you plug in a live power supply. Start by connecting the
USB Type-C end of the power supply cable to the USB
Type-C power connector of your Pi. This should be easy,
since the cable can go in either way. In case you are using a
detachable cable, ensure you plug the other end into the
body of your power supply.

28
The last step is to plug the power supply into a main
socket, the switch on the socket; the Pi should start-up
immediately. Congratulations on the successful set up of
your Raspberry Pi.

29
Setting up The Software

You have to set-up the software of your Raspberry Pi before


you can start using it, especially the operating system, the
software that controls the operation of a Pi. This is where
NOOBS (New Out-Of-Box Software) comes in, it provides
you with an array of different operating systems with
automatic installation of the OS you choose, just with few
clicks of your mouse.
At the first time you start-up your Raspberry Pi, with a
fresh installation of NOOBS on the microSD card, the
Raspberry Pi logo will be displayed on your screen with a
small progress window at the upper-left. There will be a
short pause, at most a minute, the screen will indicate that
you are using the NOOBS microSD card for the first time.

Note

30
You are looking at the NOOBS menu, a system that allows
you to choose the OS you want on your Raspberry Pi. The
standard version of NOOBS includes two OS options: the
Raspbian, a version of the Debian Linux designed specially
for the Pi; and LibreELEC, a version of the Kodi
Entertainment Centre software.
If you don’t want one of these two OS, you can connect
your Pi to a wired network or a Wi-Fi (from the ‘w’ option
on the top bar of icons), then you can download and install
another OS.
To install an operating system, use the mouse to mark the
box in front of the OS; (We will be installing the Raspbian
in this tutorial, but the instruction applies to any OS) move
the cursor to the white box, then click the left button of the
mouse once.

31
This will cause the ‘Install (i)’ menu icon which was
formerly greyed out will be displayed properly indicating
the operating system is ready for installation.

Use the left button of the mouse to click once on the


‘Install (i)’ icon and a warning message will be displayed,
saying that installing the Operating system will overwrite
all the data currently saved on the microSD card (except
the NOOBS itself). Click ‘yes’ to start the installation.

32
It will take about 10 to 30 minutes to complete the
installation process, depending on how fast the microSD
card is. During the installation of the operating system, a
progress bar will be displayed at the lower part of the
window, a slideshow will also commence showing some
key features of the operating system. More information on
the operating system will be provided in Chapter 3, Using
your Raspberry Pi.
A window with an ‘OK’ button will pop up after the
installation is completed; click the ‘OK’ button and the Pi
will restart into the operating system you just installed. A
lot of texts will start scrolling on your screen, these are
called the boot messages, because this is the first time you

33
are booting into the Raspbian, it will require a minute or
two for it to adjust to the space available on your microSD
card, to optimize it. It will boot quicker, next time you
start-up your Pi.

Finally, a window with the Raspberry logo on it will be


displayed briefly, after which the desktop and setup wizard
comes up.

34
Chapter 3: Using your Raspberry Pi
4

You can run a various array of software on the Raspberry Pi


that includes different operating systems, which is the
main software that runs a computer. The most popular one
is the official operating system of the Raspberry Pi
Foundation, the Raspbian. Based on the Debian Linux and
designed specially for the Pi, it comes ready to go, and with
various pre-installed extras.
Even people who have only ever used Apple macOS or
Microsoft Windows won’t have any problem: Raspbian will
feel familiar as it is based on the same windows, icons,
menus, and pointer (WIMP) principles. This chapter will
get you going and provide information on some included
software.

35
The Welcome Wizard
The Welcome Wizard will come up on your first run of the
Raspbian. The Welcome Wizard will walk you through
configuring the Raspbian to your needs and location, this
just involves changing some settings

Closing the Wizard


You may click the cancel button to close the Welcome
Wizard, but some Pi features like the Wi-Fi won’t work if
you don’t at least answer the first set of questions.
Click Next to select your country, language and time zone.
Click on each one and choose an answer from the options
in the drop-down box. Make sure the Raspbian uses the
right keyboard layout by checking the box for the US-
layout keyboard if you are using it. You can still have the
desktop and programs appear in English even if you are not
in an English speaking country, check the 'Use English
language' box for this. Then click Next, when you are done.
36
On the screen, you will be required to change the ‘Pi’ user
password from the default ‘raspberry’, create a new one to
protect your files. You must enter the same password into
both boxes, uncheck hide characters to show the password.
Click next when you are satisfied.

The next screen will provide you with a list of available Wi-
Fi networks, scroll through the list to find your network.
You can use the keyboard or mouse to scroll, then click
Next when you have scrolled to your network’s name.

37
You will be required to provide a password, also called pre-
shared key, if your network is secure (which it should be),
you may find it written on the bottom of the router or on a
card with the router. Click Next to connect to the network
or Skip if you don’t want to.

On the next screen, you will have the option to check for
and install updates for Raspbian. Regular updates of the
Raspbian are provided to fix bugs, add new features and
improve performance. Click Next to install updates or Skip
if you don’t want to install updates. Downloading the
updates will take some time, after installing the updates, a

38
window will pop up saying ‘System is up to date’, click the
OK button.

The task on the final screen of the Welcome Wizard is


pretty simple. You have to restart or call it reboot your Pi
for some changes to take effect. You will be prompted to do
so, click the Reboot button to restart your Raspberry Pi.
The Welcome Wizard has completed its job, so now it will
disappear. You can properly use your Raspberry Pi.

39
Navigating the Desktop
In reference to its main graphical interface, ‘Raspbian with
the Raspberry Pi Desktop’ is the official name of the
version of the Raspbian installed on most Raspberry Pi
boards. Most of the desktop is cover with a picture, the
image is called wallpaper A, the programs you are running
will appear on the top of it. You will find taskbar (B) at the
top of your desktop, this is where you get to load any of the
programs; the loaded programs will then be indicated by
task (C) in the taskbar.

The system tray (D) is located on the right side of the


menu bar.
40
If you plug in a removable storage such as a USB flash
drive to your Raspberry Pi, it will be displayed as an eject
symbol (E); click on it to safely eject and remove the
device. Look to the far right and you will find the clock (I);
a digital calendar will pop up when you click on it.

The speaker icon (H) is right next to it; use the left mouse
button to click on it, if you want to adjust the audio
volume, or use the right mouse button, if you want to
choose the output your Pi uses.
After that is the network icon (G); a series of bars will
indicate the signal strength if you are using a wireless
network, while two arrows will be displayed if you are
using a wired network.
41
Click the network signal to view a list of wireless networks
available nearby.
The Bluetooth icon (F) is right beside it, press it to view
and connect to nearby Bluetooth devices.

On the left side of the menu bar, you will find the launcher
icon (J), here, you will find all the programs installed along
with the Raspbian.
You will see some as shortcuts, while the others will be
hidden in the menu, click on the Raspberry icon (K) on the
far left to bring up the hidden programs.

42
In the menu, programs are separated into categories, and
the name of each category is self-explanatory: for instance
the programing category houses software that will help you
write your own programs, more details on programing is
available in Chapter 4, Programming with Scratch; while
the games category contains games, you can play to while
away time.
There are a lot more programs available apart from the
ones covered in this book, so experiment, explore and
increase your knowledge.

The Chromium Web Browser

Start practicing on your Raspberry Pi by opening the


chromium web browser: Go to the top-left of your screen
and click on the Raspberry icon there, the menu will come
up, select the internet category, then click on Chromium
Web Browser to open it.

43
Chromium is similar to the google chrome browser
available on other computers, so you will easily get used to
it. Chromium allows you to visit websites, play videos and
games, it also allows you to communicate with people all
over the globe through forums and chat sites. Maximize
the window so that Chromium takes up more of your
screen: you will see three icons on the top-right of your
Chromium window titlebar (N).
In the middle is the up-arrow icon (P), this is the maximize
button, click on it and the window will fill your screen.
The minimize icon (O) is just to the left of the maximize
icon, click on it and the window will be hidden, you can
click on it in the taskbar at the top of your screen to bring
it back up.
Look to the right of maximize and you will find close icon
(Q), click on this to close the window.
44
The big white bar at the top of the chromium window, with
a magnifying glass on its left side is the address bar. Type
raspberrypi.org, then press ENTER on your keyboard to
visit the Raspberry Pi website. Also try typing a search into
the address bar for example ‘Raspbian’, ‘Raspberry Pi’ or
‘Educational computing’.

Chromium may bring up various tabs along the top of its


window the first time you open it. Click on a tab to open it,
click the cross on the right edge of a tab to close it without
closing chromium itself.
You can open multiple tabs in a chromium window, click
on the tab button on the right side of the last tab on the list
45
or hold the CTRL key on your keyboard, the press the T
key before you release it.
Click the close button on the top right of the window to
close Chromium, when you are done.

The File Manager

The Home directory is the location on your device where


all the files you created are saved. Files that are saved here
include the following:
● Images downloaded from websites
● Videos
● Programs

To access your home directory, you are required to take the


following steps:
i. Open the menu by clicking on the Raspberry icon
ii. Select “Accessories”
iii. Click on “File Manager”

46
● Once you launch the File Manager by clicking on it,
you will be enabled to browse through files and
folders otherwise called directories located on your
Raspberry Pi’s microSD card including those that
are available on your removable storage devices
such as the USB flash drives which are connected to
your Raspberry Pi’s USB ports.
● At the initial opening of the File Manager, you will
be taken to your home directory automatically
where you will find a series of other folders called
subdirectories that are arranged in categories just
like in the menu.

The main subdirectories are made up of the following:


● Desktop: This is the folder you will be greeted with
at the initial loading of the Raspbian.

47
● Any files that are saved into this folder will
automatically show up on the Raspbian desktop
which makes it easy for you to access such files and
load them.
● Documents: The Document folder is where most of
the files created by you are saved.
● Downloads: All files that are downloaded from the
internet using the Chromium web browser are
automatically saved in the Downloads folder.
● MagPi: The MagPi is an official magazine of the
Raspberry Pi Foundation and this is the folder
where its electronic copy is stored.
● Music: The Music folder is where all music created
by you on the Raspberry Pi is being stored.
● Pictures: This is the folder where your image files
are stored.
● Videos: The video folder is where all videos are
stored. It is also the first place all programs
responsible for playing your videos will look out for
first.
● Public: All files that are saved in this folder will
appear visible to other users of the Raspberry Pi

48
even if there have their personalized username and
password.

The File Manager window is divided into two panes which


are:
● Left pane
● Right pane

The left pane helps in displaying the directories available


on your Raspberry Pi while the right pane displays files
and subdirectories of any directory that must have been
selected in the left pane.
Once a removable storage device is plugged into the USB
port of your Raspberry Pi, you will be prompted with a
window asking if you like to get it opened in the File
Manager, select the “OK” option and you will have access
to all its files as well as directories.

49
Fortunately, all files that are available on a removable
device can be copied to the Raspberry Pi’s micoSD and vice
versa even with both your home directory and the
removable device simultaneously opened in separate File
Manager windows. This process can be referred to as
“Dragging and Dropping” and to do this, you are required
to take the following steps:
i. Move the pointer of your mouse to the file you
like to copy.
ii. Click and hold down the left mouse button.
iii. Slide your mouse pointer to the other window
and release it.
iv. An alternate method of doing this is by taking
the following steps:
v. Click on the file once.
vi. Select the Edit menu.
vii. Click on “Copy”
viii. Click on the other window.
ix. Select the Edit menu again.
x. Click on “Paste”

The “Move” option also performs similar options to the


process of dragging and dropping. The only difference is
that the file gets deleted from its source after it is copied.
50
Nevertheless, both options can be performed using the
following keyboard shortcuts:
i. CTRL+C (Copy)
ii. CTRL+X (Cut)
iii. CTRL+V (Paste

To close the File Manager, go to the top-left of the window


and click on the close button. Do the same for all the
windows that are opened in case you have multiple
windows opened at once.
If you have a removable storage device connected to your
Raspberry Pi, get it ejected by clicking on the eject button
51
located at the top-right of the screen. Find the device from
the list and click on it before getting it unplugged.

The Libreoffice Productivity Suite


If you are conversant with the Microsoft Office or Google
docs then you must have used a productivity suite.
i. Click on the raspberry menu icon.
ii. Move your mouse to Office.
iii. Select the LibreOffice writer which will load the
LibreOffice’s word processor portion.

It is important to note that the LibreOffice is likely not to


be installed by default on all Raspbian OS images if this is
the case; you are advised to make use of the Recommended
Software tool.

52
Apart from writing documents with a word processor, you
can also get them formatted your preferred ways such as:
● Changing the font style, size, color
● Adding effects
● Insertion of pictures, tables, charts as well as other
content
● Other functions of the word processor include
identifying mistakes by:
● Highlighting spelling problems in red as you type.
● Highlighting grammar problems in green while
typing.

Practice
● Start by writing a paragraph on what you have
learned so far regarding the Raspberry Pi including
its software.
● Go to the top of the window and play around with
different icons to see their outcomes such as making

53
your fonts bigger and altering the colors. If you need
more enlightenment on getting this done, hover
your mouse over each icon one after the other to
access the “tool tip” which explains the functions of
each icon.
● Once you are satisfied, go to the File menu and
select the “Save” option to get your works saved.
Assign a name and click on the “Save” button.

Just like the LibreOffice writer, we also have other parts of


the LibreOffice productivity suite which are found in the

54
same Office menu category as the LibreOffice writer. These
other parts include:
● LibreOfficeBase: This is a database tool used in
storing information as well as looking them up
quickly and getting them analyzed.
● LibreOfficeCalc: This is a spreadsheet tool that
handles numbers as well as creates charts and
graphs.
● LibreOfficeDraw: This is an illustration program
tool used for creating pictures and diagrams.
● LibreOfficeImpress: This is a presentation
program used in the creation of slides and the
running of slideshows.
● LibreOfficeMath: This is a formula editor tool used
in the creation of properly formatted mathematical
formulae for use in other documents.

The LibreOffice is also applicable to other computers and


operating systems apart from the Raspberry Pi. It can be
downloaded from the libreoffice.org and installed on any
Microsoft Windows, Linux computer or Apple macOS.
The Recommended Software Tool
● The recommended software tool is made up of a
selection of the best software. It is to be noted that
55
the recommended software tool requires a working
internet connection. Once you have a working
internet connection, take the following steps to
access the recommended software tool:
i. Click on the raspberry menu icon.
ii. Go to the “Preferences”
iii. Click on “Recommended Software”
● The recommended software tool will start
downloading information about the available
software and a list of compatible software packages
will be displayed after downloading is complete.
● These software packages are then been arranged
into different categories. To view the software from
a category, click on the category in the left pane or
select “All Programs” to access all the software.

56
● If the software has a tick placed next to it, it shows
that it has already been installed on your Raspberry
Pi but if no tick is available, click on the check-box
which is next to it and get it marked for installation.
● You can get multiple software installed all at once
by marking all the preferred software though it is
important to have the recommended microSD
available to have enough room for installing the
software.
● You can also get software uninstalled similarly by
finding a piece of software with already have a tick
in its checkbox and click on it to remove the tick.
● Once you are satisfied with your selection, select the
OK button to start installing or uninstalling.
● Once you are done downloading and installing your
preferred software, you will be prompted with a
dialogue. Click on the OK button to close the
Recommended Software tool.

57
The Add/Remove Software tool is an additional tool
used for installing and uninstalling software. This tool can
be accessed from the same Preference category of the
Raspbian menu.

The Raspberry Pi Configuration tool

The Raspberry Pi configuration tool is similar to the


Welcome Wizard which is used at the start. It enables you
to change different settings that are available in Raspbian.
i. Click on the Raspberry icon.
ii. Select the Preference category with your mouse
pointer.
iii. Click on “Raspberry Pi Configuration” to get it
loaded.

58
Once the raspberry pi configuration is loaded, it splits into
four tabs with each of these tabs controlling a particular
aspect of Raspbian. The first tab you will see when the tool
is initially loaded is referred to as “System” which enables
you to change your account password, set a hostname as
well as changing a range of other settings.
MORE DETAILS
● With this brief overview, you will get more
familiarized with the tool while more detailed
information about each setting is made available in
Appendix E.

59
● Select the interfaces tab to display the next category
where you will find a range of settings that all start
disabled. It is to be noted that the settings should
only be changed if you are getting new hardware
added or being instructed by the manufacturer of
the hardware.

Nevertheless, exceptions to this rule include:


● SSH is responsible for enabling a Secure Shell and
allows you to get logged into the Raspberry Pi from
another computer that is available on your network
with the use of an SSH client.
● VNC which enables a Virtual network computer and
allows you to control the Raspbian desktop from
another computer available on your network with
the use of a VNC client.
● Remote

Shutting down
● Just like in the case of any computer, the Raspberry
Pi helps in storing the files you are working on into
volatile memory. The volatile memory can be
defined as a memory which is emptied whenever
you switch off your system.

60
● In the process of working with documents, you are
advised to save each of these documents to help in
transferring the files from volatile memory to non-
volatile memory such as the microSD card to save
you from losing your important information.
● It is to be noted that the documents you are
working on are not only the currently opened files
because the Raspbian itself keeps several other files
opened while it is working. As a result, abruptly
pulling the power cable from the Raspberry Pi while
these files are still open can get the operating
system corrupted with a need to get them
reinstalled.
● It is therefore important to get all files saved by
Raspbian and make it ready for getting powered off
which a process is referred to as getting the
operating system shut down.

To shut down, you are required to take the following steps:


i. Go to the top left of the desktop.
ii. Click on the Raspberry icon.
iii. Click on “Shutdown”
iv. You will be prompted with a window having
three options: Shutdown, Reboot, and Logout.
61
v. Selecting the Shutdown option tells the
Raspbian to get all opened software with files
closed and finally shut down the Pi.
vi. Wait a few seconds once the display has gone
blank till the flashing green light on the
Raspberry Pi goes off after which it will now be
safe to turn the power supply off.
● To get your Raspberry Pi turned back on, disconnect
and reconnect the power cable or get the power at
the wall socket toggled.

● The rebooting process is similar to the shutdown


process just that instead of turning off the Raspberry
Pi, it will be restarted just in a similar way you have
selected the shutdown or disconnected and
reconnected the power cable.
● If certain changes are made to your Raspberry Pi, it
might need to be rebooted by getting your operating
system restarted.
62
● These changes may include getting certain updates
installed to its core software or if some software has
been corrupted such as crashing thereby leaving the
Raspbian unstable.
● The Logout option is only useful when you have
multiple user accounts available on your Raspberry
Pi. With this option, you can get any currently
opened program closed which will then take you to
a login screen where you will be asked for a
username and password.
● If you have selected the Logout option mistakenly
and need to get logged back in, all you need to do is
input the “pi” as the username as well as your
chosen password in the Welcome Wizard when
setting up your Raspberry Pi.

63
Chapter 4: Programming with
Scratch
Making use of the Raspberry Pi is not just about making
use of the software that has been created by other people
but getting your software created as well based on your
creativity. The Raspberry Pi provides you with a platform
where you can get to create your programs and experiment
on them as well.
The Scratch is a visual programming language that was
developed by the Massachusetts Institute of Technology
(MIT) giving the key to the accessibility of coding on the
Raspberry Pi.
With the scratch, you will get to develop your program
step-by-step with the use of blocks which are made up of
pre-written chunks of code which are hidden behind color-
coded jigsaw pieces.
The Scratch can be regarded as a programming
environment that is powerful and fully functional for the
creation of simple games and animations as well as in the
development of complex interactive robotics projects.

64
Introducing the Scratch 2 interface

● Stage Area: Similar to the actors in a play, under


the control of your program the sprites are made to
move around the stage.
● Sprite: The sprites are referred to as characters or
objects that are controlled in a scratch program and
sits on the stage.
● Stage Controls: The stage controls enable you to
change your stage as well as getting your pictures
added as a background display.

65
● Sprites List: This is the section of the window
where all sprites that have been created or loaded by
you into Scratch are displayed.
● Blocks Palette: The Block palette displays all
blocks that are available for your program which
also features color-coded categories.
● Blocks: The Blocks are the pre-written chunks of
program code where you can build your programs
step-by-step.
● Script Area: This is the area where your programs
are built by dragging-and-dropping blocks from the
blocks palette.

Your First Scratch Program: Hello World


The Scratch 2 program loads in a similar way to any other
program on the Raspberry Pi. To load the Scratch 2
program:
i. To load the Raspbian menu, click on the
raspberry icon.
ii. Go to the Programming section using your
cursor.
iii. Click on Scratch 2 which will load up the Scratch
2 user interface after some seconds.

66
It is to be noted that unlike most programming languages
where you will need to be told what to do by the computer
through written instructions, the Scratch works differently.

To start up with Scratch:


i. Go to the blocks palette and click on the Looks
category which is found at the center of the
Scratch window.
ii. Then you will be prompted with the blocks
available under the category which is purple-
colored purple.
iii. Find the say Hello! block.
iv. Select and hold the left mouse button on it.

67
v. Get it dragged over the script area at the right-
hand side of the Scratch window before releasing
the mouse button.
vi. You will notice that the shape of the block that
has just being dropped has a hole at the top
including a matching part that sticks out at the
bottom. This indicates that your block is
expecting to have something above as well as
below it. What you have above it is referred to as
a trigger for this program.
vii. Go to the blocks palette and click on the Events
category which has a light brown color and drag
it onto the scripts area.

viii. Position it such that the bit sticking out of the


bottom gets connected into the hole at the top
of the say Hello! Block until a white outline
appears.
ix. Release the mouse button afterward.

68
x. It is to be noted that this doesn’t have to be
precise, as long as its close enough, the block
will automatically snap into place just like a
jigsaw piece. If this doesn’t happen, click and
hold on to it again to get the position adjusted
until it snaps into place.
xi. The program is now complete and can be put
into work by running the program.

To Run The Program:


● Go to the top of the stage area and click on the
green flag icon.
● If the program has been correctly written, the cat
sprite on the stage should greet you with a cheery
“Hello!” and this rightly indicates that your program
is successful.

69
● Remember to get your program named and saved
before moving on. To do this;
i. Click on the File menu.
ii. Select the Save Project.
iii. Type in a preferred name.
iv. Select the Save button.

70
Next Steps: Sequencing
● Although your program is made up of two blocks,
there is only one real instruction available which is
saying “Hello!” each time you click on the flag and
the program runs but by sequencing, you will be
able to do even more.
● Generally, computer programs are a list of
instructions with each instruction following from
the last in form of a logical progression called the
linear sequence.
● Get started by clicking and dragging the say Hello!
Block from the scripts area back to the blocks
palette which will help in deleting the block and
getting it removed from your program while leaving
just the trigger block when clicked.

71
● Go to the blocks palette and click on the Motion
category after which you can now click and drag
“move 10 steps block” so it gets locked into space
below the trigger block on the script area. According
to the name, this instructs the cat sprite to move
some steps towards a direction it is currently facing.

● To get the program running, click on the green flag.


The cat will move to the right and make the meow
sound; therefore, you need to have your speakers or
headphones connected to listen to the sound after
which you can move to the start again.
● Select the flag again for the cat to get the action
repeated. Once the sound is repeated, this indicates
that you have been able to create a sequence of
instructions for the Scratch to run through one at a
time from to the top to the bottom.
● Note that the Scratch only runs one instruction at a
time from the sequence very quickly. Try to delete
the play sound meow until it gets to the done block
by clicking and dragging the bottom about 10 steps
72
block to get it detached, getting the play sound
meow dragged until done block to the blocks palette
and getting it replaced with the simpler play sound
meow block afterward before getting your move 10
steps blocks dragged back onto the bottom of the
program.

● To run the program again, click on the green flag


and you will notice that the cat sprite does not seem
to move. It is to be noted that the sprite is actually
moving but it moves back so quickly again such that
it appears not to be moving at all. The reason for
this is that the play sound meow block will not wait
for the sound to finish playing before moving to the
next step simply because Raspberry Pi processes so
quickly ensuring that the next instruction runs even
before you get to see the cat sprite moves.

73
● This can be fixed in a different way past making use
of the play sound meow until done block, this can
be done by taking the following steps:
i. Click on the Control category of the blocks
palette which is color-coded with gold.
ii. Click and drag a wait one secs block in between
the play sound meow block and bottom move-10
steps block.
iii. Select the green flag to run the program one last
time.
iv. Once you do this, you will notice that the cat
sprite will wait for a second after moving to the
right before it moves back to the left again. This
process is called DELAY and it is important for
getting how long it takes for your sequence of
instructions takes to run controlled.

Looping the Loop

● Note the sequence that was created in the previous


section was designed to run only once by clicking on
the green flag thereby causing the cat sprite to move
and meows after which the program will stop until
the green flag is clicked again.

74
● Nevertheless, there shouldn’t be a stop because
there is a type of Control block included in a scratch
that is referred to as the LOOP.
● Go to the blocks palette and select the Control
category which is color-coded with gold and search
for the forever block.
● Click and then drag the forever block to the scripts
area and get it to drop underneath the when clicked
block afterward and just above the first move 10
steps block.

● Once this is done, you will see how the C-shaped


forever block grows automatically surrounding the
other blocks in your sequence. Select the green flag
and you will see what the forever block does: your
program will run over and over again instead of
running once and stopping.

75
● This process is called an infinite loop in
programming, which is a loop that never ends but
keeps recurring. To stop the infinite loop, click on
the red octagon which is next to the green flag
above the stage area.
● To alter the loop type, click and drag the first move
10 steps block and get it pulled out including the
blocks that are beneath it from the forever block
and drop them underneath the when click block
afterward. Then click and drag the forever block to
the blocks palette to get it deleted after which you
can click and drag the repeat 10 block below the
when clicked block for it to go round the other
blocks.
● To run the new program, click on the green flag. It
will look as if the program is performing the same
action as the original version by getting the
sequence of instructions repeated over and over
again. Nevertheless, in this case, instead of
continuing forever, the loop will be put to an end
after ten repetitions. This is referred to as the
definite loop in which case you will be the one to
decide when it finishes. Making use of the loops,

76
infinite and definite loops, comes in very handy for
most programs such as the sensing programs and
games.

Variables and conditionals


● Having a good understanding of the variables and
conditionals is very important when it comes to
understanding the concept of getting your Scratch
programs coded.
● The variable can be referred to as a value that can
change over time and under the program control.
The variable is made up of two properties which are
the name and the value it stores. Note that the value
does not need to be a number; it can also be a text,
true or false value or empty otherwise called the null
value. Examples of variables are seen in games
where you have to get things tracked, examples of
these things are the speed of moving objects, the
level that is been played currently, health of a
character as well as the score. These are all referred
to as variables.
i. Click on the File menu.
ii. Click on the Save Project to save the existing
program.
77
iii. Click “File”
iv. Click “New” to start a new and blank project.
v. Go to the blocks palette and click on the “Data
category”
vi. Select the “Make a Variable” button.
vii. Type “loops” as the variable name.
viii. Click on the “OK” button to cause a series of
blocks to appear in the blocks palette.

ix. Click and then drag the set loops to 0 block onto
the script area. This instructs the program to get
the variable to initialize with a value of 0.

78
x. Click on the Looks category of the blocks palette
and drag the say Hello! for 2 secs block below
your set loops to the 0 block afterward.
xi. Note that the say Hello! blocks cause the cat
sprite to say anything written in them. Instead of
having to write the message in the block
yourself, variables can be used instead. To do
this:
xii. Click on the Data category in the blocks palette
again.
xiii. Click and drag the rounded loops block referred
to as a reporter block which you will find at the
top of the list having a tick box placed next to it.
Get it dragged over the “Hello!” word in the say
Hello! for 2 secs block. This will result in the
creation of a new combined block, say loops for
2 secs.
xiv. Go to the blocks palette and click on the Events
category.
xv. Click and drag with when block to get it placed
on the top of your sequence of blocks.

79
xvi. Click on the green flag which is above the stage
area and the cat sprite will say “0” which is the
value given to the variable loops.

More can be done with a variable other than getting it


modified:
● Get the say loops for 2 secs block clicked and
dragged to break it out of the repeat 10 block and
then get it dropped below the repeat 10 block.
● Get the repeat 10 blocks clicked and dragged to the
blocks palette to get it deleted and get it replaced
with a repeat until block while making sue the block
is connected to the bottom of the say loops for 2

80
secs blocks and get both of other blocks surrounded
in your sequence.
● Select the Operators category in the blocks palette
which is color-coded green, then get the diamond-
shaped block clicked and dragged after which you
get it dropped into the matching diamond-shaped
hole in the repeat until block.

The operator block allows you to compare two values with


variables included. To try this out:
i. Click on the Data category in the blocks palette.
ii. Get the loops reporter block dragged into the
first empty square available in the Operator
block.
iii. Click on the second empty square.
iv. Type the number “10”
v. Click on the green flag located above the stage
area.

You will notice that the programs will work similarly just
like before with the cat sprite counting from 0 up to 9 after
which the program stops. This happens because the repeat
until block works in the same way to the repeat 10 block.
Nevertheless, rather than counting the number of loops

81
itself, it will be comparing the value of the loops variable to
the typed-in value at the right of the block. Once the loops
variables get to 10, it will stop. This is referred to as a
comparative operator which helps in comparing two
values.

i. Go to the blocks palette and click on the


Operators category. You will be greeted with two
other diamond-shape blocks which are above
and below the one with the “=” symbol. They are
both referred to as the comparative operators,
with the “<” comparing two values and gets
triggered if the value at the left is smaller when
compared to the one on the right and the “>” is
triggered when the value on the left is more than
the one at the right. To see how this works:
82
ii. Go to the blocks palette and click on the Control
category.
iii. Find the “if-then” block.
iv. Click and drag to the scripts area before getting
it dropped directly beneath the say loops for 2
secs block.
v. This will automatically surround the change
loops by one block, therefore click and drag on
that to get it moved so it gets connected to the
bottom of your if-then block instead.
vi. Click on the looks category of the blocks palette.
vii. Click and drag a say Hello! for 2 secs block to get
it dropped inside your if-then block.
viii. Click on the Operators category of the blocks
palette.
ix. Click and drag the n>n block into the diamond-
shaped hole located in your if-then block.

83
The if-then block can be regarded as a conditional block
meaning the blocks that are located inside it will only run
if some conditions are met.
i. Go to the blocks palette and click on the Data
category.
ii. Drag and drop the loops reporter block into the
first empty square in your symbol block.
iii. Click on the second empty square.
iv. Type in the number “5”
v. Lastly, click on the word “Hello!” in your say
Hello! for 2 secs.
vi. Type “That’s high!”
vii. Click on the green flag for the program to run.

The program will work similarly as before with the cat


sprite counting from zero upwards. When the number gets
to 6, the first number which is more than 5, then if-then
block will be triggered and the cat sprite will then
comment on how high the numbers are getting. With the
above instructions correctly followed, you now have a good
knowledge of the variables and conditionals.

84
Chapter 5: Project 1--Astronaut
Reaction Timer
● The Astronaut Reaction Timer is designed in honor
of the British ESA astronaut, Tim Peake and his time
while aboard at the International space station.
● It is advisable to have your existing program saved if
you like to keep them and click on “File” and “New”
afterward to start with a new project.
● Assign a name before starting by clicking on the File
and Save project. You can call it “Astronaut Reaction
Timer.”
● Note that this project will be based on two images,
first to indicate stage background while the other as
a sprite both of which aren’t included in the built-in
resources of Scratch.
● To get them downloaded, you are required to take
the following steps:
i. Load the Raspbian menu by clicking on the
raspberry icon.
ii. Move the mouse pointer to the Internet.
iii. Click on “Chromium Web Browser”

1
iv. After the browser loads, type in rpf.io/astronaut-
backdrop in the address bar.
v. Hit the ENTER key.
vi. Right-click on the picture of space.
vii. Click on “Save image as…..”
viii. Select the “Download folder”
ix. Select the Save button.
x. Click the address bar again and type in
rpf.io/astronaut-sprite.
xi. Hit the ENTER key.

xii. Right-click on the picture of Tim Peake again.


xiii. Click on “Save image as….”
xiv. Select the Download folder.
xv. Select the Save button.

Once both images have been saved, you can now choose to
close Chromium or leave it opened and make use of it in
the taskbar to get switched back to Scratch 2.

2
Now get started by taking the following steps:
● Right-click on the cat sprite located on the stage.
● Remove it by selecting Delete.
● Go to the bottom-left of the Scratch 2 window to
find the stage controls.
● Select the upload backdrop icon.
● Go to the Downloads folder to find the file Space-
background.png.
● Click on it to get it selected and click OK.
● Note that the plain white background will change to
the space picture with the scripts area replaced with
the backdrops area. You can now draw over the
backdrop here but only click on the tab marked
Scripts located at the top of the Scratch 2 window
for now.

3
● Click on the upload sprite icon which is next to the
word “New sprite” located at the top of the sprites
pane to get a new sprite uploaded.
● Search for the file Astronaut-Tim.png in the
Downloads folder, click on it to get it selected and
click on OK. Once this is done, the sprite will
automatically appear on the stage though might not
be in the middle. Click and drag it using your mouse
and drop it such that it is placed near the lower
middle.
● Once you have your new background as well as a
sprite in place, you can now start to create your
program. To get started:
● Get a new variable created called “time” ensuring
that the “For all sprites” is selected before clicking
on OK.

4
● Click on your sprite to get it selected either on the
stage or in the sprite pane.

● Lastly, get around Operators block dragged into the


middle blank space after which you should drag a

5
distance reporting block into the new blank space
that is created.
● Note that the round block gets numbers rounded up
or down to their nearest whole number to eliminate
the problem of having a hyper-accurate or difficult
to read the number of kilometers.
● To run your program, click on the green flag and
observe how far the ISS will travel in the time it
takes to press the SPACE key. Always get your
program saved when you are done to get it easily
loaded again whenever you need it without having
to start all over again.

6
Chapter 6: Project 2--Synchronized
Swimming
The project has been designed to show that games can
make use of more than a single button by offering two-
button control making use of the ← and → keys with the
keyboard.
i. Get a new project created and get it saved as
“Synchronised Swimming”
ii. Go to the stage control section and click on
Stage.
iii. Select the Backdrops tab.
iv. Select the water-like blue color from the palette.
v. Click on the white backdrop.

vi. Right-click on the cat sprite and select “delete”

7
vii. To access a list of built-in sprites, select the
“choose sprite from library” icon.
viii. Click the Animals category and then the “Cat1
Flying” and select OK. Note that the sprite also
comes in handy for swimming projects.

ix. Click the new sprite and drag two when space
key pressed Events blocks into the scripts area.
x. Select the small down arrow which is next to the
word “space” onto the first block and select the
“left arrow” from the list of possible options
afterward.
xi. Get a turn 15 degrees Motion block dragged
under your when left arrow pressed block.
xii. Repeat the previous step with your second Event
block with an exception to choosing the “right
arrow” from the list and making use of a turn 15
degrees Motion block.
8
xiii. To test your program, press ← or →. It will be
observed that the cat sprite turns as you do
moving in the direction you must have chosen
on the keyboard. You will also notice that you
didn’t need to select the green flag because the
Events get blocks you must have used triggered
and are active at all times even with the program
not running as usual.
xiv. Execute the same steps twice but choose the “up
arrow” and “down arrow” this time for the
Events trigger blocks and move 10 steps for the
Motion blocks. Now press the arrow keys and
you will find out that the cat can turn around
and swim forward and backward as well.

The Scratch has a term referred to as its costume in which


you can change how the cat sprite appears in a bid to make
its motion more realistic. To do this, take the following
steps:
i. Click on the cat sprite.
ii. Above the blocks palette, click on the Costumes
tab.
iii. Click on the “cat1 flying-a” costume.

9
iv. Click on the round X icon that is displayed at the
top right corner to get it deleted.
v. Click on the “cat1 flying-b” costume and make
use of the name box located at the top to get it
renamed to “right”
vi. Get the costume renamed as “right” on this copy
to get it selected.

vii. Click on the flip left-right icon and Right-click


on the newly renamed “right” costume.
viii. Select “duplicate” to get a copy created.
ix. Click and then rename it to the “left”
● With these instructions correctly followed, you
would have finished with two costumes for your
sprite having an exact mirror image with one
referred to as “right” in which the cat will be facing
the right and the other called “left” where the cat
faces left.
10
● Above the costume area, click on the Scripts tab and
drag two switch costumes to left Looks blocks below
your left arrow and the right arrow Events blocks as
well as changing the one under the right arrow
block into read switch costume to right. Give the
arrow keys a try again. You will notice that the cat
will turn to face the direction it is swimming.

In the case of the Olympic-style synchronized swimming in


which more swimmers are needed, there will need to reset
the position of the cat sprite. This can be done by taking
the following steps:
i. Add a when clicked Events block.
ii. Add a go to x: 0 y: 0 Motion block underneath,
getting the value changed if the need arises, and
a point in the direction 90 Looks block.
iii. Select the green flag.

11
Now you will notice that the cat will move to the middle of
the stage while pointing to the right as well.
● To get more swimmers created, get a repeat 6 block
added by changing from the default value of 10 and
getting a created clone of myself Control block
inside it added.
● To make it such that the swimmers are swimming in
different directions, get a turn 60 degrees block
added above the create clone block while it remains
inside the repeat 6 block. Select the green flag and
give the arrow keys a try again and you will get to
see how the swimmers come to life.
● You can get some music added to get the Olympic
feeling completed. To do this, you are required to
take the following steps:
i. Click on the Sounds tabs located above the
blocks palette.
ii. Select “choose new sound from library” icon.
iii. Select the Music Loops category.
iv. Select the small play icons until you find your
preferred music.
v. Select the OK button to select the music.

12
vi. Click on the Scripts tab to get the scripts area
opened again.
vii. Get another when clicked Events block added to
your script area again.

viii. Add a forever Control block.


ix. Add a play sound until done block inside the
Control block while remembering to search for
the bale of whatever music you must have
chosen.
x. Test your new program by clicking on the green
flag.
xi. To stop the music, click on the red octagon
which will stop the program thereby silencing
the sound.

13
Lastly, you can get to stimulate a full dancing routine by
getting a new event trigger added to your program. You
can do this by taking the following steps:
i. Add a when space key pressed Events block.
ii. Add a switch costume to the right block.
iii. Below this, get a repeat 36 block added while
also remembering to get the value changed from
the default. Also inside this is a turn 10 degrees
block and a move 10 steps block.
iv. Start the program by clicking on the green flag
and hit the SPACE key to try the new routine.
v. Get the program saved when done.

14
Chapter 7: Project 3--Archery Game
The Archery game involves players trying to hit a target
with a randomly swaying bow and arrow.
To get started with this project:
i. Open the Chrome Web browser
ii. Type in rpf.io/archery-resources after which you
can hit the ENTER key. It will take a few seconds
for the resources for this game to download
completely. Iii.
iii. Switch back to Scratch 2
iv. Select the File menu
v. Click on the Load Project.
vi. Go to the Places pane located at the left-hand
side of the window and click on “Pi”
vii. Click on the “Downloads folder”
viii. Click on the ArcheryResources.sb2 followed by
the “Open button”
ix. You will be prompted with a question if you
want to get the contents of your current project
replaced. In a case where your changes are not
saved yet, click Cancel and get them saved,
otherwise select OK.
1
Note that your new project is made up of a backdrop and a
sprite without any of the actual code for making a game. It
is mainly your job to get the codes added. To do this, you
are required to take the following steps:
i. Add a when clicked block.
ii. Add a broadcast message 1 block.
iii. Go to the end of the block and click on the down
arrow and then “New Message.”
iv. Type in “new arrow” before selecting the OK
button which results in your block now reading
broadcast new arrow.
● The broadcast can be defined as a message from one
part of a program that can be received by any part of
your program. To execute a broadcast, add a when I
received message1 block and get it changed to read
when I received new arrow.

2
● In this situation, you can click on the down arrow
and select “new arrow” from the list available with
no need to create a message again.
● Add a go to x: -150 y: -150 block below the when I
receive a new arrow block and then get the size set
to 400%. Note that these are not the blocks’ default
values so you will need to get them changed once
they have been dragged into the script area.
● Select the green flag to see how the programs you
have written so far works. You will notice that the
arrow sprite which the player uses for aiming target
will jump to the bottom-left of the stage and will be
quadrupled in size.
● To assign a challenge to the player, get movement
simulating swaying as the bow is drawn added
including the archer taking aims. To do this, you are
required to take the following steps:
i. Drag a forever block and then followed by a glide
1 secs to x: -150 y: -150 block.
ii. Get the first box edited to say “0.5” rather than
“1.”
iii. Place a pick random -150 to 150 Operators block
into each of the other two white boxes which

3
means that the arrow will get drifted around the
stage in a random direction which makes it far
difficult to hit the target.
iv. Select the green flag again.
v. Once you have clicked the green flag, you will
notice that your arrow sprite will start to drift
around the stage thereby covering different parts
of the target.

Though note that at this stage there will be no way to lose


the arrow at the target. To do this, take the following steps:
i. Drag a when space key pressed block into the
script area.
ii. Also, drag a stop all Control block into the script
area.
iii. Select the down arrow at the end of the block
iv. Get it changed to a stop other scripts in sprite
block.

4
Chapter 8: PROGRAMMING WITH
PYTHON

Python, a word that is now associated with computer


programming was coined from the Monty Python comedy
troupe.

Okay currently, Python is among the favorite programming


languages, used to create dynamic applications and
solutions around the world. It is not a visual environment
common with Scratch. You will find Python's text based
simulation handful and practical.

The text based layout allows you to write instructions with


a specific language and syntax which your computer
interprets.

If you have dabbled with Scratch for some time, Python is a


great next step for you since it offers you increased
flexibility where you enjoy a traditional programming
adventure.

At this point, you might be thinking that it is difficult to


learn, it is not. With practice, you can start writing simple

5
programs like basic calculations. When your confidence is
high, and you have mastered this programming language,
you can start designing applications like complex games
and 3D environments.

In this chapter, you will understand the terminology and


concepts introduced in the previous chapter.

Introducing the Thonny Python IDE

Toolbar— the simple mode module of Thonny Python


comes with attractive icons on its menu bar. The icons are
pretty straightforward, representing a different function

6
that allows you to save, create, load, and run your
programs in various ways.

Script area—your python programs are implemented at the


script area which is usually split into two–major and
supplementary. The major area takes the bulk of space,
serving as a canvass for your programs including a
complementary side margin that displays line numbers.

Python shell—running your codes are usually done here as


well as options about how your programs should run. In
addition, you can input individual instructions that are
quickly implemented as soon as you press the ENTER key.

Variable area—for convenience and easy tracking, all


changes–either intentional or unintentional are accessible
in this section. Think of this area as a log of your sessions
when you create and run programs.

7
Your First Python Program: Hello, World!

If you want to access Thonny from the menu, you should


go to its icon directly. Just like other pre–installed
applications on the Raspberry Pi, Thonny is quite visible
with its unique icon. Click on the Raspberry icon, move the
cursor to the programming section, and click on Thonny
Python IDE. Wait for a few seconds as the program—
usually the simple mode loads, welcoming your eyes to its
user interface.

Basically, Thonny is an integrated development


environment (IDE). And what it does is to bring together
the tools that are required to design, write or develop
software into a holistic user-interface experience. Think of
Thonny as a hybrid with a capability for supporting one
programming language unlike others that clearly supports
various languages.

The biggest takeaway from using Python is the absence of


visual feedback as you create programs unlike Scratch with
real-time graphics. You will enjoy this traditional
programming language of hard line codes better than
modern iterations available on other IDEs

8
To start your first program, click on the Python shell area
at the bottom-left of the Thonny window; type this
instruction and press ENTER:

print ("Hello, World!")

After hitting the ENTER key, your program runs instantly.


When you see 'Hello, World!' your program was run
successfully. In addition, your program runs immediately
in the shell area because the interpreter clearly examined
your codes and instructions, found it valid and interpreted
it. The whole parsing process that is displayed in the shell
area is known as the interactive mode, more like a face-to-
face interaction with your friend where communication is
enriched by sending, processing and receiving information.

Hello World!

9
Syntax error

Coding is interesting when your programs are


implemented just the way you created it. It can be
frustrating when you cannot fathom the incidents that
surrounds a 'syntax error' message. Usually, a syntax error
message is displayed at the shell area which means that
your codes are not properly written. Remember that when
you omit a bracket and a quotation mark, or misspelled
'print' with extra symbols; your program will not run. To
salvage the situation, type the instruction again, ensuring
that the codes are an exact replica of the example provided
in this book. Then press the ENTER key.

Click on the script area at the left-hand side of the Thonny


window and type your program again.

print("Hello, World!")

After you click the ENTER key, there are no changes except
a visible blank line in the script area. If you want to try this
out, click the Run icon on the Thonny toolbar. A prompt
appears immediately, asking you to save your session. Use
a descriptive name like "Hello World" while using the save
button. When your program has been stored on your
system, two messages appear in the shell area.
10
While the first message is clearly a command from Thonny,
asking the interpreter to load the program you just saved;
the other one is an output of the program.

Congratulations!

You can call yourself a coder as you have executed your


first program using interactive and script models.

Challenge: New message

Now that you can run programs using interactive and


script methods, you may face some difficulties changing
the message executed by the Python program. In addition,
you may be confused when choosing the best method to
support the addition of new messages and perhaps you

11
wonder what happens when you remove the brackets or
quotation marks from the codes and consequently run it.

Chapter Next steps: loops and code indentation

Python controls how functions and strings are arranged


and connected with a technology known as indentation.
This system ensures that your programs are interpreted
smoothly.

Create a new program by clicking on new icon in the


Thonny toolbar. A new tab is created just above the former
one where you can run new programs while working on the
other program. You may commence with the following
instruction:

print("Loop starting!") for i in range (10):

What you see on the first line as an output in the shell area
resembles the earlier feedback from the Hello world
program. The second output kick-start a definite loop
similar to Scratch where (I) is assigned to the loop with a
series of numbers. The numbers in the loop begin at 0
oscillating between 0 and 10 but never quite reaching 10.
The colon symbol (:) means that subsequent instruction

12
after the symbol is invalid and will not be parsed by the
interpreter.

Python has a similar function too, utilizing a different


method evident with indenting codes. Indenting your code
on python is present by default and makes your lines clear
with serial numbers attached to each instruction. Failure to
implement and understand this concept leaves you with
blank spaces and a headache.

CHALLENGE: ALTER THE LOOK

To create content that engages your end users, employ


images to create fun just like other popular culture with
Halloween costume. Here, you will create a prank using
colours and image where you create a wonderful
experience with a picture. You can go about this by
drawing your own spot-the-difference and scary images
(using a graphics editor such as GIMP). Similarly, you
could also raise the credibility of this challenge, putting in
place tracking measures to ascertain users who correctly
spotted the difference.

13
Chapter 9: Project 1: Turtle
Snowflakes
Now that you understand how Python works, it’s time to
infuse graphics and create a snowflake using a tool known
as a turtle.

Physical robots imitate the natural order of things in the


environment, especially animals. A turtle in the wild just
like its digital companion moves in a straight line make
turns, with minimal limb coordination. Think of that
motion on your screen where the turtle draws a line from a
point to another. Unlike some other languages, namely
Logo and its many variants, Python doesn’t have a turtle
tool built into it. However, a huge library of add-on codes
allows the motion of the turtle to be quite practical.

Libraries are arrays of code that adds new instructions and


variables stretching Python's realm of possibilities further.
Using an import command, you can start creating awesome
content with this skill.

To Create a new program to test your skill in this area,


click on the New icon, and type the following: import
turtle
14
When you use a data from a library, it is expedient that you
use the name of the data followed by a syntax arrangement.
You are required to use the library name followed by a full
stop, then the instruction follows. That can be annoying to
type out every time, so you can assign a shorter variable
name instead –preferably one letter which doubles as a pet
name for the turtle. Type the following:

pat = turtle.Turtle()

To test your program out, you’ll need to give your


turtle something to do. Type:

pat.forward(100)

Click the Run icon, and save your program as Turtle


Snowflakes. After doing this, a new window called ‘Turtle
Graphics’ will appear where you get a taste of your
program: your turtle, Pat, will move forwards 100 units,
drawing a straight line.

15
Pat drawing a line!

When switching back to the Thonny window from the


graphics canvas, you may not easily find it because it is
usually at the background. Take your cursor to the
minimize function and click it or you move to the task bar
directly at the top of the screen where you can also hit the
stop button to collapse the Turtle Graphics window.

Typing out every single movement instruction by hand


would be tedious, so delete line 3 and create a loop to do
the hard work of carving out shapes:

for i in range(2):

pat.forward(100)

pat.right(60)

pat.forward(100)
16
pat.right(120)

Run your program, and Pat will draw a single parallelogram

To transform this into a snowflake-like shape, click the


Stop icon in the main Thonny window and create a loop
around your loop by substituting this instruction in line 3:

for i in range(10):

…and the following at the bottom of your program:

pat.right(36)

Your program won’t run as it is, because the existing loop


isn’t indented correctly. To fix that, click on the start of
each line in the existing loop – line 4 through 8 – and press
the SPACE key four times to correct the indentation. Your
program should now look like this: import turtle

Click the Run icon, and watch the turtle: it’ll draw a
parallelogram, as before, but when it’s done it’ll turn 36
17
degrees and draw another, then another, and so on until
there are ten overlapping parallelograms on the screen –
looking a little like a snowflake

While a robotic turtle draws in a single colour on a large


piece of paper, Python’s simulated turtle can use a range of
colours.

Add a new line 3 and 4, pushing the existing lines down:

18
You can also have the colours chosen randomly from a list,
using the random library. Go back to the top of your
program and insert the following as line 2: import random

In your line 4, change the background colour from ‘blue’ to


‘grey’, then create a new variable called ‘colours’ while
inserting a new line 5:

colours = ["cyan", "purple", "white", "blue"]

U.S. SPELLINGS

Many programming languages use American English by


default, especially spellings. Python is no exception. The
earlier command in line 5 ought to be spelled color rather
than colour. When you use British spellings, your program
will fail to run. This rule does not overlap to words
associated to Variables where you exercise freedom with
semantics.

Using the line 5 example again, this type of variable is


called a list, and is marked by square brackets where the
snowflake appears in specific colours but you still need to
tell Python to choose one each time the loop repeats itself.
At the very end of the program, enter the following –

19
making sure it’s indented with four spaces so it forms part
of the outer loop, just like the line above it:

pat.color(random.choice(colours))

Click the Run icon and the snowflake-stroke-ninja-star will


be magically drawn. This time around, Python will choose
a random colour from your list as it draws each petal –
giving the snowflake a pleasing, multicolour finish.

Using random colours for the ‘petals’

Now that you can create a ninja star, you should write
codes that will bring to life a benign snowflake, that looks
closely like real life. To make this happen, add a new line 6

20
directly below your colours list with the following
instruction:

pat.penup() pat.forward(90) pat.left(45)


pat.pendown()

The penup and pendown instructions moves a simulated


pen off and on the graphics page just like what obtains
with a paper surface. Rather than using a loop, like you
have been doing, you’re going to create a function that can
be recalled when you need it. And the function remains in
your portfolio.

Start by deleting the code for drawing your parallelogram-


based snowflakes: that’s everything between and including
the pat.color("cyan") instruction on line 10 through to
pat.right(36) on line 17. Don't tamper with
pat.color(random.choice(colours)) code but inject a hash
symbol (#) at the start of the line. Using a hash creates an
emphasis known as commenting which can follow the
instructions which Python ignores when interpreting the
lines of code. You can also add explanations to your code
with comments for clarity where you come back to it after
some time or share it.

21
Function is created by first defining it. Define your
function with ‘branch’, by typing the following instruction
in line 10, just below pat.pendown():

def branch():

This instruction defines your function, using the choice of


values you want in the branch container. When you press
the ENTER key, Thonny will include an indentation for the
function’s instructions. Type the following while paying
close attention to indentation because a misplaced blank
space would affect your nesting efforts sooner, rather than
later.

for i in range(3):

for i in range(3):

pat.forward(30)

pat.backward(30)

pat.right(45)

pat.left(90)

pat.backward(30)

pat.left(45)
22
pat.right(90)

pat.forward(90)

Make sure that the new loop you create remains above the
commented-out colour line. You should as well run and
call your new function:

for i in range(8):

branch()

pat.left(45)

Your finished program should look like this:

import turtle
import random
pat = turtle.Turtle()
turtle.Screen().bgcolor("grey")
colours = ["cyan", "purple", "white", "blue"]
pat.penup()
pat.forward(90)
pat.left(45)
pat.pendown()
def branch():
for i in range(3):

23
for i in range(3):
pat.forward(30)
pat.backward(30)
pat.right(45)
pat.left(90)
pat.backward(30)
pat.left(45)
pat.right(90)
pat.forward(90) for i in range(8):
branch()
pat.left(45)
# pat.color(random.choice(colours))
Click on Run and watch the graphics window as Pat
implements your instructions.

Congratulations: your snowflake now looks a lot more like


a snowflake than anything else.

24
Finally! A snowflake to remember.

CHALLENGE: WHAT NEXT?

Can you use your commented-out instruction to have the


branches of the snowflake drawn in different colours? Can
you create a ‘snowflake’ function, and use it to draw lots of
snowflakes on the screen? Can you have your program
change the size and colour of the snowflakes at random?

25
Chapter 10: Physical Computing
with Raspberry Pi
Like the name, physical computing is when you write some
programs that work with hardware to give a physical
action, like move, jump, and so on. Best example is your
washing machine. You switch it on and set the temperature
or the spinning rate to your desired level. The washing
machine starts working and performs a physical action
with the press of buttonss. That is Physical Computing at
work.
Learning about physical computing can get a lot easier
with the help of Raspberry – a cool tool to learn physical
computation better. Its key component is the general-
purpose input/output (GPIO) header.

Introduction to GPIO header

The GPIO header is located at the top edge of the Pi circuit


board that looks like 2 rows of iron pin. It is the way to
connect the light-emitting diodes (LEDs) and switches
which are the hardware to the Pi for the programs you have
written in order to give you a physical computing output.
The name, even though sounds confusing but defines its
features well. You can use the pins for input and output, as

26
they serve more than one purpose. When pins are in the
open such as this, they are called Header which brings us
back to the initial name: General-purpose input/output
header

There are 40 male pins of which the Raspberry Pi GPIO


header consists of some of which are accessible to use for
physical computation while some produces power and
others are reserved for add-on hardware communication
such as the Sense HAT.
Pin types are categorized into several ways with each
having a defined function:

27
WARNING!
You have to be careful with dealing with Raspberry Pi’s GPIO
header. Do not bend the pins in the connecting and
disconnecting process of the hardware. Two pins should never
be connected one at a time or except you are instructed to do so
in a project. Connecting two pins at a time is called short circuit
and it can destroy the PI permanently.

Electronic components
What you need to commence your physical computing consist of
the GPIO header and other electrical features that will be

28
controlled from the GPIO header. There are lots of components
but GPIO projects are mostly done with the use of these
common parts.

Breadboard: This make your physical computing way easier.


You will need not to go through connecting several components
wires with Breadboard; it lets you do that easily with the metal
tracks below its upper surface. Breadboards also have power
distributions that let you create your circuit easily. Even though
it is not a must to have, but you will save yourself some stress
using Breadboard. It can also be called Solderless.
Jumper Wires: This connects your electrical components with
the Raspberry Pi. There are three versions of Jumper wires; M2F
(male-to-female), it is needed to connect your solderless to the
GPIO pins; F2F (female-to-female), it makes it possible to

29
connect component individually when you are not using a
solderless; M2M (male-to-male).
This is a tool for connecting across the solderless. u will need
these three types of Jumper wire depending on your project.
M2M and M2F can be avoided when you are using a Solderless.

Push Button Switch: It can also be called a momentary switch.


This is the kind of switch that is used in the controller of game
consoles. It usually comes with 2 or 4 stands, whichever one will
do just fine with the Raspberry’s Pi. The push button serves as an
input device that lets you command your program to perform a
certain action. Other types of switch is Latching switch, where
you will have to hold down the push button before it becomes
active. Latching switch can be activated at one toggle and can be
deactivated when toggled again.

30
Light-emitting diode (LED): Unlike the Push-button, LED
serves as an output device and can directly be controlled from
your program. It comes up when on, and can be found all
around your building, from the small one to the big ones. They
come in various shapes, sizes and colors. However, not all LED
are compatible to use with Raspberry PI. Some are designed for
12 V or 5 V power supplies, please avoid them.

Resistors: This is the component that is in charge of controlling


the current flow and is in different values which can be
measured in ohms (Ω). The resistance provides resistors based

31
on the number of ohms. In Raspberry Pi physical computing
projects, the resistor is usually used to safeguard the LEDs from
attracting excess electric current and destroy one another. You
will need a resistor of 330 ohms to create more flexibility.

Piezoelectric buzzer: also called a sounder is an output device


but not like an LED that produces light. Buzzer is an output
device that produces a buzzing noise. Piezoelectric buzzer
contains two metal plates that vibrate opposing each other when
activated. Buzzer has two types which are active and passive. An
active buzzer is the perfect choice on your physical computing.

32
Motor is another recognized component that requires a special
control board to get tit connected to the Pi. Infrared sensors are
a device that detects the temperature, humidity sensors and
movement. Also the LDRs which mean light-dependent resistors
is an input device that works like reverse LED.
Sellers all over the world provide components for physical
computing with the Raspberry Pi, either as individual parts or in
kits which provide everything you need to get started. Some of
the most popular retailers are:
Retailers’ worldwide stock electrical components for physical
computing along with the Raspberry Pi, they sell in bit or in kit
that gets you started. These are some of the notable sellers
around the world:
● RS Components – uk.rs-online.com
● CPC – cpc.farnell.com
● ModMyPi – modmypi.com
● Pi Hut – thepihut.com
● PiSupply – uk.pi-supply.com
● Adafruit – adafruit.com
● Pimoroni – pimoroni.com
To complete the projects in this chapter, you should have at
least:
● 3 × LEDs: green, yellow, and red or amber
● 2 × push-button switches
● 1 × active buzzer

33
● Male-to-female (M2F) and female-to-female (F2F)
jumper wires
● Optionally, a breadboard and male-to-male (M2M)
jumper wires

Reading resistor color codes


There is a spectrum of values for resistor starting from zero-
resistance versions that are made up of just small pieces of wire
to the high-resistance versions of the size of which can be
compared to a human leg. However, you can only see the value
written on only a few of these resistors which are usually in
stripe color on the resistor

34
You can read the value of a resistor by positioning the bands to
the left and lone band to the right. Now the first thing to look
out for in the first band is the color which can be found in the
1st/2nd Band’ of the table to acquire the 1st and 2nd figure. There
are two orange bands in this example with both having the same
value ‘3’ and makes a total of ‘33’. Your band may have more than
3 bands; you will have to write down what the value of the third
band is (for five/six-band resistors, see rpf.io/5-6band).
Now go to the last group of bands and check for the color of
either the third or fourth band, it can be found in the ‘Multiplier’
section. It informs you about the number you will multiply the
present number by to get the right value of your resistor.

There is a scientific notation ‘x101’ that stands as a brown band


in this example which translates to ‘include a 0 to the last

35
number’. For blue, it is x106 which means to add six 0s to end of
the number. The orange band is 33 with the addition of the 0
from the brown band, it will make it 330: The resistor’s value
that is measured in ohms.
On the right is the final banding that serves as a tolerant for the
resistor. It is likely to be near its value this way: Since cheaper
resistors are bound to have a silver band, when trying to figure
out its exact value, it may go 10% higher or lower than the actual
value, there is no band which indicates that it can go 20% higher
or lower, this is because resistors that are the most expensive
comes with grey bands which means that it is just in between
0.05% of actual rating. You really need no precision if you are on
hobbyist projects.
Values of resistors that are over 1000 ohms are measured in
kiloohms (kΩ) and if it is over 1 million ohms they are called
megohms (MΩ). You have 2200 Ω resistor indicated as 2.2 kΩ
while 2200000 Ω would be indicated as 2.2 MΩ.

36
Chapter 11: Your first Physical
Computing Program: Hello, LED!

Creating the LED light is the beginning of the journey to


learning physical computing just as writing ‘hello world’ to the
screen is the traditional start to learning programming. On this
project, an LED with a 330 ohm resistor will be needed or any
rating close to 330 ohm with a F2F (female-to-female) jumper
wires.
RESISTANCE IS VITAL
The resistor plays an important role in the circuit because it
serves as a protection for the LED and the Raspberry Pi by giving
a limit to the electrical current flow that the LED draws.
Without the resistor, the electrical current can become excessive
for the LED which could lead to burning itself or even the PI.
When it is utilized this way, it serves as the current-limiting
resistor. The precise value of resistor you will use will be
determined by the LED in use. However, the resistor whose
value is 330 ohm works for most LEDs.
The effects of the resistors value work like this on the LED:
When a resistor value is higher, the LED becomes dimmer and
when the value is lower, the LED is brighter. Do not connect the
Pi and the LED together without the interference of the current-

37
limiting resistor only if the LED comes with a built-in resistor of
the required value.
Begin your work by confirming if your LED is functioning.
Position the Raspberry Pi in a way that will separate the GPIO
header into 2 vertical stripes off to the right. Make a connection
of Raspberry Pi with first 3.3 V pin.
With the use of a F2F jumper wire. Join the other end to the log
leg to either the anode or positive of your LED using yet another
F2F jumper wire. Pick the last F2F jumper wire and join the
short leg with either the cathode or negative of the LED to the
first ground pin.

Connect your LEDs to these pins and do not forget the resistor.
In as much as you have your Raspberry Pi on, the LED light will
be up. And if in case it does not, cross check your circuits to
38
confirm whether you are doing it exactly as you are being
taught. Check the connections and ensure that the resistor value
is not too high for your LED and the Raspberry Pi.
After you have confirmed that your LED is working, now it is
time to do the programming. Disconnect the 3.3 V pin from the
jumper wire and connect a jumper wire to the GPIO 25 pin. This
will make the LED go off, when it happens, do not fret, it is okay.

After you have confirmed that your LED is working, now it is


time to do the programming. Disconnect the 3.3 V pin from the
jumper wire and connect a jumper wire to the GPIO 25 pin. This
will make the LED go off, when it happens, do not fret, it is okay.

39
Now it is time to create a Python to control the power
switch of the LED.

CODGEDING KNOWLE
You have to be able to use the Thonny Python IDE comfortably
to be able to continue this project. Chapter 4 contains some
projects that will give you the comfortability to do so, please
check and go through the project before you continue.

40
Chapter 12: LED Control in Python
The Thonny can be loaded from the programming area of the
Raspberry menu. Press the NEW button to get a new project
underway and click ‘Save’, it will be saved as Hello LED. A library
known as GPIO zero is needed to be able to get access to the
GPIO pin from Python. Only the part of the library is required to
work with LEDs on this project. Import the area of this library by
inputting the below into the Python shell section:
from gpiozero import LED
Next, you have to let GPIO Zero understand which GPIO pin is
connected to the LED. Write the below code:
led = LED(25)
Both lines let Python control LEDs that are connected to the Pi’s
GPIO pin and inform it which (pin) s. If the LEDs in your circuit
are more than two, you will have to write the below code to
control it.
led.on()
To turn of the LED again, write:
led.off()
Well Done! You now have the ability to control the Raspberry
Pi’s GPIO pin that is in Python. Attempt to write those codes
again. When the LED is off the led.off() will not be effective, the
same thing happens when the LED is on and your write led.on().

41
To make a real code, write the below code into the script
section:
from gpiozero import LED from time import sleep
led = LED(25)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
This code will import the LED from the GPIOZero library and
also the Sleep function. After this, it will build an infinite loop to
switch the LED on for a sec and off for another sec continuously.
Press the Run key to watch the action: The LED will start
flashing.

CHALLENGE: LONGER LIGHT-UP


How to alter the program for the LED to stay ON or OFF for a
longer period of time? The smallest delay that can be used while
the LED is going on and off.

42
Chapter 13: Using a Breadboard
The project we are about to dive into in this chapter will be
much easier if you make use of a breadboard to keep the
components together to connect the electric features.

There are holes that cover the breadboards to match with the
components, apart from 2.54 mm. Metals strips are found under
these holes and serves as the jumper wires that have been in use
till now. They operate in rows all across the breadboard that
always has a gap across its middle to separate into two.
Majority of breadboards have letters over the top and numbers
written below the sides. This gives you the ability to locate the
specific hole: A1, the left corner. B1: the hole to the immediate
right. B2: a hole down from there. The hidden metal connects

43
the A1 to B1 but the number 1 hole is always connected to the
second hole except you add a jumper wire.
On bigger breadboards, there are strips of holes at the down
sides that are in color red, blue or black stripes. They are known
as the power rails which makes the wiring process a lot easier.
Connect a wire right from the Pi’s ground pin to one of the
power rails that are usually in blue, red, black or minus sign (-)
to give a ground for many features of the breadboard and same
can be done if 3.3 V or 5 V power is required in your circuit.
It is quite easy to add electronic features to a breadboard: Put
their leads in line (the sticky-out metal area) with the holes and
carefully until it is put in place.
To connect, you have to make more than what the breadboard
has provided. M2M can be used; to connect from the
breadboards to the Pi, make use of the M2F jumper wires.
Do not memorize more than a jumper wire or component lead
into a hole on the breadboard. Since holes are in rows apart from
the separation down the middle, the component lead within A1
is connected electrically to whatever you include to B1, C1, D1,
and E1.

44
Chapter 14: Reading a Button
When you see ‘input/output’ portion of ‘GPIO’, it means that
pins can be used as inputs as well. Things you will need for this
project are breadboard, M2M, M2F with a push-button switch.
F2F can be used in case you do not have a breadboard available;
however, you will find it more difficult to press without breaking
the circuit.
Begin with the adding of a push-key to the breadboard. Your
push-key has two legs? Ensure that they are in different rows on
the breadboard. If your push-key has four legs, change its
position to make the sides at which the legs pops out from are in
line with the holes on the breadboards and the smooth legless
sides are positioned at the top of the bottom.
Make a connection of the ground rail to the ground pin of the
Raspberry Pi. With the M2M jumper wire. Now make a
connection of a leg on of your push-key with the ground rail
using an M2M jumper wire.
And lastly, join the second leg of your push-key, in case you are
using a four legged switch to your GPIO 2 pin of the Pi with a
M2F jumper wire.

45
Reading a button in Python

Press the New key in Thonny to begin a new project, and press
on the Save key. Save it as Key Input. There is huge similarity in
the use of a GPIO as an input for a button and a pin as an output
for LED. The difference is that you will have to import a portion
of the GPIO zero library. Write the below script section:
from gpiozero import Button = Button(2)
To have the code run when the button is pressed, GPIO Zero
provides the wait_for_press function. Type the following:
button.wait_for_press()
print("You pushed me!")
Tap the Run key and then click the push-button. Your input will
be printed to the shell of the Python that can be found at the
down part of the Thonny window:

46
An input has been read from the GPIO pin then click the GPIO
pin. In case you want to retry the program, re-click the Run key
which will stop immediately it is done with the printing of the
message to the shell because the program contains no loop.
For expansion of your program, including the LED and resistor
back in the circuit: Do not forget to connect the GPIO 25 pin to
the resistor and the longer leg of the LED and the shorter leg of
the LED to the breadboard’s ground rail.
If you want to control the LED and read a button, importing the
Button and LED function from GPIO zero library is important.
Also, the sleep function will be needed. You can scroll back to
the top of the program and write the below as the new 1st two
lines:
from gpiozero import LED from time import sleep
Below the line button = Button(2), write:
led = LED(25)
Clear the line print("You pushed me!") and instead input:
led.on() sleep(3) led.off()
Your program should look like this when done: from gpiozero
import LED
from time import sleep
from gpiozero import Button
button = Button(2)
led = LED(25) button.wait_for_press() led.on()
sleep(3)

47
led.off()
Press the Run key and tap the push-button: the LED light will
ON for three seconds, then go off after. You can now control an
LED using the key from Python.

CHALLENGE: ADD A LOOP


How to add a loop to repeat the program? What are the things
that must be altered to let the LED stays on when you do not
click on it and OFF when you do?

48
Chapter 15: Make Some Noise:
Controlling a Buzzer

LEDs serve as unique output device but too much of LED cannot
be used if you are aiming for another direction. Here is the
solution: Buzzer, it produces quite audible noise in the room.
Things you will need for this project include M2F, breadboard
and a functioning buzzer.
You can use F2F jumper wires to connect your buzzer in case
you do not have a breadboard. You can use the same treatment
of the LED for an active buzzer when it comes to programming
or circuitry.
You can use the circuit you use for LED for the buzzer. But use
the active buzzer in place of the LED and then leave out the
resistor, because the buzzer requires more current to function. A
leg of the buzzer should be connected to the GPIO 15 and the
second leg to the ground pin (as in GND in the diagram) with
the use of the breadboard and M2F jumper wires.
Your buzzer may be a three legged one, just ensure that you
mark the leg with a minus sign – and connect it to the ground
pin and also mark it with ‘SIGNAL’ or S connecting it to the
GPIO 15, and the left leg should be connected to the 3.3 V pin
(labeled 3V3.)

49
Controlling a buzzer in Python

The control of an active buzzer with the GPIO zero library is


similar to the control of a LED. There is ON and OFF states.
Different function will be required even though there is a
buzzer. Begin a new project on Thonny, save Buzzer and write
the below code:
from gpiozero import Buzzer from time import sleep
As it is with LEDs, GPIO Zero has to understand which of the
pins your buzzer is connected to for the control. Write the
following:
buzzer = Buzzer(15)

50
It is now the same as the one for LED; the only difference (apart
from a different GPIO pin number) is that it is the buzzer being
used and not a led.
Input the below:

while True:
buzzer.on()
sleep(1)
buzzer.off()
sleep(1)

Press the green flag for your buzzer to start buzzing: If the
buzzer is heard clicking just once in a second then that is a
passive buzzer and not an active one. An active buzzer will
generate a fast changing signal for the metal plates to vibrate
itself which is oscillating. A passive buzzer on the other hand
will require an oscillating signal.
Press the Stop key to close the program but ensure that the
buzzer is not buzzing at that moment or else it will keep on the
buzz until you decide to make a rerun of the program.

51
CHALLENGE: A BETTER BUZZ
How to alter the program for the buzzer to buzz for a shorter
period of time? How to create a circuit that controls the buzzer
with a button?

Chapter 16: Python Project 2 Quick


Reaction Game
LEDs and buttons can now be used as input and output devices,
you can now be set to create a real physical computing. Two-
player quick-reaction game created to discover whose reaction is
the fastest. Things you will need for this project are LED,
breadboard, a 330 ohm resistor, 2 push-button switches, M2Fs
and M2M jumper wires.
Firstly, you will build a circuit: make a connection of both the
switch at the left of your board and the GPIO 14 pin (labeled
GP14, Fig 6-7). The 2nd switch at the breadboard’s right to GPIO
15 pin (labeled GP15), and the longer leg of the LED should be
connected to the 330 ohm resistor and join the GPIO 4 pin
(labeled GP4) of your Raspberry Pi and the 2nd leg on every
component on the ground rail.
Lastly, make a connection of the ground rail and Raspberry Pi’s
ground pin (labeled GND).

52
On Thonny, launch a new project which is to be saved as
Reaction Game. You will need the button and LED functions
from the GPIOZero library with the sleep function too. They can
be saved and import together using a comma sign (,) to divide
them. Write the below in the script section:
from gpiozero import LED, Button from time import sleep
As usual, inform the GPIO Zero which of the pins are the two
buttons and the LED are connected to. Write the below:
led = LED(4) right_button = Button(15) left_button =
Button(14)

Now include instructions to switch the LED on and off, to


confirm if it is working perfectly:
led.on() sleep(5) led.off()
Press the Run key, this will make the LED come up for 5 secs and
go off then the program will exit. The light going off at a fixed
53
time can be predictable, include the following line from the time
import sleep:
from random import uniform
The random library allows you to shuffle and garner random
numbers( with a uniform distribution- rpf.io/uniform). Search
for the sleep(5) and alter it to the below:
sleep(uniform(5, 10))
Tap on the Run key again: This will make the LED remain lit at
random seconds around 5 – 10. Observe and read the time it
takes for the LED to come off and press the RUN KEY few times
more: there will be different time interval for every run which
makes it difficult to predict.
Trigger the buttons for every player which will require you to
include a function. Stroll down to the very end of the program
and write the below code:
def pressed(button):
print(str(button.pin.number) + " won the game")
Indentation is the tool Python uses to identify lines that are in
your function. Thonny will indent the 2nd line automatically.
Lastly, include the below line to discover which of the players is
pushing the keys and do not forget that the lines must not be
indented or else it will be treated as a function on Python.
right_button.when_pressed = pressed
left_button.when_pressed = pressed

54
Open your program and push one of the buttons immediately
the LED is off. A message for the number one button to be
pressed will be printed by Python shell at the down part of the
Thonny window.
Message will pop up every time they press the button and a pin
will be used for their names. Request for the names of the
players, below the line from shuffled import uniform, write the
below code:
left_name = input("Left player name is ") right_name =
input("Right player name is ")
Go back to your function and replace the line
print(str(button.pin.number) + " won the game") with:

if button.pin.number == 14:
print (left_name + " won the game")
else:
print(right_name + " won the game")
Tap the Run key and input the names of the players into the
Python shell. When the button is pushed this time around, do it
as fast as you can before the LED goes off, this will reveal the
actual players’ names and not pin numbers.
To amend the problem reported on the pressed buttons, you will
introduce a new function from the sys that is ‘system’ library.
Exit. Beneath the end of the import line, write the below code:

55
from os import _exit
At the last part of your function, below the line
print(right_name + " won the game"), write the following:
_exit(0)
The indentation is very vital in this part: identify _exit(0) by
four spaces and make it in line with else: let the be 2 line at the
top of it.
This will instruct the Python to put an end to the program after
pressing the first key which means that the player with the
secondary pressed button got nothing for losing the game.
Your final program should look like this:
from gpiozero import LED, Button from time import
sleep
from random import uniform
from os import _exit
left_name = input("Left player name is ") right_name =
input ("Right player name is ") led = LED(4)
right_button = Button(15)
left_button = Button(14)
led.on() sleep(uniform(5, 10)) led.off()
def pressed(button):
if button.pin.number == 14:
print(left_name + " won the game")
else:
print(right_name + " won the game")

56
_exit(0)
right_button.when_pressed = pressed
left_button.when_pressed = pressed
Tap the Run key and input the player names, hold on for the
LED to go off to see the name of the winner. The two lines from
Python will also be visible: when you see’ Backend terminated
(returncode: 0)’ that is Python informing you that it got your
_exit(0) command and exit the program.
The ‘Start/Stop’ is to restart the backend which means that the
program is paused but not cancelled. To stop the program press
the ‘Stop’ soft key.

Quit
the program when you have discovered the winner!
Hurray! You have successfully created your own physical game
CHALLENGE: IMPROVE THE GAME
57
Do you know how to address a loop for the game to keep
running repeatedly?
Do not forget to clear the _exit (0) instruction!
How do you add a score counter to know who is winning even
after multiples of rounds? Do you know you can set a timer to
make you know the time it takes you to react to the light when
going off?

Chapter 17: 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.

58
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

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.

59
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.

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
60
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.

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
61
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. 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.

62
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. 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,

63
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.

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.

64
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. 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.

65
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
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.

66
A Note from the author

Thanks for reading this book; I hope you have been well
informed.

67

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