Professional Documents
Culture Documents
MagPi40 PDF
MagPi40 PDF
Raspberry Pi Zero is a real $5 computer. Learn to code while you play Minecraft
(or do just about anything else you can dream up)
ze
l si
tua
*ac
12
9 772051 998001
Serial Pi Plus
RS232 serial communication board.
Control your Raspberry Pi over RS232
or connect to external serial
accessories.
Breakout Pi Plus
The Breakout Pi Plus is a useful
and versatile prototyping expansion
board for the Raspberry Pi
ADC Differential Pi
8 channel 18 bit analogue to digital
converter. I2C address selection
allows you to add up to 32 analogue
inputs to your Raspberry Pi.
IO Pi Plus
32 digital 5V inputs or outputs. I2C
address selection allows you to stack
up to 4 IO Pi Plus boards on your
Raspberry Pi giving you 128 digital
inputs or outputs.
RTC Pi Plus
Real-time clock with battery backup
and 5V I2C level converter for adding
external 5V I2C devices to your
Raspberry Pi.
1 Wire Pi Plus
1-Wire to I2C host interface with ESD
protection diode and I2C address
selection.
www.abelectronics.co.uk
S
SAVE
15%
MagPi15 BrickPi
discount code
GoPiGo
Everything you need to
build a Raspberry Pi robot!
$89 / 59
GrovePi
Connect hundreds of sensors
to your Raspberry Pi!
$89 / 59
www.dexterindustries.com
Welcome
FREE
RASPBERRY PI ZERO: CA B
ACCESS TO TOOLS B U
LE
FOR SU
N D LE
BSCRIB E
y first computer, a second-hand BBC Micro RS
PAGE 42
M
!
with its built-in BASIC, cost me 220 in
1989. Thats 500 in todays money. My
Amiga was a little cheaper, costing 200 in 1993,
but I had to save for three more months to buy the
software and documentation I needed to program it.
Throughout my childhood, cost limited my access
to the tools I needed to learn. This is why, of all the
work that we do at Raspberry Pi, driving down the
cost of computing is the single thing that matters
most to me.
The original Raspberry Pi Model B and its
successors put a programmable computer within
reach of anyone with $20-35 to spend. Now were
taking the next step: in Raspberry Pi Zero, we finally
SEE PAGE 42 FOR DETAILS
have a computer we can sell for $5, or give away on
the front of a magazine.
We all need access to tools. Cost should never be a
barrier. Enjoy your Raspberry Pi Zero.
THIS MONTH:
Eben Upton 8 INTRODUCING THE TINY $5 PI ZERO
Find out what the Zero is and what you can do with it
This magazine is printed on paper sourced from The MagPi magazine is published by Raspberry Pi (Trading) Ltd., Mount Pleasant House, Cambridge, CB3 0RN. The
sustainable forests and the printer operates an publisher, editor and contributors accept no responsibility in respect of any omissions or errors relating to goods, products
environmental management system which has or services referred to or advertised in the magazine. Except where otherwise noted, content in this magazine is licensed
been assessed as conforming to ISO 14001. under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0). ISSN: 2051-9982.
raspberrypi.org/magpi December
March 2015 3
Contents
Issue 40 Christmas 2015 raspberrypi.org/magpi
COVER FEATURE
8
RASPBERRY PI ZERO
Learn all about this evolutionary leap and how you can get started with your Pi Zero today!
THIS MONTH IN
> SONIC PI: MUSICAL MINECRAFT
Make much more than just music with the aid of Sam Aaron
60 88 RASPBERRY PI
Join us for a new regular feature
> GAMES WITH PYTHON: PART 10 62 The Raspberry Pi Foundation and that looks at whats going on in
Raspberry Pis own Simon Long gives us the Code Club have merged to further
In this final instalment, we add some extra features and the Raspberry Pi community in
lowdown on the latest tweaks and changes
polish to our space shooter game written in Python their joint goal of righting past wrongs the past 3o days
SUBSCRIBE TODAY!
to get a free Pi Zero
cable bundle! 42
THE BIG FEATURE
Astro Pis mission aboard the ISS is starting. We find out more
and show you how to join in the fun with the Sense HAT
70 Matt Richardson talks about Pi Zero, the tiny 96
computer with a big impact
> EVENTS 90
Find a community gathering near you in the coming weeks
46 REVIEWS
> PI-TOP 82
SEEMORE Has this Raspberry Pi laptop delivered on its promise?
This Pi-powered parallel processing sculpture will take your breath away
> DIGITAL SOLDERING STATIONS 84
MAGIC MIRROR 44 We look at Tenmas new adjustable soldering iron
NEVER
BEFORE
PRINTED
All the best articles
from issues 31-35
RASPBERRY PI
PROJECTS BOOK
Amazing hacking and making projects
from the makers of magazine
Inside:
How to get started with Raspberry Pi
able
Availw
no
SWAG.RASPBERRYPI.ORG
and from all good newsagents
ZER0
RASPBERRY PI
A new revolution in
computing is upon us
W
ed like you to pick up
the Raspberry Pi Zero
that came with
this very magazine.
Youre holding
in your hands a
fully functional
computer thats
going on sale for $5
and that you could lose
in a small purse. Its
quite the amazing feat
of engineering and were
very excited to bring it to
our readers, along with 32
30m
mm
pages of content that will
take you from a Zero Novice to a 65
m
Zero Master.
Over the course of our expansive
coverage, we talk to the people
behind the Raspberry Pi Zeros
development, teach you how to
hook it up, and also suggest some Broadcom BCM
great uses for your Zero. With 2835 system-
its even smaller size, there are MicroSD card on-a-chip, the
some amazing things youll be slot for storing same chip
able to do with it. Check out the the operating Mini-HDMI port that powered
contents on the facing page to jump system, files, for digital sound the original
to what interests you, and just have anddocuments and 1080p video Raspberry Pi
a good time with your new Pi Zero.
CONTENTS
40-pin Unpopulated Unpopulated
unpopulated RUN mode pins RCA composite SIZE MATTERS
GPIO port for which can be video out pins so
you can connect How big is a Pi Zero? Weve been
connecting to used to add a
to an old TV comparing them to all sorts of things
your electronic reset button to
circuits the Pi Zero
> 10
Power and
activity LED this
lets you know the THE STORY OF ZERO
Pi Zero is on and We talk to Eben Upton and Mike
working away Stimson about Zeros development
> 12
QUICK PROJECTS
THE SPECS Some quick taster projects that
improve traditional Raspberry Pi uses
> 22
CPU: BCM 2835 (same as the original
Raspberry Pi), 1GHz single core ARM11 SOLDER A GPIO PORT
Want to access the GPIO pins? Heres
RAM: 512MB our guide to soldering them on
> 23
Storage: Via microSD
Power: Micro-USB connector ZERO PROJECTS
Get started straight away with your Pi
Video out: Mini-HDMI Zero with these great projects
> 24
Connectivity: 1 micro-USB, unpopulated 40-pin GPIO
connector, unpopulated Composite Video Out
3D PRINTED CASE
Learn how to 3D print your own custom
Dimensions: 65mm 30mm 5mm Weight: 9g MagPi case for your new Pi Zero
> 41
PI ZER
IN PICTURES
0
Weve been so enamoured with the size of the Raspberry Pi Zero
thateveryone here got into a small competition to show off their
bestsizecomparison photos!
Send us your best comparison shots on Twitter to @TheMagP1
ZER0
RASPBERRY PI
RASPBERRY PI ZERO:
$5 3X
IN NUMBERS
The Raspberry Pi Zero is the first ever But its nearly three times smaller than
1080P
full computer that costs only $5 the original Raspberry Pi
Its about one Minifigure wide and under two Minifigures long.
Also, they can easily carry one!
143
Above A LEGO Minifigure is just a bit taller than the Zero is wide.
2.5KG
The Raspberry Pi Zero can easily play 1080p video, even
though its so tiny and draws very little power
8128 MFLOPS
battery and
everything in an
Altoids mint tin. You
can fit six in one!
Below Putting
a Raspberry Pi A 2.5kg box of Zeros contains 8,128 MFLOPs of processing power, which makes it
Zero in a pack of more powerful than 50 Cray-1 supercomputers!
512MB
cards sounds like
proper James Bond
territory, although It also launches
youd lose the with twice as
cards you need to
play poker much RAM as
the very first
160mA
Raspberry Pi did
(it 256MB)
WHEN WE LAUNCHED
RASPBERRY PI,
WE CHANGED THE
PRICE OF THIS KIND
OF HARDWARE...
WITH THE ZERO,
WE WANTED TO
DO IT AGAIN
INTERVIEW
ZER0
RASPBERRY PI
I
of the Raspberry had a really interesting expensive, and at the time we from Ebens conversation with
Pi Zeros life on a
conversation with Eric had a potential route to make this Eric, though:
scrap of paper
Schmidt [CEO of Google], Pi 2 much more powerful He The other thing was trying
Eben Upton, CEO of Raspberry said dont be an idiot. Thats a to look at what we could do to go
Pi Trading, recounts to us over ridiculous idea. You have to try and lower than $25.
a Skype chat one rainy morning be as close to free as possible The first result of this new
in late October. its very hard to compete with outlook was selling the Pi Model
A+ for $20, but after drastically
To take a Raspberry Pi
Model A and make it as
cheap and small as possible
It was strange actually, recalls instincts when it comes to these
Mike. I was in the middle of doing kinds of things, though.
THE
something else when someone The first prototype was turned
came over and said that there was around pretty quickly once Mike
DESIGN
a new project: basically, to take a got on to actually designing the Pi
Raspberry Pi Model A and make it as Zero. However, that didnt mean it
cheap and small as possible [while was easy.
ZER0
RASPBERRY PI
The first and final design, as still having the same specs]. Then Originally, we were talking about
created by Mike: The biggest we went through a list of features something in the region of 35mm
difference between the final that we thought we could get rid of, wide and the same length as the
and early version is obviously ones we had to keep, and a few that A+, Mike explains to us. It looked
the height. When we looked we werent quite sure about. challenging because the other thing
at the layout, there seemed There was enthusiasm. And we also wanted to do to keep costs
to be an awful lot of empty scepticism, Eben laughs as he down was to make it single side
space relatively speaking, recalls the original pitch meeting. assembly. Not only is it considerably
of course. Youve got a room full of the smaller than an A+, its a lot more
brightest guys on the planet, right, dense component-wise on that
and you say hey, were going to do top layer. Theres a lot more clever
this and its going to have a business routing that has to be done in order
model that looks a bit like this. to get that size down.
Its going to be great! Scepticism, I made it to about 65 by 35mm
obviously, but also enthusiasm. and then we looked at it and thought
Enthusiasm that if we can pull it we could probably shave off a few
off, then weve managed to do again more millimetres. So we rearranged
what we did before. a few of the connectors and we got
I think my natural reaction it to the 30mm-wide crazy size
to all these things is that its all it is now.
crazy talk, Mike says of the pitch. Once the design was complete and
FROM PI TO ZERO
Ive learnt to doubt my own first Raspberry Pi was happy with the
29 01 06 07
FEB RASPBERRY PI JUL A NEW OPERATING SEP LOCALLY APR INDUSTRIAL PI
2012 RELEASED 2012 SYSTEM 2012 GROWN 2014
At 6:00 GMT the original A couple of months or so Manufacturing of Raspberry The Compute Module Raspberry
Raspberry Pi goes on sale, selling later, people begin receiving Pis moves to factories in Wales Pi is released, a miniature
out within minutes. It is one of their Raspberry Pis. Based on managed by Sony, bringing the Raspberry Pi on a SODIMM
the top-read stories on the BBC Debian Linux, the new Raspbian Raspberry Pi home to be a fully laptop memory-style circuit
website, and over 100,000 pre- operating system is released for British computer. board, that can be used to bring
orders are made in the first day. the Raspberry Pi and adopted as Pi power to any device.
the recommended OS.
WHAT IS THE
From inception in January to
peoples hands in November,
ON THE COVER
RCA VIDEO OUT the Raspberry Pi Zero didnt take
Were the first ever magazine in the world to give away
CONNECTOR FOR? very long at all, especially when a real computer on the cover. Here are some other
you compare it to six years for notable covermount firsts through the years...
the original Pi and over two years
The final product has the
for the Pi 2. 1960S SATIRE ON RECORD
composite signal brought out
Its quite fast for us; its being Some issues of satirical magazine Private Eye would
to a 0.1 inch pad, so if you want
helped by the fact it is a real have covermounted floppy 7 vinyls which had
to solder an RCA cable onto it
Raspberry Pi, Eben tells us. So comedy recordings on them. In classic Private Eye
you can.
theres no significant software style, they all had punny titles which we wont subject
Were psyched about the you to here.
engineering involved in doing it
idea of people being able to
it is quite an aggressive schedule,
take it and solder it inside an old
but its good! 1970S FLEXI-DISC MUSIC
television you know, get an old With the popularisation of these flexi-discs on covers,
Commenting on the final
television and crack it open. Turn pop music mags began mounting samples and songs
product, both Eben and Mike seem
your television into a computer. on the front of their covers. NME did this a lot in the
very pleased with it, both in terms
We think thats really good for Seventies with plenty of rock vinyls.
of the technological feat theyve
developing world applications.
accomplished and the aesthetics 1980S NEW HARDWARE
of the Pi Zero as well. As computer magazines took off, so did shareware
I just hope people like it, software attached to the front. It started with floppy
prototypes, they began the process Eben says. I hope that it helps disks, but as CDs became much cheaper, magazine
of making sure there would be the education mission a lot. Its covers began appearing with data CDs on the cover.
enough Raspberry Pi Zeros available great to make computers and
1990S DEMO DISCS
for launch. stuff, but all the money is going
When video games moved to discs with the advent of
We spent a couple of months, back into the charity, so we kind
CD-ROM drives and the PlayStation, cover discs with
June and July, getting manufacturing of hope that the existence of this
game demos were big business.
quotes. We were very pleased to cheap thing will let even more
see that UK manufacturing was people in the door. And maybe 2000S DVDS FOR ALL
very competitive. It was by far thats not even people in the UK As prices for optical media fell, any magazine with an idea
the cheapest way of making it. any more, but also people in the for disc content would have a covermounted DVD. Film
Then we committed orders in developing world. trailers, software, art assets, commentary, instructional
August and manufacturing started Having cheap, open, general- videos, and much more made their way to magazine
[on] 27 October mass volume purpose computing thats got covers the world over.
manufacturing. The first 10,000 are to be good for something. Were
2015 A COMPUTER ON THE COVER
for The MagPi, so the Pi Zero you hold building 100k of them at first, but
The MagPi is the first magazine to give you hardware
in your hand may very well be being Im just hoping it will have a life
on its cover. The Raspberry Pi Zero is the worlds first
manufactured as I speak. after that.
covermounted computer its never been done before.
14 10 02 A NEW 26
JUL A BETTER NOV A CHEAPER FEB NOV FROM ZERO
2014 RASPBERRY PI 2014 RASPBERRY PI 2015 RASPBERRY PI 2015 TO HERO
The Raspberry Pi B+ is The Raspberry Pi A+ is announced, The Raspberry Pi 2 is announced, The Zero is launched, with the first
announced by the Foundation, a a much smaller version of the completely shocking the 10,000 units being stuck to the
redesign of the Raspberry Pi that Raspberry Pi Model A that is also community. With much improved front of TheMagPi in newsagents
contains more USB ports and a even cheaper at $20. Much like power and memory, the across the UK. Its a $5 computer
better layout of its components. the B+. there are no changes in Raspberry Pi finally reaches its that will hopefully further change
The form factor will lead the way the spec, although it does lose full potential and leads to better the computing landscape.
for the Raspberry Pi. one of its output ports. making and educating.
ZER0
Lets take a
closer look at
this miniature
UNBOXED
Raspberry Pi
Youll need a microSD A mini-HDMI to HDMI cable This micro-USB port is for This is the power jack
card so you can actually is required to hook up a data; to actually use it to plug dont get it mixed up with
give the Raspberry Pi Zero monitor to the Raspberry Pi in a mouse, keyboard, or a the data port! Youll need
an operating system. Zero a normal HDMI cable wireless dongle, youll need a a mobile phone charger, or
Some come with SD will not fit. micro-USB to USB adaptor. one of the official Raspberry
adaptors so you can plug Pi power supplies, to turn
it into your PC. the Zero on.
BUNDLE!
Pi Zero hooked up are not
Youll need to install NOOBS
particularly common; although
SUBSCRIBE TODAY (New Out Of Box Software) onto
you might have a mini-HDMI
Page 42 your Raspberry Pi Zero, enabling
cable if you bought a really nice
you to choose an operating
camera in the last few years, the
system. Plug your microSD card
micro-USB adaptors are much
into another computer and visit
less common. With that in mind,
theRaspberry Pi download site
Raspberry Pi has put together a
(magpi.cc/1MYYTMo). Download
cable bundle that will help you
the NOOBS zip file and unzip it onto
get your Zero working in no time.
the SD card to install it. Once thats
Just head over to the Swag Store
done, slot it in. Below These two
(swag.raspberrypi.org) to get a special cables
allow the Pi Zero to
bundle today!
be teeny-tiny
ZER0
RASPBERRY PI
one at this point it should be the
only one left. Plugging the other end
of the power supply into a wall socket
will immediately turn the Raspberry
Pi Zero on. Youre now ready to start a
new chapter in hacking and making!
GET TO KNOW
PI ZER0
Whether this is your first ever Raspberry Pi, or you want to know more about
how the Zero actually performs, lets get to know it...
Run commands the
old-fashioned way
The Raspbian in the terminal or
interface should be via the command-
familiar to almost line interface,
anyone who has on the Pi Zero or
used computers remotely over
the network
ZER0
RASPBERRY PI
DESKTOP SETUP
standard pieces of software youd open the Zero up to be used for
need already installed. Theres a many purposes which well cover
web browser, an email client, and throughout the rest of this feature.
office software called LibreOffice. If you had any doubts, then, Want to set up the Raspberry Pi Zero as a desktop
Theyre all optimised for use on that the Raspberry Pi Zero would replacement? Its really quite simple most
the low-power Raspberry Pi, and be a very stripped-back version of of the hard work has been done for you already
even though theres a much more even the original Raspberry Pi, you
powerful Raspberry Pi alternative, have nothing to fear. At least on a First of all, theres the hardware setup. To make
they all work absolutely fine on the software level, it will run the same the Pi Zero a desktop PC, you need the basic
Raspberry Pi Zero. code and programs in the same components: a monitor, keyboard, mouse, and
LibreOffice especially was a way with the same performance wireless dongle. Connecting the monitor is easiest,
concern as its a very new piece as before. Its now just the size as you just need to get a mini-HDMI to HDMI cable
of software for Raspbian, but it of a stick of gum. that can plug into a monitor with a HDMI port. For
the rest of the components, youll need to first
look into getting a USB hub that can be powered if
ESSENTIAL
PI ZER0
TIPS
GIVE YOUR PI ZERO
HOW TO CONNECT TO WIFI
ON THE COMMAND LINE
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
A NETWORK NAME wpa-ssid
MyWirelessNetwork
If you set a static IP as shown in wpa-password
the wireless tutorial on this page, AGoodPassword
then youll always be able to
access the Raspberry Pi Zero with You can also give the Raspberry
that IP address from any remote Pi a static IP. To do this, you first
service. However, for those who need to do some prep work which
want the easier automatic way, Above To set a requires you to use a computer
you can still make it just as easy static IP on the While Raspbian makes it dead easy which is already connected to
desktop interface,
to connect to the Zero over the youll have to to connect to WiFi on the desktop your wireless network. Open the
network by setting up Zeroconf. go through the interface, theres a little more command line in Windows or
sameprocess
From the command line or in the involved in getting it working the terminal in OS X or Linux.
terminal, type the following to from the command line. Before For Windows, type ipconfig; for
make sure it is installed: we begin, there is one trick you OS X and Linux, use ifconfig
can do: if you set up the WiFi at followed by netstat -nr. Note
sudo apt-get install the desktop, it will still work while the IP address (inet), the broadcast
ZER0
RASPBERRY PI
avahi-daemon in the command line. That isnt address, the subnet address,
always possible, though, so you the router IP (Destination), and
By default, the Pi will now be may need to use the manual way. Gateway address. After that,
accessible via raspberrypi.local First, find out the name of your modify the interfaces file like so:
over the local network. network and the password. In the
Raspbian command line, type: iface wlan0 inet static
sudo nano /etc/network/ wpa-ssid MyWirelessNetwork
interfaces. There will already be wpa-password AGoodPassword
some information in here, but to address [IP address]
get the wireless to connect, make netmask [Subnet]
Left On some
sure the file has these lines in it, network [Router address]
versions of with your network name (SSID) broadcast [Broadcast
Raspbian, avahi
it may already be
and its password replacing whats address]
installed already here: gateway [Gateway]
Thanks to a piece of software called This is especially good if you want to use your
RealVNC, you dont even need to Raspberry Pi Zero as a file server. For this, or just
plug your Pi Zero into a monitor generally to be able to access the files on your Zero
to use its desktop; you can simply from anywhere on the network, youll need to
control it from another computer. use Samba. First, you need to install it:
First of all, go to magpi.cc/PiVNC
and download RealVNC onto your sudo apt-get install samba samba-common-bin
Raspberry Pi. Also obtain a free
licence key (magpi.cc/1O8Hz4J), as Above On some versions of Raspbian, Avahi You need to configure Samba to work as intended.
youll be needing it. may already be installed Still in the terminal or command line, type:
Once the file is on your Pi,
open the terminal, use cd to -add [License Key] with your sudo nano /etc/samba/smb.conf
navigate to the file in Downloads key. Type vncserver into the
(cd Downloads should do) and terminal or command line for it First of all, if you have a Windows workgroup with a
use the following two commands, to begin, type in your Raspberry specific name on your network, find the line starting
replacing the square brackets with Pis password (its raspberry by workgroup = WORKGROUP and change the uppercase
the appropriate names: default) and make a note of the WORKGROUP to your workgroups name. If you
display number. In our case it was have no idea what a workgroup is, you can leave
tar xvf [VNC file name]. 1, and as Avahi was installed, we this setting alone. Find the line # wins support
tar.gz can connect using raspberrypi:1. = no, delete the # character, and change the no
sudo dpkg -i [VNC Server to yes. Scroll down to the section labelled Share
package name].deb [VNC Install a VNC viewer from Definitions and enter the following chunk of code:
Viewer package name].deb here: magpi.cc/1M4uzfG
on your platform of choice, [pihome]
Copy the licence key you got and then connect with: comment= Pi Home
and then run sudo vnclicense raspberrypi:[Number] path=/home/pi
browseable=Yes
writeable=Yes
Via the SSH protocol, you can access From an OS X or Linux terminal, you Press CTRL+X, then Y and ENTER to save the file. To
the Raspberry Pi from any other can access the Pi remotely with: start the sharing, enter the following in the terminal
computer on your home network. and use your Pis password (raspberry by default):
SSH should be activated by default, $ ssh pi@raspberrypi
but to make sure it is on, you can go smbpasswd -a pi
to Raspberry Pi Configuration from You will need to set up a network
the Preferences category in the Menu name (see box on previous page).
(or by typing sudo raspi-config Type yes to trust the connection,
from the command line) and ensure then enter the password raspberry to
SSH is turned on in the Interfaces tab log in. If using PuTTY, just type pi@
(or under the Advanced menu in the raspberrypi into the address field
command-line version). If SSH was and click Connect. Again, youll have
disabled, enable it and reboot. to agree to trust the Pi Zero, then use
In OS X and Linux, you can use SSH the password raspberry.
from the terminal; in Windows, You can now control the Raspberry
however, youll need to download Pi in as you would normally do via
Above The configuration file looks complicated, but you only need
PuTTY (magpi.cc/1Mm5Npi). the command-line. to change a couple of bits!
WEB-CONTROLLED HTPC
Turbocharge your TV with nothing more than an HDMI cable and a wireless dongle
Project
n HTPC (home theater PC) is an excellent use
A for the Raspberry Pi, and a very popular one
Project ULTRA-LOW
data PROFILE FILE SERVER
CATEGORY:
Utility
Upgrade your network-
Project
DIFFICULTY:
Easy attached storage by making it
much, much smaller INCOGNITO data
The Raspberry Pi is the perfect low-power file
COMPUTER CATEGORY:
Fun
server for your home, requiring very little wattage
Keep your Raspberry Pi
to keep running when idle, while also being very DIFFICULTY:
easy to access remotely via SSH over the network. Zero hidden and safe in an Easy
With an original Raspberry Pi, it was a small setup,
inconspicuous tin of mints
but now with a Pi Zero you can basically have a NAS
ZER0
RASPBERRY PI
box that is no bigger than While you wait to get a case for your Raspberry Pi Zero,
the actual storage itself. theres a few things you can do to keep it safe from
Get a small USB hub, a a normal dusty environment; you could keep it in an
portable USB hard drive, anti-static bag, the blister packet it came with on top
and a tiny USB dongle of this magazine, or you could keep it hidden inside
and youve got yourself an Altoids tin.
a complete NAS box All youd need to do is affix it to the tin, either with
that can be controlled Blu-Tack or some carefully measured and drilled screw
from anywhere on your mounts, and cut a few holes to allow for connecting
local network. the normal cables to it. Quick, simple, and it makes
you feel like a spy.
Project
data
PI ZERO GPIO
SOLDERING
CATEGORY:
Utility
DIFFICULTY:
Medium
The Pi Zero comes with a full-size GPIO header but no pins. Even if
youve never touched a soldering iron before, dont panic: fitting the
pin header block can be a quick and easy job
Need
(GPIO), then you have a decision to make: you
can solder your wires directly to the unpopulated GPIO
header and dedicate the Pi Zero to the job, or you can
> 2.54mm Male Pin solder a header block and make it easily detachable -
Headers
magpi.cc/
just like on the Zeros bigger siblings.
1PCpMVa
> Soldering Iron Preparation Above Take your time when soldering the pins, and be careful not
and Solder Before you plug your iron in, get your workspace ready. to connect two or more together with excess solder
magpi.cc/ That means making sure that its free from anything
1Oa5ksX
breakable or flammable, that youve put something Finally, moisten your sponge, plug the iron in, and
> Blu-Tack protective down on the surface to guard against clean the tip by melting a small amount of solder
(optional)
scorching from solder splashes, and that youve laid directly to the metal before wiping it on the sponge.
> HAT (optional) everything out where you can easily get to it.
The GPIO header blocks themselves, technically Soldering
known as 2.54mm male pin headers, will also need Putting the iron back in its stand for now, begin by
some preparation. Theyre typically supplied in rows of putting the pins through the GPIO block of the Pi Zero,
36 or more, while the Pis GPIO block is laid out in two with the short ends sticking through and the black
rows of 20. Thats easy to rectify: count 20 pins out, plastic blocks resting on the circuit board. Youll need a
then put your fingernails in the divot between pins 20 way to hold these in place while you flip the Pi Zero: try
and 21 before snapping the excess off with a twist of a blob of Blu-Tack or, if you have one, insert the long
your fingers. Do this twice and youll have the precise ends of the pins into a HAT or other accessory with a
number of pins required. female GPIO header.
Flip the Pi Zero over to expose the short pins, and
Pick an iron with a begin soldering. Making sure the pins are properly lined
reasonable power up, target the bottom-right pin first. Place the heated
output, not below
25W, and with a iron against both the leg of the pin and the copper-
reasonable fine coloured soldering point, and wait a couple of seconds
tip - not the sort of
thing youd use for for it to heat. Then, without removing the iron, touch
plumbing repairs! the solder to the base of the pin. It should melt, then
be quickly sucked into the hole to make a conical
Pin headers are connection; if not, reposition your iron and try again.
usually supplied
in odd-numbered
With one down, its now merely a question of
quantities, but repetition: keep soldering each pin in turn, making sure
they are easily
snapped to
not to use too much solder and cause a short, until they
length with are all complete. Clean your irons tip, allow the Pi Zero
nothing
more than
to cool, and youre ready to attach some GPIO hardware
your fingers. or, optionally, wash off the soldering residue with flux
cleaner fluid for a neater finish.
Youll
Need
> A 3D-printed
KOROBOT shell
and wheels,
or some craft
materials
ZER0BOT
Robots are always fashionable projects for Pis. The Pi Zero
makes it possible to create even smaller programable vehicles
magpi.cc/
1PCfwMK he tiny form factor of the Pi Zero means cause the motor to rotate, you provide a sequence
> HC-SR04
ultrasonic sensor
T you can develop equally titchy and highly
manoeuvrable bots. The Pi is not the only thing
of high and low levels to each of the four inputs.
The direction can then be reversed by reversing the
magpi.cc/
1PCfAMs
to get itself a zero makeover. The fabulous GPIO Python sequence. In the case of the 28BYJ-48, there are four-
library has recently been made even more user-friendly step and eight-step sequences. The four-step is faster,
> Two 28BYJ-48
stepper motors &
and accessible through the new GPIO Zero library. but the torque is lower. The example code lets you specify
ULN2003A driver Combined with the latest version of Raspbian (Jessie), the number of steps through the seqsize variable.
boards we can also omit the sudo before running our scripts. Each motor has a connector block at the end of its
magpi.cc/
1PCfCE3
Coding robots has never been easier or smaller! coloured wires that slots into the white header on
First of all, make sure youve got the latest version the ULN2003A. The GPIO pins controlling that motor
of pip for Python3: connect to the four input pins below the IC, while the 5V
power and ground connections go to the bottom two pins
sudo apt-get update on the right (see Fig 1).
sudo apt-get install python3-pip
Eyes to see
Then install GPIO Zero (gpiozero) and the library well Well give our ZeroBot some simple eyes that allow it
use for our robots eyes. to detect obstacles, courtesy of the HCSR04 ultrasonic
sensor. This has four pins, including ground (GND) and
sudo pip install gpiozero hcsr04sensor 5V supply (Vcc). Using Python, you can tell the Pi to
THE CASE send an input signal to the Trigger Pulse Input (TRIG)
This bots body is Stepper motors by setting a GPIO pins output to HIGH. This will cause
3Dprinted, but The 28BYJ-48 is a cheap but versatile stepper motor that the sensor to send out an ultrasonic pulse to bounce off
the lightweight
requirements can normally be bought with an ULN2003A driver board nearby objects. The sensor detects these reflections,
mean that for under 4. Stepper motors can be programmed to measures the time between the trigger and returned
you can easily move in discrete steps rather than just turned on/off like pulse, and then sets a 5V signal on the Echo Pulse
make one out
of household servos. Using the Pi Zero, youll be able to control the Output (ECHO) pin. Python code can measure the time
scraps. speed and positioning of the motors very accurately. To between output and return pulses. Connect the HC-
zerobot.py Language
import time, sys
>PYTHON
import gpiozero as g0
from threading import Thread
import hcsr04sensor.sensor as sensor DOWNLOAD:
github.com/top-
IN1_m1 = g0.OutputDevice(17)
shed/ZeroBot
IN2_m1 = g0.OutputDevice(18)
IN3_m1 = g0.OutputDevice(21)
IN4_m1 = g0.OutputDevice(22)
StepPins_m1 = [IN1_m1,IN2_m1,IN3_m1,IN4_m1] # Motor 1 GPIO pins
IN4_m2 = g0.OutputDevice(19)
IN3_m2 = g0.OutputDevice(13)
IN2_m2 = g0.OutputDevice(5)
IN1_m2 = g0.OutputDevice(6)
StepPins_m2 = [IN1_m2,IN2_m2,IN3_m2,IN4_m2] # Motor 2 GPIO pins
Seq = [[1,0,0,1], # Define step sequence
[1,0,0,0], # as shown in manufacturers datasheet
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
Fig 1 Theres a lot of wiring for this bot. If motors dont turn as
[0,0,1,0],
expected, check the GPIO pins for the coils are connected correctly
[0,0,1,1],
[0,0,0,1]]
SR04 as shown in Fig 1. Its ECHO output is rated at 5V, StepCount = len(Seq)
all_clear = True
which could damage the Pi. To reduce this to 3V, use
running = True
two resistors to create a simple voltage divider circuit,
as shown. def bump_watch(): # thread to watch fro obstacles
The hcsr04sensor Python library provides a simple global all_clear
interface to enable our bots eyes. Once you have all your while running:
components connected, you can test the code on a bench value = sensor.Measurement(20, 16, 20, 'metric', 1)
if value.raw_distance() < 10: # trigger if obstacle within 10cm
before building the full robot. Point the eyes away from
all_clear = False
else:
all_clear = True
Youll W communications industry branched and that the body of the HAT is covering the body of
Need
out into consumer products and became the Pi Zero, then push down firmly.
the Internet of Things (IoT), it was only natural it
would focus on easy wins, and with programmable >STEP-02
> GPIO headers RGB LEDs dropping in price, mood lighting was Install software
magpi.cc/
a great start. What took companies like Philips years Youll need some extra software to run the Unicorn
1PCpMVa
of research and development, though, can now be HAT, which can pose a problem for the network-less
> Unicorn HAT
achieved by the hobbyist in minutes. The Pi Zeros Pi Zero. You can either connect a USB WiFi dongle
magpi.cc/
1PCpRZ5 low power draw and small size make it perfect for with a USB OTG adaptor, or remove the microSD
adding intelligence to even the smallest of household card and insert it into a networked Raspberry Pi to
> USB WiFi dongle
or second gadgets, and existing LED HATs are entirely perform this step.
Raspberry Pi compatible, meaningyou can build something At the terminal, type the following three commands
magpi.cc/
smart-looking in well under an hour. to install the software youll need to control the
1PCpVb5
Unicorn HATs numerous LEDs:
> Diffuser or
lamp housing
>STEP-01
(optional) Install Unicorn HAT sudo apt-get update && sudo apt-get
If your Pi Zero is fresh from the factory, youll need to upgrade
solder on a set of GPIO headers before you can attach a sudo apt-get install python-dev
HAT (Hardware Attached on Top). If you havent done sudo pip install unicornhat
so, head on over to page 23 to see how this is done.
With headers in place, installing the Unicorn HAT is If youre using a networked Pi for this, shut down
no more difficult than with any other Pi model: place when youre done and put the microSD card back
it carefully on top of the male pins, making sure that in the Zero.
>STEP-04 i = 0.0
offset = 30
Configure on-boot behaviour while True:
Nobody wants to have to plug a keyboard and mouse i = i + 0.3
into their lamp every time they turn it on, so we want for y in range(8):
the rainbow.py code to run every time the Pi Zero is for x in range(8):
switched on. At the terminal, type: r = 0#x * 32
g = 0#y * 32
xy = x + y / 4
sudo nano /etc/rc.local
r = (
math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0
Type the following line in, just below the lines g = (
commented out with hash symbols: math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0
b = (
python /home/pi/rainbow.py & math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0
r = max(0, min(255, r + offset))
g = max(0, min(255, g + offset))
The last symbol, an ampersand, is important: it
b = max(0, min(255, b + offset))
allows the Python program to run in the background
unicorn.set_pixel(
and not tie up the Raspbian boot process. Save with x,y,int(r),int(g),int(b))
CTRL+O, and exit with CTRL+X. unicorn.show()
time.sleep(0.01)
>STEP-05
Shut down and install Left The small size of
By itself, the Unicorn HAT is a little distracting. To the Pi Zero means its
tone things down a little, have a look in cheap or hidden away entirely
underneath most
second-hand electrical shops for a lamp functional HATs, making for a
or otherwise from which you can steal a diffuser. compact build
Project
Stats
CATEGORY:
Fun
DIFFICULTY:
Medium
This enclosure
is watertight, so
take this project
in the rain or on
the open seas
Youll
Need
ZER0 GPS
LOGGER
> USB GPS
receiver
> Enclosure
> Micro-USB to
USB adaptors
> GpsPrune
magpi.cc/
Track yourself anywhere on Earth by making your own tiny,
1PxO5Fg hackable GPS logger and map viewer
sing off-the-shelf components and a GPS basics
U Raspberry Pi Zero, you can create a small and
inexpensive GPS location logging device to
As were sure you know, GPS technology uses
satellites orbiting the Earth in order to determine your
take hiking, kayaking, or in the car. And since the position with longitude and latitude coordinates. So
Raspberry Pi is a full computer, you can even connect as you work on this project, it helps if the GPS receiver
a monitor, keyboard, and mouse to it so that you can has a clear line of sight to the sky. If youre working
view your routes on a map and analyse the data youve indoors, you may want set yourself up near a window
collected. In this project, youll learn about how GPS and have the GPS receiver positioned facing upwards
devices deliver location information over serial, and outside the window.
how you can use Python to parse and save that stream Most USB GPS receivers should work, but wed
of data to a file. definitely favour those devices that have clear
$GPRMC,204311.602,A,3747.3392,N,12223.8954,
W,0.50,324.18,061115,,,A*7A
Above GpsPrune runs on the Raspberry Pi Fig 1 The key fields of an Parsing the data and saving it
and lets you view the data on a map NMEA RMC sentence
While there are drivers and code libraries for working
with GPS devices, we decided to parse the NMEA
DATA DESCRIPTION FORMAT
sentences manually in Python, since that language
$GPRMC Protocol header is especially good for working with text. The main
purpose of the Python script is to log the latitude and
204311.602 Time (UTC) hhmmss.sss longitude to a text file with comma-separated values.
Thats what it does in the main loop at the bottom of
A Status A (valid) or V (not valid) the code. You might notice that it will only log to file
when theres a valid fix. You can tell if theres a valid
3747.3392 Latitude ddmm.mmmm
fix when the status field has the letter A.
Northern / Southern N or S The code has two helper functions. The first helper
N
Hemisphere indicator function takes the full NMEA sentence and creates a
Python dictionary out of the data. This just makes the
12223.8954 Longitude ddmm.mmmm data easier to work with in case you want to enhance
the script for your project.
W Eastern / Western E or W The other helper function takes the degrees-minutes
Hemisphere indicator and hemisphere data that the GPS outputs and converts
it into decimal degrees. Working with decimal degrees
061115 Date ddmmyy
will be easier if you want to enhance the project to
Project
data
The Pi Zero
is a great size
for wearable
technology
CATEGORY:
Utility
DIFFICULTY:
Advanced
Youll
Need
PI ZER0
CONFERENCE
> Battery
> Display
BADGE
(optional)
> Accelerometer
(optional)
> WiFi or Bluetooth Why settle for a scrappy piece of paper shoved in a plastic wallet when
breakout board
(optional) you could provide your conference guests with an interactive slice of Pi?
onference badges can be very dull: a boring
C piece of card with your name on the front
and if youre lucky a brief schedule on the
back. The Pi Zero offers some fantastic opportunities
for producing a truly disruptive digital badge.
The possibilities are endless, but there are a couple
of key things youll probably want to include: a
battery and a display.
As it is going to be hanging around someones
Right A small
neck, weight is obviously a key issue. A standard
LCD would be
sufficient to show power bank (like the ones used for recharging
the delegates
phones) would probably be too heavy, but some of
name and basic
information the skinnier credit card-sized examples might be
THINK OF IT LIKE
A PI VERSION OF BADGEr
These were produced for the Open Hardware
Summit in 2013 and based on the Arduino derivative
ATmega328. The Pi Zero allows you to have a fully
functional Linux computer hanging from your lanyard
and takes this concept to the next level.
and talk to the Pi Zero that way. But why not weight and battery life of your badge. Unless youre
make it easier by adding some buttons and a small really out to impress, some of the more advanced
digital joystick (like the one on the Sense HAT)? functionality might be overkill for a simple, one-off
A simple on-screen menu could allow the delegate conference. Adding in and supporting any kind of
to customise their display (even seemingly tiny network architecture is not for the faint-hearted.
modifications like changing the font and size can However, if you run regular events and have your
have a big impact). own site, it might be worth the extra development
Why stop there? Add a version of Snake or Flappy time. If thats the case, you might also consider a
Bird to keep the attendees occupied in the lunch final enhancement: how about some kind of RFID
queue. Store the conference schedule on the Pi Zero capability to stop people forgetting to hand
and enable that to be displayed on the screen too. An in their badges after their visit.
Project Youll
data Need
CATEGORY:
> Bare Conductive
Fun Electric Paint
magpi.cc/
DIFFICULTY:
1SKZeRE
Easy
> LEDs (even
better if you can
get components
designed for
ZER0
RASPBERRY PI
e-textiles)
PI ZER0
OTHER THINGS TO MAKE WITH
Hack a toy
Grab something
from a budget
store and open
it up youll be
amazed at what
you can do!
Youll
Need POTHOLE
MAPPER
> A Microstack GPS
module
magpi.cc/
1Sx0BCP
> A box, some small and low-power project-friendly device, The Adafruit You don't need
cable ties, and it's still a little chunky for some applications. LSM303 contains an a Microstack
a bike accelerometer and baseboard just
However, the Pi Zero's tiny form factor opens up a a magnetometer connect directly
whole range of possibilities in this case, mounting it to the pins on the
GPS module
to the forks of a bicycle. Well use an accelerometer to
measure the deflection of the sensor as you bump and Python2 only. You can either update it yourself, or
bounce around the mean streets of wherever you live, download a modified version by cloning the GitHub
and use a GPS module to record your position. repository for this project.
into the Pi Zero and bending the legs, this is only really
good enough for simple bench tests, so youll need Connect the accelerometer as shown in the main
to add a permanent male header that can be used for image, and then run the example Python script to test
prototyping and the final device. Make sure your Pi that it works.
Zero is held tightly when soldering the header, and
avoid touching any of the adjacent components with cd PiPotholeMapper
the tip of the iron. python3 Adafruit_LSM303.py
Now configure the Pi using the new Raspberry Pi
Configuration GUI tool that comes with the Jessie Jiggle the LSM303 around and you should see the
version of Raspbian: under the Interfaces tab, enable changing values for the x, y and z axes displayed.
I2C and disable Serial.
>STEP-03
Below Use your
>STEP-02 Find my Pi
data to map out the Accelerometer Now add the GPS module. Once again, there are several
ruts and potholes
on the roads around
There are plenty of accelerometers available, but this available. This tutorial describes the Microstack board
you. Hack the tutorial assumes youre using the LSM303 which also because it tends to be one of the cheapest. Dont worry
code to adjust the
granularity of the
includes a magnetometer. Unfortunately, the latest if you havent got a Microstack Base Board, however,
plotted points official version of the LSM303 Python library is for as were going to connect the GPIO pins directly to the
GPS module itself.
pothole.py Language
and carry out the trilateration process needed to
calculate position. You should see a red LED start to
flash on the board after a few minutes; this means it >PYTHON 3
has received a GPS lock and knows its position. import microstacknode.hardware.gps.l80gps as mst
import lsm # Our Python3 version of the LSM303 DOWNLOAD:
>STEP-04 library magpi.cc/1PKzk0j
Project
TRUE
All Raspberry
Pis include
data
an integrated
hardware random
number generator
(HWNG), and the Pi
CATEGORY: Zero is no exception
RANDOM
Utility
DIFFICULTY:
Advanced A cheap dongle lets
you connect the
NUMBER
3.3V TTL serial on
the Pis GPIO header
GENERATOR
If the security of your servers is
important to you, get the benefit of a
hardware TRNG without the expense
with this low-cost build
N
o server administrator would argue that With the Pi Zero powered on, enter the Raspberry
Youll cryptography isn't important, and few would Pi Configuration tool by typing the following at the
Need
try to claim that cryptography without console (or in a terminal):
entropy - a source of good-quality randomness - is
in any way secure. Previous solutions to the problem sudo raspi-config
> 3.3V USB TTL have included everything from webcams pointing at
serial dongle lava lamps, to expensive hardware random number Choose 8 Advanced Options, A8 Serial, and confirm
magpi.cc/
1HVkwWn
generators. However, you can achieve the same effect that you do not want the serial console active by
for your Linux server with your Pi Zero, thanks to a choosing No. Choose Finish then allow the Pi to
> Female jumper
cables hardware random number generator (HWRNG) built reboot; this will free up the serial port on the GPIO
magpi.cc/ directly into its chip - and at a fraction of the cost of header for our own use, rather than automatically
1HVnLNx an off-the-shelf equivalent. spawning a console session.
> GPIO headers
magpi.cc/
1PCpMVa
>STEP-01 >STEP-02
Prepare the Pi Activate the HWRNG
If you havent yet soldered GPIO headers onto your Pi While all Pis have a built-in hardware random number
Zero, head over to page 23 to see how its done. generator, its disabled by default. To enable it, edit
the modules file with the following command:
bcm2708-rng
Right You only need
to connect the TX
Place a blank line beneath it, then save the file and
and Ground pins
on the Pis GPIO quit by pressing CTRL+O and then CTRL+X. To avoid
header, but make
having to reboot again, finish with the following
sure you havent
made a mistake! command at the console:
Project
data
CATEGORY:
Entertainment
DIFFICULTY:
Advanced
CONSOLE-TROLLER
Slip a Raspberry Pi Zero into the casing of a USB NES
Youll controller and youve got yourself a fully working NES
Need emulator in ultra-compact form
> USB NES Below We bought
hile were big fans of the educational mission
W
controller this NES controller
of the Raspberry Pi project, and we fully from eBay: we had
> Micro-USB male to file down the
connector support it of course, wed be lying if we plastic a little bit
> Solder
said we dont love to use the Pi for entertainment to slot in the Zero
as well. Whether its the Pi we have stuck to the
> Drill
back of the TV for streaming media, or gaming with
> RetroPie RetroPie, the Pi is well suited to these uses. So when
magpi.cc/
1HVgNba we first heard of the Pi Zero, we thought of all of the
great hacks that Ben Heck has done over the years,
and we realised that the Pi Zero could perfectly slot
into a USB NES controller. With a bit of creative
wiring, it could be made into a fully functional games
console that exists entirely in the controller itself.
THINK OF The USB NES controllers all have a standard USB Once all the hardware is complete, you can then set
IT LIKE cable; this provides enough power to the controller so up RetroPie (magpi.cc/1HVgNba) on a microSD card.
that the individual button presses can be registered. If you have a spare Raspberry Pi lying around, it might
Atari Plug n Play In order to repurpose the controller, begin by snipping be best to get the initial setup sorted on there first
TV games
off the original USB cable that pokes out of the rear before plugging it into your NES controller to set the
The originator of the unit. You can now solder the wire to a male buttons. Remember that you only have the buttons
of the console micro-USB port. This way, you can use the hole for which exist on an NES, so make sure any games you
in a controller
concept popular the trailing USB cable for the mini-HDMI cable. put on there dont require more than you have.
at Christmas, but Youll need to find a cable that has a relatively short Finally, plug it into a TV and have some fun!
a bit limited once connector. Alternatively, you could drill the hole
youve played
every possible larger to accommodate it.
variation of Pong The only thing remaining to make the whole
and Asteroids thing work is to give the Raspberry Pi power. Youll
either have to drill a second hole so that you can
plug the power cable in, or you may be able to use
the original hole depending on the design of the USB
NES controller you have and how the mini-HDMI is
mounted. Alternatively, you could try binding the
USB and HDMI cables together; in this case you will
need to use a television with a USB port that will
provide adequate power.
PRINT YOURSELF A
PI ZER0 CASE
Get a 3D-printed case today for your brand new Raspberry
Pi Zero with our pre-designed, printable case!
Below Print your
own Pi Zero case
with our design: it
has our name on it!
SUBSCRIBE TODAY!
Subscribe to the Official Raspberry Pi mag today for a whole host of benefits
FREE
Subscription benefits
ZEBRO
Save up to 25% on the price
Free delivery to your door
LES
CA Never miss a single issue
WITH YOUR
SUBSCRIPTION #40 free Zero cable bundle
SAVE
UP TO
25%
Address ........................................................................................................................
30 (UK) *If giving The MagPi as a gift, please complete both your own details (above) and the recipients (below).
Address ........................................................................................................................
Address ...........................................................................................................................
80 (EU) ........................................................................................................................................
n n n n n n Account number n n n n n n n n
Branch sort code
Direct Debit
bank/building society.
MAGIC
A network engineer and aspiring
professional geek who loves to use
and sing the praises of the Raspberry Pi.
imgur.com/A4kjx7w
MIRROR
Mirror mirror on the wall, whats
Its an extra-useful mirror It looks like a mirror, but its
the weather going to be like today? as it displays up-to-date actually a cunning disguise
weather information taken a monitor, and some two-way
Should I bring an umbrella? from the internet glass covered by a frame
Facts
people due to the way
they portrayed almost-attainable
technology. Watching someone
> The project look over sunny Malibu while the
is made with
Google Coder weather info was displayed right
in front of them was a great visual.
> It took a week
to do the frame, Its not exactly brand new, unseen
a few days for technology cars have been
the code
projecting HUDS onto windscreens
> This is Bradleys for a while now but it has never
first creative
been popularised in a major
Piproject
blockbuster before. While we
> In the past, he
dont seem to have quite reached
has used Pis in
his home Cisco the stage of the incredible glass
networking lab tech of Tony Starks bedroom just
> The online yet, apparently were close enough
community to get mirrors working in the same
helped a lot to
way, or at least Bradley Melton has
get this to work
managed it with his Magic Mirror.
Its called a Magic Mirror,
buta more accurate name would
be a Smart Mirror, Bradley tells
us. Its a mirror that displays the
information you need to knowat
a quick glance: the time,the
date, the weather, and of course
a compliment!
Its not the first mirror of its
type, and Bradley admits that hes
taken some cues from a previous
project by Michael Teeuw (see more
details about it on Michaels blog:
magpi.cc/1PzFbWa), taking the
concept and bringing it down to
a more beginner level for himself
so he could learn more about Of course, a mirror should
also be able to reflect your
webdevelopment. image and make sure youre
Plus, because I know what each looking good
A TECH REFLECTION
Quick
Facts
> 580lb (263kg)
of high-density
plastic was
used in the
construction of
SeeMore
SEEMORE
THE PI-POWERED PARALLEL
COMPUTING SCULPTURE
> It comprises
1,280 moving
parts and
7,312 pieces of
hardware
Powered by a cluster of 256 Raspberry Pis, Virginia Techs
> 1,320ft (402m)
of extruded stunning kinetic sculpture gives a visual representation
aluminium was
used to create of how parallel processing works
the framework
> SeeMores tanding nine and a half panel, whose articulating arm to help create an interactive art
construction
involved 60
hours of CNC
S feet tall, the SeeMore
sculpture-cum-
swings outwards whenever that
particular Pi is actively working on
installation for that purpose. Since
Sams main area of interest lies in
machining supercomputer suddenly whirrs a parallel computing task. robotic creations, he immediately
and 80 hours
of volunteer into life, its green translucent The idea for SeeMore originated suggested making a kinetic
assembly panels sliding fluidly outwards in 2013 when Virginia Tech (vt.edu) sculpture that responds to whats
> It takes around in mesmerising waves across its computer science professor Kirk going on inside the computer.
one and half spiral surface, delivering a physical Cameron was working on a 32- LCDs are cool, explains Sam,
days to wire representation of the computations node Raspberry Pi cluster in his but you can really get a visceral
it all up, using
1,536ft (468m) being performed. Resembling lab. Seeking a way to help more reaction from people by showing
of USB cable something from a science-fiction people understand the concept of them something that is moving
and 2,200ft movie, SeeMore is powered by a parallel computing, he approached and has a presence in a space.
(670m) of
Ethernet cable network of 256 Raspberry Pi Model his colleague Sam Blanchard, Sam tells us that the cylindrical
B+s; one is attached to each plastic assistant professor of sculpture, design of SeeMore was partially
Scaling it up
Having started out with a modest
budget, the project was gradually
scaled up via three prototype
stages, which used first one
Raspberry Pi, then nine, and then
30 (see Prototyping process
boxout). Extra funding was
subsequently provided by the
National Science Foundation and
Virginia Techs own Institute for
Creativity, Arts and Technology,
which enabled it to be scaled up to
the final 256-node version.
SeeMores mechanisms were
all custom-made and designed by
Sam, and their design evolved over
time. Most notably, the articulating
arms that move the panel-mounted
Pis were designed specifically to
create a more fluid effect. The
Above Each panel When SeeMore was exhibited database of points of interest. In movement of the Raspberry Pis is
moves out in
proportion to its recently at the World Maker Faire this example, the Pis in our cluster actually a curve so it doesnt just
Pis workload in New York City, it was set up with would be assigned portions of a flap out, it articulates outward,
a local open-source database to database to search and all of them says Sam. It has a double linkage
enable users to search (via a custom would be given the same subway that some might see as superfluous,
touchscreen) for points of interest stop as their token to use in the or overly complex, but I think that
around a given subway stop. Kirk search. This divide-and-conquer what you get is this waveform
tells us that multiple steps are approach is a common algorithm that relates to these ideas of fluidity
required to for such a task. The used in parallel computing and and that springs from what a lot
first is to break this problem into this example is similar to the of parallel computers are built
smaller sub-tasks such as having algorithm used in Google search to process: things like weather
each Pi search part of a very large and demonstrated on SeeMore. simulation or fluid dynamics.
BUILD CONTINUED...
PROTOTYPING
Also, rather than moving straight hours machining those pieces,
to its maximum 90-degree outward laughs Sam. He tells us that this
PROCESS
position when triggered, each provided students with many hours
panel moves in proportion to the of milling experience.
percentage of computing capacity The plastic panels are all laser-cut
being used by the respective and etched with the IP address of Before scaling up to the final full-scale version of
Raspberry Pi. To achieve this, the attached Pi in two places, so they SeeMore, three prototypes were created
each Pi is linked to its arms can be seen whether the panel is flat
servo via a GPIO pin. While in the or has moved out. Having started
prototype designs, the servo also out with blue and clear panels, the
received its power from the Pi, a team changed them to a translucent
switch from the original Pi Model green for the New York Maker Faire.
B to the B+ for SeeMores final I like the idea of customising the
version necessitated that both be project for where we show it.
EVERYDAY
Simon Monk is the author of
the Raspberry Pi Cookbook and
ENGINEERING PART 10
Programming the Raspberry Pi: Getting
Started with Python, among others.
simonmonk.org
monkmakes.com
PIPE
TEMPERATURE
MONITOR Solve real-world electronic and engineering problems with your Raspberry Pi
Youll and the help of renowned technology hacker and author, Simon Monk
Need
t this time of year, our roof spaces can get temperature measured by a temperature sensor falling
> Encapsulated
DS18B20
A pretty chilly and if there are pipes up there,
there is a chance they could freeze. As anyone
below some threshold.
The way this works is that the Raspberry Pi sends
(eBay, Adafruit,
ProtoPic)
whos put a bottle of wine in the freezer to cool and a web request to IFTTT as a trigger and then IFTTT
then forgotten about it knows, ice takes up more space performs whatever action you have specified for it.
> 4.7k resistor
(often supplied than water and can burst pipes as it expands. This is In this case, the trigger is to send an email.
with DS18B20) often only discovered when the ice thaws again and The various channels available to IFTTT often
> Three-way screw your bedroom has water dribbling through the ceiling. require their own logins, so IFTTT will from time
terminal block This project monitors the temperature of your pipe to time ask you to enter a user name and password
> 3 female-to- and uses the If This Then That (IFTTT) web service to for a particular channel.
male jumper alert you by email or other mechanism of your choice
wires
WARNING!
if the temperature falls below a threshold that you set.
> USB WiFi IFTTT is a web service that allows you to set up
adaptor
triggers that then cause an action. For example, you
> Small food could create an IFTTT Recipe that sends you an
container as Do not rely solely on this project to protect your pipes
email (Action) whenever someone mentions you on
anenclosure from frost. This is a DIY project intended to illustrate the
Twitter (Trigger). As well as actions and triggers from principles of making a temperature monitor and is in no
> Drill
all sorts of social media and email services, IFTTT can way guaranteed to protect your home.
also be set up to work with physical events like the
DS18B20 is a digital
device, accurate to >STEP-01
0.5 degrees C Connect female header leads
Put the red (positive supply), black (ground), and yellow (data) wires from
the temperature probe into the screw terminal, with the leads of the
As youll see from the list of required components,
resistor between the red and yellow wires. You may find it helps to wrap the
this project does not call for any soldering. The
bare ends of the wires around the resistor leads before tightening up the
leads to the temperature probe are connected to screw terminals.
the Raspberry PI GPIO pins using a combination of Fit the male ends of the jumper wires into other half of the terminal block.
electrical terminal block and female-to-male jumper Your probe lead may also have a separate bare wire connector to the
wires. You will find the screw terminal block at any leads screening; you do not need to connect this to anything.
DIY or hardware store that sells electrical supplies.
>STEP-03 use SSH for, so that you can connect to the Raspberry
Pi remotely using the WiFi USB dongle. You can find
Start a new recipe in IFTTT
If you dont have one already, instructions on setting up your Pi to use SSH on the
create yourself an account on official website: magpi.cc/1GULmTr.
IFTTT (ifttt.com). Then click on Before you can use the DS18B20 temperature sensor,
the Create a Recipe button. you need to enable the 1-wire interface of the Raspberry
Pi. To enable 1-wire, edit the file /boot/config.txt using
>STEP-04 the command:
Create a Maker Channel Trigger
Click on the IF part of the new sudo nano /boot/config.txt
recipe and search for the Maker
Channel in the list of channel icons Add the following line to the end of the file:
that is shown. Select the only
trigger option available (Receive dtoverlay=w1-gpio
a web request) and enter the
text pipe_alert into the Event
Now reboot your Raspberry Pi and 1-wire should
Name field.
beenabled.
>STEP-05 You can download the program for this project from
your Raspberry Pi command line using:
Choose an Action
Now we come to the THAT part of
IFTTT. So, click on THAT and select git clone https://github.com/simonmonk/
the Email action channel, and then pi_magazine.git
select Send me an email. This
will use the email address that Before running the program, open it with the nano
you specified when you signed editor and change the line:
up to IFTTT.
Complete the action fields. KEY = cyR3vPNFlP9K32W4NZB9cd
The subject field will become the email subject, and the body field
will contain the text of the email. Notice the use of the special names
Change this to the IFTTT key that you found earlier. Run
contained between {{ and }}. These are called ingredients and allow
the program as superuser using the command below:
you to customise the text. In this case, the OccuredAt is a timestamp
for when the trigger event happened, and value1 will contain
the temperature. sudo python pipes.py
Language
The constant MIN_T_BETWEEN_WARNINGS prevents
messages being sent more frequently than once every
hour. You might want to change this while you are Pipes.py >PYTHON
testing theproject.
import glob
The next set of variables are used to identify the
import time
location for the file of your particular temperature
import urllib, urllib2
sensor. This will be in the folder /sys/bus/w1/devices/,
but then the folder name after this will be different for ALARM_TEMP = 5.0 # degrees C
every DS18B20. MIN_T_BETWEEN_WARNINGS = 60 # Minutes
The function read_temp reads the content of the EVENT = 'pipe_alert'
device file. This will be a two-line message from the BASE_URL = 'https://maker.ifttt.com/trigger/'
temperature sensor that looks something like this: KEY = 'cyR3vPNFlP9K32W4NZB9cd' # Place your own key here
>STEP-03
Basic GPIO Zero
The LEDs have a GPIO number attached, as do the
button and buzzer. We can use that in conjunction
Above We wrote the code on a computer and moved it to the with GPIO Zero to activate the LEDs manually in the
Raspberry Pi, but theres no difference from writing it on the Pi itself GPIO Zero style. Open up a new Python script in IDLE
TrafficLights.py Language
>PYTHON
from gpiozero import TrafficHat
from time import sleep
th = TrafficHat()
try:
while True:
# Traffic light code
Above You can also install the GPIO Zero software under Python 3; # First, turn the green LED on
in fact, its recommended by the creator. However, youll need to th.lights.green.on()
change the print lines in our code
print "Press the button to stop the lights!"
and start it with the following code, so it knows what
# Next, we want to wait until the button is pressed
functions to use:
while(th.button.is_pressed == False):
#While not pressed do nothing
from gpiozero import LED pass
Then write in the following so the red LED, # Button has been pressed!
connected to GPIO 24, lights up: th.lights.green.off()
# Amber on for a couple of seconds
led = LED(24) th.lights.amber.on()
led.on sleep(2)
th.lights.amber.off()
# Turn the red on
Press F5 to run it and see the results. Buzzer and
th.lights.red.on()
Button are the other functions that you can import
# Buzz the buzzer 20 times with 0.1 second intervals
for the Traffic HAT.
th.buzzer.blink(0.1,0.1,20,False)
sleep(1)
>STEP-04 th.lights.red.off()
Dedicated GPIO Zero # Red off and blink amber 4 times with 0.5 second intervals
A slightly easier way of programming the Traffic HAT th.lights.amber.blink(0.5,0.5,4,False)
with GPIO Zero is by using the actual Traffic HAT
function built into Zero. You can make use of it by except KeyboardInterrupt:
changing the first import line to: exit()
MIKES PI BAKERY
Veteran magazine author from the old
days and writer of the Body Build series.
Co-author of Raspberry Pi for Dummies,
Raspberry Pi Projects, and Raspberry Pi
Projects for Dummies.
magpi.cc/1NqIdHU
3D viewer
Side-by-side
stereo images
Miniature tripod
3D STEREO IMAGES
See 3D images on your Raspberry Pi monitor - through a viewer,
Youll through a 3D monitor, or with nothing added
Need igital imaging offers many options for both an ordinary monitor is simply that our eyes are not far
> Thin self-
adhesive acrylic
D taking and viewing stereoscopic images, and
here we present three variations on how to
apart enough to make it work without a lot of painful
optic muscle contortions. The solution is to extend
mirrors (IKEA view them. First, there is the wiggle method, where the distance of the image by using a pair of horizontal
sells them)
the left and right image are flashed alternately on miniature periscopes.
> 5mm foam the screen at a slow rate; while not spectacular, it The project consists of slide show software and a
mounting board
does give an impression of 3D. At the other end of viewer comprising four mirrors mounted on a plate.
> UNC the spectrum is using a 3D TV for a monitor on the This should be attached to a miniature tripod and set at
half nut
Raspberry Pi; this involves displaying the pictures side a height equal to halfway up the screen. It should be set
> 6mm thick MDF by side, turning on the 3D SBS (Side By Side) mode at a distance away from the monitor thats comfortable
220 63mm
of the TV, and donning your glasses. What we will for your eye focus. The slide show software displays
> Miniature tripod
concentrate on here is making a unique 3D viewer, full-screen images that can be in two file formats. The
> Hot-melt glue but software for the other two methods is on GitHub viewing program will display all the images in a user-
as well. Note that not everyone can see the effect: selectable folder, advancing the image on a key press
only 95% of people are able to perceive the 3D in or automatically after a set period.
images presented in this way.
The stereoscopic file formats
The project There are two formats that the software can handle.
A stereoscopic image is created by taking two images The first is a normal JPEG image, but with the left
about 75mm apart to simulate those received by each and right images placed side by side. This sort
of your eyes, but the images are taken from a slightly of file might have a file extension of .jpg or .jps,
different angle. To view this, you need to feed each of which are essentially the same thing; however,
those images into a separate eye. There are quite a few the .jps extension tells you to expect a side
ways of doing this, but the main problem with using by side stereoscopic image.
40mm
the first image with any JPEG viewing application. The
trick in displaying the second image is to find where
it is: theres nothing in the file header that will tell
you it immediately follows the end of the first JPEG.
However, Python doesnt make that easy to do, and the 220mm
only strategy for finding that second image is to search
for it by looking for the JPEG header sequence of bytes
ffd8ffe1. A sure-fire way is to look from the start
of the file, but this is going to take some seconds for a 8mm 4mm
large file. You might think that halfway through the file
15mm
might be a good place to start, seeing that the MPO file
63mm
30
m
has some specific MPO metadata in it before the images.
m
However, the left and right images are not the same
22mm
size. You might think that since the images have the 11mm
same dimensions, theyd have the same size file, but in
fact they are slightly different images and they compress 25mm
m
m
into different sizes. We checked about 20 files and found
60
67mm
that while most second images were over halfway, a few
were just under. We settled on starting the search at
0.49 of the way through the file, which seems to work 75mm
for most things.
Centers of Mirrors
The screen display
Having isolated the individual images in the file, they >STEP-01
have to be scaled down to fit the screen and placed in Making the 3D viewer
the correct location. The centre of each image must be The actual dimensions will depend on the size of your monitor. The outer
placed halfway along the Y axis, and one-quarter and two mirrors must be apart by half the width of your screen, whereas the
centre of the inner two mirrors must be as far apart as your eye pupils,
three-quarters of the way along the X axis. To cope
which is normally 75mm. We made the dimensions to suit our 15 TV
with different screen sizes, the operating system must
monitor; if you are using a bigger one, make the outer mirrors further
be asked what size of screen is being used in terms
apart and larger. Dont worry if they are too big: you can always use black
of pixels. insulating tape to cut down the field of view to just half the screen.
We are using the Pygame framework for this, in a
mode not often used: full-screen mode. This is tricky
to work with, because any errors result in the system
freezing. To get round this, there is a nearly full-
screen mode that has just the window bar showing; we
used this for debugging till all errors were eliminated,
then the full-screen mode could be used. The debug
mode is defined by a Boolean variable. The full-screen
must be disabled before you can choose a folder
containing the images to show in the slide show, and
then full-screen mode can be restored for the display.
import pygame
from pygame.locals import *
import time, os
from cStringIO import StringIO
from Tkinter import Tk
from tkFileDialog import askopenfilename
pygame.init()
pygame.event.set_allowed(None)
pygame.event.set_allowed([pygame.KEYDOWN,pygame.
QUIT])
debug = False
screen = pygame.display.set_mode((0, 0))
>STEP-03 # with window bar - use for debugging
if not debug :
Make the mirrors pygame.display.toggle_fullscreen()
Cut out two 60 40mm pieces of foam mounting board for the outer pygame.display.set_caption("3D Slide Show")
mirrors, and two 30 40mm pieces for the inner mirrors, then cut pieces xs, ys = screen.get_size()
back1 = pygame.Surface(screen.get_size())
out of the acrylic mirrors to match. Use a sharp knife, or better still a erase = pygame.Surface(screen.get_size())
scalpel, to make the cuts. With the mirrors, its best to score both front back1 = back1.convert()
and back and snap them. Then peel the adhesive backing off the mirrors displayTime = 4.0 # seconds to show each image
and fix them to the mounting board; keep the clear plastic mirror covers hold = False
advance = False
on for the time being.
back = False
newList = False
sbsSwap = False # swap left and right on sbs files
mpoSwap = False # swap left and right on MPO files
Tk().withdraw()
def main():
global newList, hold, advance, back, imageList
getFolder() # get the directory to show
newList = False
interval = time.time()
while True:
image = -1
while image < len(imageList)-1 :
checkForEvent()
if newList:
newList = False
>STEP-04 break
image += 1
Fixing mirrors to the board fName = imageList[image]
Mark up the base with the lines to align your mirrors and remove the clear ext = fName[len(fName)-3:len(fName)]
plastic film protecting the surface. Use hot-melt glue to fix the two inner if ext== "mpo" or ext == "MPO":
mirrors; a miniature try square will help you get these vertical. Then fix processMPO(fName)
interval = time.time() + displayTime
the outer mirrors one at a time. You can do it by eye, adjusting the vertical elif ext== "jpg" or ext == "JPG" or
angle of the mirror as the glue sets. This is what we did; however, after we ext== "jps" or ext == "JPS":
made it we thought of a much better way of aligning the mirrors, using processSBS(fName)
a laser line from a pointer or DIY level to make sure everything lines up. interval = time.time() + displayTime
if hold :
Finally, cut and glue the blocking piece between the two inner mirrors.
# hold = image on for 1 hour
image. The displayTime variable sets how long an similar to the version used with the viewer, the scaling
image is shown when in the hold mode, this is is different. With the side by side view, the images are
extended to an hour. scaled with the correct aspect ratio. However, when
a 3D TV goes into a side by side mode, it pulls half
Other versions the screen into a full screen. So, to compensate for
If you go to the GitHub repository, you will find this, the scaling of the images aspect ratio has to be
two other variations of this code. The first is called wrong in order to look right in the 3D mode.
View3DWiggle.py; this scales both images to the full
size of the screen and then displays them alternately Getting the images
in quick succession. This gives an impression of the There are many cameras that claim to be able to
stereoscopic view, and we have found it works better produce a 3D image; most do this by getting the user
on some images than others. to scan across the scene, and the software takes two
The other version is called View3Dsbs.py and is samples to create a left and right image. This is fine
designed for use with 3D monitors. While this is very for scenes with little or no movement, but not much
MUSICAL MINECRAFT
This month Sonic Pi creator, Sam Aaron, makes much more than just music
Need
Pi, which can turn your Raspberry Pi into a to reach for the mouse and keyboard and start walking
performance-ready musical instrument. So far, weve around. That works, but its pretty slow and boring.
learned how to: It would be far better if we had some sort of teleport
> Raspberry Pi
running Raspbian machine. Well, thanks to Sonic Pi, we have one. Try this:
live_loop :bass_trail
tick
x, y, z = mc_location
b = (ring :melon, :brick, :glass).look
Magic blocks mc_set_block b, x, y -1, z
Now youve found a nice spot, lets start building. You note = (ring :e1, :e2, :e3).look
could do what youre used to and start clicking the use_synth :tb303
mouse furiously to place blocks under the cursor. Or you play note, release: 0.1, cutoff: 70
could use the magic of Sonic Pi. Try this: sleep 0.125
end
x, y, z = mc_location
mc_set_block :melon, x, y + 5, z Now, whilst thats playing, start changing the
code. Change the block types: you could try :water,
Now look up: theres a melon in the sky! Take a :grass, or yourfavourite block type. Also, try
moment to look at the code. What did we do? On line one changing the cutoff value from 70 to 80 and then up
we grabbed the current location of Steve as the variables to100. Isnt this fun?
x, y, and z. These correspond to our coordinates
described above. We use these coordinates in the Bringing it all together
function mc_set_block, which will place the block of Lets combine everything weve seen so far with a little
your choosing at the specified coordinates. In order to extra magic. Well combine our teleportation ability with
make something higher up in the sky, we just need to block placing and music to make a Minecraft music video.
increase the y value, which is why we add 5 to it. Lets Dont worry if you dont understand it all: just type it in
make a long trail of them: and have a play by changing some of the values whilst
its running live. Have fun, and see you next time...
live_loop :melon_trail do
x, y, z = mc_location live_loop :note_blocks do
mc_set_block :melon, x, y-1, z mc_message "This is Sonic Minecraft"
sleep 0.125 with_fx :reverb do
end with_fx :echo, phase: 0.125, reps: 32 do
tick
Now, jump over to Minecraft, make sure youre in x = (range 30, 90, step: 0.1).look
flying mode (double-tap the space bar if not) and fly all y = 20
around the world. Look behind you to see a pretty trail of z = -10
melon blocks! See what kind of twisty patterns you can mc_teleport x, y, z
make in the sky. ns = (scale :e3, :minor_pentatonic)
n = ns.shuffle.choose
Live-coding Minecraft bs = (knit :glass, 3, :sand, 1)
Those of you that have been following this tutorial b = bs.look
over the last few months will probably have your minds synth :beep, note: n, release: 0.1
blown at this point. The trail of melons is pretty cool, mc_set_block b, x+20, n-60+y, z+10
but the most exciting part of the previous example is mc_set_block b, x+20, n-60+y, z-10
that you can use live_loop with Minecraft! For those sleep 0.25
who dont know, live_loop is Sonic Pis special end
magic ability that no other programming language end
has. It lets you run multiple loops at the same time end
and allows you to change them whilst they run. They
are incredibly powerful, and amazing fun. I use live_loop :beats do
live_loop to perform music in nightclubs with Sonic sample :bd_haus, cutoff: 100
Pi: DJs may use discs, but I use live_loop instead! sleep 0.5
However, today were going to be live-coding both end
music and Minecraft.
THE ALIENS
ARE HERE
& THEYRE
COMING IN
WAVES!
This is the final part of our Pygame series. Were going to give the space
shooter game we started in the last issue some extra polish
ello everyone! Welcome back to the final part A tour at warp speed
H of this making games with Pygame series. Its
been ten months! Gosh, youve been patient -
Weve seen most of this code before, obviously, but a
good deal has changed, so were going to zip through
thanks for sticking with us. Havent we had some great where those changes are before we look at them in
times? Though soon well part ways, for a little while more detail.
at least, now is no time to get weepy WE HAVE ALIEN Lets look at the key differences of aliens.py first...
HORDES TO FINISH DECIMATING, PEOPLE! So lets get On line 7 of aliens.py, we now import another file,
down to it. gameLevels.py. This file contains a list with a bunch
If you look over the code from the last issue and of dictionaries that well use to place our enemies
compare it to the code for this issue, youll see that, in the different levels of our game. Its a big file,
despite having the same foundations, theres quite a bit but its not a complicated one, and well take a look
more going on in the code this time around. Last time at that shortly.
we dealt with creating a start screen, moving our ship, On lines 24-29, we have some new variables. Well
firing our weapons, creating enemies, having them use these to keep track of our games progress and
fire their weapons, and then removing them from time state, as well as changing levels.
and space whenever we hit one another. This time, On lines 39-42, we load a couple of extra images
were going to add shields to our spaceship and create to use in our game; these will be our game over and
a simple health/shield bar to show their status. Were wave announcement graphics.
also going to write some code that lets us create levels Weve done away with the lastEnemyCreated
and waves for our enemy spaceships to fall into, as well variable we used last time to generate enemies
as writing some logic for announcing that the next level after a certain time interval. Instead, we now have
of bad guys are on their way. Finally, well create two a launchWave method that will unleash a group
end screens: one for if the aliens kill us, another for if of enemy spaceships, based on the pattern we
we survive all of the levels of the onslaught. pass it from our gameLevels.py file. updateGame
Above A visual
representation
Lets take a look at a matrix If we wanted that row of ships to be followed by a row
of how we can The biggest change in this version of our game is of six ships with a gap in the middle, wed add two lists
determine enemy that we can now define levels and formations for our to structure one for the first row of spaceships, and
spaceship positions
using a matrix enemyships to attack us with. If you take a look at another for the second:
gameLevels.py, youll see there is only one variable,
level. This is a dictionary that contains objects which [1,1,1,1,1,1,1,1,1,1],
describe our levels. Our first level or wave is the first [1,1,1,0,0,0,0,1,1,1]
dictionary, the second level is the second dictionary,
and so on. Each level dictionary has two properties: This structure is known as a matrix, which you
interval and structure. Lets take a look at the can think of as a list with an X and Y axis (sort of). If
structure property first: this is a list of lists, and you wanted to know whether or not we were going to
in each list is a series of 1s and 0s. Each list is a wave. create a spaceship in the second grid down from the
Think of structure as a map of our game window. top of our screen and three across, you could check
The width of our game window is represented by one with levels[0].structure[2][3], but thats not
list inside of structure. For each 1 in our list, we want quite how were using this in our game.
to create an enemy spaceship in corresponding space in The other property of our level objects is interval.
our game window, and for every 0 we dont. Using this This value sets how many seconds should pass before
approach, we can define levels of different difficulty and we move on from one wave and create the next.
Below
appearance, just by changing the values of structure. Tweaking this value can greatly change the difficulty
By adjusting
patterns and For example, if we wanted to create ten ships that of each level. For example, if you have five waves of
intervals, you
spanned the width of the screen at equal intervals, enemies with a 5 second interval between each row,
can make levels
completely wed add a list like this to our structure list: youll have ten spaceships being generated every 5
different from one
seconds that you need to destroy. Thats quite a lot, but
another with very
little effort [1,1,1,1,1,1,1,1,1,1] 50 enemies over 25 seconds is pretty easy to deal with
- after all, were awesome. However, if you create ten
rows of ships and set the interval between waves to 2
seconds, youre going to be dealing with 100 ships in
20 seconds! Thats an onslaught. To illustrate this, the
final level included in gameLevels.py contains five
times the number of waves than any other level, but
there is only one ship in each wave and the interval
is 0.5 seconds. This creates a zigzag pattern of ships,
which makes for interesting gameplay when youre
being fired at by ships across both the X and Y axes.
With this knowledge, you can create a limitless variety
of levels for our game; all you have to do is copy one
of the level objects, and edit the structure and interval
as you see fit. Thats much more fun than spawning
enemies at random X/Y coordinates.
Launch wave!
So, now that we know how to structure our levels, how
do we put them together in our game? Back in aliens.py
we have the launchWave() function. This takes the
current level and wave, and generates enemies at the
correct positions and correct time for our game. At the
end of our main loop, we have a tiny bit of code on
lines 222 and 223 that checks how long its been since
a wave of enemies has been spawned. If more time has
passed than is allowed by our interval value for the
current level were playing, launchWave is called. Other tweaks and tidbits Above A visual
representation
The first thing launchWave does is create the We mentioned earlier that wed added a checkForHit of how we map
the matrix to the
variable thisLevel. We dont have to do this, but it function to our projectiles.py Bullet class. Lets talk
dimensions of our
makes what were trying to do a little more obvious about why we need this for a moment. In a perfect world game window
when we access our level structure, rather than using where everyone owns a Raspberry Pi and wants to use
gameLevels.level[currentLevel][structure] it exclusively for making Pygame games, every object
every time. Next, we check that the wave were about in a game is responsible for handling itself inside of
to create actually exists in our level. If our level has four the larger context of the game. When a projectile hits
waves and we try to access a fifth one, our game will a target, it runs all of the code it needs to run and then
crash. If the wave we want to access does exist, we take removes itself from the game. Unfortunately, the world
that wave and assign it to the thisWave value. Again, is not an ideal place; each object in our Pygame shooter
this just makes our code a little nicer to read. We then is aware of itself and can interact with the things we
work through the values of that wave. tell it to, but they cant be responsible for removing
First, on line 64 of aliens.py, we check whether or themselves from the game when theyre no longer
not we want to place an alien spaceship here (1) or not useful, so we need a little bit of code that decides for
(0). If we do, we then do a little bit of maths to work
out where to place it. First, we divide the windowWidth
by the length of the list that makes up the wave; The first thing launchWave does
is create the variable thisLevel
we then place the ship at the X coordinates that are
windowWidth / the number of slots in the wave *
the index of this ship. So, if we have ten slots in this
wave, and each one wants to have a ship created in us. In part 9, we had each ship be responsible for each
each slot, launchWave will create ten enemies at equal bullet that it fired; as such, each ship kept a reference
distances across the width of the game screen. If every to all the projectiles it had fired in a list accessed with QUICK TIP
other slot in that ten was a 0 and didnt want to have self.bullets and this was a great solution kind of.
a ship drawn, then five ships would be drawn at equal Each ship was responsible for cleaning up its own mess; Just because
intervals across the game screen. makes perfect sense, right? Well, yes, so long as there is youre following a
tutorial, it doesnt
Once launchWave has created the enemies it needs a ship to clean up after itself. But we destroy spaceships mean you have
to, it lets the game continue on its way until its called - Earth needs defending, and if nobody else is going to to use all of the
by our main loop again. If, the next time launchWave do it, weve got to step up - and when we destroy the resources we
provide. Why
is run, it finds that there are no more waves in this enemy spaceships, what happens to bullets theyre not tweak some
level, it will check to see if theres another level it can responsible for? Yup, they get destroyed too, which of the images
move on to. If so, it will recharge our ships shields, doesnt make sense because the bullet left the ship a to create your
own unique
increase the level number, and reset the wave number long time ago. Its a bit like a car catching fire in a car spaceship? Or
to 0. New level! If launchWave finds that its run out of park because theres a blaze in the kitchen back home: mess around
waves to create and that there arent any more levels the two are related, but not inextricably connected. with the level
structures and
to play, it assigns the gameWon variable to True. This So how do we go about solving this? By taking over ships classes to
is a preliminary value, as nothing will happen until responsibility for orphaned projectiles, of course! On create more than
all of the enemies have been destroyed, either by our line 48 of aliens.py, we have leftOverBullets. This one enemy ship?
Learning comes
bodacious laser blasts or by them simply flying off the is an empty list. When an enemy is removed from our from trying these
screen to their oblivion. If we survive all of the levels game (because weve destroyed it or some other reason), things out and
and arent destroyed by a lucky potshot from one of just before we delete the reference, and any reference seeing how far
you get!
our alien foes, then weve won the game! Hurrah! to the enemy ships projectiles entirely, on lines 114-
levels.py 79.
80.
81.
[0,
[0,
[0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
1,
0],
1],
0],
82. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
01. level = [ 83. [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
02. { 84. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
03. "structure" :[ [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 85. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
04. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 86. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
05. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 87. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
06. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 88. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
07. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 89. [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
08. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 90. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
09. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 91. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
10. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 92. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
11. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 93. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
12. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 94. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
13. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 95. [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
14. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 96. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
15. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] 97. [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
16. ], 98. [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
17. "interval" : 1 99. [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
18. }, 100. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
19. { 101. [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
20. "structure" :[ [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 102. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
21. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 103. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
22. [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 104. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
23. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 105. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
24. [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 106. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
25. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 107. [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
26. [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 108. ],
27. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 109. "interval" : 0.5
28. [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 110. }
29. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], 111. ]
30. [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], 112.
31. [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
32. ],
33.
34. },
35. {
"interval" : .3
ships.py
36. "structure" :[ [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 01. import projectiles, random
37. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 02.
38. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 03. class Player():
39. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 04.
40. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 05. x = 0
41. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 06. y = 0
42. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 07. firing = False
43. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 08. image = None
44. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 09. shieldImage = None
45. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 10. drawShield = False
46. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], 11. soundEffect = 'sounds/player_laser.wav'
47. [1, 0, 1, 0, 1, 0, 1, 0, 1, 0], 12. pygame = None
48. [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] 13. surface = None
49. ], 14. width = 0
50. "interval" : .2 15. height = 0
51. }, 16. bullets = []
52. { 17. bulletImage = "assets/you_pellet.png"
53. "structure" :[ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 18. bulletSpeed = -10
54. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], 19. health = 5
55. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], 20. maxHealth = health
56. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], shields = 3
21.
57. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], maxShields = shields
22.
58. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], 23.
59. [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], def loadImages(self):
24.
60. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], self.image = self.pygame.image.load("assets/you_ship.png")
25. self.shieldImage = self.pygame.image.load
61. [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
62. [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], ("assets/shield2.png")
63. [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], 27.
64. def draw(self):
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0], 28.
65. self.surface.blit(self.image, (self.x, self.y))
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0], 29. if self.drawShield == True:
66. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], 30. self.surface.blit(self.shieldImage, (self.x - 3,
67. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
self.y - 2))
68. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], 31. self.drawShield = False
69. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], 32.
70. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], 33. def setPosition(self, pos):
71. [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 34. self.x = pos[0] - self.width / 2
72. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], 35.
73. [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], 36. def fire(self):
74. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], 37. self.bullets.append(projectiles.Bullet(self.x + self.width
75. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], / 2, self.y, self.pygame, self.surface, self.bulletSpeed, self.
76. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], bulletImage))
77. [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], 38. a = self.pygame.mixer.Sound(self.soundEffect)
78. [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], 39. a.set_volume(0.2)
aliens.py
41. a.play()
42.
43. def drawBullets(self):
44. for b in self.bullets:
45. b.move() 01. import pygame, sys, random, math
46. b.draw() 02. import pygame.locals as GAME_GLOBALS
47. 03. import pygame.event as GAME_EVENTS
48. def registerHit(self): 04. import pygame.time as GAME_TIME
49. if self.shields == 0: 05. import ships
50. self.health -= 1 06.
51. else : 07. import gameLevels
52. self.shields -= 1 08.
53. self.drawShield = True 09. windowWidth = 1024
54. 10. windowHeight = 614
55. def checkForHit(self, thingToCheckAgainst): 11. timeTick = 0
56. bulletsToRemove = [] 12.
57. 13. pygame.init()
58. for idx, b in enumerate(self.bullets): 14. pygame.font.init()
59. if b.x > thingToCheckAgainst.x and b.x < 15. surface = pygame.display.set_mode((windowWidth, windowHeight),
thingToCheckAgainst.x + thingToCheckAgainst.width:
pygame.FULLSCREEN)
60. if b.y > thingToCheckAgainst.y and b.y <
16.
thingToCheckAgainst.y + thingToCheckAgainst.height:
17. pygame.display.set_caption('Alien\'s Are Gonna Kill Me!')
61. thingToCheckAgainst.registerHit()
18. textFont = pygame.font.SysFont("monospace", 50)
62. bulletsToRemove.append(idx)
bC = 0 19.
63.
for usedBullet in bulletsToRemove: 20. gameStarted = False
64.
del self.bullets[usedBullet - bC] 21. gameStartedTime = 0
65.
66. bC += 1 22. gameFinishedTime = 0
67. 23. gameOver = False
68. if thingToCheckAgainst.health <= 0: 24. gameWon = False
69. return True 25.
70. 26. currentLevel = 0
71. def __init__(self, x, y, pygame, surface): 27. currentWave = 0
72. self.x = x 28. lastSpawn = 0
73. self.y = y 29. nextLevelTS = 0
74. self.pygame = pygame 30.
75. self.surface = surface 31. # Mouse variables
76. self.loadImages() 32. mousePosition = (0,0)
77. 33. mouseStates = None
78. dimensions = self.image.get_rect().size 34. mouseDown = False
79. self.width = dimensions[0] 35.
80. self.height = dimensions[1] 36. # Image variables
81. 37. startScreen = pygame.image.load("assets/start_screen.png")
82. self.x -= self.width / 2 38. background = pygame.image.load("assets/background.png")
83. self.y -= self.height + 10 39. loseScreen = pygame.image.load("assets/lose_screen.png")
84. 40. winScreen = pygame.image.load("assets/win_screen.png")
85. class Enemy(Player): 41. nextWave = pygame.image.load("assets/next_level.png")
86. 42. finalWave = pygame.image.load("assets/final_level.png")
87. x = 0 43.
88. y = 0 44. # Ships
89. firing = False 45. ship = ships.Player(windowWidth / 2, windowHeight, pygame, surface)
90. image = None 46. enemyShips = []
91. soundEffect = 'sounds/enemy_laser.wav' 47.
92. bulletImage = "assets/them_pellet.png" 48. leftOverBullets = []
93. bulletSpeed = 10 49.
94. speed = 2 50. # Sound setup
95. shields = 0 51. pygame.mixer.init()
96. 52.
97. def move(self): 53. def launchWave():
98. self.y += self.speed 54.
99. 55. global lastSpawn, currentWave, currentLevel, gameOver, gameWon,
100. def tryToFire(self): nextLevelTS
101. shouldFire = random.random()
56.
102. 57. thisLevel = gameLevels.level[currentLevel]["structure"]
103. if shouldFire <= 0.01:
58.
104. self.fire()
59. if currentWave < len(thisLevel):
105.
60.
106. def loadImages(self):
self.image = self.pygame.image.load("assets/them_ship.png") 61. thisWave = thisLevel[currentWave]
107.
108. 62.
109. def __init__(self, x, y, pygame, surface, health): 63. for idx, enemyAtThisPosition in enumerate(thisWave):
110. self.x = x 64. if enemyAtThisPosition is 1:
111. self.y = y 65. enemyShips.append(ships.Enemy(((windowWidth /
112. self.pygame = pygame len(thisWave)) * idx), -60, pygame, surface, 1))
113. self.surface = surface 66.
114. self.loadImages() 67. elif currentLevel + 1 < len(gameLevels.level) :
115. self.bullets = [] 68. currentLevel += 1
116. self.health = health 69. currentWave = 0
117. 70. ship.shields = ship.maxShields
118. dimensions = self.image.get_rect().size 71. nextLevelTS = timeTick + 5000
119. self.width = dimensions[0] 72. else:
120. self.height = dimensions[1] 73. gameWon = True
121. 74.
122. self.x += self.width / 2 75. lastSpawn = timeTick
LEARN
MORE
ONLINE:
astro-pi.org
HIGH FLIERS
British ESA astronaut Tim Peake wont be the only Brit aboard the
International Space Station next year. David Crookes looks at how
the Pi got into the sky and what it means for future generations
n 15 December, British ESA astronaut Tim skywards on a Cygnus cargo freighter on 3 December,
O Peake is set to make history as the first British
astronaut to visit the International Space
going ahead of Tim thanks to a lack of room on the
Soyuz flight. But it means the computers will be ready
Station. For the next six months, he will achieve most to be unboxed by the time Tim arrives. And then the
childrens dreams as he lives and works 400 kilometres fun and games can begin.
above the Earth to carry out a comprehensive science The Raspberry Pis space adventure is referred to
programme during a mission called Principia. as the Astro Pi mission and, while it hasnt been an
His role will be to run experiments using the unique easy ride for those involved, it is certainly set to be
environment of space and to try new technologies that rewarding. Thats because the computers have been
may become crucial when humans begin to visit other equipped with an expansion sensor board called the
planets such as Mars. But he will not be alone. Aside Sense HAT, and have been placed inside a cutting-edge
from living with five international colleagues, all of aerospace case that has been built to withstand any
whom have spent years training for their difficult conditions space will throw at it. As well as allowing the
roles, Tim will be greeted by another Brit one set to Raspberry Pi to measure the ISSs environment, follow
accompany him throughout his time away from Earth. its journey through space, and pick up the Earths
That extra colleague will, of course, be the magnetic field, it will give schoolchildren the chance to
Britishmade Raspberry Pi which, by the time Tim have their code run in space for the first time ever. And
sets off on a Soyuz spacecraft from Russias Baikonur that, says Tim, is proving to be most exciting of all.
cosmodrome in Kazakhstan, will already be waiting [Astro Pi] has got a great sensor suite with
on board the ISS. Two Raspberry Pis will be flown temperature, pressure, humidity sensors, all sorts of
ASTRO PI UP CLOSE
01 The most noticeable part of 06 To allow the astronauts 05
the Astro Pi assembly is the 88 to navigate the screen and
RGB LED matrix on the Sense options, there is a five-
HAT. It has a 60fps refresh rate button joystick which allows
and 15-bit colour resolution. for up, down, left, and right
movements, as well as
02 The all-in-one gyroscope, an Enter via a click.
accelerometer, and 04
magnetometer will measure the 07 This hole allows air to enter
orientation of objects, an increase the Astro Pi device, where
02
in speed, and the strength and it can be detected by the 06
direction of a magnetic field. sensors and tested.
03 08 07
03 A temperature and humidity 08 The actual casing is made
01
sensor not only measures hot and from aerospace-grade aluminium
cold, but the amount of water and it is said to have cost 3,000
vapour in the air. It can detect to make.
whether a person is standing
close by, for instance. 09 As well as the various
special components of the
04 The barometric pressure Sense HAT, the usual functions
sensor is able to measure the of the Raspberry Pi are used.
force exerted by small molecules This is the power socket.
in the air.
10 Here we see the various
05 The graphics are connections of the Raspberry Pi,
09 10
driven by this microcontroller. from USB sockets to LAN.
Pi in the sky
It is not the first time a bare-bones computer has gone
into space (and its not incidentally the Pis debut
either, given Dave Akermans efforts in strapping Pis
to high-altitude balloons and taking snapshots from
the edge of space). But while Arduinos were the first to
boldly go where no other widely accessible device had
gone before (on to satellites orbiting the Earth), Astro
Above Tim encourage schoolchildren to become more interested Pi was created to be different.
Peake (far in space and open their eyes to its employment Never before have we had a situation where the
right) attends
the final press possibilities. The bottom line is that the UK space crew of the space station are using the same machine
conference industry wants to ensure that there are enough people as your kids, says David. But this is that time: we
before launch
in the future to hire to carry on doing what they are created the Sense HAT add-on board for the Pi and
just seven winners proved tricky. It came down to Pi sensors within Minecraft so that the environmental Above Tim
during training
the completeness of the ideas and the quality of the measurements are represented in the game. in the Soyuz TMA
coding, reveals Libby. The things the kids came up SpaceCRAFT logs all sensors to fill a massive CSV simulator
with are far more creative than adults. file and it works with code on the ground that plays
Indeed, the winners are certainly impressive. The it back in Minecraft, says David. Hannah dressed
Cranmere Code Club run by teacher (and The MagPi in a spacesuit to appear alongside Tim during
writer) Richard Hayler at the Cranmere Primary School his BBC interview.
tests the humidity surrounding Astro Pi. If fluctuation One particular favourite among those involved
is detected, it is a possible indicator that an astronaut with Astro Pi is Flags, created by Thirsk School under
has come close, so the Pi will deliver a message on the watch of teacher Dan Aldred. The program uses
its 88 LED screen and take a photo via the camera, telemetry data and the Astro Pis real-time clock to
hoping to snap one of the ISS crew in action. They work out the ISSs location. It searches its database
are looking to see if humidity is a good indictor of the to find the relevant flag and displays it on the screen
presence of the crew near the Astro Pi, David explains. with a phrase in the local language.
SpaceCRAFT is equally ingenious, with Hannah Its lovely because the children have looked and
Belshaw from the Cumnor House Girls School thought about where the astronauts are in the world,
suggesting using the output as a CSV file from the Astro says Libby. David agrees. The crew will like it, he
Above The says. The kids learned a lot about geography and they
International
Space Station made the code recognise the boundaries of different
countries. If its above the sea, it shows a twinkly blue
or green pattern.
Watchdog, by Kieran Wand at Cottenham Village
College, makes good use of the Astro Pi sensors by
measuring the temperature, pressure, and humidity
on board the ISS, raising the alarm if they move
outside acceptable parameters. Trees, by EnviroPi
a team at Westminster School points the NoIR
camera on the Astro Pi out of the window and allows
it to take images of the ground, after which it can
produce a Normalised Differentiated Vegetation Index
ON THE CASE
AstroPi Vis
Did you know that the casing for the by the Pi must also be conducted
Astro Pi is possibly the Raspberry Pi away via thermal radiation, so the
Foundations biggest achievement casing has lots of pins, each of
(aside from making the Pi itself, which can remove 0.1 watt of heat.
that is)? Large and chunky, it has The Pi itself is in contact with the
had to adhere to the regulations case, which aids heat removal, and
stipulated by the European Space tests show that it will not get hotter
Agency, and that means it must be than 32C 13C below the cutoff
as safe as a childs toy. point. There was no aesthetic
All of the edges were inspected consideration in designing
to ensure they were not sharp, so the case, says David Honess,
testers ran their gloved hands over the Raspberry Pi Foundations
the casing many times to check for education resource engineer,
potential drag. The heat generated but it does look awesome.
FIND THIS
& OTHER RESOURCES:
raspberrypi.org/resources
r = [255, 0, 0] Y
o = [255, 127, 0]
y = [255, 255, 0]
g = [0, 255, 0]
b = [0, 0, 255]
i = [75, 0, 130]
v = [159, 0, 255]
FIND THIS
& OTHER RESOURCES:
raspberrypi.org/resources
Youll
Need GRAVITY
SIMULATOR
> Raspbian
magpi.cc/
1MYYTMo
> Scratch
(pre-installed
on Raspbian)
The Sense HAT, a fundamental part of the Astro Pi mission, allows your
Raspberry Pi to sense the world around you. Heres how to get started
n space, it feels like everything is floating. Youll need to choose a sprite to use as your character.
I This is because everything becomes weightless
outside of our planet, Earth. This is probably
You can use the Scratch cat sprite, or you can use our
Mooncake - the Astro Cat sprite. You can find Mooncake
the biggest difference from being on Earth, where here: magpi.cc/1PEbjIm. Once youve got it, add it as a
everything is pulled down towards the ground. On Earth new sprite by clicking on the middle icon on the sprites
we can all feel this downward pull, but we are so used to palette, selecting Astro-cat.png from the choices and
it that we sometimes don't even think about it. This pull clicking OK.
or attraction we feel is called gravity. In order for your gravity simulator to work with
You can recreate the effects of the force of gravity on this sprite, youll need to set the costume center of
Earth in this Scratch simulation! Mooncake the Astro Cat by selecting the sprite, then
Open Scratch by clicking on Menu and Programming, clicking on Costumes followed by Edit. In the Paint
followed by Scratch. Alternatively, you can use Scratch Editor window, youll see a button with a + symbol on
2.0 online for this activity, although some of the blocks it. When clicked, it will show a crosshair over the sprite,
may be slightly different. Once opened, create a new file which youll be able to move with your mouse. Move it
by selecting File and New. so that it selects the tummy of Mooncake and when you
Next, delete the Scratch cat sprite by right-clicking on are happy, click OK.
it and selecting Delete from the menu that is displayed. Click on the Scripts tab of the sprite and save your
For this project, you need to create a new background to Scratch project work by clicking on File and Save As.
act as the Earth. To do this, click on Stage in the sprites Name your program Gravity simulation and save it in
palette (bottom-right) and then click on Backgrounds your home directory or some place that you can find
next to the Scripts tab. Click on Paint to draw your own it later.
background, then select the rectangle icon and a green
colour. Its important that you fill the rectangle with one Storing data
solid colour. Draw a green rectangle at the bottom of the To create a variable, click on Variables in the blocks
image to represent the Earth. Once youre happy with palette (top-left) and then click Make a Variable.
your stage design, click OK. The New Variable window opens and asks you to type
a name for your variable. Name the first variable velocity by block. Drag the gravity variable and place
gravity and ensure that For all sprites is checked it in the right side of the multiplication operator, and
before clicking OK. A variable holds a value that can be then type 0.1 in the other.
changed, and can be used elsewhere in your program. The last block needed is a Motion block to move
Youll see some orange blocks are added to your the Mooncake sprite. Use the change y by motion
Variables area, called gravity, and a small counter block and add it into the loop, then drag the velocity
box will appear on the stage. Youll also need to make variable and add it into the white space in the change
another variable in the same way as youve just done, y by block. The script should look like Fig 01. Save your
called velocity. program and click the green flag to check that it works.
Now we have variables, you can start to build up the The program so far simulates gravity by dropping
script. Return to the Scripts tab, then click on Control Mooncake from the top of the screen to the bottom, but
in the blocks palette. Begin by dragging a When green she isnt landing on the carefully drawn Earth. You can
flag clicked block into the main script area. change this by adding a conditional statement inside
To make sure that Mooncake starts at the top of the the simulation loop.
screen at the start of the program, youll need to set Select the Control blocks area and drag an if block
the coordinates. Use a go to x: 0 y: 0 block from the onto the scripts area. Place it inside the forever loop,
Motion blocks area. Drag it over and clip it beneath wrapping around the set velocity and change y by
When green flag clicked, then enter x as 0 and
FIND THIS
& OTHER RESOURCES:
raspberrypi.org/resources
Youll
Need ASTRONAUT
REACTION
> Raspbian
magpi.cc/
1MYYTMo
TIMES GAME
> Scratch
(pre-installed
on Raspbian)
FIG 02
background in Scratch, click on Stage in the sprites Operators block called join hello world inside the Above left This
is similar to the
palette and then click on Backgrounds next to the white space in the say block. Replace the word world sort of training
Scripts tab. with the word seconds. Tim will be
doing on the
Click on Paint to draw your own background, or You will then need to replace the word hello with International
Import to use the same images as this resource. another join hello world Operators block, replacing Space Station
Connect your Raspberry Pi to the internet and you can the hello text with Your reaction time was , and the
download a space background (magpi.cc/1MYZBcx) world text with the timer Sensing block.
and Tim Peake astronaut sprite (magpi.cc/1MYZDRs). Make a new variable called time, then select the set
Save them somewhere that you will be able to find time to Variables block and add it to the script. Place
them on your Raspberry Pi. the timer Sensing block in the 0 space (Fig 01). Save
Next, add a new sprite by clicking on the import your game and test it out by clicking the green flag.
a new sprite icon on the sprites palette (which When Tim says Hit Space!, press the space bar.
looks like a star coming out of a folder), selecting
Astronaut-Tim from the choices and clicking OK. Program the distance
Save your Scratch project work by clicking on File linked to your reaction time
and Save As. Name your progam Astronaut Reaction If you are happy with the reaction game so far and
Game and save it in your home directory or some place have tested that it works, then you can move onto
that you can find it later. adding to the script to compare the players reaction
time to the speed at which the ISS is travelling, to
Begin the game script calculate how far it would travel in that time.
First, click on your Astronaut-Tim sprite to select First, you will need to make a new variable called
it in the sprites palette. Select the when green flag distance, in the same way you did earlier. Attach a
clicked Control block from the blocks palette and set distance to Variables block to your script. Place
place it onto the scripts area, then click on Looks and an Operators multiply block 0*0 inside where it reads
connect the say for 2 secs block to the first control 0. To calculate the distance travelled by the ISS, you
block on the scripts area. Amend the text to say: need to take the players reaction time, stored in the
Hello! British ESAAstronaut Tim Peake here. Are you time variable, and multiply it by 7. This is because, on
ready?. Add a wait 1 secs Control block underneath average, the ISS travels 7 kilometres per second.
and then connect another say block and change the Add the time Variables block into the right-hand
text for it to Hit Space!. side of the multiplying operator and type 7 in the
Next, click on Sensing and connect the reset timer other side, so the whole block reads set distance to
block. This will set the timer to 0 so that you will get time * 7. Next, add a wait 4 seconds Control block.
an accurate measurement of how long it takes for Add a say block. As in the previous step, place a
someone to hit the space bar. Use the Control block join hello world block inside. Replace world with
wait until and place a key space pressed Sensing kilometres. Insert another join hello world block
block inside the white space of the wait until block. to replace hello. Replace the hello text in this new
This will pause the program until the player presses join block with the text In that time the ISS travels
the space bar. around. Then replace world with a round Operators
Connect another say block. Once the space bar block and fill the white space with the distance
has been pressed, you want to display the reaction Variables block, as in Fig 02. Finally, save your game
time to the player. To do this, you need to place an and test that it works by clicking on the green flag.
195 / $300
PI-TOP
A laptop built from a Raspberry Pi and crafted yourself.
Is it too limited by the Pi, or is it a great little portable teaching tool?
ts really not that old, but Brush away those foam. Youll have to look carefully
I do you remember the One
Laptop Per Child (OLPC)
first impressions
The pi-top has a big educational
to find the laser-cut removable
circuit cover and the selection of
project? It was a cheap laptop focus built into it. Each pi-top required screws and cables, but
with yesteryears components, user has to create a cloud account theyre all there.
created specifically to try to make before logging in, which then syncs The instructions, and indeed
getting computing into the poorest settings and such to this account. the assembly, are quite simple.
of developing nations as easy It also syncs data from CEED There are three main parts of
Related
as possible. It was also very green, Universe, the gamified learning the laptop chassis, and only two
and we dont mean ecologically software that is custom-made to pieces of circuit board including
- although it was also quite meet the new GCSE curriculum. the Raspberry Pi, so the majority
KANO low-powered, so it technically This, on top of the usual Raspberry of the process is preparing and
Similar in terms
is green in that sense. When Pi teaching resources, gives it an fitting the parts together. While
of gamifying
programming we got the pi-top out of its box, edge in the classroom, as students the instructions are generally
education that was the first thing that came can use whatever pi-top they want good, they dont distinguish very
and building,
into our minds, but definitely not without having to carry too much in well between the two types of
although its not
the all-in-one in a bad way! the way of data around with them. screws.Hint: the screws that look
product pi-top is. The elevator pitch for the pi-top It sounds great in theory. Lets like motherboard spaces need
is that its a crowdfunded laptop first go back to the box opening, to be affixed to the PCBs; they
kit that the user needs to assemble, though, before we start discussing have a thread running down the
which is powered by an included its other merits. The box itself is centre of the head. Also, one of
Raspberry Pi. Theres a lot more to lovely, with the first thing you see the connection orientations is
it, though, and well get into that being the detached laptop screens not completely clear. We found
shortly, but already this gives you bright green back with the pi-top ourselves having to take it apart a
120
a basic impression of what were logo in it. All the parts are stored in bit so we could construct it properly
uk.kano.me
dealing with. layers, carefully packed with a soft at one point.
Maker
Says
Use me
to play, learn,
and create!
Pi-Top
fine, thanks to the extra oomph starting off with something akin
to Hello World. Its very gamified,
of the Pi 2s processor and the final version could be really
something if done right.
Otherwise, assembly was quite The interface is roughly the same The pi-top, then, is a great piece
quick. We stuck on Netflix and as normal Raspbians, but with the of kit. While its probably not going
after a couple of episodes of BoJack panel down at the bottom and a to replace a normal laptop in a
Horseman it was ready to boot up, bit more of an OS X vibe with some similar price range, its an excellent
so less than an hour and probably of the display characteristics. It educational tool. Its also a portable
quicker without giggling every looks great and works absolutely Raspberry Pi with a ten-hour
minute. Make sure all the ports and fine, thanks to the extra oomph of lifespan, which is pretty great on its
cables are properly connected and the Pi2s processor; the only issue own. Hopefully, it will make its way
you can turn it on for the first time. we had was that the Chromium into classrooms or into the hands
Its quick and easy to set up browser selected by default is still of budding young coders.
an account the first time, and a little too slow.
you get some choices as to what The CEED Universe, currently in
software you want to be able to early alpha at the time of writing, Last word
quick-launch from the panel. The is quite interesting. Taking the
Makes great use of the Raspberry Pi to create
pitopOS is a custom interface resource-gathering and building
a fully functional laptop that you build with
built on top of Raspbian Wheezy elements from Minecraft, and
your own hands the entire system is a great
that has a different offering of applying them to a top-down experience for those wanting to learn.
default software, albeit with full aesthetic from early nineties PC
access to the standard packages games as a way to teach coding and
you can get on Raspbian anyway. physical computing, is fairly unique.
Maker
Says
Provides
almost
instant
working
temperatures
Tenma
Related
and start soldering something to back it up. tracked and adjusted by the on-
together. Whether its fixing To get something out of the board controller. If a large joint is
something thats broken or way early on in this review: no, drawing heat away from the tip too
WELLER building something new, soldering you almost certainly dont need quickly, the output is increased;
SP25N is an important skill, and one a highly accurate, temperature- if the tip gets too hot, the output is
For small which can be made easier or harder controlled soldering station. It can, decreased. The aim is temperature
soldering
jobs, a good depending on the tools you choose. however, make life easier. If youve stability of a single degree. Its a
quality fixed- The Tenma 60W Digital Soldering ever tried soldering and found that powerful feature, and a definite
temperature Station is designed to bridge the sometimes the solder just doesnt step up from cheaper variable-
iron like this
Weller SP25N gap between ultra-cheap fixed- want to flow - in particular when temperature irons which don't
is a cheaper temperature irons which are the making large connections - then adjust their output automatically.
alternative to a mainstay of hobbyist solders, youve experienced the frustration As an entry-level example,
bulky soldering
station. and the high-end, finely tuned of using an underpowered iron though, youd expect to see some
tools youd find at a professional that couldnt supply the heat fast corners cut in Tenmas build.
engineers workstation. Selling enough. If youve watched an LED Looking at the base unit, theyre
for sub-50/$70, the feature or other heat-sensitive component not obvious: the unit is solidly
list is nevertheless impressive: go up in smoke during soldering, built and includes a physical
the hefty base unit provides then youve experienced the power switch, while the large
20 / $14
control of the iron temperature flipside: an iron which delivered backlit LCD display at the front
amazon.co.uk
between a minimum of 150C and too much heat. is clear and easy to see while
47 / $79
PROGRAMMING
from how to do it to how it works
Price: 22.99
in each example, building through
ISBN: 978-1785887024
magpi.cc/1SNfQbu COOKBOOK semaphores, conditions,
and queues.
A short but handy roundup of Author: Giancarlo Zaccone He moves onto process-
many ways that your Android Publisher: Packt based parallelism, with
device can be used with a Price: 31.99 a useful exploration of
Pi2, from remote desktop and ISBN: 978-1785289583
sensors, through surveillance collective communication;
magpi.cc/1SNgPYZ
cameras and media centres, to asynchronous programming,
collecting automotive data.
including Python 3.2s
A cookbook but concurrent.futures module,
PYTHON GAME also a tutorial, teaching parallel Asyncio to manage events
LEARN GAME
Publisher: No Starch
plenty to offer on the Pi. This isnt
Price: 19.99
PROGRAMMING
a book about Gosu, or even solely ISBN: 978-1593276409
about Ruby, but about the nostarch.com/doingmathwithpython
CODING BACK
THE YEARS The Raspberry Pi Foundation has merged with Code Club in the continuing
quest to educate children and right some past wrongs
n 2012, two organisations and the deal looks set to reinvigorate The merger will allow us to set
I embarked on a path towards
a computing revolution.
the drive to encourage more
youngsters to get under the hood
ambitious goals and provide the
strength, network and resources to
The Raspberry Pi Foundation began of their machines. achieve them, adds Clare. There
selling the credit card-sized single- Ive been a huge fan of Code are many in the Raspberry Pi
board computers that we have come Club for a long time, Philip tells us. community that already volunteer
to know and love, and Code Club was Theyve got a fantastic model that for Code Club, but I cant wait to
established to teach children aged matches volunteers with schools introduce ourselves to many more.
9-11 how to program. and provides them with everything Philip is also clear that this is
Since then, the numbers have they need to run a club. Its simple, something he wants to see. Code
stacked up. Some 7 million low-cost and effective, which is Clubs are a great fit with our
Raspberry Pis have been sold, and why theyve been able to reach so mission, he says. They create
there are now 3,800 Code Clubs in many young people in such a short opportunities for kids from all
the UK alone, with 1,000 more in spaceof time. backgrounds and levels of ability
70 other countries. There is also a Indeed, 44,000 children currently to get involved and learn about
greater awareness of the benefits of attend a Code Club, where they learn programming. Theyve also got
coding, thanks to a new computing how to program in Scratch, HTML, phenomenal reach already and I
curriculum in England. CSS, and Python. But the new think they have real potential to go
It therefore makes sense for the partnership wants to reach even even further. Were serious when
Below Code Club two organisations to work closely more children, and the aim is to put we say the goal is to put a Code Club
CEO Clare Sutcliffe together. In November, Philip such clubs in every primary school in every community.
is excited by the
opportunities the Colligan, CEO of the Pi Foundation, in Britain. Thats all 21,000 of them. Under the deal, Code Club
merger presents announced a merger with Code Club, I have always hugely admired becomes a wholly owned subsidiary
and respected the work of the of the Raspberry Pi Foundation, but
Raspberry Pi Foundation, says itll continue to be run in the same
Clare Sutcliffe, co-founder and way as it does today: volunteers will
CEO of Code Club. When we were be matched to schools, free training
talking, it became clear that we will be given, and projects will
both share the same mission and be provided for children to work
have very ambitious goals to bring through at their own pace.
digital making to as many people Yet Philip is keen to widen the net
as possible. of volunteers and draw in people
from a variety of backgrounds: If
Volunteer effort I had to call out one thing Code
Code Clubs take place for an hour Club does, its making it easy and
each week and children are shown rewarding for people to volunteer.
how to produce games, animations, While lots of the volunteers are
and websites. They are run by engineers and programmers, its
volunteers who embark on online also a good way for non-technical
training courses, which encourages people to volunteer at school and
a structured learning pattern over learn how to make things with
four terms. computers themselves.
A two-pronged effort
As such, the merger will help
programming grounding, then why
have extracurricular activities? DIGESTING
make for a more coherent, two-
pronged effort to educate children
Weve made great progress in
England with the new computing
MORE THAN PI
in the ways of programming. The curriculum, and the Foundation
Since they were set up in 2012, Code Clubs have
Foundation puts a lot of effort into puts a lot of effort into training
been platform-neutral. This will remain the case
training teachers, says Philip, but teachers. Its great to see that
under the merger, with teachers, volunteers and
we also need to create opportunities being replicated around the world
children encouraged to use the best hardware and
for kids outside the classroom, and now, explains Philip. I think
software available for their students. They will not be
Code Clubs are a big part of that. of it a bit like sport at school.
forced to use a Raspberry Pi. But why?
The Raspberry Pi Foundation We will always need dedicated
Schools have different levels of resources
will therefore continue to offer its curriculum time in the school day
available, and students have different levels of
existing educational programmes, to make sure all boys and girls
capabilities, explains Philip Colligan, CEO of the
resources, teacher training, and get the opportunity to participate
Raspberry Pi Foundation. Our job is to provide
open-source software, while in sport, but we also need after-
them with the best support we can.
He says this is an important point for the
It became clear that we both Foundation as a whole. Of course, a lot of our work
focuses on the Raspberry Pi computer as a tool for
share the same mission... education, and it always will. But our mission and
activities are much broader than that, and many of
our programmes, like Code Club, are designed to
the Code Clubs help to expand school and weekend amateur
be platform-neutral Sonic Pi is a great example.
childrens knowledge in a less clubs, and those will often be
It works brilliantly on the Raspberry Pi, but you can
formal environment. led by volunteers.
also use it for free on a Mac or PC.
Its all part of the overall plan He says Code Clubs are
Clare Sutcliffe, co-founder and CEO of Code Club,
to shift children away from just perfect for children who show
wholeheartedly agrees, believing a platform bias
learning how to use pre-written a real talent: We want to have
would only hamper the progress of children. Its
desktop software, something which programmes that help them
important that we remain platform-neutral so that
is said to have caused a major skills advance their skills and ultimately
our projects can be accessible to as many schools
gap during the 1990s and 2000s. make successful careers. Making
and venues as possible. The requirement for specific
Both the Foundation and Code Club things with computers needs the
hardware or platforms for our core curriculum could
want to encourage kids to write same kind of ecosystem. Code Club
exclude venues who might not be able to afford to
their own software. is a first step in creating that.
change their current kit.
If were going to tackle the Clare agrees: Code Clubs give
problem of kids not learning how to children the opportunity to use
make things with computers, then their new digital skills in a sociable
we need to change what happens in environment, on creative projects
formal settings, like the classroom, they can fully engage with. The
and informal settings, like clubs opportunity to practise new skills
and peoples homes, says Philip. is as important as being taught
But is the Foundations in the first place. What Code Club
merger with Code Club an tries to do is facilitate the setting
acknowledgement that children are up of such groups for children,
still not being taught adequately in and I am so excited that we are
schools? After all, if young people trying to meet our goals with
are already being given a solid the Raspberry Pi Foundation.
6 RASPBERRY PI DC
Washington, DC, USA
7 RASPBERRY JAM
SILICON VALLEY
Mountain View, CA, USA
RASPBERRY
JAM EVENT
CALENDAR
Find out what community-organised,
Raspberry Pi-themed events
are happening near you
5 RASPBERRY PI DAY
Glasgow, UK
1 PI WARS
Cambridge, UK
4 CHRISTMAS
RASPBERRY PI
Chatham, UK
3 A SLICE OF PI CLUB
Redditch, UK
DONT
PI WARS
RASPBERRY JAM
SILICON VALLEY
MISS:
When: Saturday 19 December
Where: Computer History Museum,
Mountain View, CA, USA
magpi.cc/1O6SHin
When: Saturday 5 December Where: Cambridge Computer Laboratory
A monthly Jam in the heart of
Silicon Valley. Maybe youll
find a startup or two. The second CamJam Pi Wars is a
challenge-based robotics competition
LEEDS RASPBERRY JAM in which Raspberry Pi-controlled
When: Wednesday 6 January 2016 robots compete in various challenges
Where: Swallow Hill Community to earn points, with prizes awarded
College, Leeds, UK at the end of the day. Last year there
magpi.cc/1O6SITu were 20 teams taking part, including
This Jam aims to bring people together schools, families, and hobbyists. This
from across a wide area to discover annual event offers fantastic fun for
the potential of the Pi through talks, participants and spectators alike.
demos, and hands-on workshops. For more details, visit piwars.org.
THE MONTH IN
RASPBERRY PI
Everything else that happened this month in the world of Raspberry Pi
A SPOOKY MONTH
FOR RASPBERRY PI
As we finish writing this issue of The MagPi, weve just
experienced another frightfully excellent Halloween.
You may remember in issue 38 that we had an entire
feature on scare-tastic Halloween projects powered
by Pi, and it seems as though many people were at it
again this year with more horrifying Pi projects. Brace
yourselves as we show you some of our favourites that PI-CONTROLLED GHOST
were tweeted at us
ASTRO DESIGNS
twitter.com/AstroDesignsLtd
youtu.be/WlD0Ysn7YrA
This one must have been genuinely quite scary (we gave
it a 4/5 on our SPOOK-O-METER on our Twitter), and
apparently took Astro Designs a couple of late nights to
get it working before the big day. The floating, flickering
and screaming ghost, as they describe it, is made of a
Pi, some Lego, and a fan to keep it aloft. We definitely
wouldnt have wanted to come across that while trick-
or-treating one cold October evening...
HALLOWEEN PAINTING
WITH MOVING EYES
HALLOWEEN PUMPKIN PIBORG
magpi.cc/1LbAuf6
STEWART WATKISS / PENGUIN TUTOR
This one is a bit of a classic,
twitter.com/stewartwatkiss
youtu.be/Yy6c2NUA1Fw although it reminds us a
bit more of Scooby Doo
Stewart was the man who made the Haunted House we than any of the old horror
featured in our original Halloween article in issue38, movies it was popularised
posing as Count Dracula and simulating a veritable by. The robotic geniuses
monster mash in his garage. This year hes gone a at PiBorg cut out the
little smaller scale by hacking some pumpkins to show eyes of an already quite
a variety of colours. The pumpkins are carved and creepy portrait print and then mounted them on a
have NeoPixels put in, which shift and change colour magnetically controlled moving frame. This was then
so that neither pumpkin is ever the same shade at mounted to the frame the actual picture. The result
once. It creates an eerie effect that really makes the is a Pi-powered shifty-eyes ghost portrait for all your
pumpkins stand out even more. dramatic close-up needs.
month that you should check out and will make using your Pi so much better
PIPLAY DESKCADE
kck.st/1GfmWU2
129.99
We know what youre thinking another arcade maker-sphere.co.uk
machine case for the Raspberry Pi, and another one
thats being Kickstarted. This one is a little simpler,
and comes with a much bigger screen than some of
MAKER-SPHERE STARTER KIT
its spiritual predecessors. At the time of writing, its A Raspberry Pi starter kit from the folks at SB Components, the
already hit its goal and will be just about finished MakerSphere comes with a Raspberry Pi and 16 accessories that allow
when you read this. However, we think its one you you to not only get the Pi up and running perfectly, but also start on your
should be keeping an eye on for Christmas presents first ten projects. Quite unique to this kit is the inclusion of the new Sense
for the retro gamer in your life. HAT, the add-on board with environmental sensors thats being sent to
the International Space Station for Astro Pi. Theres also a breadboard for
creating solderless circuits and a few components to go with it.
You can also sign up for the Maker-Sphere Project Club once you have
the kit, which will give you two extra projects every week.
TINGBOT
kck.st/1SipiDv
45
iqaudio.com
SAVE COMMAND
LINE
45%
with a Newsstand
WITH OUR NEW
subscription ESSENTIALS
E-BOOK
(limited time offer)
AVALIABLE ON
THE MAGPI APP!
ESSENTIALS
[ CHAPTER FIVE ]
CUSTOMISE THE
Share your Pi:
make new user
accounts and
others can log
in or switch
COMMAND LINE
users from a
command-line
session
The command-
New user
sudo
24 [ Chapter Five
One ] [ Customise the Command Line ] 25
Subscribe from
Magazine
2.29 19.99
rolling subscription
or
full year subscription
Review
YOU MAKE
INCLUDES:
> 1 3.2 LCD TFT
USING THE
screen
CONTROL
Raspberry Pi 2
CASE BUNDLE?
(with 3m cable)
Tell us by 21 December
for your chance to win!
How to enter:
Simply email competition@raspberrypi.org
with a 100-word (max) overview of your project idea.
A TINY
COMPUTER
WITH BIG IMPACT
Matt Richardson loves Raspberry Pi Zeros low price,
small size, and maker-friendly features
f youre reading this months issue of Size zero computer
I TheMagPi in print, youre holding a tiny
piece of Raspberry Pi history in your hands.
Along with my colleagues at Pi Towers, weve
exploited the small size of Raspberry Pi Zero by
Could you have ever imagined that a Linux putting them on our keychains, inside our wallets,
computer could be small enough to be attached and even sewing them onto our gloves. The small
to the front cover of a magazine? Could you have size allows you to hack existing products and
ever imagined that youd be able to purchase a squeeze a Raspberry Pi into them. It allows you
computer that runs a full-featured desktop operating to make Linux-powered wearables or build your
system for just five dollars? Or could you have ever own portable devices. With my Raspberry Pi Zero,
imagined that it would be so easy to embed such a I created a portable, hackable GPS logger from
tiny computer into your own project? The size, price off-the-shelf components. You can see how I made
and maker-friendly features of Raspberry Pi Zero it on page 28.
make it a groundbreaking product for our Foundation For those of you who consider yourself
and our community, and were so excited to share makers, Im sure Raspberry Pi Zero will be a welcome
it with you. addition to your toolkit. For the first time ever,
Making affordable computers is one way that we a small, affordable and hand-solderable Raspberry Pi
make computing more accessible, especially for will be available to embed directly into your projects.
children. Raspberry Pi Zero is an experiment in And, of course, since its a Raspberry Pi youll have
taking that affordability to extremes. At risk of all the community support, tutorials and software
sounding like Im making an appeal for donations, available to make your project a reality. Since
for the cost of two candy bars, you can now buy your Raspberry Pi Zero has standard pitch solder pads for
own computer. 2-by-20 header pins, it can be easily soldered onto
Each time we decrease the price of a computer, perfboard, or you can work with it in PCB design
theres likely to be a huge increase in the amount software like KiCad. Whats even more amazing is
of people who can afford one to experiment with. that you can actually download and run KiCad on
Increasing these opportunities is a major part of the Raspberry Pi Zero itself.
what the Raspberry Pi Foundation is all about. With the release of Raspberry Pi Zero, Im
Ive had a Raspberry Pi Zero for a few weeks now glad that the cat is finally out of the bag and Im
and I still havent become accustomed to the tiny size incredibly eager to see what all of you do with it.
of this powerful computer. Back when the Model A+ Please dont hesitate to share ideas and post your
was originally released, I was delighted that it could completed projects. If youre not sure exactly what
fit into an Altoids tin. These pocket-sized mint tins you want to do with it yet, heres my suggestion:
are a popular enclosure for small electronics projects. put it on your keyring, in your wallet, or keep
Now, not only can you easily fit a Raspberry Pi Zero it in your pocket so that youll be ready at any
into an Altoids tin, the tin can actually hold six of moment to show off how amazing it is to anyone
them. (And yes, Ive tried!) who will listen.
swag.raspberrypi.org
IQaudIO
K
U
e
th
in
e
ad
M
Audiophile accessories for the Raspberry Pi
Pi-DAC+
Raspberry Pi HAT, no soldering required
Full-HD Audio (up to 24bit/192MHz)
Texas Instruments PCM5122
Industry standard Phono (RCA) sockets
Headphone Amplifier / 3.5mm socket
Out-of-the-box Raspbian support
Integrated hardware volume control
Access to Raspberry Pi GPIO
Connect direct to your own HiFI's line-in/aux
Pi-DigiAMP+
Raspberry Pi HAT, no soldering required
Up to 2x30w of crystal clear stereo amplification
Full-HD Audio (up to 24bit/192MHz)
Out-of-the-box Raspbian support
Integrated hardware volume control
Provides power to the Raspberry Pi
Software controlled AMP mute on GPIO22
I/O available (i2c, 3v, 5v, 0v, GPIO22/23/24/25)
Just add speakers for a complete HiFi streaming solution
Designed for custom install, retro radio restoration, in car, etc.