Professional Documents
Culture Documents
CH UNO
MAKE SCRAT FFIC
VIDEOGAMES IAL
BUILD ROBOTS
AND GADGETS!
Welcome to
It can help you do your homework. It can help you record a timelapse video.
It can even help you build a mighty robot. But most importantly, this powerful
device can fit in the palm of your hand. The Raspberry Pi is a revolution within
computing, letting you create almost anything you can think of with simple
coding software and add-ons that won’t cost the world. But while the Pi is
definitely fun, it’s also a great learning tool, introducing you to coding and
programming, and letting you develop valuable skills. There’s no wonder why the
Raspberry Pi is so popular in schools and homes across the world, with Coding
Clubs and Pi related events popping up all over the place. In this book, we will
teach you the basics about open source, operating systems and coding, and help
you test your skills with fun projects that include Minecraft, Scratch video games,
Explorer robots, animated teddy bears and video projects. All you need to start
is a Pi, a healthy dose of imagination and a helpful parent to help you with tricky
skills like soldering. Ready? Get set…GO!
Imagine Publishing Ltd
Richmond House
33 Richmond Hill
Bournemouth
Dorset BH2 6EZ
+44 (0) 1202 586200
Website: www.imagine-publishing.co.uk
Twitter: @Books_Imagine
Facebook: www.facebook.com/ImagineBookazines
Publishing Director
Aaron Asadi
Head of Design
Ross Andrews
Editor in Chief
Jon White
Production Editor
Sanne de Boer
Assistant Designer
Steve Dacombe
Photographer
James Sheppard
Printed by
William Gibbons, 26 Planetary Road, Willenhall, West Midlands, WV13 3XT
Distributed in Australia by
Gordon & Gotch Australia Pty Ltd, 26 Rodborough Road, Frenchs Forest, NSW, 2086 Australia
Tel: +61 2 9972 8800 Web: www.gordongotch.com.au
Disclaimer
The publisher cannot accept responsibility for any unsolicited material lost or damaged in the
post. All text and layout is the copyright of Imagine Publishing Ltd. Nothing in this bookazine may
be reproduced in whole or part without the written permission of the publisher. All copyrights are
recognised and used specifically for the purpose of criticism and review. Although the bookazine has
endeavoured to ensure all information is correct at time of print, prices and availability may change.
This bookazine is fully independent and not affiliated in any way with the companies mentioned herein.
ISBN 9781785464263
Part of the
bookazine series
MEET THE PI
10 What is a Raspberry Pi?
12 The anatomy of a Raspberry Pi
14 Bring your Pi to life
16 5 Things to try straight away
18 5 Cool things to try with a Pi
20 Know your Raspberry Pi
22 Go Go Gadget Pi!
24 What NOT to try with a Pi
26 The Pi Survival Kit
28 Operating System: The Pi Brain
30 Meet your desktop
32 Raising the bar: the taskbar
34 Working with the desktop
36 The desktop menu
38
58
60
How to edit files
Set up your Pi
Plug in a memory card
76
61 Let’s get visual
62 Connect a USB hub
63 Connect a keyboard and mouse
64 Connect to the internet
66 Configure your Pi
70 Advanced Options
72 Safely shut down your Pi
73 Reboot your Pi
80
6
30
ATI N G
PROJECTS
E R
THE OP 76 Protect your Pi
108 52 PYTHON
108 Advanced Minecraft project:
Beat the sandstorm
114 What is Sonic Pi?
52 LINUX 116 Code music with Sonic Pi
124 Make your own sunrise alarm
with Blinkt!
128 Make a traffic-light door entry
system with Scratch
136 Build an explorer robot
142 Build a teddy bear guardian
152 Parent’s guide to soldering
154 Glossary
142
7
PI SURVIVAL GUIDE
10 What is a Raspberry Pi? 20 Know your Raspberry Pi
12 The anatomy of a Raspberry Pi 22 Go Go Gadget Pi!
14 Bring your Pi to life 24 What NOT to try with a Pi
16 5 Things to try straight away 26 The Pi Survival Kit
18 5 Cool things to try with a Pi
DISSECTING
THE PI BRAIN
28 Operating System: The Pi Brain 40 What is Raspbian?
30 Meet your desktop 44 What is Scratch?
32 Raising the bar: the taskbar 48 What is NOOBS?
34 Working with the desktop 52 What is Python?
36 The desktop menu 56 What is Linux?
38 How to edit files
56 28
8
5 COOL THINGS TO
18 TRY WITH A PI!
10 STEPS BEFORE
YOU START
58 Set up your Pi
60 Plug in a memory card 20
61 Let’s get visual
62 Connect a USB hub
63 Connect a keyboard
and mouse
64 Connect to the internet
66 Configure your Pi
70 Advanced Options
72 Safely shut down your Pi
73 Reboot your Pi
44
26
9
THE PI SURVIVAL GUIDE
??
Wha t i s a
Ra s p b e r r y P i ?
IT’S CHEAP, TASTY AND IT IS A COMPUTER
CRAMMED FULL OF The Raspberry Pi is a basic but
GOODNESS surprisingly power ful computer,
which lets you browse the
It might look strange and small but the Internet, check your email,
Raspberry Pi is the mighty pocket-sized do your homework and
lots more. It doesn’t run
computer that’s taking the world by storm.
Windows like an average
It was designed to inspire a new generation
PC, but it still does many of the
of young coders with a computer that was same tasks, using free software
cheap, open for tinkering and easy to that you can customise to suit you
program. Its makers wanted to encourage and what want to do.
us to spend less time using apps and
programs, and more time building our own.
But the great thing about Raspberry Pi is
that you can use it in many ways. It’ll work
as a pint-sized desktop PC or as a media IT IS A GENIUS
player under your TV. You can turn it into
the brain of a robot or a games console SCIENCE TOOL
that plays retro games. You can use it film There are some brilliant science
on a Raspberry Pi, but
wildlife, browse the Internet, create music or and maths programs that will run
can connect to it.
do a dozen other brilliant things. And while also a whole range of add-ons you
tion sensors and
you’re using it, you’re also learning about Temperature sensors, cameras, mo
, observing wildlife
computers, coding, electronics and more, all more are ideal for building robots
l instruments.
while having fun. and transforming items into musica
10
WHAT IS A RASPBERRY PI?
IT IS A GAMES CONSOLE
The Raspberr y Pi might no
t have the 3D graphics IT IS A MEDIA PLAYER
t that doesn’t mean
power of a PlayStation 4, bu Get the right software installed and the
u can run Minecraft
it’s no good for gaming. Yo Raspberr y Pi transforms into a speedy media
emulator,
on it for a start, or install an player, ready to stream music and movies
an old
which makes the Pi work like from a hard drive, the Internet and other
at what computers. Plug it into your TV, connect
console. You’ll be amazed
one tiny box can do! it to your network and you’re ready to
watch YouTube, iPlayer and a whole
lot more. You can even use a
smartphone to control it.
IT IS A
ROBOT’S BRAIN
sors
With the right gears and sen
ct robot’s
the Raspberr y Pi is the perfe
ls, tracks or a
brain. Just add some whee
ild and race robot vehicles,
robot arm and you can bu
program robot rovers to
high-five a robot hand and
ase your pet).
explore your house (and ch
PROGRAMMER’S TOOLKIT
IT IS A
get kids involved in programming, so it has
The inventors of the Raspberry Pi wanted to
programs and games. You can star t easy
everything you need to star t coding your own
tch, then move on to Python when you’re
with simple drag-and-drop languages like Scra
ready for more complex stuf f.
11
THE PI SURVIVAL GUIDE
The anatomy of a Pi
THE WHAT’S WHAT OF YOUR RASPBERRY PI
PROCESSOR
ARM
This surprisingly little black chip contains an
CPU, a Broadcom graphics processor and the
Raspberr y Pi’s RAM – all the essential stuff that
makes the Pi tick.
12
THE ANATOMY OF A PI
GET CONNECTED
With four USB 2.0 ports you can connect the Pi to
a mouse and keyboard, USB hard disks, games
controllers, printers and more.
GLOSSARY
The Central Processing Unit.
The
13
THE PI SURVIVAL GUIDE
a Pi to li fe
The Pi usually comes without instructions
READY TO GO
14
HOW TO BRING A PI TO LIFE
4. POWER IT UP
or
SB power supply
Plug your micro U sh the
wer socket and pu
charger into a po input
tor into the power
micro USB connec wer LED
I port. The red Po
next to the HDM e green
ld come on and th
at the front shou
ld star t flashing.
5. GET INSTALLING
activity LED shou
15
THE PI SURVIVAL GUIDE
5 Things to try
straight away
ND
BOOT UP YOUR PI A
OCK!
YOU’RE READY TO R
GO ONLINE
pberry Pi has
When you want to go online the Ras
Epiphany Web
you covered, thanks to its built-in
ipedia, this
browser. From CBBC through to Wik
all the sites you
simple, speedy browser will load
mations, making
love, even handling video and ani
on the Pi.
it one of the most useful programs
SEND AN EMAIL
You can use Web-based email services like
Outlook.com and Gmail through the browser, but
the Raspberry Pi also has its own email client.
Called ClawsMail, it works with any email service
that supports the usual POP3 and IMAP standards,
and you can use it to check and write all of your
emails, straight from your Pi.
16
5 THINGS TO TRY STRAIGHT AWAY
PLAY GAMES
The Raspberry Pi was designed to
educate you, but that doesn’t mean it
can’t be fun. Not only does it come with
its own version of Minecraft installed,
giving you all you need to get building,
but you can also find old classics like
Tetris and Snake, ready to play.
DO YOUR HOMEWORK
The Pi is a proper computer, complete with its
own office programs. Whether you need a word
processor to write your homework or a presentation
program to create your own slideshows, you’ll find
LOOK AT
what you’re looking for. Or why not start work on
your first best-selling book?
YOUR PHOTOS
The Raspberry Pi doesn’t have any
built-in music or video players,
though these are easy enough to
add. It does, however, have an
image viewer. Put a USB memory
stick full of photos in a USB slot
and you can easily flick through
them, putting your favourite shots
up on the screen.
17
THE PI SURVIVAL GUIDE
UR OWN GAME
WRITE YO your very own ga
me.
u ca n de ve lo p
With the Pi yo d you can code yo
ur own
w ith Sc ra tc h an
Get star ted sics, move on to
Py thon
. M as te r th e ba
retro games next Flappy Bird
or
ht ju st bu ild th e
and you mig
Crossy Road.
Difficulty:
BUILD A RETRO
GAM ES C ONSO LE
g
Pi an d it be co m es a retro gamin
your
Install RetroPie on from an ci en t Atari VCS games
to
ever yt hi ng
console, playing Yo u w ill ne ed to get hold of
the
n ga m es .
vintage PlayStatio gr ea t w ay to bring those go
lden
lf, but it’s a
game files yourse
oldies back.
Difficulty:
18
5 COOL THINGS TO DO WITH YOUR PI
BUILD A
ROBOT
R2-D2 or BB-8 might be
tricky, but with a kit like
PiBorg’s DiddyBorg you can
easily build a two or four-
ol
wheeled bot. You can contr
your droid using a games
gram
controller or phone, or pro
a ball.
it to follow a line or chase
Dif ficulty:
BUILD A LASER
HACK
TRIPWIRE MINECRAFT
Fancy your own high-tech
security? Combine a Pi, a Minecraft runs brilliantly on
light sensor and a laser the Raspberry Pi. In fact, a
pointer and you can have special version is installed with
your own laser tripwire to the standard Raspbian OS.
aler t you when unwanted But while just playing it is fun,
intruders (or younger it’s not as fun as changing it
brothers) break into from the inside using Python.
your room. While you’re Make normal blocks explosive.
building it, you can learn Create a working clock. Add
some basic electronics on houses that build themselves!
the way. It just takes code.
Difficulty: Difficulty:
19
THE PI SURVIVAL GUIDE
Raspberry Pi
ÊÕÌÊÌ >ÌÊ
À i «ÀViÃÃiÃÊ
ÃÌÀÕVÌÃÊ
Ã`iÊ>Ê *1°Ê/ iÊÀiÊVÀiÃÊÌÊ >Ã]Ê
Ì iÊÀiÊLÃÊÌÊV>Ê`Ê>ÌÊVi°ÊÊ
µÕ>`VÀiÊ *1ÊÌ>ViÃÊvÕÀÊLÃÊÜ iÊ
,
WITH FIVE JUICY MODELS TO CHOOSE FROM >Ê`Õ>VÀiÊ *1Ê >`iÃÊÌÜ°
Ê" Ê Ê
UÊÊÇääâÊ *1]Ê
x£Ó Ê,]Ê{ÝÊ1- Ê
«ÀÌÃ]Ê,>ëLiÀÀÞÊ*Ê
ÃÊvÊÌ iÊ
/ iÊ«ÀÛi`ÊÛiÀ V>iÀ>Ê>`Ê`ë>ÞÊ
Ê >À`ÊÌÊ}iÌÊ
À}>Ê*ÊÃÊÜ ViVÌÃ
} ÌÊwÊ`ÊiÊ
`Êv]ÊLÕÌÊÞÕÊ ÊÊÊÊÊÊÊÊÊÊÊ -/Ê",ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
ÀÊ}iÌÊÌÊÕÃiÊ
V i>«ÊÊi >ÞÊ UÊÊ Õ`}iÌÊ«ÀiVÌÃ
ÃÊ>ÊLÌÊÃÜ]Ê
iÊ>ÌÊÃV °Ê̽ UÊÊ*ÀiVÌÃÊÜ iÀiÊëii`Ê
Õ°
LÕÌÊÃÌÊÛiÀ ÞÊÕÃiv ýÌÊ«ÀÌ>Ì
20
KNOW YOUR RASPBERRY PI
Ê" Ê ÊÊ £ Ê,]Ê{ÝÊ1- Ê
«ÀÌÃ]Ê,>ëLiÀÀÞÊ*Ê
/ iÊÃiV`}iiÀ>ÌÊ*ÊÃÊ V>iÀ>Ê>`Ê`ë>ÞÊ
Õ«ÊÌÊÃÝÊÌiÃÊv>ÃÌiÀÊÌ >ÊÌ iÊ ViVÌÃ
Ê
À}>]ÊÜÌ Ê>ÊiÜʵÕ>`VÀi ÊÊÊÊÊÊÊÊÊÊÊ -/Ê",ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
°Ê
«ÀViÃÃÀÊ>`Ê`ÕLiÊÌ iÊ, UÊÊ Ì }°Ê̽ÃÊÃÌÊ>Ê
"Ì iÀÜÃi]ÊÌÊ >ÃÊÌ iÊÃ>iÊ }Ài>ÌÊ*ÊvÊÞÕÊ >ÛiÊ
vi>ÌÕÀiÃÊ>`ÊViVÌÃÊ>ÃÊ i]ÊLÕÌÊÌ iÊ*ÊÎÊ
Ì iÊ`iÊ ³° `iÊ ÊÃÊLiÌÌiÀt
Ê"1/Ê /1, Ê
Ê,-* ,, 9Ê*ÊÎ Ê
Ê Ê-/
UÊÊ£°ÓâʵÕ>`VÀiÊ
*1]Ê£ Ê,]Ê{ÝÊ
Ê" Ê Ê 1- Ê«ÀÌÃ]Ê7Ê
>`Ê ÕiÌÌ
/ iÊ>ÌiÃÌ]Ê}Ài>ÌiÃÌÊ,>ëLiÀÀÞÊ*]ÊÜÌ Ê
ÊÊÊÊÊÊÊÊÊÊÊ -/Ê",ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ
>ÊiÛiÊv>ÃÌiÀÊ«ÀViÃÃÀÊ>`ÊLÕÌÊ
UÊÊ iÃÌ«ÊV«ÕÌiÀÃ
ÕiÌÌ Ê>`Ê7°ÊÊ/ ÃÊÃÊÌ iÊwÊÀÃÌÊ*Ê
Ì >ÌÊÞÕÊVÕ`ÊÕÃiÊÃiÀÕÃÞÊ>ÃÊ>Ê`iÃÌ«Ê UÊÊi`>Ê«>ÞiÀÃ
V«ÕÌiÀ]Ê>`ÊÌÊÜÊ >`iÊ>ÞÌ }ÊiÃiÊ UÊÊ>iÃʳÊiÕ>Ì
ÞÕÊ} ÌÊÌ ÀÜÊ>ÌÊÌ° UÊÊ*À}À>}
UÊÊ`Û>Vi`ÊÀLÌVÃ
21
THE PI SURVIVAL GUIDE
EYE SPY A PI
Take a Raspberry Pi, a keyboard, a mouse and a screen,
and there’s a whole world of computing fun to get stuck into.
However, if you want to make the most of your Pi, then you’ll need
The Pi’s official 8 megapixel
to spend a little more on useful accessories that make the life of
camera module, the Raspberry
Pi that bit easier. What’s more, if you fancy exploring the equally
Pi Camera Board v2, is an
exciting world of electronics, then you’re going to need some t
essential par t of some of the bes
add-on boards. We’re talking sensors that can look for motion or
Pi projects, par ticularly those
measure the temperature, cameras that take photos and capture
involving time-lapse photography
video, and break-out boards that put the Pi at the centre of brilliant
and wildlife. A black-and-white,
electronic projects. Why not give your Pi the add-ons it deserves?
infrared version, the NoIR, is
per fect for use in the dark.
PROTECT YOUR PI
There’s nothing to stop you using your Pi as it is, but
putting it in a case keeps it safe and makes it easier
to plug every thing in. Loads of different cases
are available, but we’ve gone for the Official
Raspberry Pi 3 case.
22
GO, GO GADGET PI!
WHAT IS A HAT?
ge of
lop ed for us e in sp ac e, the Sense Hat crams a whole ran
Deve rific
rs an d a sim ple , 8x8 sq ua re LED matrix display into one ter
senso rature
T. Wi th a mi x of mo tio n sen sors, magnetic sensors, tempe
little HA
rs an d ba rom ete rs, it ’s a tiny scientific lab on a board.
senso
VERY SENSE-IBLE
Developed for use in space, the
Sense Hat (below) crams a whole
range of sensors and a simple, 8x8
square LED matrix display into one
terrific little HAT. With a mix of mo
tion
GET YOUR
sensors, magnetic sensors, temper
sensors and barometers, it ’s a tiny
ature
THINKING HAT ON
scientific lab on a board. ctronics,
If you’re stepping up into real ele
a great
Pimoroni’s Explorer HAT (above) is
ge of
buy. It packs in four LEDs plus a ran
motors,
inputs and outputs for sensors and
m simple
enabling you to build any thing fro
even a proper
games to alarm systems. There’s
into.
breadboard to plug components
23
THE PI SURVIVAL GUIDE
Things NOT to
try with your PI
YOUR PI MIGHT BE SUPER-POWERED BUT IT’S NOT QUITE INVINCIBLE
24
THINGS NOT TO TRY WITH YOUR PI
DON’T DROP IT a
ht by the standards of
The Pi is tough and lig y
is why you’ll see so man
laptop or a tablet, which
les, parachutes, drones
at tached to robot vehic be
is doesn’t mean it can
or helium balloons. Th
dropped from heights,
thrown at hard surface
s,
DON’T BLOW AN
LED (OR WORSE)
bashed
fired from a catapult or
with blunt objects.
t
electronic projects, bu
We love using the Pi in
e wrong thing to the
be careful. Connect th
out a crucial resistor
wrong GPIO pin or miss e
Ds or components you’r
and you can fry the LE
– your Pi. Be especially
connecting or – worse
and Ground pins and
careful with the Power
pply.
any battery or power su
25
THE PI SURVIVAL GUIDE
The Pi
Survival Kit THE RIGHT GEAR IN PLACE
PI PROJECT BY GETTING ALL
PREPARE FOR YOUR NEXT
SPARE MICRO S D C A R D
to run more than one operating
You’re soon going to want
setups for different
system or have different sof tware
cheap, so you can have
projects. Luckily, micro SD cards are
erent needs.
a few hanging around to cover diff
STARTER
ELECTRONICS KIT
bunch of
You can buy a breadboard and a
nics
basic components for your Pi electro
er to buy a
projects, but it’s easier and smart
nics Fun Kit,
starter kit, like this Elegoo Electro
with all the basics packed in.
EMERGENCY
PHONE CHARGER
power, and
Portable projects need a portable source of
5v and at
a power bank is perfect. Find one that delivers
of the more
least 1A of power, and it’ll be good to run one
power efficient Pis for more than a day.
26
THE PI SURVIVAL KIT
HEADPHONES CLEAR
Unwilling to share your secret plans? WORKING SPACE
Nothing beats a pair of headphones something tricky it
When you’re working on
for a) enjoying your Pi project without ar space. Clear your
helps if you have a cle
annoying others and b) keeping your ble and get the stuff
desk or dining room ta
grand masterpiece secret until it’s . It will make life
you need close to hand
ready to inspire slack-jawed awe. s your parents too).
easier (and may impres
A NOTEBOOK
AND PENCIL g complex
ming or buildin
If you’re program s, jot
ts, yo u’ll w an t to sketch out idea
projec record
lu es an d va ria bles and keep a
down va s you
t w or ke d an d what didn’t. Unles
of wha n for you,
a se rvan t to ta ke this stuf f dow
have n yourself.
ne ed a no te bo ok to take it dow
you
27
DISSECTING THE PI BRAIN
Pi brain
WHAT DOES YOUR BRAIN AND THE PI OS HAVE IN COMMON?
MORE THAN YOU THINK!
28
OPERATING SYSTEM: THE PI BRAIN
GLOSSARY
rt, is the most important
The operating system, or OS for sho
bles you to control the
OS piece of sof tware on your Pi. It ena
grams and much more.
hardware, sign in, install new pro
29
DISSECTING THE PI BRAIN
THE MENU
The Menu is like the drawers on your desk: it contains a
lot, but it is organised and hidden neatly away, until you
open it. From the Menu, you can select program, games,
access the internet and also use the Office programs.
Towards the bottom of the Menu are programs to
customise your Pi and change the settings.
FILE MANAGER
The File Manager icon looks like a filing cabinet and
is responsible for giving you access to your files and
documents. Double-click it with the mouse to load your
home folder and access your files. You can also right-click a
file and change the settings.
30
MEET YOUR DESKTOP
EJECT A
MEMORY STICK
Sometimes you may want to transfer or
save work onto a memory stick so you
can use it on another computer. Plug your
memory stick into one of the USB sockets
and it will load. When you have finished
using it, left-click the triangle symbol on
the far right of the screen. This is the eject
devices option and ensures that your USB
stick can be safely removed.
NETWORKS
If you have a Raspberry Pi 3 or a USB Wi-Fi
dongle, you can connect to your home
network. The available networks are
displayed in the top right of the screen,
under the two blue screens. Left-click on
the icon and it will display the available
wireless networks. You can then click one,
add the required details and connect to it.
31
DISSECTING THE PI BRAIN
32
RAISING THE BAR
I
3. ALTER TASKBAR
SIZE AND POSITION
You can change the size of the taskbar, the
size of its icons and even where it is located
on your screen. To move the taskbar to the
bottom of the screen, right-click on the grey
area of the taskbar, then select Panel Settings
from the menu. Select the Geometry tab, then
click the Bottom option under Position Edge.
You can also alter the taskbar width and
height under Size, along with the icon size.
33
DISSECTING THE PI BRAIN
Working with
the desktop
GETTING TO KNOW THE DESKTOP
34
WORKING WITH THE DESKTOP
2. CHANGE THE
BACKGROUND
COLOUR
Change the colour of the background
by right-clicking on the desktop. Select
Desktop Preferences and click the
Background Colour. This opens the colour
wheel and you can scroll and select one
that matches your own desktop image.
3. ADDING FAVOURITE
PROGRAMS TO THE DESKTOP
If there is a program which you use
regularly, you can add a shor tcut icon
to the desktop so that you can open it
more quickly. Say you use Scratch a lot;
simply open Menu>Programming and
scroll down to the Scratch icon. Right-
click on it and it will load the option to
“Add to desktop”.
35
DISSECTING THE PI BRAIN
36
THE DESKTOP MENU
2. GAMES
Both Minecraft Pi Edition
and a selection of Python games
are stored under this menu. You
may be wishing that there were
more games to play, and you can
install others. The main purpose
of these built-in games is to
support you while you’re learning
coding and programming skills.
Python can be used to create and
modify both Minecraft and each
of the Python games.
3. ACCESSORIES
This menu has useful tools like
a calculator, image viewer and
PDF viewer. There is also an SD
card copier which you can use to
make a backup copy of your card.
Another useful program is the
Task Manager, which shows the
programs your Pi is running and
how much of the processor’s power
they are using.
37
DISSECTING THE PI BRAIN
1. REMOVE A FILE
Sometimes you want to delete a file from your Pi.
This uses the command rm. Say you have a file
called scratch_game_1 and you want to delete
it. First, open your Terminal and type rm scratch_
game_1. Press Enter and the file will be deleted.
You can check if it’s been deleted manually by
going to the folder it was originally stored in.
38
HOW TO EDIT FILES
2. MOVE A FILE
If one of your files in the wrong
folder, you can use to File Manager to drag
and drop it into a new one. The command
line also enables you to do this using the
mv command, “mv” being short for move.
After the mv code, add the name of the file
you want to move and the new location. For
example, to move the scratch_game_1 file to
a folder called Games which is in the Home
folder, you would type: mv scratch_game_1
/home/Games
3. COPY A FILE
Copying a file keeps the
original file in its old place and
creates a new version elsewhere.
You can copy with the command
cp, short for copy. Type the name
of the file you’re moving and the
new location. To copy the scratch_
game_1 file to a new folder called
New_Games which is in the Home
folder, type cp scratch_game_1 /
home/New_Games. It will now be
stored in both the Game and
New_Games folders.
39
DISSECTING THE PI BRAIN
A first look at
Raspbian GET TO KNOW RASPBIAN AND
SOME OF ITS FEATURES
The name Raspbian is a impressive is that Raspbian named after the penguin who
combination of Raspberry and comes with over 35,000 lost his squeaker, Wheezy, and
Debian. The latter is a particular packages, in a suitable software the latest instalment after the
version of Linux and is a free format for easy installation on cowgirl, Jessie.
operating system which has your Raspberry Pi. One of the main additions to
been tweaked to ensure that it The latest version of Raspbian is the OS is the automatic bootup
works with the Pi hardware. called Raspbian Jessie, but who to the desktop (so you no longer
As with most operating is Jessie? The versions of Debian need to enter your username
systems, it features a range are named after characters from and password), along with lots of
of programs, but what is most Toy Story, with the original OS new useful software.
40
A FIRST LOOK AT RASPBIAN
IMAGE WRITER
your Pi, and with a name like
that, it sounds fun and happy!
However, the installation is On your desktop or
tricky. The OS file is stored as an laptop Windows PC,
‘image’ which has to be written go to sourceforge.
to your SD card. This requires net/projects/
additional software in the form win32diskimager/
of an SD Card Imager. You can download the
We will show you in this tutorial Win32 Disk Imager
how to download the SD Card software there.
Imaging software and install it
on your desktop computer. Then
we will download the Raspbian
OS image.
2. OPEN
Once you have downloaded AND
the file, the tutorial will walk you
through the stages to select the INSTALL
location of the SD card, select Locate the file that you
the OS image file and write it have just downloaded
to the SD card. Later on in the and double-click it.
book, you’ll be shown how to This will install the SD
download NOOBS: an easier image writer program.
method to get you started with Follow the instructions
your Pi. on the screen.
41
DISSECTING THE PI BRAIN
3. DOWNLOAD
RASPBIAN OR
ANOTHER OS
On your computer head over to
thedownload section of the Raspberry Pi
website – raspberrypi.org/downloads/ – to
find the latest OS versions.
6. OPEN THE SD
5. OPEN THE ZIP FOLDER IMAGE WRITER
Once the download is done, open the OS ZIP folder. You’ll see Now click and open the SD Image writer program
a file called something like 2016-02-09-raspbian-jessie. This is which you installed in step 2 and plug your
the install image. Copy it to your desktop or another folder. formatted SD card into your computer.
42
INSTALL RASPBIAN LIKE A PROFESSIONAL
7. SELECT
THE IMAGE
FILE
Select the Image File arrow,
which will load your file
manager program. Select the
OS image file which you copied
over in step 5. The file path will
now appear in the box.
8. SELECT
Remember
THE DEVICE
In the device drop-down
When selecting the device
box select the letter of
drive letter in step 8, make
your SD card. This is likely
sure that you select the
E. To check, open My
correct drive letter.
Computer to see the drives
and their letters.
43
DISSECTING THE PI BRAIN
What is Scratch?
GETTING TO KNOW THE SCRATCH INTERFACE
Scratch is a visual
programming language which
is suitable for beginners to
learn how to code, but also
contains complex features
for more advanced projects.
It was created by MIT and
is used across the world by
children and in many places of
education. Programs are created
by selecting the required code
and then dragging and dropping
each code block into the
scripting area. As you add new
code, the blocks snap together
to create the program. Syntax
errors are minimised, enabling
the user to focus on creating the
program rather than typing the
code correctly.
Scratch offers a range features,
such as Sounds, where you can
create songs. It comes with a
Faster Scratch
number of pre-installed images If you are using an old version of the
and backgrounds which can be Raspbian OS, you will notice that Scratch
used to create animations. These runs very slowly. However, this has been
features can all be combined now been upgraded and resolved. The
together to create interactive new Raspbian Jessie OS enables Scratch
quizzes, simulations and games, to be run faster. In tests with a laptop
making Scratch both versatile computer, it outperformed the laptop.
and fun.
44
WHAT IS SCRATCH?
45
DISSECTING THE PI BRAIN
5. CREATE A VARIABLE
TO STORE YOUR SCORE
Now create a box to store your score; this in known as a
variable and will increase each time you successfully fly
through a tube. Click the orange Variables tab, you will
see two options; click the “Make a variable” button. Name
the variable “score” by typing this the word variable into
the box, then press OK.
46
CREATE YOUR OWN FLAPPY BIRD
10. ENDING
THE GAME
The game ends when the
Remember bird hits the tube, so now
add in this final feature.
When trying to locate the code Click the bird sprite, then
blocks that you need for your add a new code block to
program, remember that they are check if the bird is touching
all colour-coded and organised sprite 2, the tube. If it is
by what they do. Choose from then stop all the scripts from
eight categories at the top left. running. The stop all (code)
block is at the very bottom
of the Control tab. You can
now modify your game to
add your own tubes, a nice
background and a game-
over screen.
47
DISSECTING THE PI BRAIN
What is NOOBS?
WHAT IS THE NOOBS OPERATING SYSTEM?
48
WHAT IS NOOBS?
49
DISSECTING THE PI BRAIN
50
BEGIN USING THE NOOBS OPERATING SYSTEM
51
DISSECTING THE PI BRAIN
What is Python?
THIS SNAKE WILL HELP MAKING CODING EASY!
52
WHAT IS PYTHON?
Use Python to
create lists
CREATE A LIST OF YOUR FAVOURITE
ANIMALS, FRIENDS OR POKÉMON
1. START IDLE
u>Programming. Star t
Star t up your Pi and open Python 3 from Men
Making a list is a useful way the page, import the time
a New File from the File menu. At the top of
of remembering things that ses to your program.
module, which will allow you to add shor t pau
you have to do. Lists can also
be used to rank your top five
2. CREATE A LIST
best friends or pop songs or
chocolate bars. Lists can be
created with Python using the Python is like a paper list.
On the next line down, create a list. A list in
code list = []. You can then case type, in the order that
It stores whatever you write down, or in this
ask a user to make an entry
you enter it. Add the code:
into the list by typing in their
list = []
item using the keyboard. The
following mini-tutorial will show
you how to do this and build up
a program that stores a list of,
say, your favourite animals or
GLOSSARY
If you append an item to a
video games. To add and item to a list –
ry end of the list.
You will use a feature called Ap pe nd list, then you add it to the ve
a loop to make the program a part
in programming to repeat
ask you, as many times as you To repeat – A loop is used
want, what to enter into the Lo o p of the program a number of
times, for example adding
de would run three times.
list. Once you have completed three items to a list, the co
entering in all your items, ry – When you
A location in the computer’s memo
then your Python program will Va ria bl e want to store some data, it is stored
in a variable so
print out the list onto the IDLE that you can retrieve it later on.
window on your screen.
53
DISSECTING THE PI BRAIN
54
USE PYTHON TO CREATE LISTS
55
DISSECTING THE PI BRAIN
What is Linux?
GETTING TO KNOW THE LINUX OPERATING SYSTEM
Linux is an open source and free operating it. It is used to power smartphones, televisions,
system which was originally released in 1991 videogame consoles and even smartwatches.
by a man named Linus Torvalds. “Open source” Linux offers all the main features of an operating
means that it is free to download, install and system, such as menus, windows and hardware
even modify your version of Linux. This has led to interaction, plus utility software to monitor your
a lot of different versions of the Linux operating computer and how well it is functioning. One
system – sometimes these are called flavours – of the main advantages of the software being
being created. The official Raspberry Pi OS uses open source is that errors or bugs can be fixed
the Raspbian flavour, which is based on a version by anyone. This means you are not waiting or
of Linux called Debian. However, the Raspberry even paying for a company to sort out a problem.
Pi Foundation also offers several other Linux Anyone can try to solve it and share the solution
operating systems via its website, which work just with other users. Perhaps you will even create your
as well. We won’t be using Linux in this book as it own version of the Linux operating system.
is a little bit more advanced, but
it’s still good to learn about it.
Linux is very commonplace
and you have probably used
a Linux-based system at some
point without even realising
56
WHAT IS LINUX?
LINUX KERNEL
for desktop and laptop computers
The Linux operating system has over 13 million lines of code, but many purists will tell you that
Linux is not an OS but a kernel. The kernel is a computer program that has complete control over
everything that happens on your Raspberry Pi, managing the processes and memory, loading
programs, saving files and so on. Sounds similar to an OS!
57
10 STEPS BEFORE YOU START
e t U
Sou r pi p
y
A QUICK INTRO ON WHAT YOU
NEED TO DO BEFORE YOU CAN
START CODING AWAY!
58
SET UP YOUR RASPBERRY PI
Set up your
Raspberry Pi
YOUR RASPBERRY PI ADVENTURE BEGINS HERE!
Your Raspberry Pi has arrived. Perhaps it came with all of the
additional components; perhaps you had to get them from a local
electronics store. Either way, you are now poised to set your Pi up
and embark upon an adventure that will see you gain new skills and
understanding of computers, electronics, and programming.
Except… you still need to get the Pi ready. You’ve already set up
your Pi to get started on page 22, but now that we are about to
do some projects, we have to make sure we’re really ready. It only
takes ten steps put the Pi together, set up an operating system,
and get started with the built in programming tools. Each one of What you need:
the components has its part to play. The HDMI cable sends pictures
to your monitor; the microSD card stores the operating system and UÊ MicroSD card
data; the mouse and keyboard let you interact with the computer.
In this section of the book, we’re going to look at the 10 Steps Before UÊ USB power supply
You Start. Before you begin any project, remember these steps first. cable
Some of the steps you will recognise from earlier in the book, but it’s
vital that you go over them one more time and complete each and UÊ Ethernet cable or
every one. Are you ready? Get set...GO! USB Wi-Fi dongle
59
10 STEPS BEFORE YOU START
1. PREPARE
GLOSSARY THE SD CARD
Data storage medium
Fl as h – Flash memory is
To format the SD card (4GB
or above), use an adaptor to
non-volatile, which means that the
data on it remains after the power insert it into your PC’s card
is switched off. So, we can store reader, then right-click the
operating system!. device in the file explorer,
and select Format.
3. INSERT CARD
2. SAFE REMOVAL INTO YOUR PI
To safely remove the SD flash memory
Eject the SD flash memory card
card from your PC, right-click the drive
from your PC, remove from the
letter and select Eject. A message will
adaptor, and carefully insert into
be displayed when the drive can be
your Raspberry Pi, ensuring it’s
safely removed.
the right way up.
60
SD CARD AND MONITOR
Try reconnecting
the cable
1. USE A HDMI DISPLAY
Whether you have a computer Occasionally HDMI devices
display or a HDTV for your Pi, it aren’t detected by the TV when
needs to be HDMI compatible. connected. If this happens when
Check the back or side of the you switch on your Pi, change
display for the HDMI port. HDMI channels on the remote,
or reconnect the cable.
61
10 STEPS BEFORE YOU START
1. TIME TO EXPAND
Modern Raspberr y Pi computers come
with four USB slots, but even this may not
be enough. If that ’s the case, you’ll need a
USB hub, available in two kinds, powered
and non-powered.
3. CAREFULLY
2. CHOOSE YOUR USB HUB CONNECT A HUB
If you’re connecting devices without Connecting a hub is simple, as it
their own power source, use a will have a USB cable to connect
powered hub. Otherwise, for things to your Pi. Once connected (and
like keyboards and memory sticks, powered if necessary) you can
non-powered should be fine. then connect your USB devices.
62
USB HUB AND KEYBOARD
1. CHOOSE YOUR
MOUSE AND KEYBOARD
You’ll need a keyboard to code, and a
mouse to open apps and other tools, but
which ones you use are up to you – as long
as they’re compatible!
63
10 STEPS BEFORE YOU START
GLOSSARY
1. ETHERNET OR WI-FI? Ser vice set
SS ID identifier –
You have two choices to get your This is the jargon term for
Raspberr y Pi online. First is Ethernet, a wireless net work name
which delivers faster speeds, but (usually the name of the
means keeping your Pi closer to router). If you know the SSID
your router. The second is wireless. and the password, you can
get online.
64
CONNECT TO THE INTERNET
4. GET WIRELESS
ON YOUR PI
To connect to Wi-Fi, open the
wpa_supplicant.conf file in the
command line and edit it, adding
your network’s SSID (the name on
your router) and your password (also
on the router). Press Ctrl+X to save
and exit; you’re online!
sudo nano /etc/wpa_supplicant
wpa_supplicant.conf
network={
ssid=”SSID”
psk=”WIFI PASSWORD”
}
While the Pi 3
comes with built in
wireless connectivity,
other models will need
a USB dongle
Stuck?
65
10 STEPS BEFORE YOU START
Configure your Pi
YOUR RASPBERRY PI ADVENTURE BEGINS HERE!
UÊ Raspbian and / or
NOOBS
www.raspberrypi.org/
downloads/
66
CONFIGURE YOUR PI
5. PREPARE FOR
THE SD CARD 6. WRITE RASPBIAN TO SD
For a more challenging With the file selected, click
installation, use Write. When the progress
Win32DiskImager in Windows bar reaches 100%, the data
(there are similar tools for is written, and you can safely
Mac OS X and Linux) to write remove the SD card from your
Raspbian to the SD card. Launch PC, insert it into your Pi, and
the tool, select correct drive boot. Using this method, the
letter for your SD card, then Pi will boot straight into the
under Image File browse for the Raspbian operating system.
unzipped Raspbian IMG file.
GLOSSARY
How data is organized
Fi le on a disk – All data on a
disk is organised in a file
sy st em system, which can be
ce in a file
resized if necessary. The more spa
e.
system, the more data you can sav
67
10 STEPS BEFORE YOU START
68
CONFIGURE YOUR PI
Another option is
to enable SSH on your
Raspberry Pi, to enable
remote access
GLOSSARY
The window
Te rm in al that gives
access to CLI – The command
14. COMMAND LINE IN THE DESKTOP line is Linux in a ver y raw form,
but if you want to use a desktop
Rather than logout of the desktop to access the command line, environment and need to access
you can access it via a Terminal session. Launch this by clicking the CLI, you will definitely need a
the black rectangle on the menu bar. Terminal window.
69
10 STEPS BEFORE YOU START
unlocked
”Advanced Options” – sounds scary doesn’t it? While the GLOSSARY
Advanced Options screen in the Raspberry Pi configuration Scure Shell – This is a
might be tricky (found by running sudo raspi-config in the SS H secure net work protocol
command line, or by opening the Menu and selecting for remotely controlling devices
ver
Preferences>Raspberry Pi Configuration), it’s easy once you over a net work. Often used by ser
understand the options. We’re looking at two such options, the admins, you can use SSH to control
first to enable SSH for remote access to your Pi and the second to your Pi via the command line.
optimise your Pi’s resources to get more power out of it. It’s also
time to meet the GPIO, the row of pins along the edge of the Pi,
intended for expansion ports and controlling other devices.
1 2 3
Find your Pi’s IP Enter the IP address Click Open, then
address with the in the PuTTY sign into your Pi as
ifconfig command window normal
70
ADVANCED OPTIONS
1 2 3
Familiarize yourself Be careful Buying a GPIO
with the GPIO, connecting wires connector?
how the pins are – some pins carry Make sure it is
identified. electricity! compatible!
1 2 3
Open Menu > Select the Edit the value using
Preferences > Performance tab, multiples of 64,
Raspberry Pi and look for GPU and then click
Configuration tool Memory on OK
71
10 STEPS BEFORE YOU START
shutdown!
TO SHUTDOWN SAFELY!
2. SAFE SHUTDOWN
FROM THE DESKTOP
To shut down safely from the
desktop, go to Menu>Shutdown,
then Shutdown, clicking OK to
confirm. Only remove the cable
when the Pi is powered off.
173
1. SAFELY SHUTDOWN YOUR PI
The biggest mistake you can make with the Pi is to remove the
power cable to shut down; doing so usually corrupts the data on
the SD card.
72
SHUT DOWN AND REBOOT
Raspberry Pi
SO SAFELY?
HANGE S E T T INGS
C
1. REBOOT TO rr y Pi after ch
anging
r Raspbe
you ’ll n e e d to restart you b e prompted to re
boot,
Often . Yo u ’ll o ft e n
config screen
settings in the
instructions.
so follow the
Often you’ll
need to restart your
Raspberry Pi after
changing settings in
the config screen
ESTART FROM THE DESKTOP
2. R
Menu and click Shutdown –
To restar t manually, open the
out and Shutdown, you can
you’ll notice that along with Log
later, the Pi will restar t.
also Reboot. A few moments
NE
3. USE THE COMMAND LI
TO REBOOT ot command. Older
To restart from the command line, use the rebo
the shutdown
versions of the Raspbian operating system use
restart.
command, with the -r condition to prompt a
sudo reboot
sudo shutdown -r
73
76 Protect your Pi
80 Make your very own videogame
with Scratch
76
LEARN HOW TO
BUILD A CASE FOR
YOUR PI!
136 BUILD YOUR VERY
OWN RASPBERRY PI
EXPLORER ROBOT ON
TRACK TIRES!
124 Make your own sunrise alarm 136 Build an explorer robot
with Blinkt!
142 Build a teddy bear guardian
128 Make a traffic-light door entry
system with Scratch
108
142 98
75
PROJECTS
your Pi
UÊ Template (see p78)
UÊ Tracing paper
UÊ Cutting board
UÊ PVA Glue
UÊ Cereal box
76
PROTECT YOUR PI
3. LAY IT ON THE
CARDBOARD
Secure the tracing paper onto the cardboard
and star t cutting around the edge. Make sure
you follow the lines carefully so as not to add
any extra space around the template, and
take care with the tabs around the edge.
4. PREPARE TO
CUT THE HOLES
The holes for the ports on your Pi will have to
2. TRACE THE TEMPLATE be cut out using scissors. This will be a tricky
ted on the job that needs to be done with precision, so
Using tracing paper, trace the template prin
writ ten be patient. It might help to colour in exactly
other side of this page, or use the dimensions
board. where you want them to be cut out.
along the lines to draw straight onto the card
2.2 cm
A A
9 cm
B 6 cm B
A A
78
PROTECT YOUR PI
8. FOLD IN
Star t folding your case, checking
if the panels height matches and
9. APPLY GLUE
ll amount of glue
ever ything fits together nicely. Try Make sure to remove your Pi first! Put a sma
ful not to add too
putting your Pi inside before you on the panels that are labelled A. Be very care
.
star t gluing to check if you have much glue, as it can make the box go soggy
access to all the ports.
79
PROJECTS
80
MAKE YOUR FIRST GAME WITH SCRATCH
1. UNDERSTAND
THE INTERFACE
Before jumping in, take a look
at the Scratch interface. You’ll
see the blocks palette is on
the left and it has eight labels:
Motion, Looks, Sound, Pen,
Control, Sensing, Operators
and Variables.
81
PROJECTS
4. ADD A
CHARACTER
Now you are familiar with the
interface, it’s time to create a
character for your game. First,
click on the Sprite1 cat and delete
it – we won’t be needing it.
82
MAKE YOUR FIRST GAME USING SCRATCH
ited
Now you’ve imported and ed
ding
your sprite, it’s time to start co
GLOSSARY
Characters
83
PROJECTS
84
MAKE YOUR FIRST GAME USING SCRATCH
GLOSSARY
Sending
Br oa dc as t messages –
85
PROJECTS
86
MAKE YOUR FIRST GAME USING SCRATCH
If you don’t
stop the ghost from
leaving the playing
area, you’ll lose it
24. PRODUCING 25. BOUNCE 26. CATCH THE
A SCORE THE GHOST GHOST
Every movement that the ghost If you don’t stop the ghost from The idea is that the witch catches
makes without being caught will leaving the playing area (ie the the ghost and puts it under her
add to the score. So, go to the Stage), you will lose it forever, hat. You won’t see this, but the
Variables palette and grab a which kind of spoils the fun. So, ghost will disappear. How do we
change score by 1 block and then from the Motion palette, drag achieve this? By adding a hide
add it to the middle of your repeat over an if on edge, bounce block block (from the Looks palette) just
until block. and place it within the repeat under the repeat until loop.
until loop.
87
PROJECTS
88
MAKE YOUR FIRST GAME USING SCRATCH
33. IMPORT
AN IMAGE
Just as with your sprites, you can
paint a background yourself or
import a ready-made one. Click
the Import button and take a look
at the backdrops that you like the
most, within the various folders.
Select one and click OK.
89
PROJECTS
WEBPAGE
with their ISP)
of website servers are running
Linux – just like your Raspberry
Before installing the required
Pi. With the right configuration,
and a suitable HTML file in place, server software, you will need 2. ADD SOME
you can serve pages to the
internet, joining the vast world
to familiarise yourself with HTML
and CSS in order to create a STYLING
wide web without paying for basic webpage. You can use the To improve the appearance of
expensive web hosting! sample code written below – the HTML file, use a cascading
We’re going to look at two save it as index.html. style sheet, or CSS. The line in the
ways of doing this. The first will <html> HTML file referring to style.css
give you the basics, explaining <head> links the two files together.
how to configure your Pi as a <link rel=”stylesheet” body {
web server, how to write a page type=”text/css” href=”style. background-color: lightblue;
in HTML, how to use CSS to style css”> }
it, and how to get it online. </head>
Meanwhile, the second <body h1 {
method allows you to set up <h1>Hello World!</h1> color: navy;
and run a full WordPress blog <p>Hi, this is your Raspberry margin-left: 20px;
on your Raspberry Pi. At the end Pi serving web pages.</p> font-family: Helvetica, Arial,
you’ll have a functional website </body> Sans-Serif;
on the internet! </html> }
90
USE YOUR PI TO HOST A WEBSITE!
6. CONFIGURE
FTP ON
YOUR PI 7. CONFIGURE 8. MAKE MORE
To upload data to the web server, FTP CONFIGURATION
you will need to enable FTP. To do
so, you need to grant permissions
With the vsftpd software
installed, you will then need to CHANGES
to the www directory, then you configure it. Firstly, you should Next, find #local_enable=YES and
need to install the vsftpd (Very open up the file with sudo #write_enable=YES, and remove the
Secure FTP Daemon) software. nano /etc/vsftpd.conf, then ‘#’ symbols. This allows them to be
sudo chown -R pi /var/www/ find anonymous_enable and read by the application, activating
html change the condition from YES them. On a new line at the end, add
sudo apt install vsftpd to NO. force_dot_files=YES.
91
PROJECTS
11. BROWSE TO
YOUR WEBPAGE
With everything configured, and your
webpage files saved to /var/www/html,
enter the Pi’s IP address in your browser to
view the page on your home network.
14. INSTALL
MYSQL
Since we have already installed
Apache and PHP5, next is
the database software MySQL,
along with the PHP-MySQL
packages. Make a note of the
password that you create during
the process – you’ll need it later.
sudo apt install mysql-server
php5-mysql -y
92
USE YOUR PI TO HOST A WEBSITE!
15. RESTART
APACHE
Changes made to the Apache
setup, following installation of
MySQL, mean you’ll need to
restart the server. Any future
changes (such as upgrades) will
19. SWITCH
WORDPRESS
OWNERSHIP
Changing ownership of the
WordPress files to the Apache
user is important; it lets the
software serve pages via Apache
without permissions issues.
sudo chown -R www-data: .
93
PROJECTS
21. CREATE A
MYSQL ÇDATABASE
Next, you need to create the database itself.
Use the create instruction to do this (note the
semicolon), and observe the response, which
should start ‘Query OK’. Exit with Ctrl+D.
mysql> create database
wordpress;
23.CONFIGURE
WORDPRESS
After setting your preferred language, you’ll
be instructed to enter your database details,
including name, username, password, host and
table prefix. You should have all these from the
previous steps.
94
USE YOUR PI TO HOST A WEBSITE!
28. CREATE A
NO-IP ACCOUNT
Head to noip.com to create a hostname, and
click Sign Up. You’ll be prompted for your
email address, name and password. Once
entered, click Create my free account.
95
PROJECTS
A static IP address
can be set manually,
and doesn’t change
30. INSTALL
NO-IP ON YOUR
RASPBERRY PI
Next, cd to the No-IP directory, and
install using the make command. After
inputting sudo make install you’ll be
prompted for your No-IP credentials.
cd noip-2.1.9-1
sudo make
sudo make install
96
USE YOUR PI TO HOST A WEBSITE!
GLOSSARY
Pi server via the hostname you created!
sudo /usr/local/bin/noip2
ol
File Transfer Protoc
F TP – This enables yo u to
wnload
easily upload and do
rver, such
data to your web se
images and
as new HTML files,
les or entire
other files. Single fi
nsferred.
directories can be tra
97
PROJECTS
UÊ USB webcam
UÊ Raspberry Pi
camera module or
UÊ Raspberry Pi NoIR
camera module
UÊ Suitable case
for camera
module
98
CONNECT A WEBCAM TO YOUR RASPBERRY PI
3. CONNECT
USB WEBCAM
Plugging the USB device into a
spare port on your Pi should be
straightforward, although you
may need to use a powered USB
hub to avoid performance issues.
99
PROJECTS
7. FLIP THE
PHOTO!
9. CAPTURE
Using raspistill, your photos may
be upside-down, or at a 90° 8. INSTALL VI DE O W ITH
angle. You can deal with this
by applying a horizontal and/
VIDEO CAPTURE WEBCAMS
or vertical flip to take a correctly
oriented photo.
SOFTWARE Using avconv to capture some
You’re not limited to snapping video means specifying the
raspistill -vf -hf -o Pictures/
stills with your Raspberry Pi. Video4Linux drivers, a frame
image4.jpg
Video capture is also possible, rate, and a resolution for your
via “avconv”, part of the libav- video. This command captures 25
tools package, which can be frames per second at 640×480
10. TWEAK installed in the usual way with the
following code:
pixels, saving to out.avi.
avconv -f video4linux2 -r 25 -s
Try a different
12. INSPECT THE USB camera
CAMERA MODULE It’s expensive buying multiple
After unpackaging the camera module, USB cameras, but if you have
you’ll find the square circuit board (PCB) with access to different models,
a camera lens mounted on the front, and a it’s worth trying them before
ribbon cable on the back. buying a module.
100
CONNECT A WEBCAM TO YOUR RASPBERRY PI
101
PROJECTS
SELFIES! camera.start_recording(‘/home/
To take a timed photo, adjust the pi/Video/video.h264’)
timer with the time.sleep(0) line in sleep(5)
the script; setting the value to 5 camera.stop_recording()
will add a delay of five seconds.
102
CONNECT A WEBCAM TO YOUR RASPBERRY PI
26. POSITION
YOUR PI
CAMERA jonarcher.info
FOR YOUR
run the Python scripts. It’s easier
powered for several hours.
than a keyboard and monitor!
CAMERA
Various cases are also available
for the camera module.
Better still, you might
find one with space
for the camera
module and
the Pi itself.
103
PROJECTS
Minecraft
trampoline
MAKE A HUMAN TRAMPOLINE
TO SEND STEVE UP IN THE AIR
Minecraft is an immensely
What you need:
popular game. The Raspberry
Pi Operating System comes UÊ Raspberry Pi
with a basic pocket edition pre-
installed. While this lacks some
1. LOAD
features of the full version, it can
be manipulated and hacked
PYTHON
with Python code. This makes it Boot up your Pi and
fun and a great tool for learning open Python 3 from the
how to program. start menu. It’s under
In this tutorial you will create Menu>Programming>
a human trampoline that sends Python3. Click this and
Steve skyward each time he it will load a program
walks on grass. Python code is called IDLE which you
used to find out which block the can use to write your
player is standing in. Each block Python code.
has a name and an ID number
which is used for reference. You
can use code to retrieve the
block ID, which returns the block
2. START A NEW FILE
type you are stood on. Now you know where the Once IDLE has loaded, start a new window
player is and if they are standing on a block of grass. for your program by clicking File>New File
If they are not standing on grass, then fine, but if they from the drop-down menu at the top right-
are, then it is jump time! hand side of the IDLE program.
104
THE HUMAN TRAMPOLINE
Change the
block type
105
PROJECTS
10. POSITION X
In the last line you typed you used the
code pos.x. This is the left to right or
horizontal position of the block that you
are standing on. If you look at the left of
the Minecraft screen, you can see the x
value changes as you walk around.
GLOSSARY
11. POSITION Z
A location in the The line also uses the code pos.z You can think of this
Var iab le computer’s memory as the forwards or backwards positon of the block
– When you want to within the Minecraft world. Again, if you look at the
tore some data like an item for the list, it is left of the Minecraft screen, you’ll notice the z value
stored in a variable so that you can retrieve
changing as you move around.
it later on.
Conditionals use
Con diti ona l if statements 12. POSITION Y-1
to check if your
movement has met a condition. In this The final position is the up and down direction, or height.
program, the condition is: “is the player This is typed as pos.y-1 because you want to check
stood on grass?” whether the block underneath you, which is the block that
you are stood on, is grass.
106
MINECRAFT TRAMPOLINE
17. BOUNCE!
Assuming that there are no errors, your program will start. Return to
your Minecraft world and take Steve on a walk, but watch out for grass
as you will be trampolined into the air at high speed!
107
PROJECTS
Stir up a sandStorm
in Minecraft
Impress your friends and challenge them to play a fun and
HOW LONG CAN YOU
SURVIVE AS SAND BLOCKS
addictive game of skill. Use Python to code a game within
Minecraft where the player, Steve, has to dodge blocks of sand DROP FROM THE SKY?
as they drop from random positions in the sky. You will first
learn how to find the position of the player in Minecraft. This location
data is then stored. Next, you will add code to drop blocks of sand
at this location, but place them 25 blocks above the player’s position.
The program actually uses gravel instead of sand because the gravel What you need:
block falls downward due to gravity. Once it starts falling, you have
little time to move out of the way of the block before it squashes you. UÊ A Raspberry Pi
In the last part you’ll code a message that’s shown if a block hits you.
108
DODGE THE SANDSTORM IN MINECRAFT
1. LOAD
PYTHON
Boot up your Pi and
open Python 3. It’s under
Menu>Programming>Python 3
(IDLE). This will load a handy
2. START A
program called IDLE which is
used to write Python code.
NEW FILE
Once IDLE has loaded,
start a new window for
109
PROJECTS
7. A QUICK
PAUSE
Now give the player five seconds
before you start dropping the
sand blocks. On the next line,
line 6, add a short pause using
the following code.
sleep(5)
Remember
If you use a colon, the : symbol 9. THE WHILE 10. WHEN DOES
in the program used on line 8,
always remember to indent LOOP IT REPEAT?
the next line of code. On line 9, add a while loop. This Now you need to tell the while
is used to keep the program loop when to repeat. In your
repeating so that the sand program, you want it to keep
blocks keep falling from the sky. repeating or ‘dropping sand’ until
You will see that the w of ‘while’ it hits the player.
8. WHICH TILE is lower case – this is correct.
ARE YOU
while
Combine the
STOOD ON? trampoline
When the game starts, find out 11. WHAT TO
where your player is standing
using mc.player.getTilePos(), CHECK You could combine this mini-
game with the trampoline code
which collects the position data Add the code line mc.getBlock() to and send Steven flying into
about the top of the block that find the position of the block the the air if he is hit by a block of
they are stood on. This is used player is standing on and check sand. Add the code mc.player.
so that the sand blocks fall from if it is NOT a block with the ID setPos(p.x, p.y+20, p.z) as the
above the player. Add this to number 13 (the Gravel block). very last line of the program
your code on line 7. while mc.getBlock(pos.x, pos.y, under the mc.postToChat().
pos = mc.player.getTilePos() pos.z) != 13:
110
DODGE THE SANDSTORM IN MINECRAFT
111
PROJECTS
24. LOAD
MINECRAFT
You have completed the program,
now to test it. Load Minecraft
from Menu>Games>Minecraft.
Start a new world and wait for it
to load. Now press Esc and return
to your Python program.
112
DODGE THE SANDSTORM IN MINECRAFT
26. SPEED IT UP
You can change the rate at which
the blocks drop by reducing or
increasing the delay on line 10.
Make this longer to make the
game easier or shorter, for more
of a challenge. Try sleep(0.6) and
see how long you last.
113
PROJECTS
114
WHAT IS SONIC PI?
PREFERENCES
PLAY CONTROLS EDITOR CONTROLS PANEL The options here
The Run button starts the code,
The Size + and Size - buttons enable you to alter the look
while the Stop button stops it. You
enable you to make the text and feel of Sonic Pi, including
can also Record the music being
in the code editor bigger and using a dark theme. You can
played to create a WAV file so
smaller. The Align button will also select the Pi’s audio
you can listen to it elsewhere.
neaten the code and create the output and system volume.
correct indents.
CODE EDITOR
This is the area where you write and HELP SYSTEM LOG VIEWER
edit your code, which is coloured This contains information about When you run your code, information
up automatically as you type. You all aspects of Sonic Pi, including a about what the program is doing
can switch between ten ‘buffers’ to built-in tutorial to get you started, will be shown here. This is very
write separate programs. and musical examples to show useful for debugging your code and
what it can do. understanding what it is doing.
115
PROJECTS
Code music
with Sonic Pi
LEARN HOW TO CREATE AMAZING
SOUNDS ON YOUR RASPBERRY PI
Sonic Pi is already
pre-loaded. You’ll find
it under Programming
in the main menu
116
CODE MUSIC WITH SONIC PI
1. PLAY SOME
NOTES
In Sonic Pi’s code editor window,
type in the following code. You
can use note names (as here) or
just numbers to set the pitch.
play :C5
sleep 0.5
play :D5
sleep 0.5
play :E5
2. PLAY A CHORD
Note the half-second sleep time between notes.
Without that, they’ll all play at the same time to form
a chord instead.
play :C5
play :D5
play :E5
3. BANG
THE DRUM
Delete that and enter the following code. Our
first live loop, it repeatedly plays a bass drum
sound every half a second.
live_loop :beats do
sample :bd_klub
sleep 0.5
end
117
PROJECTS
7. PLAY A 8. RANDOMISE
6. ADD A THE BASS SOUND
SCALE
BASSLINE We can also specify a scale to
By adding a rrand random range
for the cutoff value, we can
Add the following code under play instead of individual notes, choose to alter the :tb303 bass
it to make a bassline with the as in this version. A scale is a sound with each note.
:tb303 synth. Note the use of ring range of notes played in order live_loop :bass do
to play a note sequence. from low to high. 16.times do
live_loop :bass do live_loop :bass do use_synth :tb303
use_synth :tb303 use_synth :tb303 riff = (scale :e2, :minor
riff = (ring :a2, :g3, :e2, riff = (scale :e2, :minor pentatonic).tick
:e4).tick pentatonic).tick play riff, amp: 0.2, release:
play riff, amp: 0.2, release: play riff, amp: 0.2, release: 0.25, cutoff: rrand(60, 130)
0.25, cutoff: 80 0.25, cutoff: 80 sleep 0.25
sleep 0.25 sleep 0.25 end
end end end
118
CODE MUSIC WITH SONIC PI
9. USE A RANDOM
SEED SOUND
As Sonic Pi uses pre-generated random
sequences, we can choose to set the
starting point with use_random_seed –
here every 16 notes:
live_loop :bass do
use_random_seed 1690
16.times do
use_synth :tb303
riff = (ring :a2, :g3, :e2, :e4).tick
play riff, amp: 0.2, release: 0.25,
cutoff: rrand(60, 130)
sleep 0.25
end
end
119
PROJECTS
11. PROBABILISTIC
DRUMS
We can even create random
drum patterns by using the
one_in function to determine
the chance of a drum sounding.
live_loop :drums do
use_random_seed 1756
8.times do
sample :bd_fat if one_in(2)
sample :elec_hi_snare if
one_in(5)
sample :drum_cymbal_pedal
if one_in(2)
sample :drum_cymbal_closed
if one_in(2)
sleep 0.125
end
end
12. ADD
A CHOIR
OK, enough drumming! Type the
following code in a new buffer
for a choir sound. Try altering the
rate value to change the pitch.
live_loop :choral do
sample :ambi_choir, rate: 0.6,
amp: 0.7
sleep 1
end
120
CODE MUSIC WITH SONIC PI
13. SLICE IT UP
Using with_fx, we can add a
:slicer effect to our choir sound.
Try altering the phase and
wave values while it’s playing to
produce your own creative sounds
and effects.
live_loop :choral do
with_fx :slicer, phase: 0.125,
wave: 0 do
sample :ambi_choir, rate:
0.6, amp: 0.7
sleep 1
end
end
14. OTHER
EFFECTS
This is just one of many FX that
can be used in Sonic Pi. You can
get as musically creative as you
want! For now, let’s try adding
one of these effects to our drum
loop, as follows.
with_fx :distortion do
live_loop :breakbeat do
sample :loop_breakbeat,
beat_stretch: 2
sleep 2
end
end
121
PROJECTS
15. HOW TO
USE OPTS
Another way to control sounds is
using opts. Try changing the attack
and sustain values of the following:
live_loop :synthopts do
use_synth :prophet
riff = (scale :a3, :major
pentatonic).tick
play riff, amp: 0.3, attack:
0.1, sustain: 0.2, decay: 0.1,
release: 0.2
sleep 0.25
end
GLOSSARY con trolled using optional parameters
– opts for short
ths , sam ple s and FX can be
Sonic Pi’s syn
O pt s – suc h as am p: (am plit ude ), pan: (lef t/right stereo), cutoff: and rele
ase: to shape the sound.
16. CONTROL
CHANGES
We can also use the control
function to change certain opts
while sounds are playing, as in
the following example. This is
really cool when you’re playing
something live and you want to
change it up a bit.
s = synth :prophet, note: :g1,
release: 8, cutoff: 60
sleep 1
control s, cutoff: 130
122
CODE MUSIC WITH SONIC PI
17. MAKE IT
SLIDE
That change in cutoff was
instantaneous. Let’s make it come
in gradually instead, using the
cutoff_slide opt.
s = synth :prophet, note: :g1,
release: 8, cutoff: 60, cutoff
slide: 2
sleep 1
control s, cutoff: 130
Above: One of the most surprising features of Sonic Pi is that you can use it to control Minecraft. Start up the latter and create a
new world, then use Sonic Pi’s special functions to interact with it. You can send text messages to Minecraft with mc_message,
change location with mc_teleport and create new blocks with mc_set_block. Have fun!
123
PROJECTS
can have fun with technology and also make getting up for
school more interesting. If you search for “sunrise alarm” on Google
What you need:
you’ll get over 815,000 results. There is even a mention of these alarm UÊ Pi Zero with Wi-Fi
clocks on the Wikipedia page for “Dawn simulation”. Our project is dongle
based on the idea that as light enters your eyelids during the lighter
phases of sleep, it will help your body to prepare for waking up. UÊ Pi Zero USB OTG
In early 2016, Pimoroni (which makes Pi cases and add-ons) adaptor
released a new product with eight bright RGB (multi-colour) LEDs. This UÊ 40-pin header
is a good size display to start with – they have 4×8 and 8×8 ones, too.
Warning: Exercise caution when viewing LEDs. Do not stare directly
at them; it is easy to become dazzled. UÊ Pimoroni Blinkt!
UÊ microSD card
UÊ Computer with
SD card reader,
or separate SD card
reader
UÊ USB hub and
keyboard
UÊ Soldering iron and
solder
UÊ Flux pen
124
MAKE A SUNRISE ALARM WITH THE BLINKT!
2. SOLDER THE
PI ZERO HEADER
With the supervision of a parent,
apply a dab of flux to each of the
40 GPIO holes on the rear of the Pi
Zero. Now, with the iron heated up,
insert the 40-pin header and apply
a dab of solder to each pin. Make
sure it is straight and level before
adding solder.
125
PROJECTS
126
MAKE A SUNRISE ALARM WITH THE BLINKT!
14. PICK A
START TIME
Now that our program will
automatically star t up, let’s set
the alarm time. Edit the config.py
file in /home/pi/sunrise-alarm/
star t.sh and set the star t time,
15. TEST IT OUT your bedside table.
then make sure you reboot with
Now disconnect ever ything and transfer it to sudo reboot.
wait for the alarm.
Plug in the Wi-Fi dongle and power cable and alarm = {
otely access the Pi.
If you want to trigger it earlier, use SSH to rem “start_hour”: 10,
you’re not sure how
Just set the time in config.py and reboot it. If “start_minute”: 25
the Pi website.
to use SSH, there’s plenty of info available on }
127
PROJECTS
Make a traffic-light
door entry system
with Scratch What you need:
UÊ Solderless
CHILLING IN YOUR ROOM? GET ALERTS WHEN breadboard
SOMEONE IS AT YOUR DOOR UÊ 3 x LEDS (red,
yellow, green)
Want to chill in your room without annoying siblings or parents
bursting in? What you need is a door entry system, and that’s UÊ 3 x 333-ohm
what we’ll be making, using a Pi, some LEDs and some electronic resistors
components. Stick it to your door with a sign telling people to press UÊ Piezo buzzer
the button; they’ll see the red light
and know it’s not okay to enter.
When they press the button, an UÊ Push button
alarm will go off to alert you.
After a few seconds, they’ll UÊ 6 x male-to-female
then get the green light to jumper wires
enter, and a beeping sound.
While it won’t lock them out, UÊ 2 x male-to-male
it shows them it’s good jumper wires
manners to wait for your
permission to enter! To
make things simple,
we’ll get it to auto-start,
so you don’t need to
keep it hooked up to
a monitor. You could
power the Pi with a
phone powerbank.
128
MAKE A TRAFFIC-LIGHT DOOR ENTRY SYSTEM WITH SCRATCH
3. ADD A 4. ADD A
RESISTOR
In the column of the LED’s shorter
YELLOW LED
Place the yellow LED in a similar
GLOSSARY
leg, place one end of a resistor. fashion, with a resistor from its Solderless
Insert its other end into a nearby short leg to the ground rail. Use a B re a d b o a rd protot yping
rd enables
hole of the row marked “–” on the jumper wire to connect its longer board - A breadboa
tronic
breadboard: the ground rail. Be leg to the GPIO23 pin. Again, be you to connect elec
t the need
careful when placing them both. careful when you’re placing them. components withou
ther. It
to solder them toge
cted holes
features interconne
s, so it’s
in columns and row
base!
sort of like a LEGO
129
PROJECTS
GLOSSARY Shared
G ro un d ra il negative
connection - By connecting
the negative legs (cathodes) of
components to the same long 8. ADD A BUTTON
row on a breadboard, they can Place the push button so that it straddles the breadboard’s
share its connection to a linked central groove. On one side, connect one pin to the ‘–’ rail and
GND pin on the Pi.
the other to the GPIO21 pin.
130
MAKE A TRAFFIC-LIGHT DOOR ENTRY SYSTEM WITH SCRATCH
10. CONFIGURE
9. TURN GPIO LED PINS
SERVER ON We need to
In Scratch, we need to start the configure the
server to communicate with the LEDs’ GPIO pins as
GPIO pins. Under a “when green outputs in order
flag clicked” block, add a broadcast to control them.
block and set it to gpioserveron. This So add three
will tell the Pi when you want to use broadcast blocks
the device. set to config17out,
config23out and
config25out.
Connecting
to the ground is
important for making
your circuits safe
131
PROJECTS
132
MAKE A TRAFFIC-LIGHT DOOR ENTRY SYSTEM WITH SCRATCH
Take it a 18. 19. TRAFFIC
step further
BROADCAST LIGHTS SCRIPT
To make the project more BUTTON Now start a new script with a
“when I receive” block and set
compact and suitable for
sticking to a door, you could use PUSHED it to “pushed”, so it will trigger
a Pi Zero – powered by a phone when the button is pressed. Add
When the button is pushed, we’ll
charger – and/or a half-size “broadcast gpio23on” to turn on
broadcast a message to start the
breadboard or even a ProtoZero the yellow LED.
script for our traffic lights. Inside the
board (although the latter would
if block, add a “broadcast and wait”
involve soldering components,
block set to “pushed”.
so ask an adult). You could
even create a case to hide the
electronics apart from the LEDs,
so it’s easier to attach to a door.
133
PROJECTS
134
MAKE A TRAFFIC-LIGHT DOOR ENTRY SYSTEM WITH SCRATCH
135
PROJECTS
Build an
explorer robot
BUILD YOUR VERY OWN EXPLORER ROBOT
What you need:
AND CONTROL IT WITH A WIIMOTE
UÊ The Explorer Robot
Are you an inventor? Have you ever wanted your own robot to take Kit from Pimoroni
exploring and show your friends? This tutorial could be exactly what
UÊ A genuine Wiimote
you’ve been waiting for. It can be driven anywhere whether
that is around your bedroom, down your street or even at UÊ Bluetooth dongle
school. Join us as we guide you through putting together your
very own explorer robot. You will need a Wiimote so that you can UÊ WiFi dongle
tell it exactly where to go.
We’ve designed this project so that it works out of the box and UÊ USB hub
that means that you don’t have to learn Python programming.
Depending on how far you want to take the project we have left UÊ Soldering kit
lots of opportunities to extend the robot. Some of the parts can be
re-used in other projects such as the explorer pHAT, it’s great for
UÊ Short cable ties
reading sensors and can light up LEDs too. All the code has been UÊ Wire cutters
provided online so that you can study it and change it if you want to.
136
BUILD AN EXPLORER ROBOT
137
PROJECTS
9. MOUNT THE
8. SECURE THE
7. INSTALL THE FRONT WHEELS
TOP PLATE
MOTORS Securing the top plate can be a
We will now mount the front set
of wheels that drive the tracks.
Turn off the soldering iron and bit fiddly. Place the top plate on Find the shallow side of the wheel
let the motors cool down before a flat surface and then put the and let it point out, then slowly
touching them. Place the motors robot chassis with the empty but firmly push the plastic wheels
into the grooves on either side battery compartment pointing up down onto the shaft of the motor.
of the chassis opposite the free- on top of that. Find the first two Try to make sure these line up
wheels. They have a friction fit bolts and nuts and then carefully with the free-running wheels we
which gets stronger when the top drop a nut into the slot by the installed in the earlier step. You
plate is screwed on. Temporarily motors and turn it until it falls in may be able to turn the motors by
use the top plate to find the best place. You can now use a small hand but it is not recommended
place to route the wires through cross-head screwdriver to tighten – just check that they line up with
to the top of the robot. this down. the opposite set of wheels.
138
BUILD AN EXPLORER ROBOT
139
PROJECTS
140
BUILD AN EXPLORER ROBOT
141
PROJECTS
UÊ Micro SD + NOOBS
bear guardian
UÊ Keyboard + mouse
UÊ HDMI Cable
UÊ Micro charger
and wall plug
HOW TO MAKE A TEDDY BEAR THAT COMES
UÊ Ethernet cable TO LIFE TO PROTECT YOUR STUFF!
or WiFI
UÊ A pack of multiple Have you got a sneaky sibling that tries to come into your room to
jumper cables steal your phone charger, or perhaps try to read your diary? Don’t
(male-female) worry, with a little help from your Fairy Pi Mother, Scratch and an old
teddy bear, your brothers and sisters will soon learn not to mess with
your privacy!
UÊ 2X 3V LEDs In this tutorial, we’re going to turn a teddy bear into a fully fledged
Guardian of the Bedroom. We’ll be using an infrared sensor to detect
UÊ 2X 180 ohm movement, which will set off a trigger that makes your teddy’s eyes
resistors light up with LEDs. On top of that, with the help of some speakers, we
can make it roar to have your siblings run for their lives!
UÊ PIR sensor This project is meant to be done together with a parent, as it is very
tricky. You will learn some basic programming using Scratch, how to
UÊ Soldering iron and control external outputs and inputs using the GPIO pins on your Pi,
solder (ask your as well as some practical skills like gluing and soldering. Remember
parents for help) that you should never solder by yourself; instead, ask a mum or dad
to help out.
UÊ Heat Shrink
insulation or
electrical tape Your brothers and sisters
will soon learn not to mess
UÊ Wire with your privacy!
142
BUILD A TEDDY BEAR GUARDIAN
4. UPDATE THE
SOFTWARE
Your Pi will currently have a
dusty brainbox so lets spring
clean and update the little
fellow by running the following
commands in terminal.
Depending on internet speed it
could take about 5 to 10mins.
5. SCRATCH
INSTALLATION
To control the Pi’s GPIO
output pins we need to
install ScratchGPIO. Open the
terminal and type the following
commands to do so.
wget https://bit.ly/1wxrqdp -O
isgh7.sh
sudo bash isgh7.sh (username)
143
PROJECTS
MAKING IT EASIER
Remember that how you use your Raspberry Pi is completely
up to you. You can make things easier or harder whenever you
like. If you want to leave out the IR sensor, and just make the
LEDs light up, that’s up to you!
144
BUILD A TEDDY BEAR GUARDIAN
Merge the
discrete blocks
of instructions
13. GATHER YOUR
MATERIALS
Lay out all of the equipment and
pieces you will need to build the
circuit for your bear!
145
PROJECTS
15. LIGHT
EMITTING DIODE
Solder a 180 ohm resistor to the negative
pin of the LED, identified by the shorter
length. Remember that resistors do not
have a negative and positive so don’t
worry which way you attach it.
16. INSULATION
Using electrical tape or by sliding an appropriate
length of shrink wrap and applying heat (again, ask
a parent to do this), insulate the new joint you have
made. Be careful as it will be hot from soldering!
17. EXCESS
OF WIRES
Cut a length of wire about 6 inches
long, remove the plastic from the
tip, and solder it to the free end of
the resistor. Leave extra length if you
have a particularly large teddy bear.
18. INTERNAL
PROTECTION
Using your preferred method, shrink
wrap or electrical tape, insulate the
new joint to reduce the chance of
damage to the circuit and to protect
the teddy bear’s delicate stuffing.
146
BUILD A TEDDY BEAR GUARDIAN
23. REPEAT
Repeat steps 15 to 22 to produce
a second LED, resistor, extending
wires and jumper cables. These will
soon become the scary blood red
eyes of your teddy warrior.
147
PROJECTS
148
BUILD A TEDDY BEAR GUARDIAN
30. SEPARATE
THE EYES
In our case, the eyes had two
plastic parts: the black eye on
the outside, and the white base
on the inside. We could recycle
the white base to thread our LED
eyes through.
31. CREATE
A HOLE FOR
THE SENSOR
On the teddy’s chest, make a small hole where you want the dome
of the infrared sensor to come through. Like you did with the teddy’s
head, use the tip of the scissors, or ask a parent to use a craft knife.
Always take care with sharp tools and never use them unsupervised.
149
PROJECTS
150
BUILD A TEDDY BEAR GUARDIAN
36. FINAL
CHECKS
Plug everything back
into your Pi and
perform a final check
that everything is
working before sewing
up the hole in the back.
151
A PARENT’S GUIDE TO SAFE SOLDERING
A parent’s
UÊ Safety glasses
UÊ Ice water
guide to safe
UÊ Hair band
UÊ Heat resistant
gloves
soldering
UÊ Solder wick
How to prepare
AN EASY AND FUN, STEP-BY-STEP GUIDE UÊÊ9ÕÀÊ>Ài>ÃÊii`ÃÊ}`Ê
TO SOLDERING WITH YOUR KIDS ÛiÌ>ÌÊ°i°Ê>Ê«iÊÜ`Ü®Ê
>`Ê>Ê>ÃÊ«ÜiÀÊÃViÌ°
A soldering iron is a tool mostly used by people who work with UÊÊ «iÌiÞÊVi>ÀÊÞÕÀÊÜÀÊ
electronics, to join wires and other electrical components like ÃÕÀv>Vi°Ê ÕÌÌiÀÊÃÊ`>}iÀÕð
transistors together. It looks like a screwdriver and the tip (the UÊÊvÊÞÕÊÀÊÞÕÀÊV `ÀiÊ >ÛiÊ}Ê
‘element’) can get really hot, up to 400 Celsius. That’s hot enough to >À]ÊÌiÊÌÊL>V°ÊvÊÞÕ½ÀiÊÜi>À}Ê
melt metals like lead, so be very careful and don’t touch the tip, it will *ÀÌiVÌÛiÊ}ÛiÃ]Ê«ÕÌÊÌ iÊ°Ê
still be hot enough to badly burn you even after the soldering iron *ÕÌÊÞÕÀÊiÞiÊ}>ÃÃiÃÊ°
has been switched off. UÊÊ*>ViÊÌ iÊ«ÌÃÊÞÕÊÜ>ÌÊÌÊ
Soldering irons don’t directly melt the metal they touch. Rather, a Ã`iÀÊÌÊÞÕÀÊÜÀÊÃÕÀv>Vi°
metallic medium called solder is applied. The hot element of the UÊÊ7iÌÊÌ iÊë}i°
soldering iron melts the solder, which drops onto the points and then UÊÊ*ÕÊ>Êi}Ì ÊvÊÃ`iÀÊÕÌÊvÊÌÃÊ
cools rapidly, physically connecting them. The solder is electrically ë]ÊÃiÌÊÌ iÊÃ`iÀ}ÊÀÊÊÌÃÊ
conductive, so electricity can flow freely across the solder as if it was ÃÌ>`]Ê«Õ}ÊÌÊÊ>`ÊiÌÊÌÊ i>ÌÊÕ«°
a seamless connection.
152
A PARENT’S GUIDE TO SAFE SOLDERING
1. CLEAN 3. APPLY
THE ELEMENT THE SOLDER
A good worker maintains their 2. TIN THE TIP With the soldering iron in your
tools, so it’s important to keep Before you start soldering, you’ll dominant hand, touch the
your soldering iron clean, to need to apply a fresh layer of area you want to join with the
ensure you’re soldering efficiently. solder to the element. This is so element for just a second or two.
Once the iron is hot, wipe it heat conducts more effectively Carefully slide the solder under
against the wet sponge to remove from the iron to the solder. Once so that it’s sandwiched between
old solder from the element. This the tip of the element is shiny with the soldering iron and the join.
will reduce the amount of contact fresh solder, you’re ready. Make It will melt quickly, so feed more
time you’ll need with the solder sure you repeat steps 1 and 2 solder into the join if required –
and improve your join. (clean and tin) every few joins. most projects need very little.
153
GLOSSARY
Raspberry Pi glossary
A QUICK GUIDE TO THE VARIOUS TERMINOLOGY FOR ALL THINGS
RASPBERRY PI RELATED, FROM INPUTS TO OPERATING SYSTEMS
A UÊ Ì
In computing, booting up refers
UÊ««i`} to when a computer system is UÊ
In computing, “appending” refers started up so that it is in a state to A general-purpose programming
to the process of attaching or start executing instructions. language and one of the many
combining data with another file you can use to program your
or set of data. UÊ À>Li]Ê >Û` Raspberry Pi.
Influential games developer
UÊ«ÌÉ>«Ì}i and head of the Raspberry Pi UÊ ³³
APT stands for Aptitude, a Linux Foundation, the charity that One of the many programming
package management tool used developed the Raspberry Pi. languages that you can use to
for fetching and installing various program your Raspberry Pi.
software packages. UÊ Ài>`L>À`
A useful device for creating circuits UÊ >`Êi
UÊÕÝ>ÀÞÊVÀ` quickly and easily. A breadboard The Command Line lets a user
Audio can be played through allows you to plug in and remove directly manipulate and alter their
speakers or headphones using components without soldering. system by entering commands.
a standard auxiliary cord with a
3.5mm jack or HDMI connection.
ÕiÌÌ
Wireless technology
B that allows data to
be exchanged over
UÊ Ê >ÃV short distances.
One of the very early computer Can transmit signal
programming languages and through walls as
one of the many you can use to well as other non-
program your Raspberry Pi. metal barriers.
154
GLOSSARY
UÊ
A state when a computer is not
UÊ `i processing any data.
An electrical component that
conducts electrical current mainly
in one direction.
UÊ*"Ê*Ã
UÊ Ã«>Þ Stands for General Purpose Input/
Your Raspberry Pi needs to be Output and these are the type
connected to a display unit, such of pins that can be found on the
as a TV or monitor. You can do this Raspberry Pi for connecting other
via USB or HDMI. devices.
UÊ*1
Stands for Graphics Processing
Unit, a special processor that
UÊ Ì iÀiÌ handles graphics.
This cable and port can be used to
connect your Raspberry Pi to the UÊÀÕ`ÊÀ>
internet or to a local network. This refers to the power line on a
motherboard.
155
GLOSSARY
UÊvÀ>Ài`
An invisible radiant energy that is
typically used to control electrical
devices remotely.
J
UÊÕ«iÀÊÜÀi
An electrical wire with a solid tip
at each end used to interconnect
components in a breadboard.
Raspberry Pi Raspberry Pi
Model A+ Model B+
Middle of the range Raspberry Pi Middle of the range Raspberry Pi K
model that coats around £16/$24 model that coats around £22/$22
and includes 256MB of RAM and and includes 512MB of RAM and UÊiÀi
one USB port. four USB ports. The computer program at the
centre of your operating system:
the most important part.
UÊiÞL>À`
Any standard USB keyboard
and mouse will work with your
Raspberry Pi and you can also pair
wireless keyboards to your device.
L
UÊ
Raspberry Pi 2 Raspberry Pi Stands for Light-Emitting Diode.
Model B Zero
This is the top of the range model Currently the cheapest model of UÊLÀ>ÀiÃ
of the Raspberry Pi that costs Raspberry Pi available, retailing In coding, a library is a collection
around £30/$45 and includes 1GB at just £4 and includes 512MB of of preset routines that a program
of RAM and a powerful CPU. RAM and two microUSB ports. uses. These routines are often
called modules.
156
GLOSSARY
"" -Êis o
ne of the b
UÊÕÝ and easies
t ways, to in
est,
A free, versatile open source a distro to y stall
our Raspbe
operating system and just one of rry Pi
the many that can be run on the
Raspberry Pi.
UÊ«
A loop is a repeating
serquencnece within a program.
Most programs have a main and
minior loops.
M
UÊ Ê``ÀiÃÃ
Stands for Media Access Control
and is the id for other hardware UÊ`ÕiÃ
that is connected to your These are the routines that are "
Raspberry Pi. found in a library. These are
developed separately and work UÊÊ"«iÀ>Ì}Ê
together in a program. -ÞÃÌiÊ"-®
This is system software that is
used to run computer hardware,
N such as your Raspberry Pi.
UÊ > UÊ"ÛiÀVV}
An easy-to-use text editor that When a computer is configured
possesses all of the features to operate at a faster rate than
UÊVÀ- needed to edit files on your intended or possible.
A portable storage card and Raspberry Pi.
port that lets you store your
programming. UÊ "" - P
Through this easy-to-use app
UÊVÀÊ1- you can choose the preferred UÊ*iÀ« iÀ>
This refers to a cable and port operating system for your This refers to additional devices
that can be used to charge your Raspberry Pi and then manage that can be used with the
Raspberry Pi. the installation process. Raspberry Pi, such as a keyboard.
157
GLOSSARY
UÊ,>ëL>
This is the standard operating
system for the Raspberry Pi.
UÊÊ,>ëLiÀÀÞÊ*Ê
Õ`>Ì
The charity that developed the
Raspberry Pi to promote the study
of computer science and related
topics in schools.
UÊ,iLÌ
,>ëLiÀÀÞÊ*ÊÕ`>Ì\Ê Execute the ‘sudo reboot’
This charity was set up to help command to restart your
put the fun back into computing Raspberry Pi, such as when
system files have been modified.
UÊ*iÀ UÊÊ*7\Ê*ÕÃiÊ
A group of general-purpose 7`Ì Ê`Õ>Ì UÊ,i`iÀ}
computer programming This is a modulation technique This refers to generating an image
languages that can be used with used to encode a message into by means of computer programs.
your Raspberry Pi. a pulsing signal. It is mainly used
for controlling the power to various UÊ,iÃÃÌÀ
UÊ** electrical devices. An electrical component used to
Designed for web development lower voltage levels in circuits.
but can also be used as a general- UÊ*ÞÌ
purpose programming language A widely used programming UÊ,ÕLÞ
for use with your Raspberry Pi. language and one of the many A general purpose programming
you can use to program on your language and one of the many
UÊ*ÌiÌiÌiÀÃ Raspberry Pi. that you can use to program your
This is a three-terminal resistor Raspberry Pi.
with a sliding or rotating contact
that adjusts the voltage in a circuit. R
S
UÊ*ÀViÃÃÀ UÊ,
An electrical circuit that executes Stands for Random-Access UÊ- Ê >À`
programs or performs operations Memory and is a form of A Secure Digital storage card for
on an external data source. computer data storage. use in portable devices.
158
GLOSSARY
-VÀ>ÌV V
Scratch is one
of the easiest
UÊ6>À>Li
In programming, variables
programming
represent values that can change.
languages for the
Raspberry Pi and
can be used to
UÊ6
Stands for Virtual Network
create interactive
Computing and is a server that
games and stories.
Raspberry Pi Users can connect to.
UÊ-iÃÀÃ T W
A sensor is designed to detect
changes within its environment UÊ/iÀ>Ê UÊ7Ê }i
and then provide a suitable output This refers to the command Portable adaptor that plugs into a
in relation to the change. line interface on a Unix-based USB port to allow your Raspberry
computer such as the RasPi. Pi to connect to a wireless
UÊ- ÕÌ`Ü network.
Be sure to power-down your
Raspberry Pi correctly by executing U 6 ÊiÌÃÊÞÕÊÜÀÊÊÞÕÀÊ
the command ‘sudo shutdown’. ,>ëLiÀÀÞÊ*ÊÀiÌiÞÊvÀÊ
UÊ1- >Ì iÀÊV«ÕÌiÀo
UÊ-Õ` Stands for Universal Serial Bus
Stands for ‘super user do’ and is and is an industry standard for
used to execute a command on connecting computers
your Pi. and other
electrical devices.
UÊ-ÞÌ>Ý
This is the set of rules that define UÊÊ1- Ê
the combinations of symbols used 7ÀiiÃÃÊ
in computer programs. }i
This is an
UÊ-ÞÃÌiÊÊ « alternate means
Sometimes shortened to SOC, of connecting
this is a microchip containing all your Raspberry
of the parts of the Raspberry Pi’s Pi to the internet
computer system. (see WiFi dongle).
159
of al
r
al ci
fe
tri pe
S
Enjoyed
this book?
Exclusive offer for new
Try
3 issues
for just
*
£5
* This ofer entitles new UK Direct Debit subscribers to receive their irst three issues for £5. After these issues, subscribers will then pay £25.15 every
six issues. Subscribers can cancel this subscription at any time. New subscriptions will start from the next available issue. Ofer code ‘ZGGZINE‘ must
be quoted to receive this special subscriptions price. Direct Debit guarantee available on request. This ofer will expire 29 September 2017.
** This is a US subscription ofer. The USA issue rate is based on an annual subscription price of £65 for 13 issues, which is equivalent to $102 at the
time of writing compared with the newsstand price of $16.99 for 13 issues, being $220.87. Your subscription will start from the next available issue.
This ofer expires 29 September 2017
The magazine for
the GNU generation
Written for you
Linux User is the only magazine dedicated to
advanced users, developers & IT professionals
In-depth guides & features
About Written by grass-roots developers & industry experts
subscribers to…
Also available…
A BOUT S CR ATCH,
LEARN ALL P YT HON ,
OOB S,
RASPBIAN, N RAFT!
I AND M IN EC
SONIC P
BECO
MAST ME A
ER CO
DER!
GET READY
FOR A CHALLENGE!