Sunteți pe pagina 1din 116

DISCOVER THE WORLD OF RASPBERRY PI! NEW MAG!

E
URC FOR R
SO

AS
YOUR NEW

PB
ERRY PI
HE PI
JOIN T
UTION
Issue 01 // Winter 2016
REVOL

EVERYTHING YOU NEED TO POWER UP YOUR

RASPBERRY PI!
AMAZING
11 Pi PROJECTS

Build a
Pi drone
Step-by-step guide to
making your own drone!

Make a
retro arcade
classic
Games are better
played on the Pi

20
Learn to program
in Minecraft
How to code and hack
with your favourite game

Awesome
Pi add-ons
Make your Pi into
something special

PIU01 2016
The home of technology

techradar.com
CE FOR R
UR A
SO

SP
YOUR NEW

BER PI
RY
 



 


If youve got a Raspberry Pi, or youre thinking of
getting one, then youve come to the right place!
I grew up learning to weve come full circle. The low-cost,
code in Basic at home revolutionary single board computer
on my Acorn Electron. has brought back the programming bug
I typed in the code for among school children the world over, not
games from magazines to mention quite a few adults too!
like Electron User and At Pi User were here to do more than
saved them on a get you started programming with the Pi,
cassette recorder. although well show you how to do that as
Eventually I got good enough to write well. Well inspire you with the latest Pi
my own games, and got one published projects, reviews and Pi news. Drop me a
in Electron User myself, and another line and let me know what you think of our
one sold by a software company. This first issue. You can email me at piuser@
inspired me to pursue computer science futurenet.com and find us on Facebook
all the way to University. Sadly, by then at www.facebook.com/PiUser/
the home computers of my day had
been replaced by Windows PCs, and
programming by kids just for the fun of it
was starting to become a forgotten art.
My love for computer magazines didnt
go away, though, and ultimately thats
why Im here writing to you now. And
thanks to the Raspberry Pi I feel like Graham Barlow Editor-in-Chief

Winter 2016 // //3


59

35
10 06

20 48 69

WORLD OF Pi Pi PROJECTS
Get your Pi connected and use the Pixels desktop Have an adventure with your Raspberry Pi

06 Eben Upton
interview 22 How to install
Raspbian 48 Get started with
the SenseHAT 69 Build your
first robot

10 Our favourite
home Pi projects 26 Using networks
on the Pi 54 Recreate the
Enigma machine 72 Master the Pi
Camera Module

14 Buying the
right Pi for you 28 Master the
Pixels Desktop 59 Build your
own drone 75 Make speakers
Wi-Fi-enabled

20 Get started with


Raspberry Pi 35 The top 20 Pi
add-ons 64 Set up a cloud
data server 78 Enjoy internet
radio on the Pi

4 // // Winter 2016
92 95 102

104 112

108

Pi CODE
Learn how to code in your language of choice
Pi REVIEWS
Tested and rated: the latest add-ons for your Pi

86 Get started with


Scratch 100 FUZE
Workstation 108 Picon Zero

92 Get to know
Python coding 102 PiBorg
ZeroBorg 110 CamJam
EduKit 3

95 Begin coding in
Minecraft 104 Drum HAT
112 Picade by
Pimoroni

106 Explorer
HAT Pro

Winter 2016 // // 5
6 // // Winter 2016
Eben Upton INTERVIEW

Eben
Upton
Pi User pays tribute to the inventor of the worlds
best-selling credit-card-sized computer, and finds
out why the future of computing should still be
firmly rooted in the 1980s

Winter 2016 // // 7
INTERVIEW Eben Upton

E
ben Upton, the Chief Executive Pi User: Whats the genesis behind the Raspberry
of Raspberry Pi and a CBE Pi, beyond your obvious love for fruit-based tech-
(Commander of the Most Excellent firm nomenclature?
Order of the British Empire), is the EU: I didnt really get into the hardware side of
genius behind the Raspberry Pi and things until I finished my PhD in 2006. I was really
its success. He began tinkering with computers burnt out and took a consulting gig with a guy
at an early age. When he wasnt sending off who made motor controllers he did a lot of
to BBC shows like Think of a Number for Robot Wars hardware work before it became a
pamphlets about maths problems, he was popular TV show. This got me into AVR hacking,
copying reams of Basic code from computer which is a really interesting halfway house between
books and magazines onto his trusty BBC software and hardware. You write software that
Micro. Today, hes sold ten million Raspberry has this really low-level, deterministic interaction
Pis and is CEO of a non-profit organisation with the hardware, and thats what really got me
that is dedicated to democratising computing. interested in building computers, even considering
To celebrate the first issue of Pi User we my limited hardware skills at the time.
decided we needed to sit down with Eben I built my very first computer back in 2006,
Upton CBE to find out where it all started and and that was the very first thing you could call a
what the future has in store for the Raspberry Raspberry Pi. I then started working for Broadcom,
Pi Foundation, and to discuss the enormous but that idea of building a computer never went
contribution hes made to technology. away. It wasnt until a bit later, when I was thinking
about the computer-science recruitment crisis we
Pi User: Were you always destined to work in had at Cambridge University, that the idea of
technology? What do you think hooked you as making a small computer for the students to use
a boy growing up in the 1980s? came about. The notion of fixing this recruitment
Eben Upton: I always had lots of type-in-code problem by making a piece of computer hardware
books, but I also had some higher-level, So, whats seemed like a good idea at the time.
a computer? books. They were all telling me that
in the future there would be a computer in every Pi User: How has the reception of the Raspberry
home as common as having a telephone or Pi differed from your original vision?
cooker. It seemed incredible at the time. EU: The success has been a real surprise. Its
My youth made it really easy for me to be easily three or four orders of magnitude larger
suckered into being a computer programmer. than we were ever expecting. We thought wed
2016 has
I think it helped that Im one of those minority sell between one and ten thousand units. Today, been a fruitful
kinds of people who actually find computer were at ten million units. (sorry) year for
programming itself interesting, rather than just Our big worry when we first started the Eben and the
the end goal. Raspberry Pi project was that the kids wouldnt Raspberry Pi.

8 // // Winter 2016
Eben Upton INTERVIEW

care about it; that wed make this thing and it just
wouldnt work out. As far as we could see, there
were two possible explanations as to why kids
werent programming any more: one was that they
didnt have access to the hardware they needed
to program, and the other was that they simply
didnt care about it, that they just wanted to go on
Facebook. It turns out that our first hypothesis was
correct: the lack of a programmable platform was
the only thing standing between a bunch of kids
doing a bunch of programming.

Pi User: Has your end goal changed as a result?


EU: Our goals now are basically the same, but
much bigger. Its not just about an extra 200
applicants for Computer Science at Cambridge
any more; its about making sure no one in the
world including the developing world is held
back by the lack of accessible hardware. Thats a
satisfyingly vast goal. Were not yet anywhere near Eben aims to inspire kids to do it yourself when it comes to technology.
achieving that one, and were not going to have
achieved it until weve sold at least 100 million raise public awareness. Did it work?
Raspberry Pis. EU: Im the kind of guy whos excited by
computing, but most people arent like that.
Pi User: Are you confident the Raspberry Pi is Most need the eye candy, an extra interest factor
fulfilling the original goal of encouraging more to inspire them. Astro Pi has been a real success
kids to try computer science and follow careers in generating excitement around computer
in the technology sector? science, and its been successful in the UK. Weve
EU: Were seeing an impact on the uptake of got two Raspberry Pis on the International Space
computer science in universities, and thats due Station and, provided we can get astronaut time,
to the combined efforts of a lot of organisations wed love for it to continue theres plenty of
like the Raspberry Pi Foundation pushing in the scope to take it further.
same direction at the same time. Anecdotally It was wonderful to see schoolchildren in
speaking, I definitely think its encouraging the UK get so excited about Tim Peake going to
children into computing. All youve got to do is go space. When I was a kid, I used to care a lot about
to a community event like a Raspberry Jam, or astronauts going to space, [but] do kids these
look at what the kids are putting on Twitter and days want to be astronauts? It turns out they
Facebook there are thousands of kids doing do. Its great to see so many kids excited about
things with Raspberry Pis, and its a great sign for technology in general, and not simply passive
the future. Am I totally happy with the diversity? consumers of stuff. Thankfully, theyre as excited
No. Were doing better, but we need to keep by the idea of someone climbing into a spacecraft
working to make sure we get girls as excited about with a million moving parts and going into space
computer science as boys. We need to continue to as I am.
do more to help people from less advantaged
backgrounds, too thats a key area for us. A Pi User: What sort of future do you envisage for
career in computing can be a great ladder for hobbyist computing in general?
social mobility, and a great way for people to EU: Theres always a risk of [it being] a flash in
climb up into well-paid and rewarding careers. the pan. I think the key for it not to be a fad is
Ultimately, though, I dont have a precise to put proper infrastructure around it teaching
answer to that question, and thats a bad thing. materials, teacher training, and things like after-
As the Raspberry Pi Foundation scales up, were school clubs, community events and so on. In the
continuing to do research to go out and measure 1980s, there was a whole infrastructure around
our impact and learn from it. Were finally in a hobby computing, and we need to boot that back
position where we can do that. up in a stable way so that it cant wither and die
again it needs to be sustainable. Theres much
Pi User: The Raspberry Pi Foundation teamed more involved with it than making a small
up with British astronaut Tim Peake, with the computer. Theres a lot of work to be done, but
Astro Pi project. It was a great opportunity to were working on it and were not alone in that.

THE SUCCESS [OF THE PI] HAS BEEN A REAL SURPRISE TO


US. WE THOUGHT WED SELL BETWEEN ONE AND TEN
THOUSAND UNITS. TODAY, WERE AT TEN MILLION UNITS
Winter 2016 // // 9
Camera: the
Raspberry Pi Display: to
camera here create a
isnt for shooting heads-up
selfies. Its to display, Roman
enable the Eye used a semi-
to see whats transparent
around you. mirror from
an Eye of Horus
beamsplitter
and a Fresnel
magnifying lens.

Raspberry Eye
We love this head-mounted project that Pi enthusiast
Roman Rolinsky has created in his spare time

S
ome projects are created to solve a ordered an OLO 3D printer via its Kickstarter page.
RECIPE problem. Others are created out of Was the Eye his first bright Pi idea, or his last?
pure curiosity, a bit of ambition and Both, actually, Roman smiles. The Pi used for
z ITDBo
202.4E LCD a big sense of fun. Roman Rolinskys the Eye project soon died, because the board is
screen Raspberry Eye head-mounted display not really designed to be worn on a headstrap
falls into the second category: while its an without any protection. Ive got the second
z 1 x Eye
of Horus impressive bit of engineering, Roman admits it generation after that, but I havent used it for
beamsplitter was simply too bulky for something practical. Ive anything DIY yet.
z 1 x Fresnel
started to work on a smaller version using a 1-inch Like many builders, Roman has shared the
magnifying display paired to a Wi-Fi transmitter, but optics full details of his project online. How important
lens need to be much more advanced to create a is the community aspect of Pi building to him?
see-through image at a comfortable distance, It was really important to have notros FBTFT
he says. Maybe printing custom optical elements kernel driver as an open-source project with
is possible with high-end 3D printers this is a good documentation, he says. I just had to
direction I will try to explore. Roman is excited adapt some code for the display I was using and
about the possibilities of 3D printing, and has pre- to produce a mirror image. From the comments
Ive received on Hackaday I saw there are people
interested in collaborating on the project, so I will
probably contact some of them if the next iteration
finally becomes active. And of course, it is very
nice to see the stuff you are doing noticed by the
maker community.
So what other projects does CREATOR
Roman have his, ahem, Eye on?
Ive bought my first house ROMAN
The Pi isnt ROLINSKY
really designed
recently, he says. Its pretty
for head old and requires a lot of Roman is a self-
employed software
mounting, so the attention, so its probable that developer, 3D printing
Eye is a little on my next project will be using Pi enthusiast and open
the large side. for home automation. source advocate.

10 // // Winter 2016
Our favourite HOME PI PROJECTS

Magic Mirror
Mirror, mirror on the wall, what is the smartest Pi project of all?
Pi fans say this is number one

M
ichael Teeuws Magic Mirror is published the entire project details at http://
the kind of thing you wish youd michaelteeuw.nl/tagged/magicmirror. So has RECIPE
thought of: a mirror that projects he had any other retail-related revelations? Sadly
information for you while you make not but walking through a big city, in this case z 1 x Iiyama
yourself presentable. It was voted New York, can be a major source of inspiration. 24in monitor
best Pi project of all time by the Pi Foundations For Michael, Pi building is a great way to z 1 x sheet of
official magazine, and deservedly so: not only is it improve your own programming skills and help one way mirror
really clever, but it has inspired countless builders others to improve theirs If its out in the open, glass, alias
observation
to make their own. Ive seen many, many cool you want to deliver a quality product. I also find it mirror glass
use cases for the Magic Mirror, but my absolute fascinating that others have built so many different
z 1 x HDMI
favourite is one of the community members that modules for the Magic Mirror platform, modules I cable
uses the Magic Mirror project to teach kids the would never have thought of. That shows how we
possibilities of programming by letting them can all benefit from the enthusiastic and rapidly
modify and create their own modules, he says. growing building community.
If the Magic Mirror project could inspire one kid
to become a programmer, I would be absolutely
thrilled! Its likely to inspire more: Michael has
shared his code and built an entire platform for
mirror makers at https://magicmirror.builders,
and there are several possible commercial spin-
offs on the horizon.
Michael had the idea during a shopping trip,
when he stared at an illuminated mirror and
The mirrors
imagined it providing him with useful data as well
possibilities are
as reflecting his own bored expression. Wandering endless: if it can
around behind your shopping girlfriend is a great be displayed on
moment to think of new possibilities, he laughs. the screen, itll
The mirror shows the time, weather forecast, news appear through
and a nice compliment to cheer you up, and hes the glass.

Wooden frame:
this is probably
the trickiest bit;
the tech is really
straightforward,
but putting the
glass in the
frame is a bit
fiddly.

TFT monitor:
the Iiyama
monitor is
nice and thin,
CREATOR leaving
enough room
MICHAEL to mount the
TEEUW PI and wiring
without
Michael likes to make making the
things, both physical frame too big.
and virtual, and blogs
about them at http://
michaelteeuw.nl

Winter 2016 // // 11
Dummy
camera:
Jack Miller IR illuminator:
took a dummy to see in the
camera and dark you need
put an a source of
unfiltered infra-red light
Raspberry Pi to bounce
camera inside back to the
it. Dummy camera.
no more!

Night Vision CCTV


Keep an automated eye out for burglars, Santa and other
unexpected visitors with this clever CCTV setup

W
hen Jack Miller moved out of housings trying to solder the IR LEDs onto them,
RECIPE his house and into a cabin in his which I eventually gave up on, and of course I
garden weird, I know, he says burnt myself numerous times, he says. Then I
z1x
Raspberry Pi he wanted to be able to monitor dropped the ball joint down a space in my decking
camera his house in case of break-ins. So, outside, so I had to buy another one. These
without he created a Raspberry Pi CCTV camera with night incidents are better left out of the video.
IR filter
vision. He also found that in the daytime the Jack is a big fan of the sharing ethos around
z 1 x dummy camera had another benefit: Jack makes popular the Pi. Sharing and teaching is what I do best,
CCTV camera video tutorials (look up Jackktutorials on YouTube), and Ive been doing it for a long time, he says.
z 1 x IR and the camera would let him see whether I got this particular idea for the camera from
illuminator anybody was about to interrupt him while a guy on YouTube called Clayton Lambert, who
recording. As for the night vision, that was mainly demonstrated a motion detection script. I then
a feature that I thought was cool, and the no-IR found ccrisan, who developed motioneyeOS, and
filter camera was cheaper when I actually came to thus the night vision camera was born.
buying the parts. It just seemed cool, I guess. Whats next for Jack? Ive just finished a
The video Jack made of the project makes the Pentesting Dropbox using the Raspberry Pi,
entire process look effortless, but we got Jack to he told us. Its a small device with Kali Linux
admit that some moments did end up on the installed. You can drop it into a network and be
cutting room floor. I did break three CCTV dummy able to access it and conduct pentesting. That
was pretty fun and complicated, but Im definitely
going to be using it in more videos. I also have an
idea for the Pi becoming an
SSH server, and I think Im CREATOR
going to rebuild my home
The camera
automation system. Jack also JACK
can deliver a MILLER
real-time video
plans to resurrect a broken
feed as well as Nintendo Entertainment Jacks a busy man. The
Jackktutorials.com
capturing still System with a Pi inside. Watch site features reviews,
images at preset this space! forums and a popular
intervals. YouTube channel.

12 // // Winter 2016
Our favourite HOME PI PROJECTS

Game Boy Zero


Could this be the best Game Boy ever made? Meet the man
who used a Raspberry Pi to make the perfect Game Boy

W
arner Skoch says The original the most headache-inducing, given how finicky
Game Boy has been one of my SD cards can be. RECIPE
favourite consoles since I was a For Warner, the builder community is the best
kid. Ive also been really interested part of Pi projects. I recently did a second guide z 1 x broken
in electronics and tinkering in using all-custom and aftermarket parts like custom Nintendo
Game Boy
general, so when I saw the Raspberry Pi Zeros button PCBs, many of which the community and
capabilities, this was one of the first things I in particular the folks on the Sudomod forums z 1 x Adafruit
wanted to try. came up with specifically for this project. It has 3.5in composite
display
The resulting project blew up but not in just been so much fun to be part of.
a Samsung Galaxy Note sense. When Warner We love Warners quirky ideas his most recent z 1 x Adafruit
2500mAh
posted details of his Game Boy Zero on Reddit, project was a Duck Hunt gun modified to be a battery
the story made the pages of The Verge and lamp zapper, with the IR receiver hidden behind a
Popular Mechanics, among many others. Ive duck. Whatll he come up with next? Ive got a few
had hundreds of people asking to buy one from things on my to-make list, he says. Stay tuned!
me, hundreds more asking for a how-to guide, and
one marriage proposal. Making more isnt really
practical for Warner, so he decided to post full
guidance on Sudomod.com and hang around to
help others with their own Game Boy projects.
You can understand the excitement, because
Warner, alias Wermy, has done some really cool
things. Hes adapted a Game Boy cartridge to
work as a microSD card reader, and that means
the Game Boy Zero can play games from it. Hes
also added extra buttons to play other Nintendo The Game
games including NES and SNES. And hes a big Boy Zero
fan of video editing to hide the fact that there was supercharges
plenty of swearing and even some bleeding. For mobile gaming
him, the SD card reader was the worst bit. It was with Pi power.

Extra buttons:
Wermy added
two more
buttons so that
the Game Boy
Zero could play SD card reader:
NES and SNES the card reader
games too. is cunningly
housed in a
Game Boy
cartridge to
CREATOR keep things
retro while
offering stacks
WARNER
SKOCH of storage.

Warner, alias Wermy,


posts his projects
and receives
marriage proposals
at sudomod.com.

Winter 2016 // // 13
BUYING The right Pi for you

What Pi to buy
Familiarise yourself with the types of Raspberry Pi and accessories on offer

T
he Raspberry Pi Raspberry Pi 3 Starter Kit. These (General Purpose Input/Output)
is what is known are available from vendors such pins, but the Model B+ had four
as a single board as the Pi Hut (thepihut.com/ USB ports and 40 GPIO pins.
computer. In plain products/raspberry-pi-3- In February 2015, the
English, this is a starter-kit). Although you should Raspberry Pi 1 Model B+ was
complete computer built into check carefully to see whats superseded by the Pi 2 Model
a single circuit board. Single bundled with the Pi from various B. This was in turn replaced in
board computers like the Pi offer vendors, starter kits usually February 2016 by the Raspberry
many advantages over ordinary include the Raspberry Pi 3 Pi 3, the third generation
computers. First, they are a good Model B itself, an SD card with Raspberry Pi. Apart from
deal smaller the Raspberry Pi NOOBS pre-installed (more on being more powerful, the main
is only about the size of a credit NOOBS later), a power supply, difference is that the Pi 3 has
Pi bites card. Second, the Pi draws very a case and usually an HDMI or built-in Wi-Fi and Bluetooth.
little power (around 5V), so can network cable. In 2013, a low-cost variant
If you have an run indefinitely without any risk Not only will the Raspberry of the Raspberry Pi, the Model
older version of
the Raspberry Pi of overheating and does not Pi 3 be suitable for any of the A, was introduced. This was
and want to use require a noisy, bulky fan. Its projects in these pages but it is replaced by the Model A+ in
wireless, there also very inexpensive to mass fully backwards compatible, so November 2014. The main
is an official
Raspberry Pi produce Raspberry Pis, hence
wireless adapter,
available from
sites such as
the low cost of purchasing one.
One of the down sides to THE RASPBERRY PI 3 IS FULLY
the Pi Hut
(http://bit.ly/
having an entire computer on
a single circuit board is that its
BACKWARDS COMPATIBLE, SO IT
PiWiFi).
difficult to upgrade individual WILL WORK FOR ANY PROJECTS
components such as the RAM
(memory). At the same time, the YOU FIND FOR EARLIER MODELS
Raspberry Pi is not as simple to
use out-of-the-box as a new
smartphone or tablet computer will work for any projects you difference between the Model A+
might be you need to know may find for earlier Pi models. and the Pi 3 is that the Model A+
how to set it up, where to plug in The Raspberry Pi 3 is most does not have Ethernet, Wi-Fi or
the video, the storage, and so on. useful for resource-heavy multiple USB ports. It is really
The low cost is also sometimes projects like playing games or intended for embedded projects
a little misleading because you streaming video. If you dont that is, building into devices
need to add extras such as need to do this, then there are that dont require connectivity.
cables for power and a monitor, less costly Pi models available. Its not necessary to know
not to mention the monitor and every model of Raspberry Pi, but
keyboard themselves, in order to A brief history of Pi if you read older magazines or
do anything with your Pi. The very first generation of browse websites for Pi projects,
If youve just bought your first Raspberry Pi (known, a little they might refer to these models
Raspberry Pi, congratulations! In counter-intuitively, as the model being required for projects. As
the pages that follow, youll find B) was released in 2012. This weve noted, the Pi 3 is fully
out all about how to set it up and was replaced in July 2014 by backwards compatible, meaning
what it can do. If you dont yet the Model B+, which introduced it will work for any such projects.
have a Pi and simply want to various technical improvements Some websites do still sell
know what to buy to get started and several changes: among older models, and you might be
with Raspberry Pi, then wed other things, the original Pi had tempted by these because they
recommend purchasing a two USB ports and 26 GPIO are a little cheaper than the Pi 3.

14 // // Winter 2016
The right Pi for you BUYING

Sites like the


Pi Hut sell a
starter kit which
includes the Pi
itself, as well as
the necessary
cables, SD card
and a case.

This is your decision to make, Raspbian and NOOBS. Raspbian theres rarely any compelling
but bear in mind that the older is a free operating system (OS) reason to try to install a different
models are not as fast, consume designed to work specifically OS unless its specifically
slightly more power, and lack with the Raspberry Pi. Its based recommended for the project
built-in Bluetooth or Wi-Fi. If a on Debian Linux, which is an youre following.
project requires very low power OS for desktop computers. It If you buy a Raspberry Pi
draw, consider the Model A+ or contains a number of handy pre- Starter Kit, its very likely that
Pi Zero (more on this shortly). installed programs and utilities, Raspbian will have been installed
enabling the Pi to function out- already onto your microSD card
Raspbian & NOOBS of-the-box. through NOOBS (New Out Of the
While looking at the various Raspbian is in fact only one of Box Software).
Raspberry Pi models, youre a number of operating systems NOOBS is simply an operating
likely to see references to both that will work with your Pi, but system installer which allows

Winter 2016 // // 15
BUYING The right Pi for you

On-board Broadcom 40-pin USB/Ethernet 4 x USB 2.0 Ethernet


Bluetooth 4.1 BCM2837 Extended controller ports (10/100
and Wi-Fi 64-bit quad- GPIO LAN) port
core CPU at
1.2GHz, 1GB
RAM

MicroSD Card Micro USB DSI Display Full-size HDMI CSI Camera 3.5mm 4-pole
Slot (edge Power Input. Port Video Output Port Composite
connector on Switched Video and
underside) power source Audio Output
can handle jack
up to 2.5A

The Raspberry Pi 3
dimensions are a compact
85.6mm x 56mm x 21mm.

you to select the OS you want to make sure you have the most Pi. Unlike its predecessor, the
install from a friendly menu. This up-to-date version of Raspbian Raspberry Pi 2, it supports both
is not only convenient if you installed before starting any Wi-Fi and Bluetooth connection
want to try a different OS; it is project. You can do this by out of the box without the need
extremely useful if you decide to opening the Terminal app and for separate adaptors.
start a new project on your Pi as typing the following commands: If youre familiar with
it enables you to reset the Pi to $ sudo apt-get update computer hardware, it has a
how it was when you first took it $ sudo apt-get upgrade 1.2GHZ 64-bit Quad-Core
out of the box. Simply restart the Press Return after entering processor and 1GB of RAM.
Pi, then hold down Shift on your each command. The Pi 3 also has four USB
keyboard and you can opt to ports. While most USB devices
install Raspbian afresh. The Raspberry Pi 3 will work, some will require more
If youve got a brand new As weve noted, the Raspberry Pi power than the Pi can supply. If
Raspberry Pi, you should also 3 is the third generation of the you want to use the Pi with a

16 // // Winter 2016
The right Pi for you BUYING

more power-hungry device such


as an external hard drive or HD
webcam, consider buying a
powered USB hub, such as Pi
Huts 7-port powered USB hub
(thepihut.com/products/7-
port-usb-hub-for-the-
raspberry-pi). A powered hub
connects both to the Pi and a
mains plug socket to provide the
required juice, so will be able to
power any USB device.
If you cant or dont wish to
use wireless, the Pi 3 does have
an Ethernet port for networking
using a cable. If you havent
purchased a starter kit that
includes one, make sure you also
get an Ethernet cable. The Pi 3
also has an HDMI port which
can be connected to any HDMI
monitor or television. Theres
also an analogue video/audio
port, as well as a port to connect
the official Raspberry Pi Camera.
The Raspberry Pi 3 has 40
GPIO (General Purpose Input/
Output) pins. Youll find these
along the edge of the board.
These are used for hardware
projects to do things like push
buttons, light LEDs and connect
sensors. (Some Pi starter kits does not have data storage built- hungry than the Raspberry Pi 3. The NOOBS
come with a few breadboards in. This needs to be added in the Its designed for projects where installer gives you
and LEDs to begin your foray form of a microSD card, which size is critical and/or where you a choice of OS to
into physical computing.) For slides into a port on the end of dont need all the features of the install on the Pi.
Select Raspbian
more information on the GPIO your Pi. Make sure the Pi is Pi 3 such as Wi-Fi and Bluetooth.
again to restore
pins visit www.raspberrypi.org/ powered off before removing it. The Pi Zero is also a good deal
your Pi to factory
documentation/usage/gpio/. While on the subject of power, cheaper than the Pi 3 as little settings.
If you arent planning to the Raspberry Pi doesnt have as 4 from the Pi Hut. That said,
attempt any hardware projects, a built-in power switch. You can the miniaturisation comes at the
feel free to ignore these, but its however shut it down from cost of being incompatible with
a good idea to carefully examine within Raspbian. regular sized devices unless you
each side of your Pi to identify use a special adapter.
each port. Raspberry Pi Zero For instance, the Pi Zero
Unlike smartphones, tablets The Raspberry Pi Zero is both doesnt have a regular-sized
and desktop computers, the Pi smaller and far less power- USB port, but it is possible to
buy a micro USB adapter to
connect normal USB devices. Its easy to
Similarly, regular sized HDMI forget how small
cables cannot be connected to the Raspberry Pi
the Zero without a special mini board is. Even
HDMI adapter. the Raspberry
Aware of these shortcomings, Pi 3 feels tiny in
the Pi Hut website has released your hand.
an Essential Raspberry Pi Zero
Kit which includes not only the
above adapters but also some
small rubber feet, some GPIO
adaptors and a handy metal tin
to store everything in. See
thepihut.com/collections/
raspberry-pi-zero/products/
raspberry-pi-zero-essential-kit
for more information.

Winter 2016 // // 17
BUYING The right Pi for you

Raspberry Pi
Zero as sold by
the Pi Hut. Above
are a power
adapter and the
Essentials Kit.
To the left is a
micro SD, USB
wireless adapter
and shim.

If you need internet access performance. It has a 1GHZ memory. The Compute Module
on the Pi Zero, then the Official single-core processor and just is designed for specialised
Raspberry Pi Wireless Adapter 512MB of RAM. However, this industrial applications, so its
will work in conjunction with is actually ample for many Pi unlikely that youll need to use
the Zeros mini USB connector. related projects. this, but weve mentioned it here
Alternatively, Pi Hut sells a in case you see it for sale.
MicroUSB converter shim Raspberry Pi The small size of the Compute
which slots over the end of any Compute Module (67.6x30mm) makes it
USB device, saving trailing Finally, the Raspberry Pi ideal for a number of ambitious
cables. Visit thepihut.com/ Compute Module contains the projects such as the CubeSat
products/usb-to-microusb-otg- bare bones of the Raspberry Pi project, which hopes to build
converter-shim to find out more. (a processor and 1GB of RAM) shoe-box-sized satellites that
The smaller size and price of but instead of using an SD card can be launched into space, all
the Zero comes at the cost of it contains 4GB of internal flash powered by the Pi.

18 // // Winter 2016
U O
P SA 58
T

V %
FR US

E
J
O T
M
5
A GREAT GIFT
FOR EVERYONE

Treat yourself or a loved one this year with a magazine subscription

Choose from a huge range of titles Subscribe from just 5 every 3 months
Save up to 58% off the cover price Free personalised gift card when buying for someone else

2 EASY WAYS TO ORDER


VISIT myfavouritemagazines.co.uk/Z704

OR CALL US ON 0344 848 2852


Please quote Z704 when ordering by phone.
Lines are open Monday to Friday 8am to 7pm and Saturday 10am to 2pm (GMT).

Savings calculated against the full RRP (single issue price x frequency). This offer is for new subscribers only. Full details of the Direct Debit guarantee
are available upon request. You can write to us or call us to cancel your subscription within 14 days of purchase. Your subscription is for the minimum
UFSNTQFDJmFEBOEXJMMFYQJSFBUUIFFOEPGUIFDVSSFOUUFSN1BZNFOUJTOPOSFGVOEBCMFBGUFSUIFEBZDBODFMMBUJPOQFSJPEVOMFTTFYDFQUJPOBM
circumstances apply. Your statutory rights are not affected. Prices correct at point of print and subject to change. For full terms and conditions please
visit: myfavm.ag/magterms. Offer ends: 31st January 2017.
CONNECTED Get started

Get started with


a Raspberry Pi
Before you can actually do anything with your Raspberry Pi, youre
going to need to hook up all the right peripherals. Heres how...

E
ven though it might use and compatible wireless unpowered hub is an option,
not look like it, the adaptors, for example before while powered hubs can handle
Raspberry Pi is in we can move on to creating a any devices, no matter whether
a fundamental way boot disc to start it up. power is required or not.
just like any other To use the Pi as a computer,
desktop computer you might youll need to connect at least a Display me
have owned or used in the past. keyboard, a mouse, a display and Technically, the Raspberry Pi
That is to say, it has a processor, a compatible SD card. In todays works with most types of
memory and storage and, in environment, its going to be displays using the correct cable
order for you to use it, it requires useful to at least have a wired or adaptor. Its envisioned to be
being connected to all the usual internet connection around, or used with an HDMI monitor but
peripherals a display, inputs a suitable USB wireless adaptor works with older monitors with
and more. For most people, this for wireless networking. The a DVI adaptor or an HD TV.
should be straightforward, but final touch would be desktop With the HDMI connector, both
there are some finer points that speakers. On a technical level, the Pi and the display should
you should know about details peripheral support is provided automatically configure
about the correct SD card to by the Linux kernel that powers themselves correctly; weve
the Raspbian OS, but more on successfully used the Raspberry
that later Pi on a 4K display without issue,
beyond manually setting the
Need input! higher 4K screen resolution.
Ever since the Model B+, the Its possible to connect the
Raspberry Pi has been well Pi to an old TV or monitor
furnished with four USB ports. using an analogue composite
This ensures that its easy to connector this is usually a
connect all the peripherals you round yellow RCA connector.
need. The base minimum of With the Pi, the 3.5mm jack
these is a USB mouse and thats usually used for stereo
keyboard for standard input audio output carries an extra
especially considering youre line for the video. To access this,
able to get keyboards that you need a 3.5mm jack to stereo
provide additional USB ports, and composite RCA.
helping to save one or more on
ON THE CASE the Raspberry Pi itself.
Pretty much any keyboard
Sounds good
The Raspberry Pi is perfectly
We admit, it can be unnerving having a naked and mouse should work, but capable of producing plenty
Raspberry Pi sitting on your desktop, and its dont expect support for any of audio, and later well see
certainly the case that it could short on random unusual buttons (youd be projects that enable the use of
wires, screws or metal surfaces. So, a common extra surprised at how many do the Pi as an audio streamer and
that people get for their Pi is a suitable case. At this work, though...). media centre. You can get audio
point, theres quite a range available, and many leave
The important thing to out of standard Pis in two ways.
the GPIO pins and other ports open for easy access.
remember is that even with just The first is over the HDMI line.
There are more exotic options that can mount the Pi
within a display, a desktop-style case that expands four USB ports or the single When you plug the Raspberry
its capabilities, and even a laptop chassis, so you port on the Pi Zero its easy to Pi into a display that also has
can take your Pi with you. Just be aware that this expand your USB connectivity speakers, audio generated by
means you can spend anything from 5 up to 100 with a hub. For devices that dont the Pi is automatically sent over
for your Pi case! require additional power, an the HDMI line, too.

20 // // Winter 2016
Get started CONNECTED

The alternative option is to All Raspberry Pis use a normal desktop PC. The fact is, Connect it up
use the standard 3.5mm audio micro USB port to supply their the Pi was envisioned to be that and a Raspberry
jack, which can easily be plugged power. This has the advantage and so much more. A big part of Pi will form the
into most speakers. that, on the whole, you can its extra abilities comes through heart of a
power a Pi from almost any the bank of GPIO (General powerful but
Network and power phone power adaptor. The power Purpose Input Output) pins. Well very compact
computer setup.
Were going to look into Pi requirements vary, depending on explore these later through fun
networking in more detail over which Pi you have and what and exciting projects, but for
the page, largely because we youre doing with it. Old power now, its enough to know that
want to look at wireless supplies that provide only 5W these enable the Pi to control,
networking adaptors and the should cope with a basic Pi monitor and power external
newer Raspberry Pi 3 wireless Model B setup, which draws devices and projects. You dont
capabilities in full, alongside the 3.5W, but the more peripherals have to use them, but theyre
new Bluetooth features and how you add, the more power it always there if you want them.
they work. Beside this, all Model requires. The Pi 2 and 3 use 4W, Additionally, the Pi comes with
B Pis come with the wired so the draw is more critical. a camera interface although
Ethernet network port. This can Ideally, you want a 10W (2A, 5V) you can also use standard USB
be plugged into any router, and supply, which is more common cameras plus theres a
boom instant network access, these days because modern dedicated digital touch display
including internet access if that tablets and phones also have interface, too.
router is connected. For the higher power requirements. All you have to do now is
Model A Pis and Pi Zero, a USB At this point, you would have follow our installation guide over
wireless adaptor is required. your Raspberry Pi all set to be a the page and boot it up!

SD CARDS
The main storage for a Raspberry Pi is an out at 25MB/s. Its also not capable of
SD card, typically a micro SD card, though utilising the technology of the latest UHS
the original Model B and Model A Pis used high-speed SD cards.
a full-sized SD card. On the whole, you With all that in mind, the key thing to
can just run out and buy any micro SD look for in an SD card is to get one with
card and it should work, but it certainly fast read/write access, rather than pure
makes sense to ensure that the card you throughout. Its also worth keeping an eye
buy will not only work, but will also be on the list of compatible tested SD cards
large enough and as fast as possible. at http://elinux.org/RPi_SD_cards.
Not all SD cards are made the same. You should also aim to get a card at
There are various speed categories, such least 8GB in capacity. The latest build of
as Class 6 (which denotes a minimum Raspbian the main Pi OS is now larger
6MB/s write speed) and Class 10 than 4GB. That said, given the price of SD
(denoting 10MB/s write speeds), along cards, it makes sense to go for a 16GB or
with the newer and faster UHS-1/2 (Ultra 32GB card. You need to balance the slight
High Speed). One thing to keep in mind increase in price against the fact that a
here is that the Pis SD controller maxes larger card is likely to be of use far longer.

Winter 2016 // // 21
INSTALL Get started

How to install
Raspbian
Before you can do anything on your Raspberry Pi, you need some software
for it to run. With a micro SD card in hand, we guide you through the process

B
efore the Raspberry Unlike traditional computers, needs to be at least 4GB in
Pi can do anything the Pi has no internal storage, capacity. If all this seems too
(apart from sitting so the OS needs to be loaded technical, you may wish to look
there looking cute) it from an SD card. The original Pi at NOOBS (over the page).
needs an operating models (models A and B) use Note that on MacOS computers,
system (OS). The most popular full-size SD cards, whereas its also possible to write the
OS for the Pi is Raspbian, which newer models (B+, 2, 3 and Raspbian image using the dd
is based on Debian Linux. A Zero) use the smaller (and tool from the command line. If
number of other operating much easier to lose!) microSD youre comfortable working
systems are also available for variety. SD cards pre-loaded this way, the procedure is very
the Pi. Some of these can be with an OS can be purchased similar to the Linux instructions
downloaded from the Raspberry from pretty much wherever the on page 25. Alternatively, check
Pi Foundation website (https:// Pi is available, and are commonly out the instructions on the
raspberrypi.org/downloads) included in bundles, but it is also Raspberry Pi Foundation website
and some can be installed using straightforward (and cheap) to at www.raspberrypi.org/
NOOBS (over the page). Theres make your own. This can be documentation/installation/
Ubuntu MATE (Pi 2 and 3 only), done using freely available tools installing-images/mac.md.
an ARM port of Arch Linux, the on Linux, MacOS or Windows.
classic RISC OS, the OSMC If you already have a pre- Enjoy Raspbian
media centre, not to mention loaded SD card, you can skip this Once your SD card is ready
the RetroPie vintage gaming section entirely. If not, the most (whichever road you choose),
platform. Theres also Snappy straightforward way to get going youre all ready to boot up your
Ubuntu Core and even Windows with the Pi is to download the Raspberry Pi. Remove the SD
10 IoT Core. If youre a beginner, latest Raspbian image and write card from your computer, plug it
Raspbian is good to start with. it directly to an SD card, which into your Pi (along with all the
other gubbins display, power,
Raspbian keyboard and mouse), and it
should be your should boot up to the raspi-
first choice, but config program. From here, you
the other OSes should expand the filesystem (if
can be fetched
your card is greater than 4GB),
and installed with
minimum fuss.
change the default password and
enable Boot to Desktop. Select
Finish and youll be able to
reboot to the Raspbian desktop.
Theres all manner of interesting
things you can play with right
away, including Minecraft,
Wolfram Alpha and Sonic Pi.
If you have a wired network
connection, then that will work
out of the box. Some wireless
ones will as well, but for many,
this will be their first encounter
with the recalcitrance of Linux.
Just be patient, and remember,
Google search is your friend...

22 // // Winter 2016
Get started INSTALL

INSTALL RASPBIAN WITH WINDOWS OR MACOS

1 SD card tools 2 Download Raspbian image


We first have to download some additional image-writing software. For Youll find the Raspbian image at www.raspberrypi.org/downloads/
Macs, the simplest tool is Rpi-sd Card Builder (http://alltheware. raspbian. The current edition is called Jessie, the same as the Debian
wordpress.com/2012/12/11/easiest-way-sd-card-setup), but you may release its based on. Be sure to choose the full edition, rather than the Lite
also want to look at Pi Filler (http://ivanx.com/raspberrypi) or ApplePi- one, at this stage unless, of course, youre sure that youre happy at the
Baker (www.tweaking4all.com/hardware/raspberry-pi/macosx-apple- command line, with no desktop environment. You may wish to save the
pi-baker). On Windows setups, we recommend using Win32 DiskImager, Foundation some bandwidth and use the BitTorrent link. This requires
which can be downloaded from https://sourceforge.net/projects/ you to have a BitTorrent client installed, such as Transmission or uTorrent.
win32diskimager. Installation of all of these programs is straightforward. Whatever your download method, the full Raspbian image is a 1.3GB
download, so will take a few minutes.

3 Unzip file 4 Write the image


Youll end up with a file in your downloads folder, called something such as Win32 Disk Imager needs special privileges to write to the SD card. So,
2016-05-27-raspbian-jessie.zip. Make sure that youre not running short instead of double-clicking its executable, right-click it and select Run as
of hard disk space, because this file will be close to 4GB in size when its Administrator. Now choose the image file you extracted in the previous
uncompressed. Double-click the ZIP file (if youre using a Mac), or right- step. In the Device section, choose the drive letter of the SD card. Click
click it and select Extract All (on Windows). It should extract to a file called Write, double-check you have the right device, and writing commences.
something along the lines of 2016-05-27-raspbian-jessie.img in the same Wait for it to complete and, hey presto, all done. Mac tools work similarly
folder as the downloaded ZIP file. This is the image file that we need write (you may be asked for a root password), but be sure to choose the correct
to the SD card in the next step. SD card device, rather than your hard disk. Whatever destination you
choose is wiped, so you dont want to get this wrong.

Winter 2016 // // 23
INSTALL Get started

Install NOOBS
with any OS
Possibly the easiest way to get a new OS up and running on your Pi can be
achieved using any operating system as long as you know how!

N
OOBS (New Out Of so it will load the next time the just plug in and turn on.
the Box Software) Pi is rebooted. Or you can hold Once your card is ready,
makes it easy to down Shift as the Pi boots to use reboot the Pi with power,
install Raspbian (or the NOOBS installer once again. mouse, keyboard and monitor
other OSes) on your Preparing a NOOBS SD card all connected. You should see
Raspberry Pi. You can buy an with Raspbian on it requires at a list of OSes (tailored for your
SD card with NOOBS on it from least a 4GB SD card other Pi model). The Raspbian entry
many vendors, or well show you OSes (in particular, Windows 10 should have a picture of an SD
how to do it yourself below. IoT Core) will require 8GB. The card on the right, indicating that
With a correctly-prepared simple process of installing it can be installed even if the Pi
NOOBS SD card, the Pi can boot NOOBS to an SD card is outlined is not connected to the internet.
to a menu offering you a choice below. Note that if youve bought Tick the box to its left, hit Install
of OSes. Pick one and NOOBS an SD card with NOOBS already and, before long, youll be able to
installs the OS on the SD card, on it, you dont need this section reboot straight into Raspbian.

INSTALL RASPBIAN WITH WINDOWS OR MACOS

1 Format the SD card 2 Download NOOBS 3 Unzip and copy


Before you can do anything, your SD card must NOOBS is available in two forms: the regular You should have a file named something like
be correctly formatted. Freshly purchased blank edition (weighing in at 1GB, zipped) and NOOBS NOOBS-V-1-9-2.ZIP in your downloads folder.
cards tend to already be formatted as FAT32, Lite (a mere 27MB). The Lite edition does not This must be decompressed and the contents
but if youre recycling an old one, you need to do include the Raspbian image it has to be put on the SD card. On Windows and Mac, you
this yourself. First make sure there isnt anything downloaded from within the NOOBS installer. should be able to extract the files by just double-
important on it. Formatting can be done directly The full-fat edition allows Raspbian to be clicking the ZIP file. The files extract to a folder
from Windows Explorer or from Disk Utility in installed without an internet connection, but named something like NOOBS-v1-9-2. Now
MacOS. In Explorer, right-click the SD card and other OSes have to be downloaded. Again, this is they must be copied to the SD card. Be sure to
choose Format; in Disk Utility, go to the Erase easily achieved from the comfort of the NOOBS transfer only the files inside the NOOBS folder,
tab. In both cases, choose FAT32, not the NTFS installer. Both versions can be downloaded from rather than the folder itself, otherwise it wont
or HFS+ lesystems. Linux users can format www.raspberrypi.org/downloads/noobs, either work. Open the NOOBS-v1-9-2 folder and select
SD cards using Gparted, Gnome Disks or the directly or via BitTorrent. The latter is a little all the files (click the first one, hold Shift, then
command line with mkdosfs -F32 /dev/ more considerate of bandwidth but requires a click the last one). Drag them on to the SD card
sdX1 , for example. Note that NOOBS requires BitTorrent client. Many Linux distros include the icon and wait for them to finish copying (the full
that only a single FAT32 partition exists on the Transmission BitTorrent client (also available for version can take a while). Right-click and safely
card, so if there are others, these should be MacOS), and there are plenty to choose from on eject the SD card. You should now be able to use
removed with appropriate partitioning tools. Windows (uTorrent, Deluge, Bitcomet). this card to boot your Pi, as well explain later.

24 // // Winter 2016
Get started INSTALL

Install Raspbian
with Linux
If youre running any flavour of Linux on your computer, then you have an
even easier life when it comes to getting Raspbian on to your Pi

L
inux users can get The Etcher
Raspbian set up image writing
from the comfort program is
probably the
of their operating
slickest way to
system, too. Much
make SD cards
the same as on Windows and under Linux,
Mac, the first steps are to and saves you
download the Raspbian image from getting
(either from a web browser or your hands
using Wget) and unzip it. There dirty at the
are a few different options for command line.
writing the image. You can use a
graphical tool such as Etcher
(see www.etcher.io) or Ubuntus Well refer to the SD card as network to side-step filesystem
Startup Disc Creator. These work /dev/sdX (replace the X with the incompatibilities amongst OSes.
very much like the image-writing actual drive letter) and assume Still, it can sometimes be handy
tools for MacOS and Windows. youve unzipped the Raspbian (for example, if the Pi is shut
As with most tasks on Linux, IMG file to the Downloads down) to just be able to grab the
the usual approach is to use directory. In a terminal type: SD card, slip it in a slot, and grab
the command line. $ sudo dd if=~/Downloads/26- photos or edit configuration files.
Insert the target SD card into 05-16-raspbian.img of=/dev/sdX If youre not (yet) a Linux
the machine. Well use the dd bs=1M user, its also possible to use the
tool, which is part of all standard This process can take a long live disc mode of a distribution
Linux installations, to transfer time, particularly on older or (Ubuntu, Fedora, openSUSE,
the image. You definitely dont cheaper SD cards. Sometimes, Mint, for example) and create
want to accidentally wipe your even when the command the SD card from there. Theres
hard drive this way (and its completes (when you are able a slight problem downloading
possible to do just that if you to enter another command), the the image to the root filesystem,
get this wrong), so first use the job is not done. If your SD card however, because this is all in
lsblk command to see which or adaptor has an activity light, RAM for live discs (their modus
device node it is attached to. then you can see if anythings operandi is to not touch your
You should be able to identify still being transferred, but if not, hard drive), and there typically
the SD card by its capacity. It try the sync command. If it isnt enough space for several
could be /dev/sdb or it could be doesnt complete right away, gigabytes of OS image. This
/dev/sdc. Newer PCs that have data is still in-flight. Once can be worked around, though,
a native MMC controller will give everything is ready, you can because the image can be
it a slightly different name, such remove the SD card, boot your downloaded to a USB stick
as /dev/mmcblk0p1. Note that Pi and tweak the raspi-config beforehand and copied from
it is the device, not partitions on program as per the Windows there. On Ubuntu, USB sticks
that device (such as /dev/sdb1 and MacOS instructions. are mounted in a directory inside
or /dev/mmcblk0p1n2), that /run/media/ubuntu, so change
we are interested in. Any existing Linux luck the if parameter of the dd
partition information will be lost On Linux, there is a slight command accordingly.
when we transfer the image to advantage in that the SD card Alternatively, you can use the
the device. Writing the image to can be browsed natively. Its Startup Disk Creator on an
a partition wont work at all well, only a slight advantage because Ubuntu live DVD if you dont
so dont do that. things can be sent over the feel like typing things.

Winter 2016 // // 25
NETWORKS Get started

Using networks
on the Pi
Getting hooked up to a local network and the wider internet is easier
than you might think, as long as you have all the right bits...

E
veryone (and, it of the nitty gritty of networking Linux kernel they ship with.
seems, everything) from you, combined with the You can confirm whether a
is online these days, need to add wireless dongles to USB device is working correctly
and that means that all Raspberry Pi models except other than the Raspbian
if you want your the latest Pi 3, which comes with wireless being enabled by
Raspberry Pi to do anything built-in wireless and Bluetooth. opening a terminal and typing
interesting even if thats just Lets talk wireless adaptors. lsusb , then pressing Return.
browsing Facebook you need The first thing you need to do This provides a list of all your
to get it networked. As with before buying a wireless adaptor USB devices, and one should
everything Raspberry Pi, its is to check whether the one you be something that sounds like
Raspbian
now supports
made as hard as possible, to already have or plan to get will your USB Wi-Fi device.
easy GUI- ensure you learn as much as work with your Raspberry Pi. A second command, iwconfig
based wireless possible along the way! No, Thats where http://elinux.org/ provides a list of working
connections actually, the only complication is RPi_USB_Wi-Fi_Adapters wireless adaptors connected to
so modern! that Raspbian doesnt hide any comes in this is a huge list of your Pi. This offers a slightly
both verified adaptors and those more direct confirmation that
that cause issues. the USB dongle is connected
The good news is that a huge and working.
range works with Raspbian, An easy way to avoid any
thanks to its Linux kernel. It worry is to buy an official
comes with built-in support for Raspberry Pi Foundation Wi-Fi
a large number of adaptors. dongle. Designed to work with
Because of the way Raspbian is all Raspberry Pis and Raspbian,
built, an adaptor that doesnt this eliminates any worries.
work with Raspbian might work Theres also the added point
with another Linux OS, such as that it helps fund the Foundation,
Arch or OpenELEC, because of too. You can get more details
the particular version of the from www.raspberrypi.org/
products/usb-wifi-dongle/.
Back in the day, you had to
TCP AND YOUR SORE IP edit text files to configure your
wireless dongle, but these days,
If youre new to PCs and networking, then the address would be something like 192.168.0.1 Raspbian has been fully updated
sudden talk of IP numbers and the like might or 192.168.100.23. Generally, your home and to provide a GUI for connecting
be very confusing. Lets just say that local business network has its own IP range the to any wireless network. How
networks and the internet all use a very clever broadband router you use to connect to the civilised! Wi-Fi connections can
system called TCP/IP. On a pedantic level, thats internet creates this automatically using be made via the familiar network
two yep, two communications protocols: something called a DHCP server, and uses icon at the right-hand end of
TCP, alias Transmission Control Protocol; and Network Address Translation, or NAT, to route the menu bar. If a working Wi-Fi
the IP part, alias Internet Protocol. You dont messages to and from your local network and dongle is plugged in, left-clicking
really need to know anything about it, other the wider internet. See, it does get awfully
this icon brings up a list of
than this: it assigns a unique number to each complicated very quickly!
available Wi-Fi networks, as
and every device on the internet. This enables Usually, when we talk about IP addresses,
messages to get to and from your devices, its when you want to know the address of a shown in the picture on this
finding their way to the right place. device or server on your network or on the page. If no networks are found,
Each device gets an address made up of four internet, or you want to give a device a specific it shows the message No APs
numbers, separated by full stops. Each number address. You wont have to know much more found scanning... Wait a few
can be between 0 and 255. So, typically, an than this. seconds more without closing

26 // // Winter 2016
Get started NETWORKS

for transferring files and getting


an internet connection. In terms
of having to do anything, you
dont just plug in the cable,
and as long as its connected to
a working router that already has
an internet connection, Raspbian
is allocated an IP address.
Most Ethernet ports provide
two status LEDs (the original Pi
did not; these status lights were
moved to the board itself). The
green confirms a working
connection (any blinking shows
activity), while the amber one
announces a full-speed 100Mbs
connection (or 10Mbs if its off).
Its also worth noting that the
Linux kernel can happily handle
multiple network connections
over different network adaptors.
The iwconfig the menu, and it should find to show that a connection is This means you can connect to
command helps your network. being made; once it is ready, the a different network or the same
check whether a The icons on the right show icon stops flashing and shows one via both a wired connection
wireless adaptor and wireless at the same time
whether a network is secured or the signal strength.
is working.
not, and its signal strength. Click Older versions of Raspbian the kernels TCP library happily
the network that you want to provided a Wi-Fi Config tool on balances transfers over both the
Wired connect to; if it is secured, a the desktop. Theres no reason adaptors. It also means you can
networking is the dialog box appears, prompting why you should encounter an remotely connect to the Pi via
fastest and most you to enter the network key. Do older version at this point, but if either assigned IP address.
reliable way to so and wait a couple of seconds. you do, its no more complicated As with USB Wi-Fi dongles,
connect things. The network icon flashes briefly than running it and then using its also possible to add wired
its Scan button to locate your Ethernet adaptors via a USB
desired wireless network. port a full list of verified and
problem adaptors can be found
Wired networks at http://elinux.org/RPi_USB_
We should also mention wired Ethernet_adapters. While this
networks while were here. All doesnt make total sense for a
Model B Raspberry Pis have a Model B board, it may be exactly
wired network connection called what you need when it comes to
an Ethernet port. This uses an the Model A or the Pi Zero.
Ethernet cable to connect to The subject of networking
a standard router. A wired can get highly involved, so
connection remains the most were going to leave things with
reliable and the fastest option a standard IP connection.

BLUETOOTH DEVICES
With the addition of the embedded dual connecting to a wireless network. This
wireless/Bluetooth abilities in the Pi 3, goes for all Bluetooth devices, but you first
Raspbian was updated to support need to make them discoverable this
Bluetooth out of the box. Prior to this, you enables other Bluetooth devices to then
had to hack in the Bluetooth support, attempt to connect with them, at which
with the command sudo apt-get install point you have to allow those connections
--no-install- recommends bluetooth and, or not, as the case may be. Left-click the
once it was installed, use sudo service Bluetooth icon in the top-right of the
bluetooth status to enable it. Raspbian desktop, select Make
While this was a simple case of installing Discoverable, then choose Add Device to
a manager tool, its far neater having it pull up a list of nearby Bluetooth devices.
around by default. If you use a smartphone Select the correct one and click Pair. With
youre likely to have used Bluetooth, with keyboards and devices, you often have to
all the Bluetooth speakers, keyboards and enter a code on the device to finalise the
headsets available these days, but if not, connection. Youll want to ensure that you The Raspberry Pi should pair with most
the good news it thats its far simpler than choose Stop Discoverable afterwards. Bluetooth devices without an issue.

Winter 2016 // // 27
PIXEL DESKTOP Get started

Master the new


Pixel Desktop
We explore the new Pixel desktop bundled with the latest version of
Raspbian, and show you how to update your existing installation

C
hristmas has come The real treat comes when fairly easy to resize the window
early to the Pi this the desktop loads. Thanks to Pi (see NitPixels, p31).
year with Pixel (Pi Foundation Developer and skilled If the windows alone are
Improved Xwindows photographer Greg Annandale, not enough of a visual feast,
Environment, there are now over a dozen epic two of the Pi Foundations web
Lightweight). If you think of the desktop backgrounds bundled developers have spent a great
former desktop environment with Raspbian. Our current deal of time on making funky
LXDE as a generic store-bought favourite is Mountain, but yet functional icons for the
plastic tree, by contrast Pixel is theyre all stunning. Pixel desktop. You can open the
a towering Norwegian Pine laden The Pixel cheer continues applications menu to see most
with tinsel and toys. upon opening a window, as you of these but they excited us so
Pixels perfection is evident will notice that the wide frames greatly we actually headed over
from the moment you switch around the borders are now to the Add/Remove Software
on any Raspberry Pi with the gone, giving it a much more section in order to see the full
latest install of Raspbian as the contemporary look and feel set for various categories.
Quick tip scrolling line of (largely obscure) reminiscent of an actual desktop Some of the changes to the
text has now been replaced computer. Mercifully it is still desktop environment are much
All system icons
are stored in / with an elegant splash screen,
displaying only a few helpful
SWITCH ON, AND THE SCROLLING
usr/share/icons/
PiX. Feel free to messages and the version

TEXT HAS BEEN REPLACED WITH


replace them with number. (The splash screen can
your own icon
set, but keep the
however be reversed or even
filenames and
sizes the same.
switched off altogether see
Climb out of the Splash Screen
AN ELEGANT SPLASH SCREEN
on p33 for more information).

By default
Raspbian still
doesnt require
a password. You
can, however,
enable the login
screen, which will
appear on your
chosen desktop
background.

28 // // Winter 2016
Get started PIXEL DESKTOP

HIGHLIGHTS OF THE PIXEL DESKTOP


Applications New Wallpaper The Windows The clunky
apps include the desktop now has a frame around windows
Chromium Browser, choice of 16 separate is gone. You can still
the SenseHAT stunning wallpapers. resize windows by
Emulator and Visit your appearance hovering your mouse
RealVNC server. See settings as shown to pointer just outside
the main text for change these. a window edge.
more information.

Icons Icons on Integrated fonts Interfaces Wireless


the taskbar, menu The Infinality font and Bluetooth icons
and file manager rendering package now allow for power
have been redrawn is now included to switching, in that
in colourful and optimise how fonts one or both can be
painstaking detail. are mapped to Pixels disabled from within
on the screen. the desktop.

more subtle. The Roboto font, Raspbian+Pixel also now The Pixel Desktop will now be
which is still the default font for includes an initial release of bundled with all future installs of Quick tip
Raspbian, has been augmented Chromium for the Pi. If youre Raspbian and we encourage you
If you want to
with a rendering package to not familiar with it, Chromium to try it out. The simplest way if port any of the
map pixels to the screen. The is the open source project you use Raspbian with NOOBS, sample code from
effect is admittedly not very behind the Google Chrome web the easy operating system the emulator to
noticeable in many places browser. For more information, installer, is to restart your Pi a real SenseHAT,
simply change
but makes for a much more visit www.chromium.org. while holding Shift and select
sense_emu to
professional feel in others. Raspbian again. Be warned, sense_hat at
If you are unswayed by Pixels Playing with Pixel however, that this will erase the top of your
glittery showing then there are Hardware geeks may also be your existing installation. program.
also several titanic applications delighted at the inclusion of a Alternatively, you can choose
bundled with the latest version SenseHAT emulator which allows to download the latest Raspbian
of Raspbian. Chief among these for easy testing of interfacing image from the Raspberry Pi
is integrated support for VNC projects without having to buy website (www.raspberrypi.org/
out of the box (see As Easy as an actual SenseHAT board or downloads/raspbian/) and
RealVNC, p31, for details). reconfigure one each time. then follow the installation

Winter 2016 // // 29
PIXEL DESKTOP Get started

guide to move it onto a suitable by running the command best switched off if not actively
Quick tip MicroSD card from which you epiphany-browser in use) or youre storing sensitive
Consider installing
can boot your Pi (http://bit.ly/ You may want to do this if, data and dont want to be visible
the plugin Pi-install-guide). for example, you want to export on networks.
Disconnect from Thankfully its also possible to your old bookmarks into If you do choose to leave the
the Chrome Web upgrade your existing Raspbian Chromium (see NitPixels on Wi-Fi enabled, you can now also
Store. This blocks
Jessie to the latest version the opposite page for more). disconnect from your currently
websites from
tracking you and including Pixel (Raspbian+Pixel). The official Raspberry Pi connected wireless network with
can significantly See our step-by-step guide on website cautions that although two clicks of your mouse. Simply
increase your p32 for more information. Chromium runs well on the Pi 2 open the network menu and
browsing speed. and 3, it might struggle on older click on your current network
Chromium models and the Pi Zero. If this name to disconnect.
comes along applies to you, you might
Not only does Chromium provide consider using Epiphany or Sensational
a much more modern look and investing in a faster Pi. SenseHAT
feel to everyday web browsing For the benefit of those people
on the Pi, its also optimised to A word on who havent (yet) visited the
stream HD video with your Pis interfaces International Space Station,
hardware. This is achieved in By popular demand, the latest the SenseHAT is an add-on
part by the h264ify browser iteration of Raspbian gives you board for the Raspberry Pi. In
extension, which as the name much more control over your November last year it was used
suggests forces YouTube to interfaces. Its finally possible to as part of the Astro-Pi project
stream hardware accelerated disable either Bluetooth or Wi-Fi (see https://astro-pi.org for
H.264 videos. altogether from inside the Pixel more information) and is now
The Ublock Origin extension desktop environment. Simply available on sale from sites like
is also installed to prevent the click the Bluetooth/Wi-Fi icon the Pi Hut for around 30.
browser being slowed down by and choose to disable either or The SenseHAT is suitable for
The SenseHAT annoying ads. Ublock Origin is both. This is particularly useful much more than space satellites
Emulator uses based on the more well-known if youre running your Pi from a because its bristling with useful
click and slide AdBlock Plus but unlike its big battery pack (because both of sensors including a gyroscope,
buttons to brother filters all advertising these are power-hungry and are accelerometer, magnetometer,
emulate content as well as trackers
movement of
rather than let a few supposedly
the joystick and
changes in the
harmless adverts through. THE EMULATOR ENABLES YOU TO
environment. This
example program
Once its installed the web
browser button will launch TEST ALL YOUR PROJECTS BEFORE
changes the LED
colour based
Chromium by default. However,
you can launch the former
BUYING A SENSEHAT BOARD
on humidity. browser Epiphany at any time

30 // // Winter 2016
Get started PIXEL DESKTOP

Move the
mouse pointer
either to the edge
of a window or
just outside it and
you can resize
the window.

thermometer and barometer. emulator for the SenseHAT, this projects suitable for beginners,
It also comes complete with one has been developed by the as well as intermediate and
an 8x8 LED interface and a five awesome Dave Jones to run advanced examples.
button joystick. natively on the Pi. Environmental
The latest version of variables like temperature and NitPixels
Raspbian+Pixel now comes with pressure can be altered using The upgrade process is
a SenseHAT Emulator, allowing slider switches. reasonably pain free but if you
budding coders and interfacers For those who are interested choose to install Raspbian+Pixel
to test all of their projects before in getting started, the emulator from scratch, the ZIP file will
taking the plunge and buying an contains a number of example decompress from 1.8GB to just
actual SenseHAT board. projects. Launch the emulator, over 4GB in size. This shouldnt
Although the Raspberry Pi then click the File menu at the pose a problem for more recent
Foundation previously top left, then hover over Open versions of Linux but if you are
announced a web based Example. You will see there are using a different OS, older

AS EASY AS REALVNC
RealVNC have brought both their viewer browser does indeed support Java. If
and server software to the Pi, which not, youll be given the opportunity to
makes life much easier for those who install it immediately.
want to connect remotely to the rich GUI. Linux users may prefer to use the
Once RealVNC is installed, go to IcedTea-Web plugin for your browser. The
Menu > Preferences > Raspberry Pi software is open source and is capable
Configuration > Interfaces and click of running Java applets. Visit http://
Enabled under VNC. The VNC icon icedtea.classpath.org/wiki/IcedTea-Web
will appear at the top right of the desktop. for information on how to download and
Click this to open the VNC window install the latest version.
complete with a unique IP address Whichever method you use, youll be
for VNC clients for example asked to click Run to confirm that you
http://192.168.1.10. wish to use the RealVNC software. The
Alternatively if youre using a Java desktop will open in a new window. Be
enabled web browser, you can choose careful not to close this window (we
to use the relevant link to open a separate recommend moving it to a separate
Java window inside which you can access desktop if your system supports this)
the Pis desktop from another computer because if you do, youll lose access. Note down the IP address for
without installing additional programs. If you plan to use VNC regularly, you your VNC client/web browser. Use
If you choose to do this, first visit might wish to consider bookmarking the security catchphrase to stop your
https://java.com/en/download/ the Java link so that you can open your connection from being intercepted by
installed8.jsp to make sure that your desktop at any time. Man in the Middle attacks.

Winter 2016 // // 31
PIXEL DESKTOP Get started

archiving utilities may struggle never resist references to Mad blue link offering to Import
with this. To avoid this issue, Max) you may wish to import Bookmarks. Click this and locate
the Raspberry Pi Foundation your old bookmarks from the the file to bring your favourites
recommends using 7Zip for previous Epiphany browser. You across to the new browser. Bear
Windows and The Unarchiver can launch Epiphany at any time in mind that this version of
for Mac to extract the files. by opening Terminal on the Pi Chromium is experimental and
For the sake of compatibility and running the command therefore not all websites may
Raspbian may overwrite some epiphany-browser perform as youd like.
of your configuration files. If you Click the settings gear icon on
find that this interferes with the top right and then choose Getting used to it
anything and need to revert to Edit Bookmarks. A new window Resizing windows now that the
the previous state, your old will open, giving you the chance oversized frames are gone can
configuration files can be found to export your bookmarks in take a little getting used to. The
in /home/pi/oldconffiles. HTML format. resize area actually exists just
As shiny as Chromium is, The first time you run the outside the window as well as
before riding it eternal (we can Chromium browser youll see a on the very edge, so you dont

UPDATING AN EXISTING INSTALLATION

1 Run Update and Upgrade 2 Install RealVNC viewer and server


Open Terminal on your Pi or connect via SSH and run the command Once the upgrade is complete, install the RealVNC software with the
sudo apt-get update then sudo apt-get dist-upgrade Feel free to make following command:
yourself a hot beverage while you wait for the upgrade process to finish. sudo apt-get install -y realvnc-vnc-server realvnc-vnc-viewer
Keep an eye on the process, however, as you may see an alert about the Next time the Pi restarts youll see the VNC icon at the top right. See
plymouth I/O multiplexing framework. Press q to close this and proceed. As Easy as RealVNC on the previous page for more information.

3 Install Chromium intro version 4 Apply all changes


To install the introductory version of Chromium run the command: Whether or not you choose to install the emulator, you should also restart
sudo apt-get install -y rpi-chromium-mods the Pi at this stage to apply all changes with the command sudo reboot .
The Chrome plugins h264ify and uBlock Origins are included in this install, Note the understated Raspberry Pi splash screen as you do so.
so you dont need to add them manually. During the install process you
may need to hit Y to continue with loading Adobe Flash Player onto the Pi.

32 // // Winter 2016
Get started PIXEL DESKTOP

need to practise extremely downloading a fresh image from login screen to make sure
precise motor control. Simply the internet or you worked your anyone else accessing it will
move the mouse pointer to the way through the tutorial before need a password. Simply run the
corner of a window and wait a reading this warning, you can following command to open up
moment for the cursor to run the following command to your desktop configuration:
change to a resize icon. remove RealVNC server and all sudo nano /etc/lightdm/lightdm.
The Raspberry Pi website related files: conf
cautions that those using xrdp sudo apt-get purge realvnc-vnc- Now comment out the line
to access their Pi remotely server autologin-user=pi by placing a
might find that it conflicts with Finally, a lot of time and # at the start. Press Ctrl + X,Y,
RealVNC. If youre updating your effort has gone into making then Return to save and exit
existing installation of Raspbian, Raspbian into a much better and restart the Pi. If you do this,
skip step two in the step-by-step approximation of a desktop youll notice another neat
guide on the opposite page to computer. If you decide to start feature of Pixel is that your login
avoid installing VNC. If youve using a Pi as a home or office screen now appears over your
installed Raspbian+Pixel by computer, consider enabling the existing desktop background.

CLIMB OUT OF THE SPLASH SCREEN


Some users may prefer the old scrolling boot text over simply save your changes and exit.
the handy new splash screen. Nostalgia aside, if youre If you are fond of the splash screen but feel its a
experiencing errors on boot, the text can be a handy little sterile on its own, you can replace it with a picture
way to see at what stage in the process errors are of your choice. The splash screen image is located at
occurring. There are two ways to return to the former /usr/share/plymouth/themes/pix/splash.png. If
flurry of text. you do choose to replace it, make sure the new file is
The first is to open your Raspberry Configuration also called splash.png. If you choose to do this, use
by going to Menu > Preferences > Raspberry Pi the command line the folder in question is owned by
Configuration and then selecting Boot to CLI. Bear the root user. Open Terminal or connect via SSH and
in mind that this will boot the Pi to the command run the following command:
prompt. To make the desktop and rest of the GUI sudo mv /path/to/yournewpicture.png /usr/share/plymouth/
appear, simply type the following command: themes/pix/splash.png
startx In case you want to revert in the future, make a copy
The second way to see the old scrolling text is to run of the old splash image named old-splash.png by
the following command to open the boot parameters: running the command
sudo nano /boot/cmdline.txt sudo cp /usr/share/plymouth/themes/pix/splash.png /usr/
Now locate and delete the words quiet splash. Next share/plymouth/themes/pix/old-splash.png

The Pi Foundation
claim that the
splash screen
doesnt slow down
the boot process
but if you prefer the
old boot screen, it
can be disabled.

Winter 2016 // // 33
GET THE MOST FROM
YOUR RASPBERRY Pi

OUT
NOW!
WITH
FREE
DIGITAL
EDITION

ORDER YOUR COPY TODAY!


Order online at www.myfavouritemagazines.com
Also available in all good newsagents
Raspberry Pi add-ons TOP 20

The top 20
Raspberry Pi add-ons
Add multiple dimensions to the way you use your Raspberry Pi with
this collection of essential add-ons compiled by Nick Peers
he Raspberry Pi was major manufacturers to provide Well reveal how to add Wi-Fi and

T
designed to inject much- people with all manner of add-ons to extra USB ports to your Pi Zero if
needed enthusiasm back extend their Pis capabilities, without you need them, and youll also find
into computing and having to design something from out how best to enjoy games on your
electronics, and scratch. In this roundup weve Pi, whether its through a simple
thousands of Pi users focussed on 20 of our favourite Pi Pi-compatible gamepad or by housing
have showcased amazing and add-ons, all of which enable you to your Pi in a full-blown arcade cabinet.
innovative projects that show just how use your Pi in different ways. And the beauty of this roundup is,
versatile it can be. Part of this success Youll find out how to put your Pi at weve barely had time to scratch the
is down to the Pis fundamental the heart of an all-in-one desktop or surface so if you find an add-on
design, with its USB ports and GPIO tablet, give it the tools to interact with here doesnt quite do what you want,
pins encouraging people to interact its surroundings through the addition youll almost certainly be able to find
directly with the Pi to achieve... well, of sensors and robotic controls, plus something that does elsewhere. And if
just about anything. power it via batteries or even your you cant find it? Perhaps now is the
Many Pi projects have morphed network. Youll discover some novel time to build it yourself and then
into something more permanent as ways of using the camera module, share it with others. Isnt that what
crowd-funding campaigns jostle with including spying on your fish tank! the Pi is all about?

Winter 2016 // // 35
TOP 20 Raspberry Pi add-ons

pi-top CEED
Turn your Pi into an all-in-one desktop PC
119, http://uk.rs-online.com connectors are easily accessible;
This beautifully designed the adjustable kick stand allows
desktop case with integrated you to position it for comfort.
display will house any Raspberry There are two optional extras
Pi Model B form factor. The you can buy: the pi-topPROTO is
14-inch display offers a decent a HAT-compatible add-on board
1366x768 resolution equivalent for prototyping electronics; the
to an HD-ready 720p screen pi-topSPEAKER is a tiny speaker
and the Pi itself hides behind the you can also fit to the mag rail.
removable black acrylic panel You can attach up to three for
beneath. All you need to supply stereo sound, but each is 20.
is the Pi (or you can buy a CEED The CEED comes loaded with
with Pi 3 included for 142), plus the pi-topOS and CEEDuniverse,
a mouse and keyboard. a multi-player online game that
Assembly is simple: remove teaches you coding and circuit-
the panel, attach your Pi to the building skills so you can make
mag rail and slide it in. Internal hardware to use with the game.
connections are neatly hidden Also consider: The Pi-Top case
away; all the cables you need are converts your Pi into a fully
supplied, plus a power supply, functional laptop, with 13.3-inch
and theres space for your HATs screen and 10-hour battery.
too. Your Pis USB and Ethernet Around 225, www.pi-top.com

Pi-DAC Zero
Turn a Pi Zero into an audiophile-friendly
music player with this powerful DAC
13 (fitted), www.iqaudio.co.uk fully functional audio player you
Give your old stereo system a can control remotely from any
new lease of life by pairing it with web browser.
a Pi Zero. Just solder GPIO pins Rip your music in FLAC
on to the Zero, then plug in the format for maximum quality and
Pi-DAC Zero. This superb DAC then sit back and prepare to be
supports full HD audio through gob-smacked. Dont believe us?
its twin phono connectors use Weve been using it together
a standard set of phono plugs to with PiMusicBox as our primary
pair it with the AUX IN input on music player for a year, leaving
your stereo and youre away. the CD player to gather dust.
Drivers are built into Raspbian Also consider: You can add a
and comprehensive instructions headphone socket via the 12
for enabling and using the DAC Pi-DAC ZeroHP board, which
can be found at www.iqaudio. plugs into the top of the Pi-DAC
com/downloads/IQaudIO.pdf. Zero. Theres a full-size version
Or you can follow the tutorial at of the Pi-DAC Zero (Pi-DAC+,
www.techradar.com/1318771 to 31) for Pi Models B+, 2 and 3,
pair your Pi Zero with the superb and a Pi-DigiAMP+ to turn a Pi
PiMusicBox distro to create a into a full-blown stereo receiver.

36 // // Winter 2016
Raspberry Pi add-ons TOP 20

ZeroView
Take pictures with this superb Pi Zero case
7, www.thepihut.com to make them easier to remove
Youve bought a Pi camera, but in turn should you want to shift
whats the best way to mount it? your vantage point. Program
Our favourite camera-themed your Pi Zero to record your fish
case is the ZeroView, a cleverly swimming around its aquarium,
designed window/glass mount or perhaps use the simple time-
for your Pi Zero (or Pi Model A+) lapse command to shoot some
and the camera module (dont stunning footage.
forget the 4 Pi Zero Camera Pair it with MotionEyeOS
Adapter cable when you buy). (https://github.com/ccrisan/
Powerful suction cups secure motioneyeos) to turn your Pi
it to any glass surface, and the Zero into an IP camera so you
camera module is close enough can keep an eye on your home
to practically eliminate glare and in real time from anywhere.
reflections. The way the Pi Zero Also consider: For home
is mounted means you can add security the SPI-BOX (13, www.
additional pHATs, while all the sbcomponents.co.uk) has a
connectors point downward for built-in motion detector. The Pi
easy access (and tidier cables). Camera Box Bundle (22, www.
Its easy to assemble no modmypi.com) fits the module
soldering involved and the PCB and Pi Zero in a wall-mounted
board slides off the suction cups case with wide-angle lens.

Sense HAT
Multi-purpose add-on board used in space
29, https://cpc.farnell.com long you can get a feel for the
The Sense HAT was designed to Sense HAT before you buy it by
take the Pi to the International running an emulator in your web
Space Station with astronaut browser (https://trinket.io/
Tim Peake see https://astro- sense-hat note it doesnt
pi.org. Its also packed full of currently work in Firefox). This is
useful tools. The Sense refers also a great way to try out your
to its six sensors, for measuring coding projects before you apply
temperature, barometric them to your Sense HAT; theres
pressure and humidity, plus a desktop version available for
gyroscope, accelerometer and offline use through Raspbian too.
magnetometer functions. You Also consider: Sense HAT will
also get input controls via a five- work with a Pi Zero, but Enviro
button joystick and can output pHAT (16, www.pimoroni.com)
to the 8x8 RGB LED matrix. is a better fit if your interest is
Its versatility makes the the sensors. Its four sensors
Sense HAT ideal for everything measure temperature, pressure,
from conducting experiments to light level, colour, three-axis
playing games, and you can get motion, compass heading and
started with its huge Python analogue inputs. Theres a large
library at pythonhosted.org/ Python library you can import to
sense-hat. If you cant wait that interrogate it with.

Winter 2016 // // 37
TOP 20 Raspberry Pi add-ons

MoPi
Power your Pi from any portable source
25, www.pimoroni.com away. Two default profiles are
The Pis small size suggests its built in, one for non-rechargeable
perfect for portable use, but it batteries and another for eight
needs a power supply. Any NiMH AA rechargeables. (Youll
portable battery designed to need to supply your own battery
charge a smartphone over USB holder expect to pay 3-4 for
can be used with the Pi, or you one that holds eight batteries,
could look at Pi Supplys PiJuice and make sure it has a PP3 clip
Standard (25, www.pi-supply. to plug into the connector
com). Or, for maximum flexibility, supplied with the MoPi.)
consider the MoPi. It plugs into How much charge you get
the GPIO header, but requires from your batteries depends on
only four pins and can be used their load and capacity: aim for
together with other GPIO- at least 2,000mAh per battery,
connected add-ons if you choose which should give you up to ten
the Stackable version. Wire it up hours use between charges even
to any suitable power source with several connected add-ons.
one capable of at least 6.2V The MoPi also provides an on-off
under load and after a bit of switch and can cleanly shut
configuration with the aid of the down your Pi when the battery
excellent https://pi.gate.ac.uk/ level drops to critical, ensuring
pages/mopi.html website youre you dont mess anything up.

7-inch touch
screen display
Turn your Pi into a tablet
60, cpc.farnell.com it with the SmartPi Touch Case
The Pis official touchscreen has (18, pimoroni.com), which
an 800x480 display and 10-point tucks your Pi away behind the
capacitive touchscreen; install a screen and provides access to all
third-party on-screen keyboard key connections, including the
app such as Florence and you camera and display cable. The
can ditch the keyboard too. case also comes with a LEGO-
Power is supplied from your Pi compatible camera case that
through the connector, which can be attached to the main
plugs into the Pis DSI display case perfect for using the
port we recommend using the camera as a webcam.
newer 5.1V/2.5A power adapter Also consider: Want a higher-
to ensure the Pi and screen get res display? ModMyPi offers the
all the juice they need. Pair it Wareshare 10.1-inch 1024x600
with the MoPi (above) to provide touchscreen with case for 90,
power on the move. but it requires cables to connect
You could turn your Pi into a to a Pis HDMI port (display) and
compact desktop unit if you pair one USB port (touch support).

38 // // Winter 2016
Raspberry Pi add-ons TOP 20

LCD Control
Case Bundle
A case with a 3.2-inch touchscreen
From 26, http://shop. in a remote control project and
sb-components.co.uk want an attractive but accessible
Want an embedded display but screen for interacting with. The
not a full 7-inch touchscreen? case also ensures that the micro
This case (available in black, switches are accessible through
blue or transparent) for Pi Model a series of tiny holes, which you
B+, 2 or 3 has a 3.2-inch TFT can get at using something like
touchscreen, which connects a paperclip.
to your Pi via the GPIO port to The Bundle also handily
provide touch and a 320x240 includes a power adapter and
pixel display. There are also USB Wi-Fi adapter if you need
three microswitches at the them, plus an 8GB microSD card
bottom, which you can program containing a modified version of
as you see fit. Raspbian. This works out of the
Your Pi fits snugly into the box with the touchscreen,
bottom of the case, which can meaning you simply pop it in,
even be wall mounted, making it boot up and can immediately
a good choice if youre using a Pi start using the screen.

Adafruit 16x2
LCD & Keypad
Send simple messages from your Pi
26, www.pimoroni.com your Pi has four USB ports, youll
Adafruits two-line LCD, available need to place electrical tape
in positive and negative versions over these and any resistors to
with RGB backlight, can display prevent direct contact with the
either a single message or one LCD and Keypad.
that scrolls to show longer ones. Also consider: the Micro Dot
The plate also has a four-way pHAT (22, thepihut.com) offers
keypad and select button, so you six LED matrices (red or green)
can interact with the Pi using the plus a decimal point. Its meant
standard I2C protocol (Adafruit for the Pi Zero but will work with
includes several Python libraries any Pi. Even more basic, the
you can tap into). The board Blinkt! (5, thepihut.com) offers
plugs into the GPIO port to sit on eight multi-colour RGB LED
top of your Pi for easy access indicators that are individually
it uses just two pins, both of controllable and dimmable,
which can be shared with other allowing them to flash on and off,
I2C devices, leaving the other pulse, etc. Useful to talk with
pins free for other uses. Note: if your Pi in Morse code, maybe?

Winter 2016 // // 39
TOP 20 Raspberry Pi add-ons

Pi Camera
Module v2.1
The official high-res camera add-on
21, http://cpc.farnell.com and get the special cable that
The official Pi Camera Module plugs into the Pi Zeros smaller
packs an 8-megapixel Sony connector (around 4).
sensor thats also capable of The camera is supported by
shooting HD video, making it an extensive Python library for
suitable for anything from time- programmers, and all you need
lapse photography to webcam or to do is enable it via the Raspi-
home security use. Just add the config utility.
right case and software. Also consider: Pimoroni stocks
Theres one choice to make: a lens set (8) with fish-eye,
the standard daytime version, or wide angle and macro lenses,
the NoIR model for use at night complete with clip for attaching
with suitable infra-red lighting? them to the Pi camera module.
The camera connects to a ModMyPi offers a mini camera
special connector on the Pi via a stand with magnetic lens plate
ribbon cable for Pi Zero, make and a choice of lens (including
sure its the newer Pi Zero v1.3 telephoto and super fisheye) to
with camera connector built-in, securely clip on it for 9.

10

Skywriter HAT
This clever add-on enables you to control
your Pi using a series of gestures and taps
16 www.pimoroni.com and double-tap, giving you a
Imagine holding your audiences wide range of control options.
attention with a wave of your So controlling your Pi using a
hand or a flick of the wrist as you wand while yelling Expelliamus!
take control of your Pi. Thats the sounds cool, but what practical
magic behind the Skywriter HAT, projects could you use the
which enables you to control Skywriter HAT for? How about
your Pi by performing a series gesturing your way through a
of hand gestures over the top of LibreOffice presentation? Or
the HAT from up to 5cm away. making sweet music using the
It works using an electrical synth.py script thats included
near-field that circulates around as part of the HATs Python API?
the surface of the Skywriter in You could even experiment with
3D. When you move your hand using it as a touchpad, although
through this field, the HATs its lack of precision may leave
Python API is able to measure you frustrated.
the disruption and respond as Also consider: Skywriter (20,
programmed. Its capable of pimoroni.com). This is the big
reading positional data in three brother to the Skywriter HAT,
dimensions along with common and allows you to gesture up to
gestures such as flick left, tap 15cm away from its surface.

40 // // Winter 2016
Raspberry Pi add-ons TOP 20

11

Pi PoE Switch
HAT
Power your Pi from a network port
30, www.pi-supply.com The switch needs to support the
Need power plus network access 802.3af PoE protocol, and most
for controlling a project remotely dont. In this case youll need to
or retrieving the data it collects? add a PoE injector, which needs
A PoE Switch HAT provides both to sit next to your switch and a
power and a network connection power socket. One is TP-Links
from up to 100 metres away TL-POE150S (20, PC World),
using a standard Ethernet cable. which can provide up to 13W.
If you need to protect the unit, Also consider: The Pi PoE
search for Pi weatherproof Switch Hat works with the Pi
case to find some designs you Model B+, 2 or 3 if you have a
can make using a 3D printer, or Model B, then visit www.xtronix.
if the units staying in the dry, co.uk/raspberry-pi-poe.htm for
check out the PoE Switch HAT details of a compatible model. Pi
Case (8, www.modmypi.com). Zero users will have to fashion
One more thing: you cant just their own solution see https://
plug into your router or switch hackaday.io/project/9455 for
and expect it to provide power. one example.

12

Picade
Create your own arcade machine
powered by your Raspberry Pi!
180, www.pimoroni.com enough for retro gaming), stereo
The Raspberry Pi in particular speakers, joystick and 12 micro-
the Pi 2 or Pi 3 is more than switched arcade buttons. Its a
capable of running the most DIY job allow up to three hours
demanding games from decades to put it all together, but theres
gone by. Fire up the RetroPie no soldering involved and the
gaming emulator and you can result has an authentic feel
relive past gaming glories from thanks to the black powder-
various computers and consoles coated MDF and Perspex.
from the 80s, 90s and even the You also get the Picade PCB,
noughties. Theres also support which connects to the Pi via USB
for MAME, which emulates and converts the joystick and
thousands of old arcade games. buttons (which are wired via the
All you need to do is supply your terminal contacts) into keyboard
own game controller (see the presses. It also provides a 3W
final entry in this roundup). amplifier for your speakers.
But why not go the whole hog Also consider: Too pricey? 135
and emulate an arcade machine buys you the full cabinet without
in miniature? Enter the Picade, a screen, 90 just the console part
tabletop case with 8-inch screen (including joystick and buttons),
(800x600 resolution, more than and 22 the Picade PCB.

Winter 2016 // // 41
TOP 20 Raspberry Pi add-ons

13

Wi-Fi Adapter
and USB hub
Add more USB ports and Wi-Fi to Pi Zero
10, www.pimoroni.com CPU load means little impact
The one shortcoming of the Pi on your Pi Zeros performance.
Zero is its single microUSB port. Theres even a socket for an
What if you want to use a mouse, external power adapter one
keyboard and Wi-Fi? One answer with a 2.5mm jack providing
is the Broadcom Wi-Fi Adapter 5V/2A power with a positive
and 2-port USB hub. centre contact will do the trick.
It plugs into your Pis USB Also consider: Want a discreet
port for Pi Zero youll need a Wi-Fi adapter that plugs directly
microUSB to USB cable or the into the Pi Zeros lone microUSB
2 Shim youll find at most Pi port? The Pi Zero WiFi adapter
stockists. This makes it perfect (8, www.modmypi.com) is a
for general use or just to get micro-sized USB dongle no
your Pi Zero up and running need for any messy adapters or
before you switch to headless shims. Its just 23mm long and
use. The Y-shaped hub has a fast requires no drivers but offers the
150Mbps Wi-Fi adapter plus two same fast 150Mbps (802.11n)
full-size USB ports, and its low speeds as the Broadcom.

14

Cluster HAT
Discover how to combine the power of four
Pi Zeroes with this clever little add-on
28, www.clusterhat.com What youll discover is that
Cluster computing harnesses the four Pi Zeroes will work in
the power of multiple computers tandem with each other on the
to boost performance. The same task, effectively combining
Cluster HAT enables you to plug their individual capabilities
in up to four Pi Zeroes to use (including processor and RAM)
them as an array. It requires the to produce a faster computing
use of another Pi, which acts as experience. Climbers.net
the controller the HAT plugs recorded a performance
into this, and then you mount increase of over 400% when the
your Pi Zeroes on the top using four Pi Zeroes were combined
USB. Power is supplied from the using the Cluster HAT, although
controllers GPIO, and you can this is still less than half the
control its output to each of the performance of the Raspberry
Pi Zeroes independently. You Pi 3 acting alone. Still, this is a
will, however, need microSD cheap and effective way to start
cards for each individual Pi Zero, exploring the world of cluster
on to which specialised Raspbian computing, from teaching how
Jessie images will need to be it works to developing software
installed from the Cluster HAT that could then be ported to
website (click the Software link). more powerful clusters.

42 // // Winter 2016
Raspberry Pi add-ons TOP 20

15

ProtoZero
Give your latest project a more permanent
home by losing the breadboard
5, www.pimoroni.com stage by giving you a board on
The Pis educational, hobbyist which you can solder your
and practical side is never better components permanently. Its
expressed than in designing and designed to match the Pi Zeros
building your own electronics form factor, and sits neatly on
projects. When it comes to top of the Pi Zeros GPIO pins (a
testing your projects, you cant female GPIO header is included,
beat a good breadboard, which but not fitted). Here youll also
enables you to connect wires find two rows of corresponding
without soldering them, ensuring and clearly labelled connector
you dont make a costly or at holes for the GPIO pins. Theres
least time-consuming mistake also another 154 holes, split into
during prototyping. But at some logical lanes of three, into which
point youll want to move on you can solder your components
from your breadboard youll on either side of the board, so
either want it for another project, you can hide wires. For more,
or its lack of portability will visit www.protoboards.co.uk.
become annoying as your wires Also consider: The ProtoPal
fall out for the umpteenth time. (5, www.pimoroni.com) is the
The ProtoZero enables you to ProtoZeros big brother, and the
take your prototype to the next shape and size of a regular HAT.

16

Zero4U
Add four full-size USB ports to your Pi Zero
6.40, www.uugear.com and the four full-size USB 2.0
Weve already looked at one way ports each sport a handy white
around the Pi Zeros chronic lack LED activity indicator.
of ports: the Broadcom Wi-Fi Its configured to provide up
Adapter and USB Hub. If you to 2,000mA of current across
want something that better the four USB ports, which is
integrates with the Pi Zero, or drawn from your power supply
you need even more USB ports, if you want to connect the
then the Zero4U is your lifeline. Zero4U to a regular Pi model,
It matches the Pi Zeros form then youll need a USB-mini USB
factor exactly, but is cleverly cable to interface the two.
designed to sit underneath it, so Note, there are two versions
the GPIO pins and other ports of the hub available: one for the
are left accessible (and usable) original (v1.2) Pi Zero, and the
at the top. Connecting the other for the newer v1.3 Pi Zero
Zero4U to the Pi Zero requires (with camera connector). Make
no soldering instead, there are sure you get the right one!
four pogo pins on the back that UUGear also provides a Zero4U
line up with the +5V, GND, USB and Pi Zero case for just 3.20.
D+ and USB D- testing pad on Also consider: For larger Pi
the back of your Pi. Plastic models, try the seven-port USB
screws are supplied to secure it, hub (15.40, www.uugear.com).

Winter 2016 // // 43
TOP 20 Raspberry Pi add-ons

17

DrumHAT &
PianoHAT
Turn your Pi into a music machine
Piano HAT 15, Drum HAT 12, The Drum HAT has eight
www.pimoroni.com capacitive sensor pads, each
The Piano HAT has 16 capacitive labelled with a specific drum and
touch buttons, 13 arranged as containing an LED that lights up
a single-octave keyboard, plus when the pad is tapped. You can
controls for moving up and down assign a sample to each pad
the octave range and switching (musical instruments, drums,
synthesised instrument. All 16 voices, whatever) or program
have LEDs you can program to them to call any functions you
light up when the key is pressed. like when tapped or released.
A beginners guide is on the Also consider: The Adafruit
Pimoroni website, plus a MIDI Capacitive Touch HAT (15.50,
control option and a Python www.pimoroni.com) has 12
library, useful for running synths capacitive touch sensors you
like Yoshimi, SunVox, playing can connect to any conductive
music with Python or inputting object using alligator clips (not
sheet music via MuseScore. supplied) to respond to a touch.

18

4tronix Picon
Zero
A controller for your next robotics project
13.30, www.4tronix.co.uk three-pin GVS connectors, which
This is an intelligent robotics plug into most devices. Power
controller, which means theres a can come either from your Pi
built-in process to handle all the or via separate adapters, and
direct communication between a a dedicated socket supports the
robots input and output devices. optional HC-SR04 ultrasonic
It uses the I2C interface, leaving sensor, for avoiding obstacles.
all the GPIO pins free, and comes Theres an extensive Python
with two H-Bridge motor drivers, library, with ScratchGPIO
giving you forward and reverse, support also promised. It plugs
plus variable speed controls. into any Pi that has the now-
The four general purpose inputs standard 40-pin GPIO header.
support digital, analogue or a Also consider: MotoZero (10,
DS18B20 temperature sensor. www.thepihut.com) is great for
Up to six outputs are provided, motor control you can connect
supporting digital, PWM, servo up to four, and its Pi Zero size.
and WS2812 (Neopixels). Both Unlike the Picon Zero, it requires
input and outputs use standard some soldering during assembly.

44 // // Winter 2016
Raspberry Pi add-ons TOP 20

19

OSMC PiDrive
Create a media centre with its own storage
$80, www.modmypi.com less power than other WD drives.
Like to turn your Pi into a media Its based on the WD Blue slim
centre, capable of streaming and drive, a 7mm high 2.5-inch drive.
playing both local and remotely The case comes with a 3A power
stored video, music and photos? supply to power both your Pi and
The perfect operating system to the drive from a single plug
use is OSMC (www.osmc.tv), a socket, OSMC preloaded on an
specially designed version of 8GB microSD card, mounting
renowned media centre Kodi media and a single power/data
(www.kodi.tv) optimised for the cable that connects the Pi and
Pi, and this PiDrive Kit should drive, as well as linking them to
appeal to anyone looking for a the 3A power supply.
single place to both store and Also consider: The 314GB drive
stream their media. is available separately for under
The OSMC PiDrive Kit is a 30 (http://wdlabs.wd.com), or
case designed to house both 70 buys you the newer 1TB WD
your Pi and the supplied 314GB PiDrive Kit if you need additional
Western Digital PiDrive, on which storage. Note, this is 9.5mm high
youll store all your media files. and comes with the WD PiDrive
The PiDrive has been designed Enclosure and stand for housing
to work more efficiently with the your Pi and the drive, plus all
Pi than standard drives, drawing required cables.

20

Pi compatible
USB Gamepad
Add a new dimension to your gaming
7, www.modmypi.com cable means you dont have to
Not sold on the idea of building a hunch up next to the screen in
full-blown arcade cabinet? Then order to immerse yourself in a
how about this KXD-branded gaming experience guaranteed
gamepad? It follows the classic to take you on a nostalgia trip.
design with two analogue mini One final point: if you already
joysticks and a traditional D-pad, have a Windows analogue
which offers eight-way direction. controller, you might find its
It has the full gamut of trigger already compatible with RetroPie
buttons, from the X, Y, A and B plug it in and give a whirl first.
buttons on the top to the dual Also consider: Want to go even
left and right shoulder buttons, more old-school? Check out the
plus Start and Select buttons, SNES style USB gamepad (4,
giving you plenty of options www.modmypi.com). It has a
during your gaming. traditional four-way D-pad, four
The gamepad should work trigger buttons and Start and
with any emulator its plug and Select, so will suit most games
play with RetroPie and a 1.4m from the mid-90s and before.

Winter 2016 // // 45
Helping you live better & work smarter

LIFEHACKER UK IS THE EXPERT GUIDE FOR


ANYONE LOOKING TO GET THINGS DONE
Thousands of tips to improve your home & workplace
Get more from your smartphone, tablet & computer
Be more efficient and increase your productivity

www.lifehacker.co.uk
twitter.com/lifehackeruk facebook.com/lifehackeruk
Pi PROJECTS
Put your Pi to use we show you how, step-by-step!
54

48 59

ITS COLD UP THERE...


PROGRAM A SENSEHAT, AS
USED ON THE INTERNATIONAL
SPACE STATION, TO TELL YOU 64
THE TEMPERATURE

69

48 Get started with


the SenseHAT

54 Recreate the
Enigma machine

59 Build your
own drone

64 Set up a cloud
data server

69 Build your
first robot

72 75 78 72 Master the Pi
Camera Module

75 Make speakers
Wi-Fi-enabled

78 Enjoy internet
radio on the Pi
September 2016 // // 47

Winter 2016 // // 47
The SenseHAT
was used in the
Astro Pi project
on the ISS.

Get started with


the SenseHAT
Nate Drake introduces the sensational SenseHAT and explains how to use
its sensors to measure the environment around you and execute commands

A
lthough the Raspberry Pi is a powerful Top) are hardware devices which, as the name
miniature computer, its only as suggests, can be connected easily onto the top
effective as the data feeding it. Many of a Raspberry Pi via its GPIO (General Purpose
of the projects available for the Pi are Input/Output) connector. The HATs are made
only software-based, meaning they to an exacting standard and so most will work
process inputs from the keyboard or mouse or straight out of the box.
data downloaded from the internet. The SenseHAT was originally designed for the
Using additional hardware, the Pi is capable of AstroPi Mission (more about this in a moment).
sensing a number of factors in your environment It comes bristling with a veritable Swiss Army knife
including the external temperature, the orientation of gadgets and sensors, including a gyroscope,
of the Pi, light levels and much more. accelerometer, magnetometer, thermometer,
There is virtually no limit to the applications barometer and humidity sensor. This makes it
for these. In this project, we will explore how to ideal for both budding astronauts and those
use the SenseHAT add-on for the Pi to sense the interested in more mundane projects.
ambient temperature and alert you via email if it The SenseHAT also contains a 8x8 LED matrix
is too cold or too hot. This can be extremely display and a five-button joystick for interfacing
useful for budding gardeners and we hope that projects. There are in fact two thermometers,
once you become familiar with the SenseHAT and one built into the humidity sensor and one built
programming in Python (which well talk about into the barometer. For the purposes of this
shortly), you will take your coding further and project we will be using the default one built
create more exciting interfacing projects. into the humidity sensor.
In order to proceed, youll need a Raspberry Pi The SenseHAT is currently available from
Model 2 or 3 with the latest version of Raspbian the Pi Hut website for 30 including shipping
installed. You might also wish to invest in a to mainland UK. See https://thepihut.com/
SenseHAT, although as well see it is possible products/raspberry-pi-sense-hat-astro-pi for
to get going without one... more details. If you simply want to learn more
about interfacing hardware and coding, the Pi also
Enter the SenseHAT has a SenseHAT Emulator (more on this shortly).
The SenseHAT is quite simply an add on board for Two AstroPi computers, which are quite simply
the Raspberry Pi. HATs (Hardware Attached On Raspberry Pis with SenseHATs attached in a

48 // // Winter 2016
SenseHAT PROJECT

The SenseHAT
clips neatly into
your Pis GPIO
port to extend its
functionality.

special 3D-printed case, were flown to the SenseHAT isnt useful just for investigating the
International Space Station in December 2015. question of life on Mars. Indeed, when taking your
Pi bites
They formed part of British astronaut Tim Peakes first steps with projects like these, you dont even For a full list of
mission, codenamed Principia. They took need to buy any hardware beyond the Pi itself. the experiments
advantage of the huge range of data the AstroPi run by Tim Peake
can gather, and combined with the radiation and The amazing Emulator and his colleagues
on the ISS,
weightlessness of space allowed for experiments The latest version of Raspbian comes with a see https://
that cannot be performed on Earth. SenseHAT emulator, which can be launched from principia.org.uk/
Students from all across the UK took part in a Menu > Programming > SenseHAT Emulator. The the-mission/
competition and suggested various experiments to emulator will provide input in exactly the same way experiments-in-
space/
Tim, which he then performed inside the European as the real thing, except that you control elements
Columbus module, making the results available for like temperature, humidity and the joystick using
earth dwellers. See page 114 for more details. on-screen slider bars and buttons.
To date only a small number of experiments Given the low cost of the SenseHAT, you may
have been run but fortunately the AstroPis wonder what use the emulator is, considering

SOME LIKE IT HOT


Although the SenseHAT has an array of # os.system('python3 alert.py') Go to File > Save and give the project a
sensors, its a good idea to start with a memorable name, such as temp.py. Make
simple project, for instance to alert you if if temp > tmax: sure that both scripts are saved to your
the temperature is too high or too low. print ("It's too hot") /home/pi folder. Once the project is saved,
Go to Menu > Programming > Python 3 print (temp) you can go to Run > Run Module from the
(IDLE) on the Pi. Now click File > New File # Uncomment the line below (remove #) Menu or press F5 at any time to execute.
to start a new project, then write in the to execute "alert" script.
following code: # os.system('python3 alert.py')
from sense_hat import SenseHat
import os if temp > tmin and temp < tmax:
print ("Temperature is normal.")
sense = SenseHat() print (temp)
tmin = 8 The values tmin and tmax are simply
tmax = 27 your chosen minimum and maximum
temp = sense.get_temperature() temperatures for the greenhouse, so feel
temp = int(temp) free to change these.
If you want to trigger an event say,
if temp < tmin: send an email in response to sensor data
print ("It's too cold") then remove the # at the start of the lines
print (temp) reading # os.system('python3 alert.py').
# Uncomment the line below (remove #) Otherwise by default the program will run, Its time to start programming your
to execute "alert" script. display its message and then exit. SenseHAT using Python.

Winter 2016 // // 49
PROJECT SenseHAT

SET UP EMAIL ALERTS


Your alert script can execute any Python code. This sample script
will send an email from a Gmail account to the email account of body = "This is an automated message from Greenhouse One. The
your choice, but feel free to experiment with Python to change the temperature is " + (strtemp) + " degrees."
nature of the alert, for example by sending a Whatsapp message msg.attach(MIMEText(body, 'plain'))
instead of an email.
Go to Menu > Programming > Python 3 (IDLE) on your server = smtplib.SMTP('smtp.gmail.com', 587)
Raspberry Pi. Next click File > New File to start a new project. server.starttls()
Paste in the following code: server.login(fromaddr, "yourgmailpassword")
from sense_hat import SenseHat text = msg.as_string()
import smtplib server.sendmail(fromaddr, toaddr, text)
from email.mime.multipart import MIMEMultipart server.quit()
from email.mime.text import MIMEText Obviously change yourownemailaddress@gmail.com and
yourgmailpassword to reflect your own details. For security,
sense = SenseHat() its advisable to have a dedicated email account for this purpose.
Also edit recepientemailaddress@gmx.com to the email address
temp = sense.get_temperature() where you want to receive alerts. The default message simply
temp = int(temp) contains an alert stating the current temperature at the time
strtemp = str(temp) the email was sent; you can edit this too if you wish.
If you use a different email provider, you can amend server =
fromaddr = "yourownemailaddress@gmail.com" smtplib.SMTP('smtp.gmail.com', 587) to reflect your providers
toaddr = "recepientemailaddress@gmx.com" SMTP server and port for example, for Yahoo, server = smtplib.
msg = MIMEMultipart() SMTP('smtp.mail.yahoo.com', 465)
msg['From'] = fromaddr Go to File > Save and save the file as python3 alert.py. Make
msg['To'] = toaddr sure it is in the same /home/pi directory as the temp.py script you
msg['Subject'] = "GreenHouse Alert" created on the previous page.

If you use email make sure to choose a distinctive name for your email alert account, like Greenhouse A. This will avoid confusion later on.

that you can just plug in the real thing and execute Environment). This enables you to quickly
your code. In the first instance, if you have very generate and execute your own Python scripts.
specific requirements and are not sure whether When using the Python IDLE program on the Pi,
the SenseHAT is right for you, the emulator gives whenever you create a new project it will
you a chance to test drive any code youve made. automatically be saved in your home folder.
The emulator is also particularly useful when you Make sure to save it with a meaningful name.
test a number of different projects. It also allows While Python is by no means the only
easy sharing of any Python scripts you create programming language out there, it is arguably
through social media or over the web. one of the easiest for beginners to master. Theres
Pi bites Any code you write for the emulator can be also a huge amount of information available on the
The Emulator adapted for an actual SenseHAT by editing the Raspberry Pi website and elsewhere to help get
program has first line of code (see Sensory overload on the you started in Python.
some helpful opposite page for more information this). For the There is no real limit to what Python can do, and
examples of code purposes of this project, use the Temperature youll find that many Raspberry Pi projects have
for Beginner,
Intermediate and
slider to increase or decrease the temperature to been built using this language. If you have specific
Advanced users. test that your script works. requirements for your projects such as your Pi
Simply go to File > sending a tweet when your greenhouse becomes
Open Example to Pithy Python too warm, you can visit the main websites oddly
get started.
The language used in the sample scripts is Python named Cheese Shop (http://pypi.python.org/
specifically Python v 3.4.2. This distinction is pypi?%3Aaction=index) to check that what you
important as different versions of Python can use want is possible.
different syntaxes and commands. Even though its very easy to learn Python
Python is the language of choice to interact terms, you should pay very careful attention to
with the SenseHAT and is one of many supported capitalisation of words and spacing as some
programming languages on the Pi through Python Python scripts may not recognise commands
IDLE (Integrated Development and Learning without the proper lettering and/or indent.

50 // // Winter 2016
SenseHAT PROJECT

The AstroPis
heavenly body. 3D
blueprints for the
casing are available
on the Astro Pi
Missions website,
https://astro-pi.org

Image credit: https://astro-pi.org/wp-content/


You might also see that some code online is
marked as being suitable for Python 2 or Python 3.
The latest version of Raspbian supports both as
some commands are not available in the one
version or another. Go to Menu > Programming to
view the programs for each of these. The sample
code for this project was written using Python 3.

Temperate timing
By default the supplied scripts are designed to
run only once. This can be a problem if you want
the Pi to continuously measure a value such as
the ambient temperature.
The solution is the handy tool Cron, which is
built into your Pi. Its used to schedule tasks and
can be told to execute a script at certain times. command, you may be asked to choose an Editor. The emulator
For a full rundown of what Cron can do, we suggest Choose Option 2 to use the simplest version. enables you
reading the Raspberry Pi documentation at Press Ctrl + X, then Y, then Return to save and to adjust the
https://www.raspberrypi.org/documentation/ exit. You can double-check scheduled jobs by environment
linux/usage/cron.md. In brief, however, Cron is running the command crontab -l using buttons and
slider switches.
one way to have a script continuously check a If you want your sensor script to run
The sample
value. The basic format of Cron is: continuously, for example because you wish to code pictured
minute hour day of month month day of the use the LED display to show the temperature, then is to change the
week command instead of using Cron you can simply modify the SenseHATs LED
An asterisk must be used in place of any of Python code. Simply add the following: colours in line
these values that you are not using in a particular while True: with temperature.
case. If for instance you wished to execute the to the line directly above the first if to make the
script myscript.py in your Pis home folder at script run constantly.
midnight every night, the format would be: You can find examples of code which will light
0 0 * * * python3 /home/pi/myscript.py LEDs in response to temperature in both the Pi bites
This is particularly handy if youre using email Emulator examples and in the SenseHAT
The Python
to send out alerts to avoid your mailbox being documentation on the Raspberry Pi website website has
flooded with messages every few seconds. https://www.raspberrypi.org/learning/getting- some excellent
In order to set up a Cron job, open Terminal on started-with-the-sense-hat/worksheet/. tutorials for first-
your Pi or connect via SSH and run the command: timers at http://
crontab -e Sensory overload wiki.python.
org/moin/
Scroll to the very bottom of the text and paste The code you have seen in this tutorial is a very BeginnersGuide/
your job (say the midnight script example weve tiny slice of the Pis potential to use Python and Programmers
just looked at). The first time you run the crontab the SenseHAT, and should be seen as inspiration

Winter 2016 // // 51
PROJECT SenseHAT

If youre interested in understanding the


SenseHAT further, the Raspberry Pi Foundation
has produced its own free e-book SenseHAT
Essentials (https://raspberrypi.org/magpi-
issues/Essentials_SenseHAT_v1.pdf). If the
coding examples provided in the emulator seem
a little too basic for your tastes, you may also wish
to head over to the Emulator developers website
(https://trinket.io/sense-hat) for examples of
everything from how to take things a step further
with the sensors to playing the Pi at Rock, Paper,
Scissors. The website also has a handy online
A simple for more projects rather than an end in itself. The SenseHAT emulator.
Python script sample code is quite simple to execute if you have If any of your new projects require using the
using While already installed a SenseHAT. If you choose to joystick, first try to use it out-of-the-box. If
True:. Here the amend it or you simply wish to test pilot it before however you believe it needs calibrating, then
temperature
buying a SenseHAT, you can amend the scripts to follow the steps as outlined in the SenseHAT
is constantly
displayed,
use the Pis built in SenseHAT Emulator. Simply go documentation at https://www.raspberrypi.org/
rounded off to Menu > Programming > Python 3 (IDLE) and documentation/hardware/sense-hat/.
to the nearest change the very first line If your Python 3 program isnt reporting any
decimal place. from sense_hat import SenseHat errors but you arent receiving any alerts, try
to running the alert script on its own, either through
from sense_emu import SenseHat opening it within the program or by opening
You can then open the Emulator from Menu > Terminal and running the following command
Programming > SenseHAT Emulator and then use from within your home directory:
the slider switch to test different temperatures, or sudo python alert.py
run your amended code to verify that everything This will help you narrow down the issue.
works as expected. Another very helpful way to iron out any bugs in
code without having to run the program every time
Taking it further from within the Python program is to have it check
As we previously discussed, the SenseHAT has your module by holding Alt+X. This is especially
its own gyroscope, humidity sensor, pressure handy if youve set up email alerts to save yourself
sensor, joystick, LED display and much more. In from being bombarded by messages.
particular for a greenhouse project, measuring Finally, to follow the stellar AstroPi mission
the humidity as well as the ambient temperature and see many more wonderful applications of the
can be useful for knowing when conditions are SenseHAT, be sure to visit the main website at
optimal for your plants. https://astro-pi.org.

SETTING UP YOUR SENSEHAT JOB

1 Create sensor script 2 Schedule Cron job 3 Create alert script


Build your sensor script as described By default the script you created will This step is optional but adds the
in Some Like It Hot on page 49. check the sensors only once. If you icing on the cake. Follow the steps
Remember to uncomment the lines want it to do so regularly, youll need in Set Up Email Alerts on page 50 to
in the alert script if you want to to tell the Pi to execute it at certain create a script that will run if certain
trigger an action in response to sensor times. Open Terminal on the Pi and conditions are met your greenhouse
data. Save the script with an easily run the command crontab -e . temperature falls above or below the
recognisable name say, temp.py. Scroll to the bottom of the file and limits you set up previously. Dont be
into your /home/pi folder. add the following: afraid to customise this script in any
*/10 * * * * python3 /home/pi/temp.py way you see fit, but be sure to save it
The Pi will now run temp.py every in the same folder as the main script
ten minutes. you created in Step 1.

52 // // Winter 2016
The home of technology

techradar.com
Make an amazing
Enigma machine
Nate Drake explores how to crack the code and set up an authentic version
of the Enigma cipher machine used by the German military during WW2

S
ome people thought we were at war the Raspberry Pi as well as how to configure the
with the Germans. Incorrect. We were Enigma machine in a way similar to the operators
at war with the clock. These words in World War II. We will also explore the workings of
were attributed to Alan Turing, as Enigma devices in order to understand how the Pi
played by Benedict Cumberbatch in will encode your messages.
the 2014 film The Imitation Game. Turing was
referring to the Enigma machine, which was being Enigmatic myths
used by the Germans to encode military radio The Enigma machine was invented sometime
messages during World War 2 and to date had after World War I, although its inventor, German
proved near impossible for the Allies to crack. engineer Arthur Scherbius, initially saw only
In technical terms Enigma machines were lacklustre interest from private companies.
whats known as electro-mechanical rotor cipher With the outbreak of World War II the military
machines. They resembled large typewriters. An of several countries started taking an interest in
operator would configure the machine according the machine and began adapting it by beefing up
to pre-agreed settings and encode a message its security. So its misleading to talk about the
using the keyboard. For each letter that was Enigma machine there are several. Indeed, just
pressed, the mechanical parts would complete as different countries adapted Enigma to their
A four-rotor
an electric circuit. The corresponding encoded needs, different military departments within
Enigma machine.
Different letter would then light up on the machine. Each Germany used variations of the machine too.
machines were key press shuffles at least one rotor one place The py-enigma library is capable of emulating
used by different forward, meaning that the same letter is never the German Heer (Army) and Luftwaffe (Air Force)
encoded the same way twice. Enigma machines by default. Its also capable of
Image credit: Greg Goebel, Public Domain

branches of the
German military. Thanks to programmer Brian Neals py-enigma emulating the Kriegsmarine (Naval) Enigma, which
library, it is now possible to reproduce the machine had a more sophisticated design. For the purposes
exactly using the programming language Python. of this project we are going to concentrate on the
The Raspberry Pi is perfect for running as an simplest implementation of Enigma used by the
Enigma machine, thanks to the fact that it Army and Air Force.
supports Python and has an excellent hardware Another common misconception about Enigma
random number generator. In this project we will is that it was singlehandedly cracked by the code-
explore how to download the py-enigma library to breakers of Bletchley Park. It was in fact initially

54 // // Winter 2016
Enigma coding machine PROJECT

ENIGMA ENCRYPTION
To encode messages youll first need to $ sudo python pyenigma.py --key-file /home/pi/
navigate to where the handy enigma keyfile.key --start='APJ' --day=29
command line program is stored. Connect --text='UVXUVX'.

Image credit: Matt Crypto, CC BY-SA 3.0


via SSH or open Terminal on the Pi and use This gives the text output QMMZIY.
the cd command to do this e.g. Next use the message key to change the
$ cd /home/pi/bgneal-enigma-f3af458a5d2d starting position of the rotors and encrypt
Next examine your key sheet and the actual message, for instance:
determine which days settings you want to $ sudo python pyenigma.py --keyw-file /home/
use. Decide on three random letters to use pi/keyfile.key --start='UVX' --day=29
as the message key. --text='MEET ME AT MIDNIGHT'
Youll next run a command to encrypt the This gives the text output
message key. Leave the rotors in the same HPZXUWHMICMHUFCXOTU.
starting position as in your keyfile for now. Decryption works using the same Cables were used to connect letters on the
$ sudo python pyenigma.py --key-file procedure in reverse. First set Enigma to plugboard. Here A is paired with O and Y with J.
yourkeyfilename --start='ABC' the days key settings to obtain the The standard number of pairs was ten.
--day=DAYOFMONTH --text='MESSAGE KEY message key:
TEXT' $ sudo python pyenigma.py --key-file /home/pi/ $ sudo python pyenigma.py --key-file /home/pi/
For instance if its the 29th day of the keyfile.key --start='APJ' --day=29 keyfile.key --start='UVX' --day=29
month, the initial rotor positions in your --text='QMMZIY' --text='HPZXUWHMICMHUFCXOTU'
keyfile are APJ and you want to use the Next use the message key UVX to decrypt This decodes to the original message
message key UVX then you would write: the actual message: Meet me at midnight.

broken by a Polish Cryptographer Marian Rejewski. when pressed completed an electrical circuit
Rejewski designed the first clockwork bombe which would light up the encoded letter. For
Pi bites
machines which were used to test various Enigma example, when encrypting a message starting A working replica
settings and crack the code. This represented a WET..., the operator would first press the W key, of the Turing-
huge leap forward as the Polish previously had had and the Z lamp might light up, so Z would be the Welchman Bombe
to resort to perforated cardboard sheets known as first letter of the ciphertext. The operator would is at the Bletchley
Park Museum.
Zygalski sheets to try various permutations. then press E and note down the ciphertext letter, For a video of
Alan Turing designed a number of more and so on. it in action, see
sophisticated versions of the Polish Cipher http://bit.ly/
Bureaus bombe, which, as depicted in The Anatomy of Enigma Turing-bombe.
Imitation Game, worked in combination with a Each key press would turn at least one of the
crib some known text in a message, such as rotors once. The rotors formed the core of the
the word Wetter (weather), which could be used powerful code behind Enigma. Operators would
to decode German messages. place three rotors out of a possible five on a
The Enigma Machine used by the Army and Air spindle inside the machine. Each rotor had 26
Force consisted of several parts. The keyboard electrical contact pins on one side to represent

Monument to
Marian Rejewski
in Bydgoszcz,
Poland. Note
the ornamental
Enigma machine
next to him.
Image credit: Wojsyl, CC BY-SA 3.0

Winter 2016 // // 55
Image credit: RadioFan, CC BY-SA 3.0

Enigma rotor each of the letters of the alphabet, and the rotors, which would hugely increase the encryption
detail on display rotors were labelled using Roman numerals from strength of the message.
at the National I to V so they were easy to tell apart. When placed One final feature of the Enigma was the
Cryptology Umkehrwalze (reflector). The reflector could not
in an Enigma, each rotor can be set to one of 26
Museum. The
possible positions. This was known as the be easily changed but as the name suggested
internal wiring
for each separate
Ringstellung (literally the ring setting) and made sure that the encryption and decryption
rotor, for example allowed one letter to be encoded as another. process were the same. This meant that two
Rotor V, was By itself a single rotor would offer little operators who had set up their Enigmas with the
the same from protection for your message. It would be set up in same settings could easily encode and decode
machine to such a way that for example when you press the each others messages. One drawback of the
machine. letter A, it would complete a circuit so that the reflector is that a letter could never be encoded as
letter T would light up on the Enigma. The letter B itself, which is a weakness the Allies exploited.
might be Q, and so on. This is a simple substitution
alphabet and it could be broken very easily simply Enigma operators
by examining the most common letters to work Enigma operators were handed a key sheet by
out, which are E, T, A and so on, until the rest of the an officer containing the Enigma settings for that
message could be deciphered. day. First the choice and positioning of the rotors
The cunning of Enigma was achieved through would be listed for example, IV, V and I. Next
using multiple rotors. Each of the rotors had would be the initial position of the rotors either
notches at different points along the alphabet as letters or as numbers say A F P or 1 6 16.
ring. This resulted in a different substitution The plugboard settings would follow. The Enigma
alphabet being used as the rotors turned. The machine allowed for up to 13 pairings, but the
Pi bites rotor on the extreme right would move one letter Army standard was 10.
forward each time a key was pressed and the Finally the Kenngruppen would be listed.
Image credit : Tony Sale, http://www.codesandciphers.org.uk

Programmer
Louise Dades others less frequently, depending on the rotor These were a series of letters that allowed
website has an settings. Provided that a message was short operators to identify on which particular day the
excellent key book enough, the word Deutschland for instance message was sent. This is one area where the
generator which
will create a PDF
could be encoded any number of ways in the same py-enigma library on the Pi diverges from the
of random key message, making it near impossible to crack. original Enigma machine as its key sheets simply
settings for up Allied attempts at breaking the code were place the numbered day of the month at the start.
to 40 days. See frustrated even further by the Steckerbrett See The Key to Enigma opposite for more.
http://enigma.
(plugboard), which was positioned at the front of
louisedade.co.uk/
dailykeys.html the machine below the keys. Letters were wired
together in pairs through cables before the text
was encoded. For instance the letter F could be
paired with the letter J. Having steckered pairs
of letters such as these would mean that each Example of a daily key sheet. For security reasons, officers
time the letter F was pressed, the signal would be would often tear a strip off the sheet to give operators the
diverted to the letter J before going through the settings for that day only.

56 // // Winter 2016
Enigma coding machine PROJECT

THE KEY TO ENIGMA Copy of the


Keysheet used
Py-enigma closely matches the settings for the original by the Germany
Enigma machine but adds the option to choose your own Army in October
Umkehrwalze (reflector). These were hardwired into the 1944. Py-enigma
original machines and usually werent changed in the doesnt use the
field. For more information on what the reflector is and Kenngruppen,
does, see http://users.telenet.be/d.rijmenants/en/ so you can ignore
enigmatech.htm#reflector. For now we suggest using these if you wish.
type B, which was the one used by the German Army.
The easiest way to store key settings is through use of
a key file. Open Terminal on your Pi or connect via SSH
and type:
sudo nano keyfile.key
This will create a blank file. You write the settings in the
format Day, columns, rotor settings, letter pairings and
reflector.
Paste in the text below by way of an example to
get started: and/or different Enigma machines if you like. For more
# My sample key settings file information see http://py-enigma.readthedocs.io/en/
# First number represents the day of the month latest/keyfile.html.
29 II IV V A P J AV BS CG DL FU HZ IN KM OW RX B Once youve pasted in the settings you need, save and
28 IV II I C S M FA GX HL IQ KZ ME NS PR TB WC B exit by pressing Ctrl + X, Y, then Return.
27 II IV V F V P PK QH RV SA UJ WO XC ZB DL GM B Make sure that everyone with whom you want to
You can adapt the keyfile to choose different settings exchange messages has a copy of the keyfile.

The Germans quickly realised that if thousands


of messages were sent every day using the same
settings then eventually the rotors would all
revolve fully and encrypt messages in the same
way, making them vulnerable to being cracked.
For this reason, an operator would decide on a
message key for each message.
First, the Enigma machine would be set up

Image credit: Antoine Taveneaux, CC BY-SA 3.0.


exactly as outlined in the key sheet. The operator
would then choose three letters at random say,
DAX and transmit these to the receiver. The
convention at the time was to repeat the message
key twice, making our example DAXDAX. The
operator would then change the rotor positions
on their Enigma to match the message key and
send the message itself.
To decode a message, the receiving operator
would firstly only have to input the encoded
message key into Enigma to work out that their days running, meaning that if the day key had A replica of the
counterpart is using the message key DAX. They previously been cracked then a whole range of Turing-Welchman
could then change the positions of their rotors possible rotor positions could be eliminated. The Bombe at the
Bletchley Park
and decrypt the message itself. same held true for plugboard settings.
Museum. The
Despite the wisdom of using a message key,
Breaking Enigma German operators would sometimes be lazy and
bombe could try
thousands of
The reflector was a major Achilles heel for Enigma repeat keys or use ones grouped together on a rotor positions
because no letter could be encoded as itself. This keyboard. These were termed cillies, a name that per hour, which
meant that if, for instance, you believed that the may have come from the predictable day key CIL. made cracking
word ENGLAND was somewhere inside a Aware of these shortcomings, the German Enigma much
message, then you could eliminate any group of Kriegsmarine increased the strength of Enigma by easier than doing
letters containing those letters. adding three more rotors, making a total of eight. this by hand.
The Allies also made use of cribs where at They also avoided sending predictable messages,
least some of the message was known to crack so the German Naval Enigma remained largely
the day key. For instance the Germans usually impenetrable throughout the war.
transmitted a weather report around 06:00 daily Submarine commanders were also given
which followed a predictable format and would Enigma code books printed with red ink upon
contain the word WETTER (weather). paper that dissolved readily in water, an added
Certain features chosen by the Germans to precaution to prevent seizure.
increase security actually weakened Enigma. Rotor Ian Fleming, who gathered information for his
positions were not allowed to be the same two James Bond novels while stationed at Bletchley,

Winter 2016 // // 57
PROJECT Enigma coding machine

The complexity former overseas colonies and happily decoded


of the Enigma their messages for decades.
machine was
more than Enigmatic issues
equalled by the As the py-enigma software can easily be run from
complexity of
the command line, there are few ways that this
the ingenious
project can go wrong. As weve noted, there were
mechanisms
devised to crack
several different types of Enigma machines, so if
the code. you want to exchange messages, its important
that you decide to use the same kind. The military
M3 (three-rotor) machine is perhaps the most well
known and easiest to use.
While this is an excellent project to do for fun,
the fact that the Allies broke Enigma during World
War II should be reason enough not to rely on it to
store any truly private information.
For a more in-depth history of how the Allies
cracked Enigma, feel free to visit the Bletchley
Park website at www.bletchleypark.org.uk/
content/hist/worldwartwo/enigma.rhtm. For
ventured a plan to capture Naval Enigma books more information on py-enigma specifically, or if
which would do even 007 proud. His suggestion you wish to congratulate Brian on his masterpiece
was to disguise some British commandos as of coding, visit http://py-enigma.readthedocs.
downed German airmen and have them float io/en/latest/.
around in the middle of the Channel on a captured Brian has also not rested on his laurels but
fighter plane, looking helpless. Fleming believed a has taken the time to compile a Python library for
German U-boat would inevitably surface to assist two other cipher machines. The first is the M-209,
their supposed countrymen, at which point the which is a cipher machine employed by the US
Pi bites commandos would pop the hatch and raid the military during World War II. To download the
You can use the Pi sub. The plan was shelved indefinitely for being library see https://bitbucket.org/bgneal/
to create a truly too risky but does give some insight into how m209/. Brian has also created a library for the
random message valuable Enigma intelligence was. PURPLE Machine, which was used by the Japanese
key with this Thanks to the Official Secrets Act, the incredible Foreign Office before and during World War II. See
command: sudo
cat /dev/hwrng |
achievements of the codebreakers of Bletchley https://bitbucket.org/bgneal/purple/ for
tr -dc 'A-Z' | fold Park went unrecognised until the 70s. The British more information. Enigma, M-209 and Purple can
-w 3 | head -n 1 Government took advantage of this after World happily co-exist on the Raspberry Pi, so feel free
War II by selling Enigma machines to Britains to have fun with all three.

SET UP YOUR ENIGMA MACHINE

1 Download py-enigma 2 Prepare keyfiles 3 Encrypt/decrypt


library source files Use either a specialised key generator messages
Open Terminal or connect via SSH website or make up your own settings Once you either have your plain text
and run the following command to for the rotors and plugboard. This message ready to send or have
download the library: would also be a good time to decide received an encrypted message, the
$ wget https://bitbucket.org/bgneal/ on the kind of Enigma machine you steps are the same. Follow the steps
enigma/get/f3af458a5d2d.zip want to mimic (three-rotor, four-rotor, outlined in Enigma Encryption (on
Alternatively use your Pis web etc.). Once youve generated enough the second page of this feature) to
browser to download the file. keys, make sure to provide a paper encode or decode messages. For extra
Next unzip the file by running copy to everyone with whom you want security, do as the Germans did and
$ unzip f3af458a5d2d.zip then use to exchange messages. See The Key use the day key to encode the key
the command $ cd bgneal-enigma- to Enigma on the previous page for for each message separately.
f3af458a5d2d to be taken into the more information.
newly extracted folder.

58 // // Winter 2016
Build your own drone
Linux is at the heart of commercial drones, which means that with the right
kit and know-how you can build your own. Alastair Jennings explains how

Q
What you need uadcopters (drones) used to take The big turning point in drone design was the
hours of practice to master because addition of small processors on-board that were
z Raspberry Pi even the simplest manoeuvres, such able to stabilise flight and implement advance
Zero as takeoff and landing, could prove features, such as auto-braking, takeoff and
difficult. Learning to fly one took time landing. These enabled the pilot to get on with
z Erle Robotics
PXF Mini
and ultimately determination, and before you even having fun rather than worrying about the
took to the skies there was the small matter of mechanics and programming.
z Erle Robotics constructing one. As commercial drones have increased in
PXF Mini Power Now that theres a good selection of pre-built popularity and become more widespread, so have
Module
and programmed drones on the market, you can the open hardware and software communities. The
z HobbyKing go into major High Street retailers and buy one off latest open source drones are challenging their
Spec FPV250 the shelf. Drones such as the 3DR SOLO, Parrot more expensive rivals with advanced features,
Bebop and DJI Phantom have revolutionised the such as object avoidance and GPS navigation.
z 100mm male market, and slowly there are drones appearing This challenge to the commercial models is no
to male servo
cable
with advanced flight features that make flying real surprise and you dont have to look too far into
and controlling a drone much easier. the DIY drone community to find out that many of
z FlySky-i6 the main manufacturers are extremely active in
controller the open source world and regularly contribute
advice and support to those wishing to build their
z Edimax AC
EW-7811UAC

z RC XT-60
connectors

WARNING!
This project is suitable only for those aged 18 or over.
Piloting any drone is a dangerous and skilled task. Please
seek suitable guidance and training before attempting to
do so. Be aware there are serious legal consequences for
failing to follow UK Civil Aviation Authority guidelines (see
these at www.caa.co.uk).

Winter 2016 // // 59
PROJECT Build your own drone

GET THE AUTOPILOT LEVEL


Due to the small size of the drone its quite or landing, the effect as the drone tries to
difficult to keep things neat as you tuck in correct itself as can be quite dramatic.
wires, wrap insulation tape and zip ties Legs are an easy fix, but there are several
around the frame in order to hold everything other issues with the frame because it
together. Whilst it might seem fiddly and hasnt been designed for the shape or size
time-consuming to make sure that the of the autopilot were using. Not only this
PXFMini-Pi Zero combo is absolutely level, but the size of the space for the autopilot
its one of the most vital aspects of the build! is too small. This means that without filling
From the outset of building the frame you the hole its extremely difficult to get the
need to continually check that everything autopilot to sit flat. If its not flat then when it
about your build is as accurate as possible. takes off it will try to level itself, and if you do
The frame kit weve used in this project get it into the air the flight will be erratic.
does the job well despite being cheap, but In order to get around this and also to
there are some of the parts, including the help cut out vibrations from the motors,
frame legs, that take a bit to fit correctly and we added a large section of foam inside
have a habit of dropping out. The only way the slot. This helps to bulk out the section
around this particular issue is to glue them as well as create a rough damper for the
in place if one leg falls out during takeoff autopilot to sit on.

own for example, companies such as 3D at http://bit.ly/LXFdrone, with the latest


Robotics sell autopilot systems that can be Raspberry Pi Zero and Erle Robotics PXFMini.
programmed through software applications
such as Mission Planner. Setting up and soldering
3D Robotics involvement in the community is The first step is to prepare the Pi Zero and
apparent when you take a closer look at one of PXFmini. Fitting the two together is relatively
their drones. Exploring under the bonnet of the simple once the 40-pin GPIO connector has
3DR SOLO, youll see that its Linux based. The been soldered onto the Pi Zero. The connector
company also runs a huge education program, and is simply a set of two lines of pins that slot into
a full SDK is available for the SOLO. Were going to the top of the Zero and the corresponding socket
take a look at building a basic drone from a recent on the PXFMini.
open source community project, which youll find The cost of the Pi Zeros basic board is low at
just 4, but for this project you really need to get
SOLDERING IN THE PINS CAN BE the starter kit that includes the unpopulated
40-pin GPIO connector, Mini USB and HDMI
A BIT OF A CHALLENGE BECAUSE cables. A USB hub is also a good idea so that you

OF THE SMALL SIZE OF THE BOARD can connect a keyboard, mouse and Wi-Fi dongle.
Youll actually end up with two 40-pin
connectors if you buy this kit because, as it

The motors
might seem
small but theyre
powerful. Its
best to leave
the propellers
off until the
last moment.

60 // // Winter 2016
happens, theres one included with the PXFMini, the drone itself. There are many basic kits Each motor
but its worth paying 8 for the other connectors available, and theyre straightforward to use. is controlled
along with the Pi Zero. We ordered our Pi Zero from Weve gone for a HobbyKing Spec FPV250. by a separate
https://shop.pimoroni.com. Most of the small kits include all the basics, electronic speed
Soldering in the pins can be a bit of a challenge with a simple bolted-together frame, four small controller (ESC).
due to the small size of the board, and you must electronic speed controllers (ESC), and brushless
also make sure that the pins have enough length motors along with a battery.
above the board to interface with the PXFMini. The main components and electronics all need
The easiest way to do this is to use some Blu- to be taped and zip-tied to the frame, with only
Tack (or a similar removable adhesive product). the motors requiring screws. At this point, its well
We also found that sanding the pins with a bit of worth leaving the propellers off until the drone is
Wet and Dry or fine emery cloth, as you prefer, just correctly configured.
helps the solder to stick. As you put the drone together there are a
To prepare the board, place the GPIO pins into couple of key points. The PXFMini should be
the Pi Zero and turn the board over so that you can mounted with its connectors facing towards the
see the pins coming through the board. Put it on front of the craft; these pins are used to connect
the table so that its at about a 45 degree angle the ESC and the receiver if youre using an RC unit.
and use a bit of Blu-Tack to secure. Between the Pi Zero and frame, its essential
Now push the pins so that theres only a small that you add a section of foam to provide a bit of
portion a maximum of 1mm appearing through insulation from the vibration of the motors and to
the board, and use Blu-Tack to secure the position ensure that the PXFMini is level. A few additional
of the pins at one end of the board. The Blu-Tack extras that youll need during this part of the build
needs to be positioned on pins that were not are one male-to-male servo extension and four
soldering at first; then
once one end of the pins is
soldered and secured we can
remove the Blu-Tack and
finish the job. If the Blu-Tack
gets hot then it will burn and
become difficult to remove.
Youll need to solder all the
pins and make sure that you
avoid any dry solders. A fine-
tipped soldering iron with a
new tip will make your life
Check that all
easier if youre not used
wires are secure
to soldering.
and that all

Drone building
motors react to
commands from
Once you have the two boards the transmitter
connected, you can make a before attaching
start on the construction of the propellers.

Winter 2016 // // 61
PROJECT Build your own drone

Four speed
The Pi Zero can only read the
controllers
FAT32 file system, so before you
adjust the lift
and direction of
continue make sure you have
the drone. formatted your card correctly and
not used exFAT. With the OS
downloaded and the microSD card
ready, open a Terminal and type
df -h to check the disks attached
to your computer.
In order to flash the MicroSD
card with the latest OS Image,
youll need to unmount the card.
If your card is 32GB or more in
capacity, youll see that the disk
has two partitions, so make sure
you eject both. Type in:
umount /dev/disk2s1
Now to flash the OS to the card,
make sure that the file you have
downloaded has not yet been
uncompressed and type in the
following command (the initial
zcat command first decompresses
the disk image; change /Path/to/
male and female RC XT60 LiPo connectors. At the image/ to your desired destination directory):
moment the two boards are empty of commands sudo zcat /Path/to/image/PXFmini.img.gz | sudo dd
and before they can be used to control the of=/dev/disk bs=8M
drone they need to be flashed with an OS. This OS, The flashing process can take some time as the
as with all Raspberry Pi boards, is held on an SD uncompressed file is well over 7GB.
card a MicroSD card in this case which can Once the process is complete, eject the card
be quickly installed into the back of the Pi Zero. from your computer and install it into the Pi Zero.
The Pi must now be connected to a monitor,
Flashing the Pi Zero keyboard and mouse to finish the installation
The OS needed for the drone and for use with process. After the Pi boots, youll see the basic
the Pi Zero and PXFMini autopilot system has been Erle Robotics splash screen and a bar of Icons
pre-compiled by Erle Robotics and is based on showing the different Vehicle projects that the
Debian. As long as you purchased the board board can be used with.
directly from them, the company will email Click the Erle Copter picture and the screen
through a link to the latest version of the OS. If not, will disappear and the board will reboot. Leave
its possible to compile it yourself, although this the Pi Zero to run through the boot sequence
will be a more advanced task and might prove and this time rather than loading a graphical user
challenging if youre new to such things. interface, the board will boot to a command line

THE FIRST FLIGHT


Before you begin, double-check your On the transmitter, move the left stick
drone and make sure that everything is to the bottom-right position for five
in place and all wires are secure and taped seconds and, holding it in place, flick
to the frame. Because this will be your down switch D (SWD), which on the
first attempt at flying the drone, remove SKYFLY FS-i6 is the switch on the top
the propellers so that if anything does right of the handset. The motors should
go wrong the drone will at least stay now start. Flick the switch back up to stop
exactly where it is rather than bouncing the motors. Now you should be able to
around the room poking eyes out and use the throttle to start and increase the
smashing ornaments. speed of the motors. If you decide to leave
Start by switching on the controller, the drone for a short time then the start-
making sure that all switches are in the up process will need to be repeated.
up position and the throttle is in the lower If all is in order and all four motors spin
position. Now connect the battery to the and react correctly with the transmitter,
power module and you should hear a then youre ready to start your first flight
beep as the board starts loading. This once the propellers are attached. If only
can take up to a minute to complete. three motors start or you can visibly see
Another beep will signal the end of the that one motor is spinning at a much
boot sequence, and then another 5 to 10 lower speed than the others, then youll
seconds is needed before the drone is need to load AMP and configure your
ready for testing. transmitter with the drone first.

62 // // Winter 2016
showing that the installation has completed and Robotics at 55 euros. Youll need to make sure If theres
the board can be unplugged. that your machine has a 5GHz compatible Wi-Fi one thing more
At this point the drone should be ready for device in order to get things to work properly. satisfying than
its first flight test. To get it to fly youll need to Once connected you can download and install AMP flying a drone, its
flying a drone you
connect it to some type of control device such as Planner from http://ardupilot.org and run through
built yourself.
a radio control, Bluetooth or Wi-Fi with ROS the calibration and setup process in order to get
(Robot Operating System). You do need to take your drone to work correctly.
into consideration that this is an open hardware
project and the components that well be using will
be different from those used by Erle Robotics. For
ONCE YOU CONNECT EVERYTHING
complete ease, weve opted for the traditional IT SHOULD ALL WORK, WITH SOME
radio-controlled option and used a FLYSKY FS-i6
with the new FS-iA6B receiver, which we located at FINE-TUNING OF THE CONTROLS
Maplin for 50. The important factor here is that
the receiver is of the PPM type mentioned earlier.
PPM enables several servos or in this case
several ESC to be connected to one port and
controlled individually. This works in just the same
way as traditional servos would, with an individual
port in the receiver for each. This cuts down on the
amount of wires needed but more importantly its
the hardware required by the PXFMini in order to
interface with the controller. Once youve
connected everything it should work as described
here, although you may find that some fine-tuning
of the transmitter controls is needed.
The Pi Zero doesnt feature the ability to
network over the USB ports, so a Wi-Fi dongle
is required in order to connect to your machine.
Weve used a dongle bought directly from Erle

Winter 2016 // // 63
Set up a Raspberry
Pi as a private server
Nate Drake shows you how to set up your own free Dropbox-style cloud
service on the Raspberry Pi to securely store and share your data

D
ropbox, Google Drive and iCloud are like its predecessor ownCloud, strongly matches
just a few of the myriad of online the functions of services like Dropbox and Google
data storage and file transfer services Drive in allowing you to sync data, collaborate on
available. The days are long gone when documents and share files.
you stored your data on one computer However, Nextclouds software can be installed
and hoped for the best. Even backing up your on a private server, leaving you in control of your
precious files to an external hard drive, which at data, without having to pay monthly or annually
least protects to some extent against the risk of for storage space. Apps can be used to expand
data corruption or hardware failure affecting your Nextclouds functions to include calendars, editing
computers hard disk, doesnt cut it any more. documents and much more.
Now you can back up your data and share files The Raspberry Pi is a perfect candidate for
with others via the cloud. Nextclouds software because it uses very little
The terminology is romantic but imprecise. All it power when run around the clock like a web server.
means is that the servers on which you store your For this project we will go through the preparations
stuff are accessed over an internet connection. youll need to ready the Pi for Nextcloud, then the
The dozens of cloud storage services out there steps to install the software itself.
each promise a certain amount of free space on
their servers in which to store your personal data. Nextcloud preparations
One of the most recent offerings is from Although installing the Nextcloud software itself is
Nextcloud, an open source fork of the ownCloud quite easy, you will need to prepare your Pi.
project which was started in April 2016. Nextcloud, In the first instance, its best to have a dedicated
Raspberry Pi to use with Nextcloud and for no
Anyone familiar other purpose. Considering that youre relying on
with the layout it to keep your data safe, its unwise to risk any
of services like
other app interfering with the process.
Dropbox or
Google Drive
Youll next need to set up a static IP address for
will be able to your Pi so that other devices can find it. The steps
use Nextcloud outlined in the tutorial are for a Pi thats connected
right away. to your router via Ethernet cable. This is optional
but will result in a faster and more secure

64 // //Winter 2016
Nextcloud PROJECT

SECURE YOUR NEXTCLOUD


If you plan to access Nextcloud over the Youll be asked to answer a series of <IfModule mod_headers.c>
web, consider requesting a legitimate questions about your country, email Header always set Strict-Transport-
certificate from a certificate authority. address, etc. Press Return for each Security max-age=15768000;
You can obtain an SSL certificate free question to give the default answer for includeSubDomains; preload
of charge from websites such as Lets each except common name. Here you </IfModule>
Encrypt (https://letsencrypt.org) should type the IP address of your Pi </VirtualHost>
or Start SSL (https://startssl.com). in our case, 192.168.1.118.
Otherwise you can generate a self-signed Next create an empty configuration file Press Ctrl + X, then Y, then Return to
certificate (which, naturally, will be used for Nextcloud for Apache to use: save and exit.
only for accessing Nextcloud...). sudo nano /etc/apache2/conf-available/ Enable the Configuration file with:
First you need to tell Apache to use it nextcloud-ssl.conf sudo a2enconf nextcloud-ssl.conf
and where to find it. Begin by opening Paste in the following: Finally, restart Apache with the following
Terminal on your Pi or connecting via SSH <VirtualHost *:80> command and youre good to go:
and running the command sudo su - to RewriteEngine on sudo service apache2 restart
elevate your user privileges. Next run each ReWriteCond %{SERVER_PORT} !^443$
of these commands, pressing Return after RewriteRule ^/(.*) https://%{HTTP_
each to prepare Apache : HOST}/$1 [NC,R,L]
a2enmod ssl </VirtualHost>
a2enmod rewrite <VirtualHost *:443>
Next create a directory for your ServerName 192.168.1.118
certificates: SSLEngine on
mkdir -p /etc/apache2/ssl SSLCertificateFile /etc/apache2/ssl/
Now generate the SSL certificate nextcloud.pem
yourself if necessary: SSLCertificateKeyFile /etc/apache2/ssl/
openssl req -new -x509 -days 3650 -nodes -out nextcloud.key
/etc/apache2/ssl/nextcloud.pem -keyout /etc/ DocumentRoot /var/www/html/ Make sure to set the Common Name
apache2/ssl/nextcloud.key to the IP address of your Pi.

connection. If you want to use wireless, simply Once Nextcloud is up and running and you
substitute wlan0 in place of eth0 when navigate to your Admin page, you may see several
modifying your network configuration in Step 1 messages. None of them will stop you from using
of our guide on p68. Nextcloud right away to upload files and enable
Next youll need to decide on your database Apps (see over the page for more about these) but
type. If you plan to be the only person using its important to understand them. Some of them
Pi bites
Nextcloud, have only a few files and want a quick alert you to important security considerations, Be aware that
and easy setup, simply follow the steps outlined which you should give some serious thought to encryption is not
in our guide to use Nextclouds built in database and if necessary act upon before you begin using retrospective
software, which employs SQLite. If you want to Nextcloud and expose your personal data to risks that is, it will
encrypt only new
make sure Nextcloud can handle larger files and/ that are entirely avoidable. files you place in
or multiple users, consider using a MySQL Nextcloud after
database by following the steps in Using MySQL Post-install tweaks its enabled. Log in
with Nextcloud over the page. The first message in red reads Your data directory and log out again
after enabling
The next steps involve installing software on and your files are probably accessible from the
encryption to
your Pi to turn into a web server. In this case we Internet. You can test whether or not this is true get started.
are using Apache, which is the most popular web by visiting http://192.168.1.118/nextcloud/data/
server software on the internet. yourusername/files/ to see a list of your files.
Once Nextcloud has been installed via the Naturally if you want to be able to access your
command line, youll be able to navigate to it in Nextcloud from outside your home network, this
your web browser to complete the setup process may be the way you want things. One way to make
using the handy Installation Wizard. sure that your data is safe, though, is to enable
server-side encryption, which will scramble data
Nextcloud clients inside your files, making them useless to anyone
The first message youll see after creating your who downloads them without your password.
account on Nextcloud is a link to download a Click on Files at the top left of the screen,
Nextcloud client for your mobile device or then Apps, then Not Enabled. Scroll down to the
computer. This is simply so that you can sync Encryption app and click Enable. Next click your
your files between your devices and the Pi. username at the top right of the screen and select
At the time of writing clients are available free Admin. Click the Encryption tab which has now
of charge for Windows, Mac and Linux. Theres also appeared in the left-hand menu. Tick the box
a free Android client in the Google Play Store. The marked Enable Server Side Encryption and read
iTunes App Store also has a Nextcloud client for the wordy disclaimer in red. Once you feel youve
iPhones, iPods and iPads priced around 85 pence. been duly warned, click on Enable Encryption.

Winter 2016 // // 65
PROJECT Nextcloud

be told that youre accessing it over HTTP rather


than HTTPS. If you plan to access Nextcloud only
over your home network, this isnt very worrisome.
However, if you want to make sure that your
connections between your devices and Nextcloud
are encrypted, be sure to follow the steps in
Secure your Nextcloud on the previous page.
When securing Nextcloud youll need SSL
certificates which encrypt your connection. These
are usually obtained from a certificate authority
but you can generate one yourself on the
Raspberry Pi if you wish. These self-signed
The first If you dont wish to encrypt your files or you certificates are not generally considered to be as
time your run just want to share them over your home network, secure compared to those offered by a third party
Nextcloud you can move your Nextcloud data directory to because anyone can generate one. However, since
youll see links a safe location where the Apache Web Server you are the one creating the certificate, you know
to the various
cannot access it. its trustworthy.
client apps for
If you decide to do this, first open Terminal If you use the Nextcloud App on your mobile
your devices.
They can also
on your Pi or connect via SSH and stop Apache device or access it via your browser, you may see
be downloaded altogether with the command a security warning saying that the connection isnt
from https:// sudo systemctl stop apache2 trusted. Rest assured this is perfectly normal. You
nextcloud.com/ Next decide on a folder where you want to keep can add a Security Exception for your Nextcloud
install/. your Nextcloud data for example /home/pi/ instance and the client or browser will remember
nextcloud-data. Run the following command to it going forward.
move the data directory to the new location: The final error message you might see is that
sudo mv /var/www/html/nextcloud/data /home/pi/ No memory cache has been configured. In
nextcloud-data theory the memory cache contains versions of
Now youll need to tell Nextcloud where to find recent files to allow Nextcloud to access your
the new data directory. Run this command to open data more quickly. In practice we have not noticed
Nextclouds configuration file: a huge improvement in performance from
sudo nano /var/www/html/nextcloud/config/config. configuring the Pi to work with a memory caching
php program. If you are interested in setting this up,
Using the arrow keys scroll down until you you can find a list of caching programs and
find the text 'datadirectory' => '/var/www/html/ instructions at https://docs.nextcloud.com/
nextcloud/data'. Amend it to the new location, for server/10/admin_manual/configuration_server/
example something like the following: caching_configuration.html. The website asks
'datadirectory' => '/home/pi/nextcloud-data' you to check which version of php you are running
Press Ctrl +X, then Y, then Return to save and exit. before choosing a program, which you can do
Enable the Finally make sure that Nextcloud can still using the following command:
Encryption access the Data Directory with this command: php -v
Module to
sudo chown www-data:www-data /home/pi/
encrypt each
file using ultra
nextcloud-data Nextcloud Apps
secure 256-bit
Restart the Pi for your changes to take effect. By default you can upload and arrange files in
AES in future. Be Incidentally, this method is also an excellent Nextcloud as well as see your images laid out in
sure to read the way to back up your Nextcloud Configuration and a basic Gallery. This is perfectly adequate for day-
disclaimer before files or move them to a new computer. to-day use but there are a number of official and
continuing. If you revisit the Admin Panel, you might also unofficial apps which can be used to enhance your
cloud. The Encryption app if you enabled it earlier
is a great example.
You can access the list of available Apps by
clicking on the text at the top left of the screen
Files then Apps, then Not Enabled. Click on Show
Description beside an app to find out more.
In the illustration we see the External Storage
Support app, which allows syncing with regular
cloud providers such as Google Drive, Dropbox
or even other Nextcloud/ownCloud servers.
Whichever app you choose, click Enable to start
using it. The app will automatically download and
install. Usually it can then be accessed by clicking
on Apps at the top left of the screen or, as is the
case with the External Storage app, by going to
your Admin page and selecting it from the menu.
Clicking on the settings icon in the Apps page
will allow you to enable Experimental Apps. As

66 // //Winter 2016
Nextcloud PROJECT

the name suggests, these are apps which either


are still in development or have been created by
third parties and not fully tested with Nextcloud. USING MYSQL WITH NEXTCLOUD
If you choose to enable them, refresh the page
and scroll down past the official apps to see whats By default Nextcloud uses SQLite Next install the MySQL software
on offer. Bear in mind that the experimental apps to create and store your files in a itself by entering the following:
may interfere with the running of others for database. SQLite is quick and easy sudo apt-get install mysql-server -y
example the enhanced Gallery app Gallery+ will to set up and, if you plan to be the Youll be asked to type a password
require you to disable the default app. only person using Nextcloud and for MySQL root user for example
dont plan on uploading a large use the word root.
Storm Clouds number of files, then youre welcome Now restart the Pi and open
Provided that the required files are downloaded to skip this step. MySQL is a little MySQL with the command:
more difficult to set up but it is much mysql -u root -p
in advance, the setup process for Nextcloud is
more efficient than SQLite and can Enter the password you just
quite simple. If things do go wrong post-install, handle many people using Nextcloud created. Next run the following
its best to start the process over from scratch at the same time. commands to create a database
by removing the Nextcloud configuration file To set up, open Terminal on your named nextcloud. Press Return
with the following command: Pi or connect via SSH and install all after each command:
sudo shred -u /var/www/html/nextcloud/config/ the necessary prerequisites with the CREATE DATABASE nextcloud;
config.php following command: CREATE USER nextcloud@raspberrypi
When you next navigate to your Nextcloud sudo apt-get install php5-fpm php5- IDENTIFIED BY 'password';
instance in your browser for example mysql openssl ssl-cert php5-cli php5- GRANT ALL PRIVILEGES ON
http://192.168.1.118/nextcloud you will see common php5-cgi php-pear php-apc curl nextcloud.* TO nextcloud@raspberrypi;
libapr1 libtool php5-curl libcurl4- FLUSH PRIVILEGES;
the setup screen again and can create a new
openssl-dev php-xml-parser php5-dev exit
admin account. If you have encrypted your php5-gd libmemcached* memcached Feel free to change the password
documents previously, youll need to use the same php5-memcached -y from password if you wish it
password as you did with your previous account. certainly doesnt represent the level
If you choose to connect to Nextcloud over of security we would recommend.
HTTPS, you might see an error message after When you get to Step 6 of the
enabling it about Strict Transport Security. This setup process in the guide on the
is an optional setting which means that no device next page, before creating an Admin
can connect to your Nextcloud in a non-secure account click Storage and Database,
manner. However if you followed the steps outlined then MySQL/MariaDB. Enter the
username and password root (or
in Secure your Nextcloud (previous page), anyone
whichever password you chose
attempting to connect via regular HTTP will be when setting up MySQL). The
forced to use the more secure HTTPS anyway, database name is Nextcloud.
so this message can be ignored. If its simply
annoying you, follow the steps outlined in the
Hardening and Security Guidance guide in the
section marked Enable HTTP Strict Transport
Security. See https://docs.nextcloud.com/ Scroll down on the setup screen
server/10/admin_manual/configuration_server/ before creating your admin account
harden_server.html. and click on MySQL/MariaDB. Enter
If you have a large number of files then the the root username and password, as
available space on your SD card may fill up well as the name of your database.
quickly. If you need more space urgently, the
simplest solution is to copy your Nextcloud data
folder to another SD card with more storage A final word of caution is to maintain regular
space. Technically you can keep your data folder backups of your Nextcloud data. When youre The default
on an external hard drive or USB stick but this can using large services like Dropbox or Google Drive, Gallery app must
be disabled for
cause permissions issues with Nextcloud, so do several copies of your data are stored in various
the experimental
this only if you are confident both with formatting servers around the world. You most likely will only app Gallery+ to
drives and modifying file permissions. use one Raspberry Pi, so keep it somewhere safe. work properly.
If you want your Nextcloud instance to be Consider using the External Storage app to place To disable an
accessible over the internet, you will need to a copy of your files in a Dropbox account or, better app, click on
obtain a static IP for your router. You can either yet, copy your data folder onto an external drive Enabled next to
pay a fee to your ISP if they offer this service or from time to time and store it offsite. the apps name.
use a service like www.noip.com to get a
permanent website address such as http://
davesnextcloud.ddns.net. Next you will need
to forward port 80 (or port 443 if youre using
SSL) on your router to your Pis IP address. The
steps for each router are different, so we cannot
provide instructions here, but the website www.
portforward.com has some useful information
for common routers.

Winter 2016 // // 67
PROJECT Nextcloud

SET UP NEXTCLOUD ON YOUR PI

1 Assign Static IP 2 Install MySQL server


Connect to the Pi over SSH or open Terminal and run the command: This step is optional but recommended if you plan to have multiple
sudo nano /etc/network/interfaces users and/or you want to store a large number of files in Nextcloud.
Find the line iface eth0 inet manual. Delete it and replace with the seven MySQL is better suited for this than SQLite, which is what Nextcloud uses
lines shown in the screenshot above. We are assuming here that the Pi is by default to create and store files in a database. To install MySQL, follow
connected over Ethernet. If you want to use wireless, simply substitute the instructions in Using MySQL with Nextcloud on the previous page.
wlan0 instead of eth0. To apply the changes, run the command:
sudo /etc/init.d/networking restart

3 Install required software 4 Download Nextcloud software


To install Apache, PHP and other required software, run the command: To download the Nextcloud Zip file, run the following:
sudo apt-get install apache2 php5 php5-gd sqlite php5-sqlite php5- wget https://download.nextcloud.com/server/releases/nextcloud-
curl openssl 10.0.0.zip
Then restart Apache with sudo service apache2 restart Move the file where it needs to go, then move to the directory yourself:
You can check that Apache is working properly by opening a browser and sudo mv nextcloud-10.0.0.zip /var/www/html
going to http://youripaddress for example, http://192.168.1.118. If all cd /var/www/html
is working youll see a splash page saying It works! To extract the files, use sudo unzip -q nextcloud-10.0.0.zip

5 Create Nextcloud data directory 6 Launch setup from a browser


If you want your files to be accessible over the web, place your data Do the same for your data directory for example:
directory inside Nextclouds folder using the following: sudo chown www-data:www-data /var/www/html/nextcloud/data
sudo mkdir /var/www/html/nextcloud/data Now to get going, open a web browser connected to your network and visit
Otherwise use a location on your Pi, for example: http://192.168.1.118/nextcloud to visit the setup screen. Youll be asked
sudo mkdir /home/pi/nextcloud-data to create an Administrator Username and password. Before you do, check
To make sure there are no permissions issues, run the following: that the path to the data directory is correct. You also may want to click on
sudo chown -R www-data:www-data /var/www/html/nextcloud Storage and Database to use MySQL.

68 // //Winter 2016
Build your first
Pi-powered robot
Les Pounder runs through how to build a simple but elegant,
budget-busting custom robot for scaring the cat. Just because

R
obotics is an exciting way to introduce Building a robot chassis is a great activity and
people to programming but it can also the kit (mentioned above) comes with everything
be a little difficult sometimes for you need to get started. You will need to solder the
newcomers to get to grips with, as well red and black wires to the motor terminals if you
as being expensive. Enabling someone cant solder then now is a great time to learn from
to create an easy-to-build and cost-effective robot a friend or a local hackspace.
is a significant step in their learning. So in this With the chassis built, we now focus on the
project well build our own robot and create a motor controller, which is an L298N H bridge
Python 3 library that enables anyone to control it. controller. An H bridge enables a motor to go
For this project you will need: any model of forwards and backwards. Our L298N has two
Raspberry Pi; Raspbian (www.raspberrypi.org/ outputs for our motors: the left side is served by
downloads), a Wi-Fi dongle and Pi connected to OUT1 and 2, the right by OUT3 and 4. Connect
your home router; a USB battery pack, a robot the wires from your motors to these terminals
chassis kit (http://bit.ly/LXF203_Robot_kit), an and ensure they are secure. Our AA battery pack
L298N motor controller (http://bit.ly/LXF203_ connects to +12V and GND terminal. We also
L298N); four AA batteries and some Blu-tack. need to connect one of the GND from our

REMOTE CONNECTION
We set up an SSH server on our Raspberry Pi at raspberry, and once logged in, any command
the start of this project, so now lets use it to you enter will output on your Pi. Navigate to the
remotely control our robot. In Linux we can run directory where you saved the robot.py and test.
the ssh command from the terminal. To SSH into py files. To run the test code in the terminal type
our robot we need to know its IP address, which sudo python3 test.py . Press Return and the robot
we wrote down earlier, and the name of the user will come to life and perform the test sequence.
typically pi for a Raspberry Pi. We then type the It works! But lets open an interactive Python 3
following into a terminal to proceed: session and live code the robot with $ sudo
$ ssh pi@IP ADDRESS . python3 -i . We can now import the robot library
Replace IP ADDRESS with your Pis IP. Youll be and run the same functions as per the test.py
prompted for the Pi password, which is typically file. To return to the terminal just press Ctrl+d.

Winter 2016 // // 69
PROJECT Build your own robot

SOLDERING
For this project we bought a robot chassis kit Cheap soldering iron sets can be bought
from eBay that included two DC motors. These for around 10, but its worth investing in
motors come assembled but require soldering something better than a very basic, bargain-
two wires to the terminals for power. Soldering basement model. The Antex XS25, available for
is an essential maker skill and it is really easy around 25, is a great starter to intermediate
to learn, though adult supervision is essential soldering iron. Soldering should be undertaken
for our younger would-be solders out there. in a spacious, well-ventilated room with a clear
There are many helpful YouTube tutorial videos, workspace. Soldering is great fun and your
but the best weve found is from Carrie Anne local hackspace/LUG can help you to learn in
Philbin (http://bit.ly/LXF203_Solder). a safe manner.

Raspberry Pi to the L298N GND terminal. On the another LXTerminal and type the following to get
Pi bites L298N we can see four pins marked IN1 to IN4. your IP address and write the address down:
Securing your These are inputs that we use to connect the $ hostname -I .
components L298N to our Raspberry Pis GPIO (General In the same terminal type the following to
to the chassis Purpose Input/Output) pins. launch the Python 3 editor with superuser powers:
is important, By turning a GPIO pin on or off we can trigger $ sudo idle3 &
otherwise your Pi
will be dragged
the input pins accordingly and control the motor Well start our code by importing two libraries. The
along by the robot. direction. We connected our inputs to the following first enables our code to talk to the GPIO pins on
We used Blu-tack GPIO pins: IN1 to 17, IN2 to 22, IN3 to 18 and IN4 our Pi while the second provides the time library:
but for a long- to 23. We used the Broadcom pin mapping, a import RPi.GPIO as GPIO
term project cable
standard set by the Raspberry Pi Foundation. import time
ties are better.
A great reference for the GPIO is http://pi. When using the GPIO pins we will refer to them
gadgetoid.com/pinout, which explains all youll using their Broadcom pin numbering and we must,
need to know about Broadcom pin mapping. in turn, configure our code to use those numbers
with GPIO.setmode(GPIO.BCM). Rather than refer
Software setup to each pin throughout our code well create four
Boot your Raspberry Pi to the desktop and open a variables to store the GPIO pin connected to each
terminal you can find the icon in the menu bar at of the inputs on the L298N:
the top left corner of the screen. In the LXTerminal fwdleft = 17
type the following and press Return to run: fwdright = 18
$ sudo raspi-config revleft = 22
Using the arrow keys, navigate to Advanced revright = 23
Options and press Return. In the Advanced menu In order to use each GPIO pin we need to
navigate to the SSH Server option, press Return instruct the code what each pin will be: an input
and in the new screen choose to Enable the SSH or output. As we will be sending current from the
server. Exit from the menus and reboot your GPIO pins they will be an output. So using a list,
Raspberry Pi. Reboot back to the desktop, open known in other languages as an array, and a for

The screw
terminals enable
connections
between the
batteries,
Raspberry Pi
and motors.

70 // // Winter 2016
loop, we shall iterate over each item in the list, provided as the argument (i). To turn right we set Our finished
which are our variables, and configure each GPIO the right motor to reverse and the left motor to robot is fun on
pin as follows. forwards, wait for the user-defined number of two wheels!
motors = [fwdleft,fwdright,revleft,revright] seconds and then turn off the motors.
for item in motors: For our left and reverse functions you can refer
GPIO.setup(item, GPIO.OUT) to the full code at http://bit.ly/LXF203_Robot.
The last section of code is a try and except test:
Driving our robot try:
We now create four functions that will handle print("R E A D Y")
driving our motors in a particular direction. Each of except KeyboardInterrupt:
the functions will take an argument, a duration of print("E X I T")
time thats expressed as an integer or a float: GPIO.cleanup()
def forward(i): This will print R E A D Y when the code is
GPIO.output(fwdright, True) executed, but if we press Ctrl+c it will print E X I T
GPIO.output(fwdleft, True) and then clean up the GPIO pins ready for use by
time.sleep(i) another project.
GPIO.output(fwdright, False) Save your code as robot.py but we wont be
GPIO.output(fwdleft, False) running the code, rather we will now create a
Our first function, forward(i) , will turn on new file and save it as test.py in the same
fwdright and fwdleft pins and then wait for the directory as robot.py.
value of i , our argument before turning the Next, well import our robot.py code and use the
motors off. On to our second function: functions inside of it to control our robot.
def right(i): import robot
GPIO.output(revright, True) robot.forward(1)
GPIO.output(fwdleft, True) robot.right(2)
time.sleep(i) robot.left(2)
GPIO.output(revright, False) robot.reverse(1)
GPIO.output(fwdleft, False) Save the code and click Run > Run Module to
Our second function, right(i), spins our robot on test. Remember to pick up the robot before
the spot in a clockwise direction for the duration pressing Return or youll have to chase after it!

Winter 2016 // // 71
Get started with the
Pi Camera module
Mayank Sharma introduces you to the Pi Camera module
and explains how you can use it to shoot away to your hearts content

T
he official Raspberry Pi camera Once Raspbian is up to date, launch the
module is fun little gadget, much Raspberry Pis configuration script with the
like the board it complements. The following command to tweak its settings:
camera module is a Full HD camera sudo raspi-config
that plugs into the Raspberry Pi via Scroll down the list to the Enable Camera option
the Camera Serial Interface (next to the Ethernet to make the Pi aware of the newly connected
port) on the device. The camera has a fixed focus peripheral. Then exit the utility and restart the Pi.
lens and 5 megapixel sensor. It can shoot still
images with a maximum resolution of 25921944 Trigger happy
as well as Full HD 1080p video at 30 frames per When it boots up, fire up a Terminal inside the
second, 720p video at 60fps and 640x480 at up graphical desktop to test the camera using the
to 90fps. And you get all this in a module that two command-line utilities raspistill and raspivid
measures just 25x20x9mm in size and weighs to capture still images and videos respectively.
a minuscule 3 grams! The command raspistill -o image.jpg displays a
To attach the camera, locate the Camera preview from the camera for 5 seconds and then
Serial Interface on the Raspberry Pi and pull the takes a picture, which is saved as image.jpg in
tab gently up. Now push the camera modules the current folder. You can use the -t switch to
ribbon cable into the slot, with the silver contacts specify a different wait period in milliseconds.
on the cable facing away from the Ethernet port. For example, -t 20000 will display the preview
Remember not to push the cable in very deep. for 20 seconds.
Now hold it in place with one hand and push the Similarly, raspivid -d will display a five-second
CSI tab back down with the other hand to lock video demo. You can define the size and location
the cameras ribbon. for the preview window using the --preview option
With the hardware in place, its now time to for example raspivid --preview 0,0,1024,768 will
set up the software. Boot into Raspbian and log display the preview in a 1024x768 window at the
in. Before enabling the camera, make sure you top-left corner of the screen. Use --fullscreen or -f
refresh its repositories with the following: to force the preview window to use the whole
sudo apt-get update screen. The following command will capture 10
Then install any available updates with: seconds of video:
sudo apt-get upgrade raspivid -t 10000 -o video.mp4

72 // // Winter 2016
Pi Camera module PROJECT

Both raspistill and raspivid have quite a few You can take advantage of the portable nature
options to help you take more interesting image of the Raspberry Pi and its camera module to
and video captures. The --sharpness, --contrast capture time-lapse video of things that are too
and --brightness options can influence the output subtle for the human eye to perceive, such as the
of the image. The camera also supports several movement of stars or the blossoming of flowers.
exposure modes such as auto, night and sports A time-lapse video is composed of several images
that can be specified with the --exposure option. captured over several hours but played back at a
Similarly, the various white balance options much faster pace. For example, you can capture
including sun, cloud and shade can be specified an image every 10 seconds for 6 hours and then
with the --awb option. string the set of images together in a time-lapse Pi bites
Use the --width and --height option with video at 24 frames per second. This reduces the
raspistill to set the dimensions of the captured 6-hour capture to a 30-second clip. The camera
modules tiny size
image. You can also tweak the compression level
of the jpeg image by specifying a quality level Jump through time makes it ideal
for projects that
between 0 and 100 with the --quality option. It doesnt take much work to set up the Pi for require a small,
The --width and --height options can also be time-lapse photography. The following block of high-resolution
camera such as
used with the raspivid tool. It also uses the code will capture a shot every 30 second for the
surveillance.
--bitrate option to control the quality of the video. next 6 hours (21600000 milliseconds):
To capture a Full HD video at 15 Mbits per second $ mkdir ~/images
use --bitrate 15000000. Another related option is $ cd ~/images
--framerate, which can accept a value between 2 $ raspistill -o image-%04d.jpg -t 21600000 -tl 30000 &
and 30. To pause video during a capture, start it You can change the duration (-t option) or the
with the --keypress option. You can then press gap between the shots (-tl option) by specifying
the Enter key to pause capturing and resume by different durations in milliseconds. The %04
pressing the Enter key once again. Press the X instructs raspistill to save each image in a file
key followed by the Enter key to stop recording. called image- nnnn.jpg where nnnn is a four-digit

CONTROL THE CAMERA MODULE FROM PYTHON

Head to Menu > Programming to use the IDLE editor to write your Python scripts.

Pythons PiCamera library display a preview for 10 Similarly, you can record continuous() method of the
helps you control the camera seconds before capturing 5 seconds of video with the picamera library.
module from within Python. You an image: following: The picamera library includes
can install it on any distro with import picamera import picamera a number of useful modules
the following command: from time import sleep from time import sleep such as picamera.encoders,
sudo apt-get install python- picamera.streams, picamera.
picamera camera = picamera.PiCamera() camera = picamera.PiCamera() color and picamera.exec,
Or if you plan to use Python 3: camera.start_recording('video. among others. Refer to the
sudo apt-get install python3- camera.start_preview() h264') official documentation at
picamera sleep(10) sleep(5) http://picamera.readthedocs.
Once its installed you can use camera.capture('/home/pi/image. camera.stop_recording() io/en/release-1.12/ for more
the library to capture images. jpg') You can also capture time details and examples on the
Heres a basic script that will camera.stop_preview() lapse video using the capture_ various modules.

Winter 2016 // // 73
PROJECT Pi Camera module

Run sudo
modprobe
bcm2835-
v4l2 to access
the camera
board on /dev/
video0. Then
get the kernel
to insert the
module on boot
automatically
with echo
"bcm2835-v4l2"
| tee -a /etc/
modules

number incremented with each successive image. In this rather long command weve instructed
The & sign at the end of the command instructs mencoder to create a video using the mpeg4
the Bash shell to run the command in the codec from the open source libavcodec library
background. After six hours youll have 720 and without any sound since we havent captured
images in the folder named image-0001.jpg, any. The scale specifies the Full HD (1920x1080)
image-0002.jpg, and so on, up to image-0721.jpg. resolution of the video, and the aspect specifies
You can also You can now compile these individual images the widescreen aspect ratio of the video.
enable the into a video. First, save them all in a text file: Theres also a fair bit of maths involved. The
camera from $ cd ~/images bit rate is calculated using the formula (40 * 25
within Raspbians $ ls *.jpg > allimages.txt * width * height / 256), which comes out to
desktop. Head
Then install the mencoder transcoding tool with: 8100000. Then we set the frame rate of the
to Menu >
sudo apt-get install mencoder resulting video to 24fps. Given that an individual
Preferences >
Raspberry Pi
Once its installed, compile the video with: frame (or one image) represents 30 seconds of
Configuration > $ mencoder -ovc lavc -lavcopts vcodec=mpeg4: real time, the real time represented by one second
Interfaces and aspect=16/9:vbitrate=8100000 -vf scale=1920:1080 of our time-lapsed video comes to (24s * 30s) =
toggle the Enable -nosound -o timelapse.avi -mf type=jpeg:fps=24 720s, which is equal to 12 minutes or one-fifth of
radio button. mf://@allimages.txt an hour. In other words, five seconds of the time-
lapsed video represents one hour of real time.
Once youve got your head around the maths,
tweak the options for the raspistill capture and
the mencoder encoding until you get to a desired
ratio between the real time and the video time.
Depending on the images it has to process,
the mencoder command can take some time to
complete. When its done, youll have a file named
timelapse.avi inside the current directory. You
can copy it to another computer using the scp
command. Assuming the IP address of the
Raspberry Pi is 192.168.1.2, head to another
Linux computer on the network and enter:
$ scp pi@192.168.1.2:/home/pi/images/timelapse.
avi ~/Videos
This command will pull the video from the Pi
to the Videos directory on your regular distro.

74 // // Winter 2016
Turn any speakers
into Wi-Fi speakers
Mayank Sharma explains how you can stream media from iOS and Android
devices to your Raspberry Pi, to play it on speakers plugged into the Pi

T
hese days, if youre like us, youve amplifiers and other equipment to enhance your
probably got your music all over the listening experience.
place on cloud sharing services like The best thing about Volumio is that it includes
Dropbox and Google Music as well as support for AirPlay devices out of the box. This
on local NAS drives. You can stream means you can use the speakers connected to the
music from all these to Wi-Fi-enabled speakers Pi as remote speakers for your AirPlay-compatible
that cost a bomb. Or, you can use a Raspberry Pi Apple devices as well as Android devices with
and transform any plain ol speakers into AirPlay- apps such as AirAudio that are available for free
compatible wireless speakers. from the Google Play Store. Moreover, you can
For this project, youll need a pair of hi-fi control Volumio from any other remote computer
speakers that you can connect to the Raspberry Pi or device attached to your local network. This
via an Auxiliary (AUX) audio cable. If you are a true enables you to then select and queue music thatll
audiophile, you might scoff at the idea of using the play on the locally attached speakers.
Raspberry Pi to listen to music. But thats because
you havent yet tried the Volumio distro, which is Pump up the amps
designed especially for music lovers and is fully To get started, download the latest version of the
equipped to work with your hi-fi gear. Volumio distribution for the Raspberry Pi from its
Using Volumio you can set up a headless media website at https://volumio.org. The image for
server on the Pi that can play music in all the the Pi is distributed in a Zip file, so youll have to
popular formats from a connected USB device or extract it before transferring it to the SD card you
NAS devices just as easily as it can stream Internet use with your Pi. Note that since the extracted
radio. Whats more, the distro supports a large image weighs almost 3GB in size, youll need an
number of USB DACs, so you can plug in your SD card thats at least 4GB or more. Its also a
good idea to use a Class 6 or higher card. The
PLAY MUSIC FROM A CONNECTED class number represents the speed of the card

USB DEVICE, NAS, OR AN APPLE the higher the value, the faster the card.
To write the Volumio image file in Windows, grab
OR ANDROID DEVICE VIA WI-FI the USB Image Tool from http://www.alexpage.
de/usb-image-tool/download/. You dont have
to install the tool, just download the Zip file and

Winter 2016 // // 75
PROJECT AirPlay

Pi bites
Although the
Raspberry Pi does
have USB ports,
its advisable to
connect any USB
devices using a
powered USB hub
to ensure that
the devices get
enough power.

To improve
your playback
experience, tweak
the settings
available under
Settings >
Playback Options
in Volumios
browser-based
interface.

extract its contents. Now right-click on the USB card is connected using the mount command,
Image Tool.exe file and select Run as Administrator which will list all mounted devices. Assuming your
from the contextual menu. The app will list your card is mounted at /dev/mmcblk0p1, write the
card in the left-hand pane. Make sure the tool is in image to the card (rather than a partition inside it)
Device Mode by selecting this from the pull-down with the following:
menu in the top-left corner. To write the image to $ sudo umount /dev/mmcblk0p1
Its easy to the card, click the Restore button and navigate to $ sudo dd bs=4M if=volumio-0.979-2016-08-20-pi.
stream from an Volumios extracted .img file. Thats it. The image img of=/dev/mmcblk0
iOS device, but
will now be transferred to the card although the Itll take some time to write the image to
the secret sauce
process may take some time, depending on the the card. Once its done, insert the card into the
that powers
Volumio is the
speed of the card. Raspberry Pi. Now power up the Pi and wait for
venerable Music If youre using Linux, you can use the venerable about a minute to allow Volumio to boot up
Player Daemon dd command to write Volumios image to your SD completely. Thats all theres to it. Your AirPlay-
(MPD) music card. Most distros will automatically mount the compatible speakers are now ready. Grab any iOS
player server. card when you connect it. You can find where the device and make sure its connected to the same
Wi-Fi network as the Raspberry Pi. Then swipe up
from the foot of the screen to open Control Centre.
Tap AirPlay, which will bring up a list of AirPlay
devices. Tap the entry labelled Volumio to stream
audio from this iOS device to the speakers
connected to the Raspberry Pi.
AirPlay isnt the only wireless audio streaming
protocol out there, so dont feel left out if you dont
have any iOS devices to stream music. The other
popular protocol for streaming audio thats also
supported by Volumio out-of-the-box is DLNA,
and you can stream music from your Android
devices to the Raspberry Pi over DLNA with the
BubbleUPnP app (see Stream Music with
BubbleUPnP on the opposite page).

Local media library


In addition to streaming music from remote
devices, you can also use Volumio to play back
music from several other sources. It can read files
stored on the same SD card or a locally attached
USB device and even from another NFS or Samba
share on the network. You can configure and
control this and other aspects of Volumio via its
browser-based interface from any computer on

76 // // Winter 2016
AirPlay PROJECT

the same network as the Raspberry Pi. Before you Browse button in the bottom left of the screen.
can bring up Volumios interface, youll first have to This will bring up a list of the available music
find out the IP address assigned to the Raspberry sources, which includes a bunch of Internet radio
Pi by visiting your routers administration page. stations as well as any connected USB disks and
Equipped with this address, head over to another network drives. Browse through the devices, pick
computer on the same network and enter the IP a track and the song you select will pipe through
address assigned to the Raspberry Pi. the speakers connected to the Pi. You can access
Volumios web interface looks very appealing the Volumio interface from any computer on the
and the controls are very intuitive. But before you network to queue and control playback on the
can use it to play music, youll need to point it to remote speakers.
your library. If youve got music files on a USB Whats more, you can also ask Volumio to fetch
drive, Volumio will automatically import them all as music from the Internet. As weve mentioned, the
soon as you plug in the drive. On the other hand, if Browse button automatically gives you access to
you want to point Volumio to a network share that a handful of online radio stations. (Want more?
houses your music, click the gears icon in the top- Turn the page for more about internet radio.) You
right corner of the main screen to open Volumios can also point Volumio to your Spotify Premium
configuration menu and click My Music. Click the account to play music from the popular service.
Add New Drive button and fill in the IP address of For this, head to Settings > Plugins and install the
the network share, along with the path to the Spotify plugin to use the service. Also, in addition
folder that contains the music files. to the browser-based interface, you can control
Once youve added your music, head back playback with one of the several Volumio apps
to the main Volumio interface and click on the available on the Android Play Store.

STREAM MUSIC WITH BUBBLEUPNP


In addition to AirPlay, the Volumio distro the Pi, expand the list of Renderers and more. Tap the name of the service
for Raspberry Pi also supports the DLNA tap on the Volumio entry. Thats all there you wish to add and enter your login
protocol for streaming music. On non-iOS is to it. Now switch to the Library tab in credentials when prompted. Repeat the
devices such as Android, you can use the the main app window and browse and process to add other services as well.
BubbleUPnP app, a wonderful tool that select any music on the device, which When youre done, tap the name of the
can stream music to your Volumio- BubbleUPnP will them stream to the Pi. service youve added to browse its
equipped Raspberry Pi via the DLNA Besides music stored locally on the contents. Tap to select any music, and
protocol. BubbleUPnP is available as Android device, BubbleUPnP can also BubbleUPnP will pipe it through the
an ad-supported free download on the stream music from cloud-based services. remote speakers attached to your Pi.
Google Play Store. To set up the device to stream content
Once BubbleUPnP is installed, tap the from the cloud libraries, tap the menu
three parallel lines in the top-left corner button and under Library, expand the BubbleUPnP can also stream music
to open the menu. By default the app is Cloud section to view a list of supported from USB disks attached to the USB port
configured to play music on the local cloud services including Google Music, on modern Wi-Fi routers, which are usually
device. To make it stream the music to Google Drive, Dropbox, OneDrive and all DLNA-certified.

Winter 2016 // // 77
Build an internet
radio from a Pi
Nate Drake shows you how to set up your Pi so that you can enjoy
internet radio wirelessly anywhere in the house... or even beyond

O
ne of the most fun and customisable clearer audio than most household radio sets.
projects available for the Pi owner is to Because radio stations are transmitting over an
turn it into a wireless device capable of internet connection, range is no longer an issue
tuning in to internet radio stations. either, and you can tune into stations around the
Internet radio is a thing apart from world wherever you have a network connection.
regular radio stations. As the name suggests, This is especially important for people living
internet radio stations stream over the internet away from their home country. British expats living
rather than broadcasting over the airwaves. in continental Europe, for instance, have difficulty
Of course theres no reason why radio lovers receiving the BBC World Service on a shortwave
cant simply crank up their AM/FM handset radio, but an internet radio can stream it without
and listen to radio in the old-fashioned way. But any issue. Certain countries also jam certain
internet radio offers many advantages. The chief shortwave radio frequencies, but it is more difficult
among these must be audio quality: the signal to jam internet broadcasts.
strength and error checks put in place by internet A quick search online will show that a number
communication protocols offers much crisper and of people have turned a Pi into an internet radio
receiver in many different and inventive ways. For
this reason, weve included the basic information
here to get you started but leave it to you to decide
how you wish to customise it.

Radio preparations
As youll see from the next few pages, the actual
code required to set up an internet radio on your
Raspberry Pi is only a few lines long. Before you
Feel free to
get stuck in, however, its worth taking some time
be creative with
this project. This
to consider your particular setup.
vintage radio has Your first consideration should be your choice
had a Pi installed of Raspberry Pi. The Raspberry Pi 3 is the most
as well as a small expensive model but it does have a 3.5mm
RGB display. audio jack, which will be compatible with most

78 // //Winter 2016
Stream internet radio PROJECT

earphones and speakers. It also has several USB


ports if you want to use a set of USB speakers,
which can be obtained very cheaply online. Most
screens including the Official Raspberry Pi Touch
Screen are also designed to work with the Pi 3.
The Raspberry Pi Zero in many ways is perfect
for this project as very little processing power is
required. Its small size also means it can fit nicely
inside an existing radio or small case. It also is
much less expensive than a Pi 3. This said, the
Zero is not compatible with every external screen
and has no audio jack, so you will have to use USB
speakers or output your audio over an HDMI cable,
for example, to a television.
Once youve decided on your Pi model and
speakers, you may wish to consider a case for the
radio. Technically you could just connect your Pi
via HDMI to a television and listen to internet radio
stations that way, but this isnt the most elegant comfortable with a soldering iron as some The Pi Plate
way to do things. assembly may be required. comes with five
Some stylish Pi users have enthusiastically Should you wish to go for a more fully featured keypad buttons
which can be
disassembled vintage radios, removed the innards Sony Walkman feel for your Pi, you may prefer to
programmed to
except for the speaker and placed their Pi inside use a regular case in combination with a small
move between
for that rustic feel, sometimes complete with an touchscreen such as Adafruits 2.8-inch PiTFT. stations
RGB screen such as Adafruits handy PiPlate, Visit www.adafruit.com/product/1601 to see the
which has an RGB display and buttons you can display in action.
program with favourite radio stations. See www. You may prefer to do something more unusual
adafruit.com/products/1110 for information. such as make the casing out of Lego (or similar
If you choose to go down this road, make sure interlocking-block construction products) or even
you have a basic knowledge of DIY and are cardboard. It isnt particularly important which

PLAYING RADIO WITH YMPD


To get started, either visit the ympd sudo mv ympd /usr/bin stations, such as BBC Radio Four.
website on the Pi to download the Finally start ympd running with: If you like ympd and want it to start
software (www.ympd.org) or connect sudo ympd --webport 80 up each time Pi boots, you can do this
to your Pi via SSH and type this To access the ympd interface open by editing the configuration files on
command, then press Return: your web browser either on the Pi or your Pi. First enter this command:
wget https://www.ympd.org/downloads/ another device connected to your sudo nano /etc/rc.local
ympd-1.2.3-armhf.tar.bz2 network and go to http:// Then use the arrow keys to scroll to
Extract the app with the command: yourpiIPaddress:80 for example, the blank line just above the text exit
tar -xvf ympd-1.2.3-armhf.tar.bz2 && cd http://192.168.1.118:80. 0. Paste in the following:
ympd The interface is very simple and sleep 30; sudo ympd --webport 80
Now move the ympd program to your allows you to browse your music Press Ctrl +X, then Y, then return to Pi bites
applications directory by running: collection as well as play individual save your changes.
If you want a
portable radio,
consider buying a
Pi Borg from the
Pi Hut at http://
bit.ly/PiBorg.
This enables you
to power your Pi
with regular AA
batteries.

Ympd can be accessed on any web browser. Simply click on a radio station to begin playing. If
youve added new stations we show you how over the page click Update DB to load them.

Winter 2016 // // 79
PROJECT Stream internet radio

mpc play Instructs mpd to play the currently


selected track/station. You can add a number to
play the equivalent station in your current playlist
for example if youve added BBC Radio 1, 2 and 3
in that order then mpc play 3 would tell mpd to
start playing BBC Radio 3.
mpc move Changes the order in which stations are
played for example mpc move 1 2 moves a
station from position 1 to position 2.
mpc pause Instructs mpd to pause the current
track. This is very handy if the track has started
playing automatically when you dont want it to.
mpc next Instructs mpd to play the next track.
mpc prev Instructs mpd to play the previous track.
mpc playlist Lists all songs in your current playlist.

Say yes to ympd


While using mpc from the command line is very
effective, it can be a little tedious to type out
Another you choose so long as you plan the layout commands each time you want to play a track.
suggestion carefully, leaving adequate room for the power This is why there are a number of graphical front-
for your radio cable and speakers. ends for mpd.
setup. Here the Our recommended player of choice is ympd as
Pi and wiring
are inside a clip
The Music Player Daemon its very easy to set up. The program runs in the
The heart of the internet radio lies in the handy background and allows you to view your list of
lock lunchbox.
Note that a USB program mpd (Music Player Daemon). Combined radio stations through a web browser, either on
soundcard has with its handy command line tool mpc, it can be the Pi itself if you have a screen, or another device.
been added (left) used to add radio stations, as well as skip back Follow the steps in Playing radio with ympd
for better audio. and forth between them. on the previous page to get started. If youre
There are of course a number of programs accessing ympd via another device like a laptop
capable of playing internet radio such as the computer, remember that the sound from the
Pis built in web browser, but none of them can radio itself will still play through your Pi. If you
be guaranteed to work with every setup. More want to listen to internet radio on that device, you
importantly, its possible that youll be using your will need to set up separate software on there.
Pi radio without an attached monitor, so its very
useful to be able to start and stop the radio by Advanced setup
connecting via SSH. As weve mentioned, internet radio setups are
If you do want to use software to interact with often customised, and among the most common
the music player daemon, make sure to test it out customisations that people like to put into
from the command line so you can be sure the practice are either adding a small display to
Mr UK Tech basic code is working. show the track now playing, or some physical
Reviews has
The Music Player Daemon runs in the buttons to switch stations.
a customised
background, so if you have to restart the Pi, then This involves making use of the Pis GPIO
Python window
specially it will start playing again once the desktop loads. (General Purpose Input/Output) pins, which
designed for It is possible to disable this feature (see below). are used to connect hardware components. An
playing radio Some basic commands include: excellent video tutorial showing how to use the
on Adafruits mpc current Returns the name of the radio station Radio Pi plate, with links to source code, is
mini display. thats currently playing. available via the channel of a YouTuber called
Usual Panic at youtu.be/HPLh8-IVJx4.
YouTuber Steven Yoshida also provides an
excellent video summary of the parts for his
internet radio using Adafruits 2.8-inch
touchscreen display at www.youtube.com/
watch?v=Vw4_S3sb8Is.
The full steps for setting up the small screen
and connecting it to the Pi are available via the
Adafruit website at http://bit.ly/Pi-TFT.
In order to make his radio portable, Steven
Yoshida makes use of a small battery pack for the
Pi. Otherwise youre tied to your power cable.
While were on the subject of power, you might
also find it handy to have a way to mute the radio
volume. If youre using a touchscreen display its
easy to adjust the volume manually. Alternatively
you could consider replacing your regular USB

80 // //Winter 2016
Stream internet radio PROJECT

power cable with one with a switch, such as those command sudo service mpd restart . If you find
sold by Pi Hut. such problems are happening regularly, it may be
best to stop the mpd background daemon and just
Crossed wires run it manually with these two commands:
Just as there are a number of ways to set up your sudo service mpd stop
project, there are equally a myriad of ways that sudo mpd --no-daemon --stdout --verbose
things can go wrong. Its important before you Keep an eye on the Terminal window the
set up your radio to test that the sound is working --verbose flag will force mpd to show any error
properly with your speakers of choice before messages. If youre still having troubles, try visiting
trying to listen to any streams. the helpful mpd troubleshooting page at http:// Pi bites
If you have more than one audio output say mpd.wikia.com/wiki/Music_Player_Daemon_
youve connected earphones to the Pis earphone HOWTO_Troubleshoot. If you do choose
to use USB
jack but are also connected to a television by If you have any other software running on the speakers, they
HDMI then you may need to right-click the Pi that connects to the internet, you may find that may require more
volume button at the top right of the screen to you arent able to connect to ympd on Port 80 as power than your
select the output you want. outlined in Playing radio with ympd on the Pis USB ports can
supply. If so, use a
If youre connecting over SSH and cant use the previous page. If you are unable to load the ympd
powered USB hub
Pis desktop to change your audio settings, then window, first stop the program with the command which connects to
simply type mpc outputs to see a list of available sudo killall ympd and then launch it again using a mains electricity.
audio devices. The list will be numbered in a form different port for example sudo ympd webport
such as Output 1 (My Alsa Device). Use the 94 . You should then be able to access ympd by
command mpc enable # for example mpc opening a web browser on your network and going
enable 2 to enable the speakers of your choice. to http://yourpiIPaddress:94.
If mpd becomes unresponsive when youre using If you decide to use the small TFT touchscreen
it, in the first instance try simply connecting via from Adafruit, you may find it tricky to navigate the
SSH or opening Terminal and running the Pis smaller screen. You can get around this by

ADDING
STATIONS
The Pi is capable of playing any
internet radio station. The basic
format for adding new stations
using the mpc command line
utility for the Music Player
Daemon is mpc add LINK for
example mpc add http://bbcmedia.
ic.llnwd.net/stream/bbcmedia_radio
1_f_p?s=1473771325&e=147378572
5&h=01fae51e24dd4d26dc181f593a9
4defb.
This is quick and easy (if long-
winded) but you may struggle Websites like ShoutCast have downloadable playlists for radio stations. However, youll need
at first to find valid links for an actual link for the stations you want in order to be able to listen to them using mpc.
stations, particularly as the URLs
will change from time to time. 93&h=b8c1c754cb6cc971fed2 mediaselector/5/redir/ playlist files to an actual web
Stephen Phillips has also ca5b19e97d67 version/2.0/mediaset/http- stream. See https://www.
written an excellent script on his icy-mp3-a-stream/proto/http/ gebbl.net/2013/10/playing-
website (http://blog.scphillips. BBC Radio 3 : http:// vpid/bbc_radio_five_live internet-radio-streams-
com/posts/2014/05/bbc- bbcmedia.ic.llnwd.net/ mpdmpc-little-bash-python/
radio-on-the-raspberry-pi-v2/) stream/bbcmedia_radio3_mf_ BBC World Service: for more information.
which can automatically fetch p?s=1473771321&e=147378572 http://bbcwssc.ic.llnwd.net/ If you want to categorise your
the current links for BBC Radio. 1&h=c7d8a753d2663d9f4630 stream/bbcwssc_mp1_ radio stations rather than have
At press time these are: cfcbb7e1d1ae ws-eieuk_backup them all in one big list, just add
BBC Radio 1 : http:// the streams you want and then
bbcmedia.ic.llnwd.net/ BBC Radio 4 : http:// ShoutCast (www.shoutcast. save as a playlist for example
stream/bbcmedia_radio1_mf_ bbcmedia.ic.llnwd.net/ com) has links to hundreds of mpc save bbc . A playlist file will
p?s=1473771325&e=14737857 stream/bbcmedia_ radio stations which can either appear in the location /var/lib/
25&h=01fae51e24dd4d26dc18 radio4extra_ be played directly on the website mpd/playlists. You can load the
1f593a94defb mf_q?s=1473771502&e=14737 or downloaded as a playlist. This playlist again by using mpc load
85902&h=6c94d3cedf0a32e2 can cause issues for mpd, which for example mpc load bbc . You
BBC Radio 2 : http:// 8dd4e8bd33e5fe44 needs a link to work with. can then either play it using the
bbcmedia.ic.llnwd.net/ Fortunately the website gebbl. command mpc play or using
stream/bbcmedia_radio2_mf_ BBC Radio 5 Live : http:// net has an excellent script you your graphical program of
p?s=1473771493&e=14737858 open.live.bbc.co.uk/ can download to convert the choice such as ympd.

Winter 2016 // // 81
PROJECT Stream internet radio

TO PLAY DOWNLOADED MUSIC AS downloaded music as well as radio stations. In


order to do this, you only need to tell mdp where
WELL AS RADIO STATIONS, JUST your music is located. Simply edit the mdp
configuration file with the following command:
TELL MDP WHERE ITS LOCATED etc/mpd.conf
Scroll down to the words music_directory.
Replace the path /var/lib/mpd/music with the
using a larger screen such as the Official actual location of your music files for example
Raspberry Pi 7-inch Touchscreen Display (https:// something like /home/pi/Music. Press Ctrl + X,
thepihut.com/products/official-raspberry-pi-7- then Y, then Return to save and exit. Next run the
touchscreen-display), which is a good deal larger. command mpc update for mpc to detect your
The Adafruit website also links to a tutorial music. The program can recognise and play MP3
video by YouTuber Mr UK Tech Reviews, who files as well as Apples AAC files.
Pi bites designed a special window in Python complete Once this is done and you are happy with your
with handy buttons specifically for people using setup, we encourage you to share your project
For a full list of the Raspberry Pi as an internet radio with online so others can benefit from your experience.
possible mpc
commands type
Adafruits display. See http://bit.ly/Raspberry- The Instructables website (www.instructables.
mpc help in the Radio for more information. com/about/submit.jsp) has a number of Pi Radio
Terminal. If on the other hand your radio is working projects already but if you feel yours stands out,
perfectly, you might want to use it to play your please share it your fellow Pi users!

TURN YOUR PI INTO A MUSIC PLAYER

1 Set up your Pi 2 Install Music Player Daemon


Make sure your Pi is plugged into power and youve connected any Enter the command sudo apt-get install mpd mpc to install the player
speakers you want to use. Open your Pis Terminal or connect via SSH, software. The daemon will run at all times in the background. Use the mpc
then type the command sudo apt-get update and press Return to program to control it via the command line. Next add audio streams for
prepare the Pi to install the software. your favourite radio stations see Adding Stations on the previous page.

3 Play tracks/stations 4 Add interface


Use the command line to test your setup by running mpc play to make This step is optional but recommended. Although you can add just play
sure that your audio streams are working. Use mpc pause to stop when tracks from the command line, this isnt very intuitive. So use the browser
you are satisfied that the audio is playing correctly. You might need to based player ympd (see Playing radio with ympd, p75) or refer to the main
change the audio output on your Pi. article for information on more exotic options such as touchscreens.

82 // //Winter 2016
ON SALE NOW!
AVAILABLE AT WHSMITH, MYFAVOURITEMAGAZINES.CO.UK
OR SIMPLY SEARCH FOR T3 IN YOUR DEVICES APP STORE

SUBSCRIBE TODAY AND SAVE! SEE WWW.MYFAVOURITEMAGAZINES.CO.UK/T3


BECOME AN EXPERT
CODER THE EASY WAY

OUT
NOW!
WITH

FULLY
FREE
REVISED &
UPDATED
DIGITAL
EDITION EDITION

LEARN TO CODE FAST TODAY!


PYTHON SWIFT RUST R STUDIO
MARIA SQL MONGO REDIS

180 PAGES OF TUTORIALS


LEARN CORE CODING TECHNIQUES
AND ADVANCED SKILLS
FREE
Digital edition
of this book!
See page 178 for TGG14 2016

more information PRINTED IN THE UK


12.99
iPad & iPhone only

ORDER YOUR COPY TODAY!


Order online at
https://www.myfavouritemagazines.com
Also available in all good newsagents
Pi CODE
Learn how to code in your language of choice

95
86

92

TURN EVERYTHING YOU


86 Get started
with Scratch

TOUCH INTO GOLD WITH 92 Get to know


Python coding
SOME ELEMENTARY
CODING IN MINECRAFT 95 Begin coding
in Minecraft

Winter 2016 // // 85
Start programming
using Scratch
Ben Everard shows you how to build a cat and mouse game using this
straightforward beginners programming language on the Raspberry Pi

T
heres a wide range of programming At the top-left are eight colour-coded categories
EXPERT languages that can be used with the or functions. To begin, click on Control, and blocks
Raspberry Pi, but Scratch is great for of code will appear below. From these, drag When
beginners, because it introduces many Space Key Pressed into the scripts panel in the
of the concepts of programming while middle. What do you want to happen when the
being easy to use. Its especially good for creating space key is pressed? Click on Looks at top-left,
graphical programs such as games. and drag Say Hello For 2 Secs directly beneath
Youll find Scratch on the desktop in Raspbian, the first piece. The two lock together into a script.
so theres no need to install anything just click Youll notice that Hello and 2 have a different
on the icon to get started. (Many other operating background, indicating they can be edited. Click on
systems for the Pi dont support Scratch, although Hello and change this to Hello World!, then click
you can download Scratch for Windows, Mac or on 2 and change this to 4. Press Return to exit
Linux at https://scratch.mit.edu. Our tutorials the text box. To run the script, press the space key.
will be equally applicable whatever your platform.) Congratulations, youve made a Scratch program!
The main window in Scratch is split into three Want to do more? Click on Control again, drag
sections: the bits you can use to make programs When Space Key Pressed into the scripts area,
are on the left; you piece them together in the then click on Space Key and change this to Right
middle; and the programs run in the area on the Arrow. Click on Motion at top-left and drag Move
right. Each program is made up of a number of 10 Steps beneath the Right Arrow block. Now the
sprites (pictures) controlled by scripts which you cat will take a walk if you hit the arrow key. Get the
assemble in the middle panel like building blocks. idea? Lets try something a bit more complex...

Variables and messages


Sooner or later, youre going to want to get want to store different types of data, but you Sometimes you can do this with variables,
your program to remember something. It dont need to worry about that in Scratch. but it is often better to use messages.
might be a number, a piece of text, or Once youve created a variable, you can These can be used to trigger scripts in the
anything. You can do this using variables. use it in a few ways. First, you have to set it same way as keypresses can. When one
These are little pieces of the computers to be a particular value, then you can use it script broadcasts a message, it will then
memory that your program can place pieces to evaluate conditions (which well do in trigger all the scripts that start with a
of data in. In step 5, we create a pair of these steps 8 and 13), or you can output it. matching When I Receive Like variables,
to store some numbers in, although we messages have names, so they have to be
could also put text in them. Note that in Messages created first, and for a script to trigger it
some programming languages, you have to If you create a number of scripts, you might has to be linked to the same message as
create different types of variables if you need to communicate between them. the broadcast.

86 // // Winter 2016
Starting Scratch CODING

EXPLORING SCRATCH
Categories Choose Options Menus and Costumes/Sounds Canvas This is where
what type of code buttons along the top Click a tab to show sprites are displayed
you want to use next. offer further options. the costumes (that is, and their behaviour
Theyre colour-coded Under Share you can images) and sounds is previewed.
to help you identify upload your project to for the current sprite.
which type each piece scratch.mit.edu to let
of code is. the world see it.

Code Pick a category New Sprite Here


and pieces of code you can create a new
appear here. Drag any sprite directly from an
you want into the image file.
scripts panel to build
up your program.

Scripts These are the Sprite select As you


scripts for the current add more sprites, they
sprite. You can edit appear here. Click one
various parameters. to select it, then click
To remove a piece of the tabs in the middle
code, drag it back into panel to see its scripts
the left-hand panel. and costumes.

1 Create your scripts 2 Add more scripts


Well build on the trial program weve begun. At this point your scripts In the first, click on Space and change the key to Down Arrow. Now
panel should look like this. (If not, follow the steps in the introductory click Motion again, and drag Turn (clockwise) 15 Degrees beneath
text on the opposite page.) Now click on Control again, and drag two this block. In the second When ... Pressed block, change Space to
instances of When Space Key Pressed into the scripts panel... Up Arrow, then add Turn (anti-clockwise) 15 Degrees to this script.

Winter 2016 // // 87
CODING Starting Scratch

3 Create the mouse 4 Set keys


Change the sprite image from the default cat to a mouse by clicking Click the Scripts tab in the middle panel, and change When Space
the Costumes tab, then Import > Animals > Mouse 1. Next reduce the Key Pressed to When r Key Pressed. Well use this to start a new
sprite size by clicking on the Shrink Sprite icon (circled) and then the game (r is for reset). Then drag Say Hello World... off the bottom
mouse. We set it to about the size of our thumbnail. of the script. If you drop it back in the left side, it will be deleted.

5 Create and name variable 6 Reset the score


Click on Variables in the top-left (see the box on the previous page Click on Looks and drag show under the script When r Key Pressed.
for more details about what they are). Click on Make A Variable and Now click on Motion and add Go To X:100, Y:100 under the same
enter the variable name as score. Repeat the process to create a script (dont forget to change 0s to 100s). Finally, from Variables,
second variable called over. add both Set Score To 0 and Set Over To 0.

88 // // Winter 2016
Starting Scratch CODING

7 Add broadcast 8 Create a loop


From Control, add the block Broadcast to the bottom of the When We can create loops that cycle through the same code many times.
r Key Pressed script. Once its there, click on the drop-down menu Continue the script with Repeat Until (from Control), and then
and select New... and give the message the name start. Well use drag and drop = (from Operators), then drag Over (from
this to let the other sprite know that the game has started. Variables) into the left-hand side of the = and enter 1 on the right.

9 Add to your loop 10 Hide the mouse


Inside the Repeat Until Over = 1 block, add Change score By 1 (from Once the game has finished (and the cat has got the mouse), the
Variables), Move 7 Steps (from Motion) and If On Edge, Bounce Repeat Until loop will end and the program will continue underneath
(also from Motion). These three pieces of code will be constantly it. Drag Hide (from Looks) under the loop, so the mouse disappears
repeated until the variable over gets set to 1. when this happens.

Winter 2016 // // 89
CODING Starting Scratch

11 Add your cat and resize it 12 Move the cat


To import a cat, click Choose New Sprite From File above the sprites In the scripts for the new sprite, start a new script with When I
panel at bottom-right, select Cat 4, then shrink it to an appropriate Receive start (from Control), and add Go To X:-100 Y:-100 (from
size, as we did with the mouse. Each sprite has its own set of scripts. Motion). This will move the cat over to the opposite corner of the
To swap between them, click the icon you want in the sprites panel. screen from the mouse. (0,0) is the middle.

13 Give the cat a loop 14 Set the difculty


Like the mouse, the cat also needs a loop to keep things going. Inside the Repeat Until block, add Point Towards Sprite 1 (from
Add Repeat Until (from Control), and then in the blank space add Motion) and Move 4 Steps (also from Motion). The amount the cat
Touching Sprite 1 (from Sensing). This will keep running until the and mouse move in each loop affects the difficulty of the game. We
cat (sprite 2) catches the mouse (sprite 1). found that 4 and 7, respectively, worked well.

90 // // Winter 2016
Starting Scratch CODING

15 Finish the loop 16 Tell the player the game is over


The loop will finish when the cat has caught the mouse the game is We now want to let the player know that the game is over. We will
over, so we need to stop the script on Sprite 1. We do this by adding do this in two ways: with audio and by displaying a message on
Set over To 1 (from Variables) underneath the Repeat Until block. screen. Add Play Drum 1 for 1 Beats (from Sound), then Say
This will cause Sprite 1s main loop to finish. Mmmm Tasty For 1 Secs (from Looks).

17 Display a score 18 Play your game!


Finally, we can let the player know their score. We increased the Click the disk icon in the top bar to save, then press r and play! You
variable score by one every loop, so this will have continued to go up. can use the up and down arrows to move the mouse around. You can
Add Say You Scored For 1 Secs, then drag another Say for 1 make it easier or more difficult by changing the size of the sprites and
Secs block and then drag score (from Variables) into the blank field. the amount they move each loop. Good luck and happy gaming!

Winter 2016 // // 91
Take your first steps
coding with Python
Robert Jones helps you begin learning the basics of the worlds
most popular programming language on your Raspberry Pi.

T
heres a multitude of programming Because the Raspberry Pi is all about learning
languages, but if youre going to learn to code, its no surprise to find Python already in
just one, then Python is the one. the system. Click on Menu > Programming, and
Python is used by students around youll find two versions of Python available:
the world to learn coding skills and Python 2 (IDLE) and Python 3 (IDLE).
by big companies such as banks to run mission There are differences in the way Python 2 and
critical software. Python 3 code works. Even the humble print
There are many reasons why Python is such a statement works differently.
favourite. Its easy to learn but at the same time
incredibly powerful its like getting a learner Starting Python
bike, complete with training wheels, thats good Most tutorials and resources are created with
enough to enter the Tour De France. It is easy to Python 2 in mind, and most university courses
read Python code, and it goes light on syntax. teach Python 2. So its best to start with Python 2
Semi-colons and curly brackets { and } litter and move to Python 3 when you have a few lines
languages like C and Java, while Python just uses of code under your belt. So choose Python 2
indentation and line spacing to organise code. (IDLE) from the menu bar.
A window opens displaying Python 2.7.9 Shell
and three chevrons: >>>. This window is known
GPIO in Python as interactive mode, and you can enter Python
commands straight into it. Its good luck to
The great thing about the Raspberry version of Python, so you dont need
christen all new programming languages by
Pi is the GPIO pins you can access to set anything up.
on the device. These enable you to There is also a more friendly printing the traditional message Hello, World!
hook up hardware, connect circuits interface to GPIO called GPIO Zero. to the screen. Input the following command:
and build all kinds of projects. Its This provides a lot of component print "Hello, World!"
the interface between your software interface for devices such as LEDs The phrase Hello, World is outputted as a
and hardware. You can control the and sensors. You can learn more string and appears below your command. You
GPIO Pins using Python (along with about GPIO Zero at its main website, then get another command prompt.
many other languages). Support for https://gpiozero.readthedocs.io/ And so you can start programming, entering
GPIO is built into the Raspberry Pi en/v1.3.1/. commands as input and getting direct output.
This is known as interactive mode. Well come

92 // // Winter 2016
Python CODING

to script mode in a minute, but first well look


at some maths.

Python Math
Python works well as a calculator. To demonstrate
this, type in the following:
10 + 20 - 5
Youll get 25 as output. Notice that you didnt
need to enter print at the start. It outputs the
answer as an integer. You can put print before
it if you like; youll get the same answer.
Now try the following. But before you enter it,
try to guess the answer...
10 + 10 * 2
Youll be forgiven for thinking 40. But the answer
comes back as 30. Why? The reason is called There are
operator precedence. Python, like all computer print "Open the pod bay doors, " + computer two versions of
programs, doesnt work from left to right. Instead, print "I'm sorry, " + person + ". Im afraid I cant Python installed
it considers the * and / operators to be more do that." in Raspbian.
important than the + and -. So our 10 + 10 * 2 Press F5 and youll see the script appear in Python 2 is the
program goes like this: Python Shell. Now change the strings in the one you should
10 * 2 variables person and computer, so the person is start learning.
10 + 20 called Bob and the computer is called Pi. Press
30 F5 again and youll see the new script.
The power symbol, which is ** in Python, as
in 2 ** 4 (two to the power of four) is even more Variable types
important still. If you want to get around all this, Remember how we said that variables could be
you place calculations you want to be performed strings or integers (and other types)? Python gets
first in parentheses, like this: a bit confused if you try to mix the two together.
(10 + 10) * 2 This is particularly challenging when combining
Now youll get the answer you want: 40. numbers with strings. First enter this text:
answer = 42
Script mode print "The answer to the meaning of life, the
You can use interactive mode as a calculator, and universe, and everything is " + answer
experiment with basic commands. But to string Press F5 and youll get an error message:
commands together (to create that thing we call TypeError: cannot concatenate str and int
a program), youll need to create a new file and objects. This error arises because answer is an
use Script mode. integer, and the print statement needs a string.
Go to File > New File and a new window will Python cannot work with them.
open called Untitled. Now go to File > Save and You could change answer to a string by putting
name the new file hello.py. the 42 in quotes: answer = "42" . But then you Python can be
Now were going to add a one-line program that wont be able to do any maths with it. Its no run in Interactive
says hello to you by name. Add these lines: longer an integer, and you cant perform maths Mode and in
Script Mode. In
name = "Robert" with strings. A lot of the time youll want to do
Interactive Mode
print "Hello " + name some maths and then print out the result with
you can enter
Dont forget to include to space after Hello or a message. To do that you need to convert the commands and
itll say HelloRobert. Go to File > Save and press integer into a string, using a function called str() . change program
F5 to run the program. The Shell window returns, You can spot functions because they have two variables from the
and displays Hello Robert. brackets (parentheses) after them. command line.
The element name is called a variable. This
is because the thing it contains can vary. In this
instance, it includes the name Robert. Variables
that contain text are known as strings as
opposed to numbers (which are often referred
to as integers).
The joy of variables is that you can use them
again and again, and quickly change them. Create
a new file and name it movie_script.py. Enter this
code to recreate a famous movie script:
person = "Dave"
computer = "HAL"

print "Hello, " + computer + ".Do you read me, " +


computer + "."
print "Affirmative, " + person + ". I read you."

Winter 2016 // // 93
CODING Python

place the variable, as always with functions, inside


the brackets.
Enter type(age) and itll return <type str>
Enter type(new_age) and itll return <type int>
This is a powerful feature that Python has (and
most other programming languages lack). After
youve run a program, you can mess around with
the variables on the command line, checking and
changing them to see what happens. This makes
it much easier to figure out whats going on in
your program.

What Else (and If)


So far weve looked at programs that can ask for
information, store it as variables, manipulate the
variables and output it back to the user. Weve
Traditionally The str() function takes a number and spits it come quite a way.
the first program back out as a string. You put the number inside Of course, this isnt enough. Programs make
you run in any the brackets, like this: str(42) . The process is decisions based on data (in this case, your
new programming called typecasting (yes, really) and it turns one variables). To make decisions we use three
language displays
type into another. If you want to typecast a string statements: if, else and elif (else if). Lets see
Hello World on
into a number, you use the int() function. Place how this works:
the screen.
the string inside, as in int("42") , and youll get 42 password = "knockknock"
back as an integer. entry = raw_input(Enter password)
So lets try another program: if entry == password:
answer = 7 * 6 print "Welcome!"
print "The answer to the meaning of life, the else:
universe, and everything is " + int(answer) print "Wrong password. Access denied."
Typecasting is most useful when youre using Therere a couple of things here to observe.
raw_input() to request a number from the user. First, on line three we introduce the if statement
Lets try the following code: and immediately follow it with ==. This is
age = raw_input("Enter your age: ") completely different from the = symbol. The
new_age = int(age) + 10 single = is used to set a variable. If you had put
print "In 10 years time you'll be " + str(new_age) + entry = password then both would be set to
"years old!" knockknock, the same as if youd put entry =
First we see a new function, called raw_input() knockknock. But the == symbol is used to
with Enter your age: inside the brackets. check whether both things are the same.
This function displays the message inside the Confusing these two symbols is one of the most
brackets, then takes the input received from the common errors youll make. Check carefully.
user and returns it as a string. Its then stored The fourth line is indented by four spaces. You
(as a string) in the age variable. can also press Tab to indent, but you should never
On the second line we typecast the age mix and match. Pick one or the other.
variable from a string into an integer, and then Press F5 to run the program. Youll be asked to
add 10 to it. This number is stored in the new_age enter a password, and if you enter knockknock,
variable as an integer. youll get the welcome message. You now have an
On the third line, we print out the message and interactive program that responds to your input.
convert the new_age variable into a string so it Theres a lot more to learn about Python, but
can be printed along with our message. the Raspberry Pi is the ideal environment to learn
it. You can experiment to your hearts content!
Back to interactive
Were now going to head back to the Python 2.7.9
Shell to show something powerful about Python.
After youve run a program in Script mode, you Python in Terminal
can play around with it in Interactive mode. Run
the age program above, and enter 19 as your age. Python isnt just accessed in the IDLE app. Its also part
of the Raspbian Linux system, and you can run Python
Youll see the message In 10 years time youll be
programs in Terminal. You can also run Python in
29 years old.
Interactive mode (although in this mode you cant run
Now enter age in interactive mode. Itll say 19. programs and then access and adjust variables as you
Next enter new_age in interactive mode. Itll say would in IDLE).
29. Notice that 19 has single quote marks around In Terminal, enter python to access Interactive
it, and 29 doesnt. Quotation marks are a visual mode. You can perform quick math calculations and run
way to tell that the age variable is a string, while simple scripts.
new_age variable is an integer. To run a python program, simply enter python and
Another way is to use the type() function. This the name of the program (the file ending in .py).
function lets you know what type a variable is. You

94 // // Winter 2016
Get started with
Minecraft coding
Robert Jones explains how to hack into Minecraft and build
your own world with this easy introduction to the Minecraft API

M
inecraft is one of the most popular going to Menu > Games > Minecraft Pi. Click Start
games ever made. In it you control Game > Create new to start playing the game
a character, officially called the normally. You look around with the mouse, and
player but often called Steve or Alex. move with the W,A,S,D keys.
The world of Minecraft is made of Playing Minecraft normally isnt what were
blocks. In it, you dig up the blocks and craft them here for, though. So lets get to know the Minecraft
into various things houses, cars, statues, boats API. Press the Esc key on your keyboard to stop
and so on. Its like virtual Lego. the game (but dont close it down).
Minecraft for Raspberry Pi is a smaller version
of the pocket edition. It may have fewer features The Minecraft API
than the full version, but it has an ace up its sleeve. The term API stands for Application Programming
You can hack Minecraft on the Raspberry Pi using Interface. APIs are big blocks of code made by
programming languages such as Python and Java. other people that you can use. With an API you
This means that using just a few lines of code, you just need to learn a few commands, and the API
can change the Minecraft world around you, will do all the heavy lifting.
adding and removing blocks, changing blocks In Minecraft, the API works by changing the
and moving the player around. server. In this context, this is not a remote
Other players have created countless programs computer on which data is stored. Rather, this is
for Minecraft on the Raspberry Pi. These are a program which runs underneath the game. With
shared online, and you can import them, and the API you can interact with blocks and the player.
examine them. People have built giant randomly Here are some of the things you can do:
generated mazes, working clocks and even video Get the players position.
games you can play inside Minecraft. This makes Change (or set) the players position.
Minecraft an ideal environment for learning the Get the type of block.
basics of programming. Its a highly visual world, Change a block.
and you can see the results of your code in a Change the camera angle.
virtual world. And theres plenty of code for you Post messages to the player.
to play with. Above all that, its fun! Were going to use the Python API for Minecraft.
Minecraft is installed by default in the Raspbian As is tradition, the first program well create will
Jessie with Pixel operating system. Start it up by send the player the message Hello World.

Winter 2016 // // 95
CODING Minecraft

pos: and three numbers (initially all three are 0).


This represents the position, and the three
numbers are x, y and z coordinates. This time,
press Alt + Tab to switch between Minecraft and
IDLE. With this method, you can make adjustments
while Minecraft is still running.
Unlike in normal coordinate systems, the x and
z variables are for the position of the player on the
ground. Move around, and youll see them change.
The y variable is for the height. Each number
represents one block, so if you walk straight
forward (without turning), youll see the z variable
increase by one for every block you walk over.
Lets drop the player in mid-air. Delete the line
of code with mc.postToChat(Hello World!) but
leave the first two lines of the code (the ones that
Transform So, to get started, return to Minecraft and go to import minecraft and create the mc connection).
regular blocks Menu > Programming > Python 3 (IDLE). Use File Now enter this line of code:
into solid gold (or > New File to open a new window. To save the file mc.player.setPos(0,100,0)
any material you go to File > Save, and name it minecraft.py. Save the program and press F5 to run it. The
choose) using the
Next import the Minecraft API into your Python player teleports to mid-air and falls back down to
setBlock method.
program by typing this line of code in the file: the ground. Try some other coordinates to learn
import mcpi.minecraft as minecraft how they affect your hapless player!
Now create a connection between your
program and Minecraft and call it mc (which Block party
stands for Minecraft connection): Now that youve learned to print messages on the
mc = minecraft.Minecraft.create() screen and move the player around, its time to get
Minecrafts Now use mc (the Minecraft connection) to send down to business. And in Minecraft that means
unconventional a command to the game: blocks. With the Minecraft API, you can turn any
3D coordinate mc.postToChat("Hello World!") block into any other type of block. Turn sand into
system. Save the program. Return to the Minecraft air, or flowers into iron ore.
game and press Esc again. Youll now be back in Were going to turn the player into King Midas,
the game and will briefly see the message Hello turning blocks into gold as he walks around. Open
World! displayed on the screen. Congratulations, IDLE and choose File > New (and save the file as
you just took your first step into meddling with the midas.py). For this we need to import minecraft
Minecraft world. and block from the mcpi file:
import mcpi.minecraft as minecraft
Move the player import mcpi.block as block
Obviously just having Hello World appear on the mc = minecraft.Minecraft.create()
screen, although its a nice first step, isnt very To get the blocks to respond to the player, we
exciting or useful. So lets do something a bit more will need to create a variable that stores his
adventurous in our adventure. position. Traditionally this is stored as a variable
In the top-left of the Minecraft screen, youll see called p:
p = mc.player.getTilePos()
Now were going to change the tile beneath the
STROLL AROUND NEW YORK player into gold using the setBlock method.
mc.setBlock(p.x, p.y-1, p.z, block.GOLD_BLOCK)
You can use the Minecraft API to render 3D models as object files (OBJ) We use p.x and p.z to get the players horizontal
into Minecraft worlds. Martin OHanlon has a great example where hes position but p.y-1 to use the block beneath the
created New York by downloading a Google SketchUp model of Manhattan player remember that y is the vertical position.
and using OBJexporter (see http://bit.ly/OBJexporter) to export the
Press F5 to run the program and look down.
model. This is then rendered inside Minecraft on the Raspberry Pi.
Open Terminal and enter the following code:
Youll see that the block has turned to gold. But
cd ~ just one gold block isnt enough. So lets get the
git clone https://github.com/martinohanlon/minecraft-renderObj.git program to loop forever by indenting the two lines
cd minecraft-renderObj inside a while true statement, so it looks like this:
python minecraft-renderObj.py while True:
Be warned that this can take a long time (hours) to render. However, p = mc.player.getTilePos()
you can walk around as its being built. If you find yourself stuck inside a mc.setBlock(p.x, p.y-1, p.z, block.GOLD_
tower block, use IDLE to move the player: BLOCK)
import mcpi.minecraft as minecraft The while True: code creates an infinite loop,
mc = minecraft.Minecraft.create()
so this program will keep running until you stop it.
mc.player.setPos(0,100,0)
You can read more about this and see some images on Martins
Press F5 and now, as you run around, a trail of gold
website, stuffaboutcode.com, at http://bit.ly/Minecraft-NY blocks appears behind you. They even appear in
the air. Change the GOLD_BLOCK to ICE to leave
a trail of ice behind instead. Check out the Blocks

96 // // Winter 2016
Minecraft CODING

in the Minecraft API box below for a full list of


available materials.
It is also possible to change blocks when the
player hits them with his sword (by right-clicking
the mouse). You do this by creating a hit variable,
which detects an event. Remove the three lines of
while true code from the program above, and
enter the following instead:
while True:
for hit in mc.events.pollBlockHits():
mc.setBlock(hit.pos.x, hit.pos.y, hit.pos.z,
block.GOLD_BLOCK)
Press F5 to run the program. Now as you hit
blocks, theyll turn to gold.
You can create lots of blocks at once in
Minecraft. You do this by passing in two sets of
positions to setBlocks. The Minecraft API fills in the block from GRASS to FLOWER_YELLOW. (The Import code
the blanks. Minecraft API is very forgiving: you can use ID created by
Were going to create the black obelisk from the numbers or names for materials, or mix the two.) other users to
movie 2001: A Space Odyssey. Get rid of all the Enter this code in IDLE: add powerful
new features
code in IDLE and enter this: import mcpi.minecraft as minecraft
to Minecraft,
import mcpi.minecraft as minecraft import mcpi.block as block
such as this
import mcpi.block as block mc = minecraft.Minecraft.create() working cannon.
mc = minecraft.Minecraft.create()
p = mc.player.getTilePos() while True:
mc.setBlocks(p.x + 1, p.y, p.z + 1, p.x + 10, p.y + 5, p = mc.player.getTilePos() Pi facts
p.z + 10, block.OBSIDIAN) below = mc.getBlock(p.x, p.y - 1, p.z)
Save, press F5, and in the game the black tower if below == 2: If you connect
of blocks will appear just next to you. mc.setBlock(p.x, p.y, p.z, block.FLOWER_ multiple
Raspberry Pis to
YELLOW) a local network,
Finding blocks Press F5 to run the program. Now as the player players can join
the same game
You can detect a block type underneath the player runs around, the blocks of grass where he stands and play
using the getBlock() method. This method returns will turn into flowers. together. They
a number, which you can check against the API list can then see
using an if statement. Getting other programs each other in the
Minecraft world.
Were going to create a program that turns Now that youve got the basics of the Minecraft
grass into flowers as the player walks around. Well API down and created your first program, youll
do this by checking what is beneath the player want to look at something a little more complex.
using getBlock(p.x, p.y-1, p.z) and storing this in Fortunately, there are lots of examples of
a variable called below. Minecraft API coding on the Internet. You can
Then we check to see if the below variable download these programs, and play around with
matches grass (which has an ID number of 2). If them in your own copy of Minecraft. Not only are
we get a match, well use setBlock() to change many of the programs fun to play in their own

BLOCKS IN THE MINECRAFT API


Here are the blocks you can GRAVEL 13 IRON_BLOCK 42 LADDER 65
access in the API, along with GOLD_ORE 14 STONE_SLAB_DOUBLE 43 STAIRS_COBBLESTONE 67
their ID codes. IRON_ORE 15 STONE_SLAB 44 DOOR_IRON 71
COAL_ORE 16 BRICK_BLOCK 45 REDSTONE_ORE 73
AIR 0 WOOD 17 TNT 46 SNOW 78
STONE 1 LEAVES 18 BOOKSHELF 47 ICE 79
GRASS 2 GLASS 20 MOSS_STONE 48 SNOW_BLOCK 80
DIRT 3 LAPIS_LAZULI_ORE 21 OBSIDIAN 49 CACTUS 81
COBBLESTONE 4 LAPIS_LAZULI_BLOCK 22 TORCH 50 CLAY 82
WOOD_PLANKS 5 SANDSTONE 24 FIRE 51 SUGAR_CANE 83
SAPLING 6 BED 26 STAIRS_WOOD 53 FENCE 85
BEDROCK 7 COBWEB 30 CHEST 54 GLOWSTONE_BLOCK 89
WATER_FLOWING 8 GRASS_TALL 31 DIAMOND_ORE 56 BEDROCK_INVISIBLE 95
WATER 8 WOOL 35 DIAMOND_BLOCK 57 STONE_BRICK 98
WATER_STATIONARY 9 FLOWER_YELLOW 37 CRAFTING_TABLE 58 GLASS_PANE 102
LAVA_FLOWING 10 FLOWER_CYAN 38 FARMLAND 60 MELON 103
LAVA 10 MUSHROOM_BROWN 39 FURNACE_INACTIVE 61 FENCE_GATE 107
LAVA_STATIONARY 11 MUSHROOM_RED 40 FURNACE_ACTIVE 62 GLOWING_OBSIDIAN 246
SAND 12 GOLD_BLOCK 41 DOOR_WOOD 64 NETHER_REACTOR_CORE 247

Winter 2016 // // 97
raspberry-pi-minecraft-cannon.html. To
Minecraft commands download Minecraft Cannon, open a Terminal
window and enter the following, then hit Return:
We use several Minecraft API commands in this project. There are fewer cd ~
commands than you imagine, but once you learn them, you can create clone https://github.com/martinohanlon/minecraft-
some incredibly powerful programs. Here is the Minecraft API: cannon.git
postToChat(message) Communicate in the game.
Enter ls and youll see the minecraft-cannon
getBlock(x, y, z) Get a block type for a specific position.
setBlock(x, y, z, blockType, blockData) Change a block to a certain blockType.
directory. Navigate to it and run the Python code
setBlocks(x1 , y1 , z1, blockType) Create a block. contained inside to run the program (make sure
setBlocks(x1 , y1 , z1 , x2, y2, z2, blockType) Set lots of blocks all at the same youre running Minecraft first).
time by providing two sets of co-ordinates. cd minecraft-cannon
player.getPos() Get the current position of the player. python minecraft-cannon.py
player.setPos(x, y, z) Set the players position. Terminal will display Stuffaboutcode.com
player.getTilePos() Get the position of the tile the player is currently on. Cannon >>. You can use this mode to enter
For more, see www.stuffaboutcode.com/p/minecraft-api-reference. commands to control the cannon. To create a new
html. With these commands, you can alter Minecraft in any way you want! cannon and fire it, for example, you simply use:
start
fire
Pi bites right, but you can also examine the code and Here are all the commands you can use in
learn how it works. Minecraft Canon.
You can find the Were going to use Git to install the software. Git start create (start-up) the cannon
Minecraft API in is installed by default in Raspbian Jessie with Pixel, rotate [0-360 degrees] rotate the cannon
Terminal using
cd /opt/ but if you dont have it, you can install it using: tilt [0-90 degrees] tilt the cannon upwards
minecraft-pi/ sudo apt-get install git-core fire what it says!
api. Type the
command cat /
A good place to start is minecraft-clock. This exit exit the program and clear the cannon.
opt/minecraft- code draws a large circle, then uses trigonometry You can investigate the code in Python. Open
pi/api/spec/ to to find where the hands should be drawn. IDLE from within Minecraft by going to Menu >
view the official
specifications Make sure that Minecraft is running a game. Programming > Python 3 (IDLE). Now choose File
for the project. Open a Terminal window and enter this code: > Open and open the minecraft-cannon directory.
cd ~ Highlight minecraft-cannon.py and choose Open
git clone https://github.com/martinohanlon/ to view the code in IDLE.
minecraft-clock.git Here you can see how all the functions have
cd minecraft-clock been programmed. It uses the block module as
python minecraft-clock.py well as time (to create delays), math (to calculate
You will see STARTED in the Terminal and a the trajectory) and cmd (to interact with the
message displays inside Minecraft welcoming you command line).
to the clock. Then, a giant clock appears in the sky. Minecraft is a tremendously creative game, and
Switch back to Terminal using Alt + Tab and press with Minecraft API its possible to create amazing
Ctrl + C to quit the program. The clock will stop programs to take it even further. This fun gaming
running inside Minecraft. connection makes Minecraft API a great way to
learn to code, and a good start to learning complex
Building a cannon programming languages such as Python (and even
One of the most complex programs you can run is Java). As you become more advanced, its even
called Minecraft Cannon by Martin OHanlon. You possible to hook up Minecraft to the Raspberry Pi
can learn more about the code on the Stuff About hardware and blend the real world with Minecrafts
Code website (stuffaboutcode.com/2013/04/ imaginary block world. Have fun!

Create multiple
blocks at once
to create shapes
and structures.

98 // // Winter 2016
Pi REVIEWS
Tested and rated: the latest add-ons for your Pi 100

102

104
108

A SIMPLE, ROBUST AND 100 FUZE


Workstation
COMPACT PLATFORM FOR
MANY DIFFERENT PROJECT 102 PiBorg
ZeroBorg
TYPES, THIS WILL SOON BE
YOUR GO-TO BOARD
104 Drum HAT
106 Explorer
Pro
HAT

106 110 112 108 Picon Zero


110 CamJam
EduKit 3

112 Picade by
Pimoroni

Winter 2016 // // 99
REVIEW FUZE Workstation

FUZE
Turn your Raspberry Pi into an electronics workstation with the
FUZE Computer. Robert Jones reviews a great kit for classrooms

T
In brief
he Raspberry Pi
is ideal for learning THE IO BOARD, LIKE A BREAKOUT
The FUZE is
an electronics
computing and
hardware projects.
CABLE, ALLOWS YOU TO CONNECT
workstation
kit for the
The only problem COMPONENTS SAFELY
Raspberry Pi is that the Raspberry Pi doesnt
(which sits come complete with a keyboard,
inside it). It
looks more
mouse or any electronics The real advantage is the with the RC robotic arm from
like a regular components. So if you want FUZE IO Board that attaches to Maplins. This comes in kit form
computer but to use a Raspberry Pi to teach the GPIO pins of the Raspberry but is easy to build. It attaches
has an IO board
for connecting young students electronics Pi. Like a breakout cable, this to the FUZE Workstation via
electronics projects, you need to add quite allows you to safely connect USB and software is used to
components. a few things to get started. electrical components to the control it.
The FUZE Workstation is FUZE without worrying about The only hiccup is that FUZE
built around a Raspberry Pi but blowing the Raspberry Pi board. has put all of its eggs in a Basic
looks reminiscent of a home It also offers additional programming language basket.
computer from the 1980s. In features, such as analogue The FUZE Workstation runs a
fact, theres a model with a retro input and output. The FUZE stock version of Raspbian and
colour scheme designed to look Workstation comes with a box can be programmed in any
just like the classic BBC Micro of components, including LED language. But most of the
(which originally inspired it). lights (red, green and blue), worksheets and projects use
In many ways, its the complete jumper leads, buttons, light a version of Basic (based on
computer setup that many sensors, seven segment LEDs RTB: Return To Basic).
people want. and mixed resistors. Basic may have retro appeal
Theres a keyboard on the FUZE also supplies Project to teachers remembering days
front and a mouse attached to Workbook and Worksheet spent entering code line by line
one of the four USB ports on the guides for users to work with on a BBC Micro. But its been
rear, where theres also an HDMI these components. far superseded by entry-level
connection to connect the FUZE Teachers who want to take languages like Scratch and
to a television or monitor. things further can use the FUZE Python. We cant see any good

Features at a glance

Case Fuze IO Board


The FUZE case contains On top of the FUZE is an
a keyboard and external IO (Input/Output) board,
USB ports that make your which makes it easy to
Raspberry Pi look more connect electronics to the A range of bundles is
like a regular computer. FUZE workstation. available, starting at 70
without a Raspberry Pi.

100 // // Winter 2016


FUZE Workstation REVIEW

The RC robotic arm


from Maplin (shown here)
attaches to the FUZE
Worksation via USB.

reason to teach young students Reference, Project Workbook, In all, FUZE is a nicely
Basic when you can get them 840-pin breadboard, component self-contained case for the
straight into Scratch. kit, cables and robot arm kit. Raspberry Pi that turns it into
FUZE says its Basic is Even if you opt for DIY, putting a reliable computer with a built-
a stepping stone between the kit together is easy. Slot the in IO Board for using to learn
introductory tools like Scratch Raspberry Pi inside the FUZE kit electronics. Teachers find FUZE
and real-world programming and wire up the external ports to incredibly useful for teaching IT
languages such as Python. If the USB, power and HDMI ports in the classroom.
you want to investigate the Basic on the Raspberry Pi board.
supplied with FUZE, you can The Micro SD slot of the
download it for free from the Raspberry Pi sits flush against Verdict
FUZE website. the outer case of the FUZE box.
FUZE
The FUZE can be purchased This approach worked fine with
Developer: FUZE
with a Pi inside (starting at 100 the Raspberry Pi 2 and its push- Web: www.fuze.co.uk
for the basic bundle), or you can to-eject mechanism, but the Price: From 100 including Raspberry
buy the kit without a Pi and Raspberry Pi 3 requires you Pi 3, or 70 without
assemble it yourself. The top- to pull out the Micro SD card
spec kit for 230 comes with
Raspberry Pi 3, Programmers
manually. We found that a pair
of tweezers helped.
Rating 8/10
Winter 2016 // // 101
REVIEW PiBorg ZeroBorg

In brief
A robot control
board for the
serious robot
maker. Its able
to control four
DC motors or
two stepper
motors and
react to input
from an infrared
remote. Using
I2C, this board
can be stacked
with others
to provide
multiple motor
controllers for
larger projects.
Its controlled
via a simple
Python interface
that can be used
with existing
projects.

Features at a glance

Motor controllers Infrared input


The ZeroBorg can control If you have a spare remote
four DC motors with control, you can run the
individual control of zbIrRead.py code to capture
each motors power. each button press.

102 // // Winter 2016


PiBorg ZeroBorg REVIEW

PiBorg
ZeroBorg
Les Pounder prepares to be assimilated by
the latest board from the PiBorg roboteers

T
he PiBorg team is well of controlling four DC motors to control your robot. At the time
known for its robotic simultaneously, thanks to two of writing, a Python 3 library is
creations, which full H-bridge controllers. (Each being worked on, and this should
include DoodleBorg, a one is a DRV8833, which is also be released soon if its not
Raspberry Pi powered used on the 4tronix Picon Zero already available.
tank large enough to transport a and the CamJam Robotics kits.) The PiBorg ZeroBorg is a
person. For its latest project the The board can also control two serious robot platform providing
team turned to crowdfunding for stepper motors, which can be rock-solid control of motors,
a smaller, Pi Zero focused robot used for slow, precise motion- both DC and stepper. The ability
control board called ZeroBorg, control applications. to add more of these boards to
and it is rather impressive. ZeroBorg also comes with augment a creation is fantastic,
Measuring 64x40mm, this board analogue inputs for sensors, and as it enables you to combine
is designed for both models of the most useful is the infrared different motors for varying
the Raspberry Pi Zero but is receiver, which will work with functionality. The board is easy
compatible with all models most remote controls. We tested to use and it took us little time
of Raspberry Pi as it uses the the receiver with a cheap generic to get going with our infrared-
Inter-Integrated Circuit (I2C) remote, captured the data controlled motor project.
interface, which Because it
requires only
the first six THE ZEROBORG IS A SERIOUS uses only six
GPIO pins,
GPIO pins.
The board
ROBOT PLATFORM PROVIDING you still have
access to the
cradles the Pi ROCK-SOLID MOTOR CONTROL remaining
Zero from pins, requiring
below, with only that you
support posts at each corner of received by the receiver and solder a header pin to each GPIO
the board. Also present on the used it to control a series of pin you wish to use.
underside of ZeroBorg is a 9V motors attached to the board. For those just starting out
battery connector, which can The PiBorg ZeroBorg is a with robotics, something like the
power the Pi and the board little different from other motor Picon Zero or CamJam Robotics
thanks to a 5V regulator built in control boards. Given that it uses kit will be more appropriate
to ZeroBorg. The connection I2C, a data connection protocol, because it provides more inputs
between the ZeroBorg and the Pi there can be multiple ZeroBorg for sensors. For the serious
is made via six General Purpose controllers in a project, with roboteer, though, this could be
Input Output (GPIO) pins, and each giving you control of four the perfect kit to build your next
these can be soldered in place motors, so with three units you multi-motor monster.
or pins can be bent as required. could drive 12 individual motors.
Both of these connections to the Controlling the ZeroBorg is
GPIO require a Pi Zero with no handled via a robust Python Verdict
GPIO header pins soldered. For library, which is installed via an
PiBorg ZeroBorg
connection to other Raspberry automated script on the PiBorg
Developer: PiBorg
Pi models, or for a temporary website. The Python library Web: www.piborg.org/zeroborg
connection, you can use female comes with a series of examples Price: From 18 (as tested 32.50)
to female header cables.
Primarily, the ZeroBorg is
on how to use the ZeroBorg,
including how to capture infrared Rating 8/10
a motor control board capable remote signals and use joypads

Winter 2016 // // 103


REVIEW Drum HAT

Drum HAT
Tap your fingers to the beat and turn a Raspberry Pi into a drum machine
with this clever HAT. Robert Jones channels his inner Fatboy Slim

T
he Drum HAT is a Setup is so simple that you claims the blurb. Were not
In brief... crafty piece of kit can get it up and running in a even sure who he is. The built-in
Turn a from Pimoroni. With matter of minutes it just samples are limited, but there
Raspberry Pi it, you can transform slots on top of the Raspberry are hundreds of thousands of
into a drum a Raspberry Pi into Pi. Pimoroni has an installation beats available online.
machine with
this cunning a drum machine, tapping out script on its GitHub page Behind the scenes, PyGame
piece of HAT beats on the touch-sensitive (https://github.com/pimoroni/ is used to connect the audio
hardware. The
Drum HAT is
surface pads. As this is a HAT drum-hat/blob/master/ samples to the touch pads.
an 8-pad drum- (Hardware Attached on Top) README.md). Open Terminal Inside the Python code is where
kit that fits on kit, setup is simple. All you and cut-and-past the curl the real fun is found. You set up
top of your
Raspberry Pi. It need to do is attach the Drum script and youre ready to go. the pads using Python event
comes packed HAT to the GPIO pins and load
with samples,
and you can
the software from Pimoronis
GitHub (https://github.com/
USE PYTHON TO ASSIGN AUDIO
quickly turn it
into a drum
machine. Or you
pimoroni/drum-hat). SAMPLES TO EACH OF THE EIGHT
can program it
using Python.
You use Python to assign
audio samples to each of the PADS, THEN WHEN YOU TAP A
eight pads. Then when you tap
the pad with your finger, the
PAD THE SAMPLE IS PLAYED
audio sample is played. There
are two sets of drum samples Alternatively you can use git to objects. These are an index for
available in the documentation, clone the software from GitHub each pad (from 1 to 8). You
each with eight samples (such (clone https://github.com/ create hits and releases
as clap.wav and ting.wav). pimoroni/drum-hat) and run (determining how the pad
Each pad area comes with the Python setup installer. Once responds to taps and presses).
a corresponding LED. These its working, you can quickly If youre really into music on
LEDs automatically light up scan over the demo scripts your Raspberry Pi, its possible
when you tap the drum pads, and figure out how it works. to use the Drum HAT alongside
or you can also take control of An 8-pad Raspberry Pi Pimoronis other musical
them manually in code and get drum-kit that lets your fingers offering, Piano HAT. To do this
them to do what you want. think theyre Stubblefield, youll need an extra piece of kit,
the HAT Hack3r, which enables
you to connect two pieces of
Features at a glance HAT hardware to a single
Raspberry Pi.
Serious musicians can also
configure the Drum HAT to
output MIDI commands via
a USB-to-MIDI adaptor. This
enables you to connect the
Drum HAT and Raspberry Pi kit
to a synth setup. Potentially,
HAT connection Touch pads LED lights therefore, you could use it in
The Drum HAT fits neatly Eight touch pads can be Each pad has an LED light a professional environment,
on top of your Raspberry Pi, individually programmed that flashes when you tap although were not sure how
turning it into a single box. to respond to finger taps to or can be programmed reliable it would be in a studio
make a novel controller. independently if you prefer. setting. The pads on the Drum

104 // // Winter 2016


Drum HAT REVIEW

The Drum HAT


will sit neatly
on top of your
Raspberry Pi.

HAT are not pressure-sensitive, Drum HAT doesnt interact figuring out the audio aspects
either, so its unlikely to impress directly with Sonic Pi (which is of the PyGame library. Despite
a professional drummer or DJ. a shame), it could form a good the hype, its not likely to hit the
However, at just 12, it is a fun part of a wider course in music mark for expert musicians, but
piece of kit for the Raspberry and coding. We can envision it it will be good fun for budding
Pi and does enable budding working along with MIDI musicians looking to learn to
drummers to have fun with training, Piano HAT and Sonic code, and useful in education.
sound and learn PyGame and Pi coding.
Python scripting. Its a great project for
We had fun playing around the Raspberry Pi on its own, Verdict
with the Drum HAT. While the although it is a little simple.
Drum HAT
projects wont keep you Thats part of the problem.
Developer: Pimoroni
occupied for long, it does have Other projects have us soldering Web: https://shop.pimoroni.com/
a lively bash and play quality. parts and assembling hardware. products/drum-hat
Music is a great way to get By comparison, the Drum HATs Price: 12
young students interested in entertainment value is relatively
hardware and coding in a world
that they understand. While
short-lived. But it is good for
working through Python and
Rating 8/10
Winter 2016 // // 105
REVIEW Explorer HAT Pro

Pimoroni
Explorer HAT Pro
Is this the easiest, most convenient way to use your Raspberry Pi for circuit
prototyping? Robert Jones tips his hat to a cleverly thought out HAT

P
rototyping circuits is slot the breadboard on or off programs and used to control
In brief one of the real joys as you need it. the various components.
A HAT of using a Raspberry Once youve got the Explorer Once you have both hardware
(Hardware Pi. Most of the time HAT Pro attached, you can start and software set up, youre ready
Attached on this activity involves using it (thanks to the EEPROM to party. The setup is ideal for
Top) board for
prototyping, the attaching components to the that automatically connects the working with 5V powered
Explorer HAT Raspberry Pi GPIO pins using a hardware to your Pi). To get the systems thanks to four buffered
provides four
of everything:
breadboard. The Explorer HAT most from it, however, youll also 5V tolerant inputs and four
buffered 5V Pro places a breadboard right want to use the software that powered 5V outputs. These
tolerant inputs, on top of your Pi and also adds a Pimoroni has developed. Theres enable you to interface with
powered 5V
outputs, whole bunch of input and output an extensive Python library, systems safely, much the same
capacitive touch options that enable you to create
pads, capacitive
crocodile clip
prototype circuits right on top
of your Pi. Its a bit like having
ITS LIKE HAVING A BREADBOARD
pads, LEDs and
analogue inputs.
It also has two
a breadboard and advanced AND AN ADVANCED BREAKOUT
H-bridge motor
drivers and a
breakout cable all in one place
(with a few extra goodies thrown CABLE ALL IN ONE PLACE, RIGHT
convenient
mini breadboard
in for good measure).
Since this is HAT hardware,
ON TOP OF YOUR RASPBERRY PI
on top.
setup is relatively easy. We
slotted the Explorer HAT Pro into which you can learn all about as a breakout cable. There are
the GPIO pins. You can also use on the Pimoroni GitHub page also two H-bridge motor drivers.
the included mounts and screws (https://github.com/ These are used to work safely
to provide a firmer connection. pimoroni/explorer-hat). Setting with the high voltages used to
The mini breadboard is supplied up the software side of things drive motor systems and enable
as a separate piece of plastic is easy, although youll need you to drive the servo motors
with an adhesive strip on the to turn on i2c (which can be used in robotics projects.
rear. You can remove the accessed through the new There are a heap of extra
protective sheet and mount the Raspberry Pi Configuration tool). features on top of the ability to
mini breadboard on top of the The Explorer HAT Python library control voltages and motors.
HAT hardware, or you can just can be imported into your Four capacitive touch pads act
as buttons. These sit on the side
of the Explorer HAT Pro and
Features at a glance respond to finger presses. Its
easy enough to add buttons to
a breadboard, but having the
feature built-in makes it that
much simpler to prototype
circuits that respond to button
pushes. You can even use them
to turn the Explorer HAT Pro into
a drum machine (like a stripped-
Capacitive touch pads H-Bridge motor drivers Mini breadboard down version of the Drum HAT).
Four touch pads act as Two H-Bridge drivers enable A mini breadboard enables Alongside the capacitive
buttons. Responding to finger voltage to be applied across a you to prototype circuits and touch pads are four coloured
presses, they can be used to load in either direction. These attach components right on LED lights: yellow, blue, red and
interact with your programs. are used to control motors. top of your Raspberry Pi. green. These can be controlled

106 // // Winter 2016


Explorer HAT Pro REVIEW

The Explorer HAT


Pro in place gives you a
compact setup ready for
prototyping circuits.

independently for any purpose There are also four crocodile The Explorer HAT Pro is a
relating to your circuit. clip pads, of the kind found on great little prototyping add-on
The board also provides four the BBC Micro: BIT. While we for the Raspberry Pi. It extends
analogue inputs. The lack of find these clunkier than the the functionality of the GPIO
analogue input is limiting on the GPIO pins, they are an attractive pins in ways that are fun and
regular Raspberry Pi board, and alternative for many makers. functional. More importantly, its
the analogue inputs widen your Along with the other features, a neat, integrated little system
choice of devices. You can use they add an extra area for you that conveniently bundles
them with potentiometers, to experiment with. prototyping into the same
photocells, force sensitive Pimoroni sells an Explorer space as the Pi board itself.
resistors, temperature sensors HAT Pro Parts Kit (10)
and two-axis joysticks. alongside the HAT itself. This kit
On a more regular note, includes LEDs and resistors plus Verdict
there are four buffered, 5V more interesting components
Explorer HAT Pro
tolerant inputs. These act just like a Piezo transducer, rotary
Developer: Pimoroni
like the GPIO pins on your potentiometers and analogue Web: shop.pimoroni.com/products/
Raspberry Pi, and you can use temperature sensors. All of these explorer-hat
them to respond to voltage parts are readily available, but Price: 18
changes in your circuit (so as to having the kit will help you work
detect motion from a PIR sensor
or button pushes and so on).
through the features on offer
from the Explorer HAT Pro.
Rating 9/10
Winter 2016 // // 107
REVIEW Picon Zero

In brief
The Picon Zero
is a physical
computing
and robotics
platform
designed for the
Raspberry Pi
Zero, but it will
work with other
Pi models. It
has dedicated
connections for
sensors, motors
and servos along
with external
power options
for high-current
projects. It can
control Neopixel
LEDs and works
with analogue
inputs. All
components are
controlled via a
simple Python
interface using
a series of
modules and
functions.

A SIMPLE, ROBUST AND


COMPACT PLATFORM FOR
MANY DIFFERENT PROJECT TYPES,
IT WILL SOON BE YOUR GO-TO BOARD

108 // // Winter 2016


Picon Zero REVIEW

Picon Zero
Les Pounder might just have found the
ultimate platform for his robot army

C
hoosing the right Edukit 3. This dual-H-bridge
components for a controller controls two 5V
robotics project can motors, via two screw terminals
involve a lot of trial or two male pins, at around 2A
and error, but with of current, enabling a powerful
the Picon Zero we might just see robot to be built. Power for your
one board to rule them all. motors can come from the
The Picon Zero has been Raspberry Pi 5V pins, but if this
designed to match the shape of proves too much for your power
the Raspberry Pi Zero, but will supply then you can swap the
also fit on top of any 40-pin power supply, via a jumper, to an
GPIO Pi model. It has a set of external USB battery pack via a
inputs and outputs broken out handy micro USB connector on
as a series of male and female the underside of the board, or
header pins. The bank of six you can wire a battery box to
outputs, labelled 0 to 5, have the VIN terminals on the right of
three pins for each device 5V the board. The board can also
power, Ground and Signal and control servos, small motors
can connect to servos, LEDs and with a high degree of accuracy
even WS2812 LEDs (commonly which are commonly used for
referred to as Neopixels). precise control projects such
Each of these outputs can be as pan and tilt camera setups.
used digitally, either on or off, or All of the functionality is
with Pulse Width Modulation controlled via a Python 2/3
(PWM), which, for example, can library and its really simple to
be used to control the brightness use, thanks to a series of
of an LED or control the timings modules and functions that
of a signal. The bank of inputs provide a human readable
follows the same physical interface for the components
standards as the outputs but and enable this board to be
can be used with digital inputs, dropped in as a replacement for
such as buttons and switches, multiple boards. Think of it as a
as well as analogue sensors and Swiss Army knife for projects.
specialist sensors such as the Picon Zero provides a simple,
DS18B20 temperature sensor. robust and compact platform
Along the top edge of the for many different project types.
board is a series of female Other boards provide a stable
connectors, the first bank of platform for robotics but this
Features at a glance which break out a few of the really does provide everything
spare GPIO pins from your Pi you need to get hacking with the
handy if you wish to connect any minimal amount of fuss. It will
other components. Just next to soon become your go-to board
this bank is a special row of four to get a project done.
pins, designed to accommodate
the HC-SR04 ultrasonic sensor,
commonly used to measure Verdict
distance via an ultrasonic pulse
External power Ultrasonic sensor pins Picon Zero
much like a parking sensor.
Powering motors can The HC-SR04 sensor uses Developer: 4tronix
These sensors often find their Web: www.4tronix.co.uk
get a little too much for 5V logic in its signals so
the Raspberry Pi, so its requires a voltage divider,
way into robotics projects. Price: 13.30
handy that an external
USB battery connector
which the Picon Zero has,
to safely connect to the 3V
The motor controller used on
the Picon Zero is a DRV8833, the Rating 10/10
is included. logic of the GPIO pins. same chip used for the Cam Jam

Winter 2016 // // 109


REVIEW CamJam EduKit 3

CamJam EduKit 3
Inspired by the latest Star Wars movie, Les Pounder tries to build his own
robot companion but cant figure out how to fit everything into a beachball

R
In brief
obotics can become
quite personal, as THE KIT INCLUDES EVERYTHING
A robotics kit
that offers an
Robot Wars often
proves. But the first
YOU NEED FOR A MOTORISED
introduction
to the robot
barrier to entry is PROJECT JUST ADD YOUR OWN
knowing what kit to purchase to
creation
process. The
kit comes with
get started. How much should CHASSIS FOR A UNIQUE ROBOT
all the parts
you pay? What components will
required to you need? For some budding
build a robot makers, the issue is a lack of in the box include resistors for can power motors that require
but leaves the
choice of knowledge of skills such as the HC-SR04 sensor, wires, a up to 2A of current. The motor
chassis entirely soldering. Now the team behind breadboard for prototyping your control board fits over the first
up to the maker. the CamJam kits has released its robots circuits, and a ball castor. 26 pins of the 40-pin GPIO. This
Includes lessons
to encourage own robotics kit for under 20. What enables a robot project leaves a selection of pins free for
creativity. The box includes everything is a motor controller, and the use on newer Pi models but also
youd need to motorise a project. CamJam kit comes with its means the board is compatible
There are two large DC motors own controller with an H bridge with the older 26-pin GPIO
that come pre-soldered ready for a circuit that can change its Raspberry Pi, enabling older
use with a Pi. These fit directly polarity, enabling a motor to Pis to be reused for robotics
into the large wheels and provide change direction. The DRV8833 projects an ideal reuse of
for a decently paced robot. chip that powers the controller is them. The motor control board
Theres also a battery box to fully capable of controlling both also provides direct access to
power the motors, and a couple of our motors. This includes full a selection of GPIO pins to
of sensors, notably an HC-SR04 speed control thanks to PWM connect sensors and outputs,
ultrasonic sensor, which uses (Pulse Width Modulation). The should the user wish to do that.
ultrasound to detect objects in motor control board can work One key part of the CamJam
its path, giving our robot a basic with input power up to 10V and kits is their supporting tutorials
ability to see. The other sensor
is a line follower, which enables
our robot to follow a bold line
drawn on a surface. Other items

Features at a glance

Motor Controller Resources


The board was designed The kit comes with a
by 4tronix just for this kit series of lessons that We built this runaround
and provides easy access support the user through for our cat. Its nowhere
to spare GPIO pins. building their own robot. near as grumpy any more.

110 // // Winter 2016


CamJam EduKit 3 REVIEW

The CamJam
EduKit 3 comes
with everything
you need to
get started in
robotics. It has
been well thought
out and priced
accordingly.

and this kit offers the same level the EduKit is still good value. Computing class and go on to
of quality. They come as a series Its not just about what is in the build the chassis in Resistive
of 10 projects that gradually box, but rather the supporting Technologies, which has
introduce the components and documentation that raises this replaced shop or DT class, so
process of building a robot using kit above others. The lessons this kit can provide a true cross-
the kit. At present the tutorials that are built around the kit are curricular learning experience.
are written using Python 3 and a perfect fit for learning at a Its a powerful and supportive
the RPi.GPIO library, which are steady pace at home, and can platform for experimentation
easy enough to use but require also be used in the classroom for and offers a gentle entry for
a learning investment for those educators wishing to introduce those new to robotics.
new to Python. Work is currently robotics into the curriculum.
under way to port these tutorials The beauty of this kit is in
over to the new GPIO Zero the customisation options. No Verdict
library, which offers an even chassis is provided, which helps
CamJam Edukit 3 Robotics
easier method of working with keep the cost low but also
Developer: CamJam / The Pi Hut
the GPIO. enables you to experiment using Web: http://bit.ly/CamJam-EduKit
The CamJam kits are always Lego, model kits or recycled old Price: 17
good value, and although the
CamJam Robotics kit is more
toys to build a unique robot. In
schools for example children Rating 9/10
expensive than its predecessors, could code the robot in

Winter 2016 // // 111


REVIEW Picade

Picade by
Pimoroni
Warren Brown plugs his Pi into a
A fine addition to any desk,
maker bench or coffee table

retro-themed arcade gaming cabinet. (pending spouse approval).

T
In brief... he Picade offers flat-head screwdriver and Even though the Picade is
those with fond some elbow grease amazingly styled like a cabinet and great
The Picade kit memories of the enough, theres no need to for playing arcade ROMs,
from Pimoroni 80s arcade scene break out the soldering kit. This Retropie the go-to OS for retro
offers the
chance to a chance to relive being the case, the project is emulation can emulate a host
experience those misspent days of youth. very family friendly, and the of classic consoles such as the
retro gaming
emulation at its
Starting it as Kickstarter project, video instructions mean there NES, Mega Drive or SNES. Even
most authentic. the team at Pimoroni envisioned shouldnt be any of those classic computer games for the
Its a great the Picade as an affordable all- awkward IKEA half-built back- likes of the Atari ST, Amiga and
option for
those who in-one solution, one that would to-front fails. Admit it, weve all DOS can be played. Importantly,
prefer tinkering enable Pi users to get up and been there. controls can be mapped via
rather than gaming with a minimum of fuss. The cabinet sports a slick Retropie, and more specifically
undertaking
a full-sized The kit includes a case, LCD black powder coated finish that customised for individual titles.
cab build. screen, arcade PCB, speakers, when coupled with the laser But what happens when its
buttons and control stick. It all cut perspex bestows upon the game over and you need your Pi
comes in a surprisingly compact project a level of polish few back? Luckily the Picade has a
box, with the fiddly stuff
compartmentalised in easy-to-
reference tool boxes. Although
RETROPIE CAN EMULATE A HOST
any model Raspberry Pi can be OF CONSOLES; CONTROLS CAN BE
used, wed recommend going
with the latest model, the Pi 3 MAPPED AND CUSTOMISED
model B, for best performance,
and its worth pointing out that custom builds can match. handy back door and the
its not included in the box. Once everythings assembled, Raspberry Pi can be easily
Build time will take just a few the micro-switched controls feel retrieved. All-in-all the kit
hours, and youll require only a responsive, with the joystick provides a great nostalgic fix
offering satisfying clicks of for those who enjoy gamings
arcade authenticity. Sound wise golden era.
Features at a glance the speakers bring all those The Picade really is an all-in-
iconic in-game effects to life, one solution at an affordable
but quality wasnt brilliant. A price, and an excellent way to
substantial hum could be heard experience those classic arcade
when ramping the volume up gems of your youth.
high, but at this price point you
cant expect top audio quality.
The eight-inch LCD screen Verdict
may sound a tad small but it
Colour coded Plug & play didnt feel so during gaming
Picade by Pimoroni
Theres a fair bit of wiring The Pi talks to everything Developer: Pimoroni
involved, but everything is sessions. A separate 12-inch Web: pimoroni.com
via a custom PCB, making
colour coded and hooked connecting components a
screen is available but requires Price: 180
together via ready fitted
crimp connectors.
doddle. The Pi supplies all
the power; making this a
the BYO Screen Arcade Kit as
opposed to the all-in-one kit Rating 8/10
one cable cab. Very slick. featured here.

112 // // Winter 2016


 
Future Publishing, Quay House,
The Ambury, Bath, BA1 1UA, UK
Tel +44 (0)1225 442244
Email piuser@futurenet.com

 
Editor-in-Chief Graham Barlow
graham.barlow@futurenet.com
Production editor Alex Summersby
Art editors Sethnam Singh, Jamie Schildhauer,
Fraser McDermott
Editorial contributors Jonni Bidwell, Les Pounder,
Mayank Sharma, Robert Jones, Nate Drake, Nick
Peers, Ali Jennings, Ben Everard

 
Commercial sales director Clare Dove
clare.dove@futurenet.com
Senior advertising manager Lara Jaggon
lara.jaggon@futurenet.com
Advertising manager Michael Pyatt
michael.pyatt@futurenet.com
Director of agency sales Matt Downs
matt.downs@futurenet.com
Ad director Technology John Burke
john.burke@futurenet.com
Head of strategic partnerships Clare Jonik
clare.jonik@futurenet.com

  
Marketing director Sascha Kimmel
sascha.kimmel@futurenet.com

     



Production controller Nola Cokely
Head of production UK & US Mark Constance
Distributed by Seymour Distribution Ltd, 2 East
Poultry Avenue, London EC1A 9PT Tel 020 7429 4000
Overseas distribution by Seymour International

 

*#.1,"-+" %(
Senior Licensing & Syndication Manager Matt Ellis
matt.ellis@futurenet.com Tel + 44 (0)1225 442244

  
Trade marketing manager Juliette Winyard
Tel 07551 150 984

We take a look at the best open source programs      


Managing director, Magazines Joe McEvoy

you can get for your Pi, and why you need them.
Editorial director Paul Newman
Group art director Graham Dalzell

Raspberry Pi is a trademark of the Raspberry Pi Foundation.


See www.raspberrypi.org.
LINUX is a trademark of Linus Torvalds. GNU/Linux is abbreviated to Linux

,*&" .-
throughout for brevity. All other trademarks are the property of their respective
owners. Where applicable code printed in this magazine is licensed under the GNU
GPL v2 or later. See www.gnu.org/copyleft/gpl.html.
Entire contents copyright 2016 Future Publishing Ltd or published under
licence. No part of this publication may be reproduced without written permission

Do more with the SenseHAT, build a home robot,


from the publisher. We assume all letters sent by email, fax or post are for
publication unless otherwise stated, and reserve the right to edit contributions. All
contributions to Pi User are submitted and accepted on the basis of non-exclusive

create a security camera for your ofce and more!


worldwide licence to publish or license others to do so unless otherwise agreed in
advance in writing. Pi User recognises all copyrights in this issue. Where possible,
we have acknowledged the copyright holder. Contact us if we havent credited your
copyright and we will always correct any oversight. We cannot be held responsible for
mistakes or misprints.
Disclaimer All tips in this magazine are used at your own risk. We accept no liability

 *!%)$
for any loss of data or damage to your computer, peripherals or software through
the use of any tips or advice.
Printed in the UK by William Gibbons on behalf of Future.

We continue our series of tutorials on Scratch,


Python and show you even more Minecraft hacks.

"0%"1- 101." &/ * 3.!3&**&*$ &*0".*0&+*( )"!&


$.+1,*!("!&*$!&$&0(1/&*"//"." %)+."
0%*  )&((&+* &*0".*0&+*( +*/1)"./  )+*0%
*! ."0" 3+.(! (// +*0"*0 *! !2".0&/&*$

More of the latest and greatest gadgets and add-ons /+(10&+*/#+.,//&+*0" +*/1)"./+*(&*"+*0("0
/).0,%+*"*!&*,.&*0

for your Pi. Well turn your Pi into something special! 101.",( &/,1(& 
+),*5-1+0"!
+*0%"+*!+*
   &((%5*$%+.*"
Non-executive chairman "0".(("*


   "**5!'&*.*!
0+ '4 %*$" Managing director, Magazines +" 2+5
/5)+(
www.futureplc.com "(  
 

We are committed to only using magazine paper which is

**'*/.#*,%-",%--/"
derived from well-managed, certified forestry and chlorine-
free manufacture. Future Publishing and its paper suppliers
have been independently certified in accordance with the rules
of the FSC (Forest Stewardship Council).

*)-(",%!2",/,2
*Contents of future issues subject to change
LIFE OF Pi

The Astro Pi
Celebrating the big moments when the
Raspberry Pi changed the world

I
ts pretty mind-blowing to know that the from a single block of aluminium by a company
Raspberry Pi has been into space. Its even based in Derby called Pentaxia.
more amazing when you consider that The competition ran from January to July 2015
there were two of them up there on the and the seven winners all had their experiments
International Space Station (ISS), running launched into space. Between February and April
programs written by UK school children. 2016 these experiments were run on the ISS under
Back in 2015 the Raspberry Pi foundation, in the supervision of Tim himself. The experiments
conjunction with the UK Space Agency, ESA and did all sorts of cool things, using the sensors of a
the UK Space Trade Association, ran a competition SenseHAT attached to the Pi. Among other things,
for school students to design science experiments they took pictures of the astronauts using the
that would run on a specially-cased Raspberry Pi humidity sensor to detect them, they logged a
called the Astro Pi, which would be taken to the variety of sensor measurements of the ISS
ISS by British interior to be
astronaut IT TURNS OUT THAT CIRCUIT used in a copy
Tim Peake. of Minecraft
To become BOARDS WITH SPIKY EDGES back on earth
compatible with
space travel the ARENT EXACTLY IDEAL IN A ZERO as a data
visualisation
Astro Pi needed
to be housed in a
GRAVITY ENVIRONMENT tool, and they
displayed the
specially designed flag of
case. You see, it turns out that circuit boards with whichever country the ISS was currently orbiting
spiky edges arent exactly ideal in a zero gravity above on the LED. You can check out the results of
environment where theres no kind of atmosphere the experiments at the Astro Pi website https://
on the outside. Theres also the question of heat astro-pi.org/competition/science-results/
dissipation. In space the processes of convection Most importantly, of course, the Astro Pis
dont happen, and with no dissipation, the warm worked flawlessly. The experiments proved that a
air just stays around the CPU and bakes it, so the Raspberry Pi can run in space, and in the process
case needed to be really effective for thermal a number of UK school children had the pleasure
dissipation. (Theres actually a minimal level of of knowing that their projects ran on the ISS. How
airflow on the ISS, which makes this possible.) cool is that? Maybe one day theyll be taking an
Theres also a rule that any surface the crew of Astro Pi up to the International Space Station
the ISS touch must not exceed a temperature of themselves, because with the Raspberry Pi it
45 degrees. The resultant flight case was made seems that anything is possible.

114 // // Winter 2016


Get the UKs best-selling
Linux magazine

OUT
NOW!

DELIVERED DIRECT TO YOUR DOOR


Order online at www.myfavouritemagazines.co.uk
or find us in your nearest supermarket, newsagent or bookstore!
URCE FOR R
SO

AS
YOUR NEW

PBE Y PI
RR
HE PI
JOIN T
UTION
REVOL

Discover
the world of
Raspberry Pi
The latest Pi projects,
news and reviews
9001

Perfect for owners of all models


of the amazing Raspberry Pi
and the fantastic Pi Zero
116
PAGES OF Pi
GOODNESS
INSIDE!
LEARN HOW TO...
P28 P69 P86

Get to grips with the Make your own Pi Program in Scratch,


new Pixels Desktop Zero-powered robot Python and Minecraft
9000

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