MagPi93 PDF
MagPi93 PDF
CC/STORE
QuickStart
K
T O
R
Guide Inside!
HOW
WO Reviewed: ZX
Spectrum Next
E
Accelerated
O M
M
F R Learn Java &
H
electronics
Explore the
Internet of
Things
R R Y P I
R A S P B E
W I T H nline
e
Free offic
Set up software
t
Work o eam video cha
t
with your
WELCOME
to The MagPi 93
S
o it turns out a lot of people are now working at home with
Raspberry Pi. Ever since Raspberry Pi 4 arrived, our favourite
Lucy
EDITOR
computer has become quite the reliable desktop workhorse. Hattersley
Gareth takes us through How to Work from Home with Raspberry Pi
Lucy is editor of The
(page 28). It’s a great guide to some of the software and services that MagPi magazine. She
spends her mornings
you can use from home with Raspberry Pi. with Joe Wicks and
the evenings with
If you’re new to Raspberry Pi, we have a couple of absolutely fantastic Joe Exotic.
tutorials for you. Our QuickStart Guide (page 34) has been updated to magpi.cc
work with the new Raspberry Pi Imager, and Rosie has written up a
cracking tutorial that turns a Sense HAT into an LED Rainbow with a
heart and thank-you message. It’s perfect for putting in your window.
If you’re after something a little more advanced, then PJ shows us
how to Create Modules for your Magic Mirror (page 46) and Rob has a GET A
collection of amazing ideas in the At Home with the Internet of Things RASPBERRY
feature (page 70). Plus, there’s an ZERO W KIT
amazing range of projects, makes, and
the best community builds.
PAGE 26
I hope you enjoy this issue. It’s not
all work, and not all play. It’s a lovely
mixture of both.
magpi.cc 03
Contents
> Issue 93 > May 2020
Cover Feature
Project Showcases
10 Vineyard Kikushima
14 Hamster Feeder
16 DropStitch
18 Hot Spotter
20 DIY MIDI Door
22 RIoT Brick 28
18 22
DISCLAIMER: Some of the tools and techniques shown in The MagPi magazine are dangerous unless used with skill, experience, and appropriate personal protection equipment. While
we attempt to guide the reader, ultimately you are responsible for your own safety and understanding the limits of yourself and your equipment. Children should be supervised. Raspberry
Pi (Trading) Ltd does not accept responsibility for any injuries, damage to equipment, or costs incurred from projects, tutorials or suggestions in The MagPi magazine. Laws and regulations
covering many of the topics in The MagPi magazine are different between countries, and are always subject to change. You are responsible for understanding the requirements in your
jurisdiction and ensuring that you comply with them. Some manufacturers place limits on the use of their hardware which some projects or suggestions in The MagPi magazine may go
beyond. It is your responsibility to understand the manufacturer’s limits.
40 60
Tutorials
ZX Spectrum Next
Community
84 8 Bits and a Byte interview
86 This month in Raspberry Pi
8 Bits and a Byte interview 90 Events calendar
WIN
HQ CAMERAS
95
1 OF 5
Digital Making at Home
Non-technical introduction to coding embraced by families thirsty
for creative projects. By Rosie Hattersley
R
Digital
Making at aspberry Pi has had an enthusiastic
Home features
instructor-led tutorials
response to the Digital Making at Home
programme (magpi.cc/DMAH) which it
If they don’t have a
computer available, launched in early April.
learners can use Thousands of people have started engaging
a tablet
with the Digital Making at Home content.
They’ve also had kids sharing their projects
(magpi.cc/DMAHprojects).
Digital Making at Home is for kids who want
to get into making things with technology and
need a few pointers. If you or your friends are
looking for ideas of how to entertain youngsters
or simply want new project ideas, the Raspberry
Pi project portal (magpi.cc/projects) comes
highly recommended.
Like all Raspberry Pi projects, the tutorials
are both step-by-step and free. Videos explain
all about coding platforms such as Scratch and
Python, helping kids to quickly catch up.
making and coding skills themselves. All schools now teach e-safety,
so running through a checklist should be
they’ve learned to make second nature.
Race to build
Raspberry Pi ventilator
Raspberry Pi is being tested at the heart of ventilator equipment,
Eben Upton explains to Rosie Hattersley
O
Raspberry Pi is seeing rganisations and individuals around the Volume lead times on other industrial single-
incredible demand
globe are racing to build a ventilator with board computers are typically five to six months:
for its products
Raspberry Pi. too long to be of use during the anticipated surge
One example uses the $5 Raspberry Pi Zero in COVID-19 cases. However, Raspberry Pi builds
to run the user interface and direct an Arduino to stock rather than building to order, and so has
to open and close valves. This impressively boards on hand. “People have been ordering 100
low-cost ventilator is being trialled in hospitals to test, then asking for 10,000 the next week, and
in Colombia. It was put together based on every week after that,” reveals Eben.
details sketched out by robotics engineer Marco
Mascorro, and uses widely available parts from A reliable source
plumbing and car part suppliers. Supplies of the British-built computer are not
affected by Chinese setbacks to manufacturing.
Any desktop computer or device Easily create a gateway to a remote Create a virtual private internet for
using Windows, macOS or Linux network with remote.itPi your enterprise network
Vineyard
Kikushima
We’ve seen plenty of beer brewed with the help
of Raspberry Pi, but now it’s wine’s time to shine.
We paired Rob Zwetsloot with this full-bodied article
W
e’ve covered several plant and garden
automation projects in The MagPi
before, and even a robot farm or two.
However, we’ve not previously come across a
vineyard with some IoT/automation abilities
thanks to Raspberry Pi.
“We are now doing viniculture in Koshu city,
Yamanashi Prefecture, and we aim to open a
Kunio
MAKER
A Raspberry Pi monitors
several sensors that
Kunio can read at home
Quick FACTS
> The system is
called Hinno IoT
Raspberry Pi wine
The number-one
system is currently in
use and sends a data
update every hour
Hamster Feeder
A tiny Raspberry Pi Zero assisting a small rodent?
What’s not to love? David Crookes takes a look
C
hristopher Barnatt doesn’t own a hamster.
But that hasn’t stopped him working on an
automated feeding device to help anyone
who does. His project allows a portion of food to
be served at a suitable interval so that a hamster
wouldn’t gobble its whole supply at once. Chris
reckons it could be recreated in just a few hours.
“I’d made a video about controlling servo motors
Christopher
MAKER
In a real-life
situation, you’d keep
Raspberry Pi Zero,
servos, and wires
out of reach of an
inquisitive hamster
Here is how the servos are connected to the pins of Raspberry Pi Zero
“I happened to have some plasticard sheet and door should be opened. They also see if a door is
solvent adhesive, but it was very much a situation still shut by checking its pod1 or pod2 value, and
Quick FACTS
of working out what I could design and build in a setting this to 0 once a door is opened.” > A
Raspberry Pi
few hours, with the added complication of how Zero is used
to show the process in a video. I remember a very Feeding frenzy
intense and frantic morning!” Of course, improvements could be made. Servos, > T
here are
Chris says, could swing the doors open and closed. two SG90
It would just need a little “It would also need some chutes to direct the servo motors
nuts into a hamster cage with the pods and servos
refinement to be used to entirely separated from a live animal outside of > T
he Python
code can be
the cage,” he continues. There’s scope to regulate
feed a real hamster the number of nuts dispensed and to remove hard-
downloaded
DropStitch
The joy of creating something wonderful – whether in code or another medium – can turn
to despair without a means of rendering it. Rosie Hattersley applauds a new option
C
reative crafting is all the rage and can
be a fulfilling and mindful hobby that
combines easily with technology. A
workshop using one example, TurtleStitch, at last
summer’s Raspberry Pi-hosted Scratch Conference
in Cambridge was packed. It’s a popular visual
means of using Snap! (magpi.cc/snap) and a great
learning tool which will be made all the more
usable thanks to the creation of DropStitch.
Margaret Low
MAKER
16 magpi.cc DropStitch
PROJECT SHOWCASE
DropStitch magpi.cc 17
PROJECT SHOWCASE
Hot Spotter
An autonomous drone that can detect and report smouldering fires. Phil King seeks it out
W
hile commercial operations use fleets
of expensive drones to track the
spread of wildfires, it’s possible for
a previously extinguished fire to relight. It’s in
the detection of these smouldering patches where
a low-cost drone such as Jason McDonald’s Hot
Spotter could come in useful.
“I wanted to create something practical with the
Jason
MAKER
Connected to a Raspberry Pi
3A+, the thermal sensor on
the drone’s underside detects
the ground temperature
W
hen Floyd Steinberg received a
Raspberry Pi electronics kit from
his wife as a birthday gift, his first
project idea involved turning one of their home’s
internal doors into a MIDI controller. “I finally
had some time to read the manual and wanted
to make something humorous to show on my
YouTube channel,” he recalls. “The DIY kit had
Floyd
MAKER
Raspberry Pi reads
the voltage from the
potentiometer via an ADC and
turns it into MIDI note data for
a connected synthesizer
Quick FACTS
> The project
took Floyd one
afternoon to
complete
RIoT Brick
Long-distance running and a love of intrepid devices led one
creator to embark on a project demonstrating that ‘true geekery
and nature can co-exist’. Rosie Hattersley tries to keep up
M
embers of his local running club are no
Alan Peaty longer fazed when ultra-runner Alan
MAKER
Create a RIoT
The RIoT Brick consists of a Raspberry Pi Zero,
battery pack, transceiver and sensor modules,
plus related AWS scripts. Three Python scripts
manage incoming data and check for an active
internet connection.
SUBSCRIBE TODAY
FROM ONLY £5
Subscriber Benefits
FREE Delivery
Get it fast and for FREE
Exclusive Offers
Great gifts, offers, and discounts
Great Savings
Save up to 35% compared to stores
FREE Raspberry Pi
Zero W Starter Kit
WITH YOUR SUBSCRIPTION
Subscribe in print
for 12 months today
and you’ll receive:
Raspberry Pi Zero W
Raspberry Pi
Zero W case with
three covers
USB and HDMI
converter cables
Camera Module
connector
Offer subject to change or
withdrawal at any time
SUBSCRIBE
on app stores
magpi.cc 27
FEATURE
K
T O
R
W
O
HO
W
E
O M
M
F R
H WIT H R A S P B E R R Y P I
d yo urse
If you fin sing – from home llaborative
simply insert it into a USB port on Raspberry Pi. If
you’re using a Raspberry Pi Camera Module, you’ll
ciali co
simply so ith everything from onferencing
need to unpack it, then find the ‘CAMERA’ port
on the top of Raspberry Pi – it’s just between the
c
can help w oductivity to video second micro-HDMI port and the 3.5 mm AV port.
You’ll Need
insert one end of the camera’s ribbon cable into
the port so the shiny metal contacts are facing
> Raspberry Pi, the HDMI port. Hold the cable in place, and gently
keyboard, mous
monitor or TV e, and
push the tab back home again.
> Network conn If the Camera Module doesn’t have the ribbon
ection (preferab
ly wired) cable connected, repeat the process for the
> Raspberry Pi
Camera Module connector on its underside, making sure the
USB webcam or
contacts are facing downwards towards the
> USB headset,
or USB sound ca module. Finally, remove the blue plastic film from
analogue head rd with
set, or USB micro the camera lens.
phone
28 magpi.cc
FEATURE
Safety
05 Invite friends or join a chat first! and
You can invite friends to your video chat Seeing friends
by writing their email address in the Invite People family over video
y
box, or copying the link and sending it via another chat is a great wa
,
messaging service. They don’t need their own to stay in touch
but always be
Raspberry Pi to participate – you can use Google et
aware of intern
Hangouts from a laptop, desktop, smartphone, or ren,
safety. For child
Enable Camera Module access
02 Before you can use your Raspberry Pi
tablet. If someone has sent you a link to their video
chat, open the message on Raspberry Pi and simply
this me an s
asking a parent’s
e
Camera Module, you need to enable it in Raspbian. click the link to join automatically. permission befor
using an y vid eo
If you’re using a USB webcam, you can skip this You can click the microphone or video icons at and
chat services –
step. Otherwise, click on the raspberry menu the bottom of the window to temporarily disable se e an yth ing
if yo u
icon in Raspbian, choose Preferences, then click the microphone or camera; click the red handset that you don’t
on Raspberry Pi Configuration. When the tool icon to leave the call. You can click the three dots expect to see, or
loads, click on the Interfaces tab, then click on at the top-right to access more features, including that upsets you,
ur
the ‘Enabled’ radio button next to Camera. Click switching the chat to full-screen view and sharing be sure to tell yo
ian.
OK, and let Raspberry Pi reboot to load your new your screen – which will allow guests to see what parent or guard
settings. If you forget this step, Raspberry Pi won’t you’re doing on Raspberry Pi, including any
be able to communicate with the Camera Module. applications or documents you have open.
R K ON LIN E
WO TE AM
H YO UR
WIT Just beca
use you’r
e n
n
o t
’t
s
c
h
o
oulder-to
ll a
-sho
borate, th
u ld
anks
e
t
r
o
w
t
it
h e
h colleagu
s e
es
online too
ls
a
ean you c
doesn’t m
Slack
Designed for business, Slack is a text-based
instant messaging tool with support for file
transfer, rich text, images, video, and more. Slack
allows for easy collaboration in Teams, which are
then split into multiple channels or rooms – some
Google Docs for casual conversation, others for more focused
Google Docs is a suite of online productivity tools discussion. If your colleagues or friends already
linked to the Google Drive cloud storage platform, have a Slack team set up, ask them to send you an
all accessible directly from your browser. Open invite; if not, you can head to app.slack.com and
the browser and go to drive.google.com, then set one up yourself for free.
sign in with your Google account – or sign up
for a new account if you don’t already have
one – for 15GB of free storage plus access to the
word processor Google Docs, spreadsheet Google
Sheets, presentation tool Google Slides, and more.
Connect with colleagues and friends to share
files or entire folders, and collaborate within
documents with simultaneous multi-user editing,
comments, and change suggestions.
Discord
Built more for casual use, Discord offers live
chat functionality. While the dedicated Discord
app includes voice chat support, this is not yet
supported on Raspberry Pi – but you can still
use text chat by opening the browser, going to
discord.com, and choosing the ‘Open Discord in
your browser’ option. Choose a username, read
and agree to the terms of service, then enter an
email address and password to set up your own
free Discord server. Alternatively, if you know GitHub
someone on Discord already, ask them to send you For programmers, GitHub is a lifesaver. Based
an invitation to access their server. around the Git version control system, GitHub
lets teams work on a project regardless of distance
using repositories of source code and supporting
files. Each programmer can have a local copy of
the program files, work on them independently,
then submit the changes for inclusion in the
master copy – complete with the ability to
handle conflicting changes. Better still, GitHub
offers additional collaboration tools including
issue tracking. Open the browser and go to
github.com to sign up, or sign in if you have an
existing account, and follow the getting started
guide on the site.
Firefox Send
If you need to send a document, image, or any
other type of file to someone who isn’t on
Google Drive, you can use Firefox Send – even
Watch your tabs
If you find Rasp
if you’re not using the Firefox browser. All files berry Pi is runnin
how many tabs g slowly, check
you have open
transferred via Firefox Send are encrypted, and Keeping lots of in your browser.
tabs open in the
can be protected with an optional password, and great way to qu background is a
ickly switch betw
are automatically deleted after a set number of consumes memo een tasks, but
ry – and some sit
messaging tools, es, particularly
downloads or length of time. Simply open the consume proce
when they’re on ssing power ev
browser and go to send.firefox.com; you can send ly running in the en
background.
files up to 1GB without an account, or sign up for a
free Firefox account to increase the limit to 2.5GB.
OF T WARE
E OFFICE S
FRE Working a
lone ? T
t
h
e
is
v e
s
r
o
n
f t w a re will ge
eeding to
t you
leave y o
a
u
s
r
p
R
r
a
o d uctive as
spberry P
i
ithou
possible w
LibreOffice Calc
A spreadsheet application equivalent to
Microsoft Excel, LibreOffice Writer is a great
tool for everything from budgeting to complex
mathematical modelling. Point-and-click to
create new formulae or write them by hand, and
the whole spreadsheet will update automatically
LibreOffice Writer when things change. A variety of chart options
Equivalent in functionality to Microsoft Word, offer visualisation, and can be exported separately
LibreOffice Writer is a fully-featured rich-text from the spreadsheet as a whole.
editing program. You can write new documents LibreOffice Calc is found in the raspberry menu
and open existing ones in a variety of formats – under Office.
including Microsoft Word – and insert graphics,
spreadsheets, tables, and more. You can even
export your files in Portable Document Format
(PDF) for commercial printing, or choose from a
range of templates.
LibreOffice Writer is found in the raspberry
menu under Office.
Check your
Raspbian version
Raspbian is avail
Lite, Raspbian wi
able in three ve
rsions: Raspbia
n
LibreOffice Impress
th Desktop, and
Desktop and Re Raspbian with Presentations are easy to produce with LibreOffice
commended So
latter version inc ftware. Only the Impress, a tool equivalent to and compatible with
ludes additional
LibreOffice; if yo software like Microsoft PowerPoint. Templates offer an easy
ur version does
the Recommen n’t include it, us
ded Software too e way to add a splash of colour, or you can use the
menu under Pre l in the raspberr
ferences to instal y built-in tools to design your own slide aesthetics.
If you’re using the l it.
Raspberry Pi Im As you’d expect, a range of animations and other
to write a micro ager
SD card, be sure
Raspbian (othe to choose presentation features are included.
r) then Raspbia
recommended n Full to get all LibreOffice Impress is found in the raspberry
software includ the
ed. menu under Office.
LibreOffice Draw
Designed for technical drawings, flowcharts, and
the like, LibreOffice Draw includes tools for quickly
producing vector illustrations. Draw content
manually or choose from a range of predefined
shapes, icons, lines, and arrow types, then save or The GNU Image Manipulation Program
export the file directly – or copy it for pasting into Designed as an open-source alternative to
LibreOffice Writer or another application. Adobe Photoshop, the GNU Image Manipulation
LibreOffice Impress is found in the raspberry Program (GIMP) is a bitmap graphics editor. Load
menu under Office. images from a digital camera, a USB flash drive,
or downloaded from the internet to perform a
L ibreOffice Draw includes wide range of editing tasks, from simple cropping
and rotating to complex image enhancement
tools for quickly producing and distortion effects. Save the edited images in
GIMP’s internal format while you’re working,
vector illustrations then export them in a range of formats for sharing
or publication.
To install GIMP, click the raspberry menu icon,
choose Preferences, then Add/Remove Software. In
the search bar at the top-left, type ‘GIMP’ followed
by ENTER, then find ‘The GNU Image Manipulation
Program’ and click the checkbox to the left of it.
Finally, press OK and enter your password when
prompted. Once installed, GIMP will be available
from the raspberry menu under Graphics.
age
Use USB stor
LibreOffice Math
, but
If you work with mathematical or scientific icroSD card
yo ur w or k to the m ex te rnal
ve an
formulae, LibreOffice Math aims to make You can sa machines
sf er rin g it between nt . Si m pl y plug a
your life as simple as possible. Accessible for tran e convenie
vice is mor Raspberry
as a standalone application or within other storage de a U SB 3.0 port on
fla sh dr ive in to
pe ar as a device in
USB matically ap
LibreOffice packages, Math offers simple formula w ill au to en us . You can
Pi and it d application
m
gh
editing with elements including fractions,
the File Bro
w se r an driv , thou
es
even hard
integrals, and matrices. Finished formulae can us e U SB SSDs and vi ce s m ay need a
also storage de
er-hungry tly.
then be embedded in other documents. more pow b to work correc
ed U SB hu
LibreOffice Math is found in the raspberry menu po w er
under Office.
Raspberry Pi
QuickStart Guide
Setting up Raspberry Pi is pretty straightforward.
Just follow the advice of Rosie Hattersley
C
ongratulations on becoming a Raspberry What you need
Pi explorer. We’re sure you’ll enjoy All the bits and bobs you need
discovering a whole new world of computing to set up a Raspberry Pi computer
and the chance to handcraft your own games,
control your own robots and machines, and share
your experiences with other Raspberry Pi fanatics.
Getting started won’t take long: just corral all the A Raspberry Pi
bits and bobs on our checklist, plus perhaps a funky Whether you choose a Raspberry Pi 4, 3B+, 3B,
case. Useful extras include some headphones or Pi Zero, Zero W, or Zero WH (or an older model
speakers if you’re keen on using Raspberry Pi as a of Raspberry Pi), basic setup is the same. All
media centre or gaming machine. Raspberry Pi computers run from a microSD or SD
To get started, simply download the Raspberry card, use a USB power supply, and feature the same
Pi Imager tool, ready to install an operating system operating systems, programs, and games.
on your microSD (or SD) card. This guide will lead
you through each step. You’ll find the Raspbian
OS, including coding programs and office software,
all available to use. After that, the world of digital
making with Raspberry Pi awaits you.
Top Tip
Where to buy
You can buy
the parts you
need from the
Raspberry Pi store –
magpi.cc/retail-store
– or online from
official resellers.
Find links to online
sellers at
magpi.cc/products.
USB mouse
A tethered mouse that physically attaches to your
Raspberry Pi via a USB port is simplest and, unlike a
Bluetooth version, is less likely to get lost just when
you need it. Like the keyboard, we think it’s best to
perform the setup with a wired mouse. Raspberry Pi
sells an Official Mouse (magpi.cc/mouse).
8GB microSD card
You’ll need a microSD card with a capacity of
8GB or greater. Your Raspberry Pi uses it to store
games, programs, and photo files and boots from Power supply
your operating system, which runs from it. You’ll Raspberry Pi uses the same type
also need a microSD card reader to connect the of USB power connection as your
card to a PC, Mac, or Linux computer. average smartphone. So you can
recycle an old USB to micro USB cable
(or USB Type-C for Raspberry Pi 4)
and a smartphone power supply.
Mac or PC computer Raspberry Pi also sells official power
You’ll need a Windows or Ubuntu Linux PC, or supplies (magpi.cc/products), which
an Apple Mac computer, to run the Raspberry Pi provide a reliable source of power.
Imager tool in order to download and write an
operating system
onto a microSD
(or SD) card for your Display and HDMI cable
Raspberry Pi. A standard PC monitor is ideal, as
the screen will be large enough
to read comfortably. It needs
to have an HDMI connection,
as that’s what’s fitted on your
Raspberry Pi board. Raspberry
Pi 3B+ and 3A+ both use regular
HDMI cables. Raspberry Pi 4 can
power two HDMI displays, but
requires a less common micro-
USB keyboard HDMI to HDMI cable (or adapter);
Like any computer, you need a means to enter web Raspberry Pi Zero W needs a mini HDMI to
addresses, type commands, and otherwise control HDMI cable (or adapter).
Raspberry Pi. You can use a Bluetooth keyboard,
but the initial setup process is much easier with
a wired keyboard. Raspberry Pi sells an official
Keyboard and Hub (magpi.cc/keyboard). USB hub
Instead of standard-size USB
ports, Raspberry Pi Zero has
a micro USB port (and usually
comes with a micro USB to USB
adapter). To attach a keyboard
and mouse (and other items) to a
Raspberry Pi Zero W or 3A+, you
should get a four-port USB hub
(or use a keyboard with a hub
built in).
Raspberry Pi
Connect a USB wired mouse to one of the
other larger USB A sockets on Raspberry Pi. As
with the keyboard, it is possible to use a Bluetooth
wireless mouse, but setup is much easier with a
Raspberry Pi 4 / 3B+ / 3 has plenty of wired connection.
Set up
your Raspberry Pi Zero W to an
HDMI display
Raspberry
Pi Zero 02 Mouse and keyboard
You can either connect your mouse to a
USB socket on your keyboard (if one is available),
You'll need a couple of adapters to then connect the keyboard to the micro USB
socket (via the micro USB to USB A adapter).
set up a Raspberry Pi Zero / W / WH
Or, you can attach a USB hub to the micro USB
to USB A adapter.
Get it connected
01 If you’re setting up a smaller Raspberry
Pi Zero, you’ll need to use a micro USB to USB A
More connections
adapter cable to connect the keyboard to the
smaller connection on a Raspberry Pi Zero W. The
03 Now connect your full-sized HDMI cable
latter model has only a single micro USB port for to the mini-HDMI to HDMI adapter, and plug the
connecting devices, which makes connecting both adapter into the mini-HDMI port in the middle of
a mouse and keyboard slightly trickier than when your Raspberry Pi Zero W. Connect the other end of
using a larger Raspberry Pi. the HDMI cable to an HDMI monitor or television.
Set up
the software
Use the new Raspberry Pi Imager
tool to install Raspbian OS on
your microSD card
N
Write the OS to the microSD card
ow you’ve got all the pieces together, it’s
time to install an operating system on your
02 Attach your microSD card to your PC or
Raspberry Pi so you can start using it. Mac computer: you will need a microSD card USB
Raspbian is the official OS for Raspberry adapter unless you have a card reader built in. Note
Pi, and the easiest way to set up Raspbian that the card doesn’t need to be pre-formatted.
on your Raspberry Pi is to use the new Launch the Raspberry Pi Imager application.
Raspberry Pi Imager tool (magpi.cc/imager). Click the ‘Choose OS’ button to select which
This method supersedes installing your OS via operating system you would like to install. The top
NOOBS, although the latter is still available from option is standard Raspbian – if you’d prefer the
magpi.cc/downloadnoobs. Pre-installed NOOBS slimmed-down Raspbian Lite, or Raspbian Full
microSD cards are also on sale. See the ‘Using (with all the recommended software pre-installed),
NOOBS’ box for instructions. select ‘Raspbian (other)’. There are also options
to install LibreELEC (choose the version for your
Raspberry Pi model) and Ubuntu Core or Server.
Note: If you want to install a different OS, such
as Lakka, simply download the image from the
relevant website, then select the ‘Use Custom’
option in Raspberry Pi Imager.
With an OS selected, click the ‘Choose SD card’
button and select your microSD card (typically
there will be just the one option).
Finally, click the ‘Write’ button and wait while
the utility writes the selected OS to your card and
then verifies it. When complete, you may remove
the microSD card.
You’ll Need Download Raspberry Pi Imager
01 Download the Raspberry Pi Imager
> A Windows/Linux application from magpi.cc/imager. This utility
PC or Apple Mac
Assemble your Raspberry Pi
computer
is available for Windows, macOS, and Ubuntu
Linux computers, so choose the relevant version
03 Now it’s time to physically set up your
> A microSD card for your system. Raspberry Pi. Plug your PC monitor into the mains
(8GB or larger)
On macOS, double-click the downloaded DMG and attach its HDMI cable to the corresponding
> A microSD to file. You may need to change your Security & HDMI port on your Raspberry Pi. Plug in the power
USB adapter (or Privacy setting to allow apps downloaded from supply but don’t attach it to Raspberry Pi just yet.
a microSD to
‘App Store and identified developers’ to enable Use two USB ports to attach keyboard and mouse.
SD adapter and
SD card slot on it to run. You can then just drag the Raspberry Pi Finally, remove the microSD card from the SD
your computer) Imager icon into the Applications folder. card adapter and slot it into the underside of your
On a Windows PC, double-click the downloaded Raspberry Pi 4, 3B+, or 3. Raspberry Pi Zero W
> Raspberry Pi
Imager EXE file. When prompted, select the ‘Yes’ button owners will need to attach a USB hub to connect
magpi.cc/imager to enable it to run. Then click the ‘Install’ button to mouse, keyboard, and monitor; the microSD card
start the installation. slot is on the top of its circuit board.
Power up
04 Plug in your Raspberry Pi power supply and,
after a few seconds, the screen should come on.
The Raspbian OS (or alternative OS that you have
installed to the microSD card) will then boot up.
Using NOOBS
T
he new Raspberry Pi High Quality Camera
(HQ Camera for short) can capture higher-
resolution images than the standard
Phil King
MAKER
You’ll Need
> Raspberry Pi High Back focus adjustment ring
Quality Camera 02 The back focus adjustment ring should be
and lens
magpi.cc/hqcamera screwed in fully for the shortest possible back-
focal length. Tighten the back focus lock screw to
Adjust aperture
03 To adjust the aperture, hold the camera with
the lens facing away from you. Turn the middle
ring while holding the outer ring, furthest from
the camera, steady. Turn clockwise to close the
aperture and reduce image brightness. Turn anti-
clockwise to open the aperture. Once you are happy
with the light level, tighten the screw on the side
of the lens to lock the aperture ring.
6
3
Adjust focus 5
04 To adjust the focus, hold the camera with 1. T
he dust cap should be used when a lens
the lens facing away from you. Hold the outer two is not attached, as the camera sensor is
sensitive to dust
rings of the lens; this is easier if the aperture is 4. T
his enables you to mount the camera
2. S
upplied with the camera, the C-CS on a standard tripod
locked as described above. Turn the camera and adapter should be used when attaching
the inner ring anti-clockwise relative to the two a C-mount lens 5. T
he camera is supplied with a 20 cm ribbon
cable to connect it to Raspberry Pi’s
outer rings to focus on a nearby object. Turn them 3. T
he back focus adjustment ring can be used Camera port
clockwise to focus on a distant object. You may find to alter the focus when using a fixed-focus
lens, or to change the focal range of an 6. T
ighten this screw to lock the back focus
you need to adjust the aperture again after this. attached adjustable-focus lens adjustment ring in position
Top Tip
Longer cable
The HQ Camera Adjust aperture
is supplied with 04 To adjust the aperture, hold the camera
a standard 20 cm
ribbon cable for
with the lens facing away from you. Turn the
connection to inner ring, closest to the camera, while holding
Raspberry Pi. the camera steady. Turn clockwise to close the
However, longer aperture and reduce image brightness. Turn anti-
camera cables clockwise to open the aperture. Once you are
are available
Fit the lens to the camera
from the usual 02 Rotate the lens and C-CS adapter clockwise
happy with the light level, tighten the screw on
the side of the lens to lock the aperture ring
online retailers.
all the way into the back focus adjustment ring. into position.
Figure 1
Adjust focus
05 To adjust the focus, hold the camera with
the lens facing away from you. Turn the focus ring,
labelled ‘NEAR FAR’, anti-clockwise to focus
on a nearby object. Turn it clockwise to focus on a
distant object. You may find you need to adjust the
aperture again after this.
Connecting and
using the camera If using a Raspberry Pi Zero, its Camera port
is found on the edge of the board. However, as Top Tip
With your HQ Camera and mounted lens ready, it’s a smaller size than the regular one on other
it’s time to connect it to your Raspberry Pi and Raspberry Pi models, you’ll need a camera adapter Permanent
start capturing some images. cable to use it (magpi.cc/zerocamcable). preview
Connect ribbon cable to camera
01 On the bottom of the HQ Camera board,
To keep the
preview window
Enable the camera showing on
you’ll find a black plastic flap (Figure 1). Carefully
pull the sticking-out edges until the flap pulls
03 Connect the power supply back to Raspberry
screen, then take
a photo whenever
part-way out. Slide the ribbon cable, with the Pi and let it load Raspbian. Before you can use the ENTER key
silver edges downwards and the blue plastic facing the camera, you’ll need to tell Raspberry Pi it is pressed, use
upwards, under the flap you just pulled out, then has one connected: in the Raspbian menu, select this command:
push the flap gently back into place with a click; Preferences, then Raspberry Pi Configuration. raspistill
it doesn’t matter which end of the cable you use. When the tool has loaded, click the Interfaces tab, -t 0 -k -o
my_pics%02d.jpg.
If the cable is installed properly, it will be straight find the Camera entry in the list, and click on the
Press CTRL+C
and won’t come out if you give it a gentle tug; if round radio button to the left of ‘Enabled’ to switch to exit.
not, pull the flap out and try again. it on (Figure 2, overleaf). Click OK, and the tool will
prompt you to reboot your Raspberry Pi. Do so and
your camera will be ready to use.
Figure 3
CAMERA
GUIDE
Take pictures and shoot video with your
Raspberry Pi and official camera
A
s we’ve covered in the previous magic module: "clock",
mirror tutorials, there are hundreds of position: "top_left"
PJ modules out there to display custom }
MAKER
cp ~/MagicMirror/config/config.js
You’ll Need How to create a module
~/MagicMirror/config/config-backup.js
03 Each MagicMirror2 module is a JavaScript
> A magic Now have a look at the file: file and the code inside is called a class. The class
mirror running has several built-in methods (like functions) that
MagicMirror2
nano ~/MagicMirror/config/config.js we don’t see and the server calls them to get the
> J avaScript code information it needs to create the display. What
editor such as
You will see JSON-formatted text. Find the we need to do is replace (or ‘override’) one or more
Visual Studio Code
magpi.cc/ ‘modules’ section and remove everything so it looks of the methods to get the output we want. You’ll
visualstudio like this: find all modules in the ~/MagicMirror/modules
directory. The built-in displays such as the clock
> 3D-printed case
(optional) modules: [ are, unsurprisingly, in ‘default’. Create a folder
{ alongside default called MMM-Hello-World
When developing
modules, keep the
clock enabled so you
can quickly see if
something has frozen
Hello World
04 As you’ve probably guessed, we’re
going to create a simple ‘Hello World’ module.
Enter the code in listing1.js (or download it from
magpi.cc/mm4git) using your code editor. Use We’re going to display the
latest small robot, but we’ll
nano if you wish, but a proper editor will do all
have to invert the image first
kinds of highlighting and syntax checking which
makes it much easier to fix typos and bugs. The code
overrides the ‘getDom’ method, which is called
when the server wants us to return some content.
Here we create a HTML element, ‘div’, and add the
text to it that is defined in the defaults section. We
then return that HTML object to the server to place position: "top_left"
on the display. },
{
syntax checking
Save the file and restart MagicMirror2 as in the
Top Tip
earlier step. You should now see ‘Hello World!’ What’s
Try it! this ‘Dom’
05 To actually get our message to display on
displayed at the bottom of the mirror. You’ve
created your first module! You can also specify a business?
the screen, we have to ask MagicMirror2 to load the custom message in config.js like this:
The ‘Dom’ in
module. Let’s go back to the config file:
‘getDom’ and
{
‘updateDom’
nano ~/MagicMirror/config/config.js module: "MMM-Hello-World", refers to the
position: "lower_third", Document Object
Find the ‘modules’ block, as we did previously, and config: { Model (DOM),
modify if so it looks like this: text: "MagPi rocks!" which is how
} the browser
structures the
modules: [ }
webpage you
{ are viewing.
module: "clock", This overrides anything in ‘defaults’ in your module.
step in your favourite editor and enter the code in Restart MagicMirror2 as before. Within a few
listing2.js. This is JavaScript, so be careful with seconds, a delightful robot will grace your screen.
the curly brackets and semicolons. Again, we’re The code has accessed the API, located the URL to
overriding ‘getDom’ but this time we’re using the the image, and created a block of HTML that calls
built-in ‘fetch’ function to get information from the image in at a reasonable size (feel free to tweak
the Smol Robots API. If you want to see what we’re this). The HTML object generated is then returned
getting, enter the following URL in a web browser: to the server, which places it in the desired position.
listing2.js
invert all the colours. Save the file and reload your > Language: JavaScript
magic mirror. Ah, that’s much nicer: our robot now
seems to float on the screen. 001. Module.register("MMM-Smol-Robots", {
002. // Default module config.
003. defaults: {
004. feed: "https://mrpjevans.com/smol/api/latest/1",
More robots! 005. updateInterval: 3600 * 24,
10 Our robot is displaying, but what about
006. fadeSpeed: 4000
007. },
when a new robot is unleashed from the Smol
008.
Robots laboratory? Typically this happens a few 009. // Override dom generator.
times a week, so a daily check should suffice. We 010. getDom: async function() {
can do this by setting up a timer function to refresh 011.
the module. Right after the ‘defaults’ block, add 012. Log.info("Refreshing Smol Robot");
listing3.js. This override is called once when the 013.
server is started. We use it to set up a timer that will 014. // Get the latest Smol Robot
call updateDom (which in turn triggers getDom) 015. const response = await fetch(this.config.feed);
once a day. You can change this value in the defaults 016. const bots = await response.json();
017. const bot = bots[0];
section or specifying a value in config.js. Now your
018.
robots will appear like magic.
019. // Wrap the image URL in an IMG element
020. const img = document.createElement("img");
021. img.src = bot.image.url;
022. img.style = "width: 300px;";
Publishing modules
11 If you’ve got an idea for a module, and
023.
024. // Add title and description
now have enough knowledge to get started, 025. const title = document.createElement("div");
great! When it’s done, why not share it with the 026. title.innerHTML = bot.name.full;
community? The main page for third-party modules 027. const description = document.createElement("small");
028. description.innerHTML = bot.description;
is magpi.cc/mirrormodules. We recommend
029.
hosting your module on a service like GitHub. Then
030. // Create a wrapper element and return
you can edit this webpage and add your module 031. const wrapper = document.createElement("div");
to the list. Make sure to read (and follow) the 032. wrapper.appendChild(img);
guidelines and be prepared to offer support. 033. wrapper.appendChild(title);
034. wrapper.appendChild(description);
035. return wrapper;
036. }
Experiment 037. });
12 This has been only a brief introduction
to the world of MagicMirror2 modules. There is a
wealth of information in the official documentation
(magpi.cc/mm2doc), where you can learn about
the other tricks possible. As well as communicating
listing3.js
with the outside world, as we have done here, you
can communicate with other modules. The weather
> Language: JavaScript
module can tell you the temperature, or alert you
001. start: function() {
when there’s new data. The calendar broadcasts an
002. Log.info("Starting module: " + this.name);
alert when it’s time for an appointment and you can
003.
react to that. We hope you get planning and would
004. var self = this;
love to see the results.
005.
006. // Schedule update timer.
007. setInterval(function() {
008. self.updateDom(self.config.fadeSpeed);
Many thanks to Thomas Heasman-Hunt for letting us borrow their
009. }, this.config.updateInterval);
robots. Check out their latest book at magpi.cc/smallrobotsbook.
010. },
Also, thank-you to Tom Panton for provision of the API.
D
id you know that Java is still the most Java command to check the installed version. Open
popular programming language in the a Terminal and type:
world, according to the Tiobe Index
(magpi.cc/tiobe)? And Raspberry Pi with java -version
Raspbian OS is the ideal tool to get started with
Frank Delporte
MAKER
Java, whether the Java language is new to you or And you will see:
you want to use your existing Java skills and learn
Java developer
at work, sharing to work with hardware components. openjdk version "11.0.6" 2020-01-14
knowledge as In this tutorial, we will guide you through OpenJDK Runtime Environment (build
a blogger and the different steps to get started with Java and 11.0.6+10-post-Raspbian-1deb10u1)
CoderDojo
lead coach. electronics with Raspberry Pi. OpenJDK Server VM (build 11.0.6+10-post-
Programming Raspbian-1deb10u1, mixed mode)
since he was
eleven and got a
Because we are starting the Java executable with
Commodore 64.
Prepare the Raspberry Pi
webtechie.be 01 A simple basis to start with: we’re using
the option -version, the output shows the version
and additional information about the installed
Raspberry Pi with the most recent Raspbian Full OS, version of Java.
screen, and keyboard. An internet connection will
be needed to get additional tools on the board later.
When you start from a new and empty microSD
Our very first Java application
card, use the new Raspberry Pi Imager tool from
magpi.cc/imager. Make sure you select Raspbian
03 From Java version 11, you can run simple
(other) > Raspbian Full as the OS. Java code without the need to compile it, in the
When done, put the microSD card in your same way as you can run a Python or Bash script.
Raspberry Pi, start it up, and go through all the Traditionally, we test this with a ‘Hello World’
steps to configure your language, keyboard layout, application. Let’s move to the home directory and
and wireless LAN connection. create a new file by editing with the nano text editor.
cd /home/pi
You’ll Need nano HelloWorld.java
Test the Java installation
> Raspberry Pi 2, 3,
3A+, 3B+, or 4
02 In the release notes of Raspbian In this file we add code from the HelloWorld.java
(magpi.cc/releasenotes) you can see that since listing, including the main method. This is the
> Raspbian Full
version 2019-06-20, Java OpenJDK 11 is included: minimal required code for any Java application.
version
Save this code by exiting from nano with CTRL+X
> LED 2019-06-20: and pressing Y. Press ENTER to confirm the file
> 2 × 330 Ω resistor, * Based on Debian Buster name. To execute the code, we call Java with the
push-button, * Oracle Java 7 and 8 replaced with OpenJDK 11 name of the file we just created as an argument:
breadboard
and wires
The JDK (Java Development Kit) is a software cd /home/pi
> Optional T-Cobbler package containing everything to develop, java HelloWorld.java
connection
compile, and run Java applications with extra
between Raspberry
Pi and breadboard developer tools. And because this JDK is already The program will run and output the following text
part of Raspbian, we can immediately run our first on the command line:
Hello World
DOWNLOAD
And there is our first working Java 11 code on
HelloWorld.java THE FULL CODE:
Raspberry Pi.
> Language: Java magpi.cc/github
cd /home/pi
nano HelloLoop.java Y ou can now run simple Java code
Now enter the code from the HelloLoop.java without the need to compile it
listing. This example should not contain
any surprises if you’ve already used another
programming language. Some variables are defined
and when startup arguments are provided, the HelloLoop.java
application will behave differently.
Save the file and start it without and with one or > Language: Java
two number arguments…
001. public class HelloLoop {
java HelloLoop.java 002. public static void main (String[] args) {
003. String message = "Hello loop";
004. int loopCounter = 1;
The code will return:
005. int multiplier = 1;
006. int numberOfLoops = 3;
Hello loop: 1, calculated: 1 007.
Hello loop: 2, calculated: 2 008. if (args.length >= 1) {
Hello loop: 3, calculated: 3 009. multiplier = Integer.valueOf(args[0]);
010. }
011.
Now try:
012. if (args.length >= 2) {
013. numberOfLoops = Integer.valueOf(args[1]);
java HelloLoop.java 7 014. }
015.
And then: 016. while (loopCounter <= numberOfLoops) {
017. int calculated = multiplier * loopCounter;
java HelloLoop.java 2 4 018. System.out.println(message + ": " + loopCounter +
", calculated: " + calculated);
019. loopCounter++;
…to get different output. Now is the perfect time 020. }
to do some experimenting. Can you pass a third 021. }
string argument to be used instead of ‘Hello loop’? 022. }
Or change the output to two separate lines?
Connect hardware
Top Tip 05 Let’s add hardware to use the full power of
also read the button state from BCM 24 and output
a text if it is pressed. All this is done in a while loop
Raspberry Pi. Tip: check pinout.xyz for more info with a sleep. As Java requires us to handle possible
Use pinout about the GPIO pin numbers and a clear overview. exceptions, there is some extra try/catch code.
We start with an LED and 330 Ω resistor We use the Java runtime executor to run the
Open a command- connected to the physical pin 15 (= BCM 22). We will exact same commands we used before in the
line Terminal and
also use a push-button and 330 Ω resistor connected Terminal. This functionality is provided in a
enter pinout to
view a display of
between 3.3 V and physical pin 18 (= BCM 24). separate method called execute, which returns the
the GPIO pins. You To check if we’ve connected the LED in the result of the command. This way, we can check
can also open correct direction, we can temporary change the the state of the button.
the pinout.xyz cable connected to pin 15 to a 3.3 V pin. If the LED Running this code can be done in the same way,
website from a doesn’t turn on, we need to swap it. without compiling:
Terminal with
pinout --xyz.
java HelloGpio.java
Take a look
import java.io.IOException; Visual Studio Code will be added to Raspbian’s
at Raspberry
Pi’s GPIO import java.util.Scanner; Programming submenu, and its built-in terminal
documentation allows you to start your program from there.
if you need a The lines which start with ‘//’ are comments and When you open a Java file for the first time
refresher on not used by Java. They are added here to explain the in VSC, it will immediately ask you to install
how the GPIO code. In the main method, we initialise BCM 22 to the ‘Java Extension Pack’. This is an extension
pins work:
be an out-pin and toggle it between ‘on’ and ‘off’, from Microsoft which combines multiple other
magpi.cc/gpio
with an interval of one second. At each interval, we extensions to make it easy to write Java in Visual
Rotary encoders:
Part 02
Polar Etch-A-Sketch
Use rotary encoders to create a special Etch-A-Sketch device
L Figure 2
ast month, we explored how to read a
rotary encoder with Raspberry Pi and
created a Simon Safe Crack game with it.
Now, let’s see how to use two encoders to make a
unique Etch-A-Sketch, and explore the world of
Mike
MAKER
The grid
05 Our grid was devised mainly to make things
easier for the calculations, and fit in with what
the arctan2 function returns. This is a function
required when converting between Cartesian and
polar co-ordinates. However, like all computer
trigonometry functions, it works in radians and
returns an angle between π and -π radians. We
wanted to use degrees between 0 and 360, so
we ended up with the grid shown in Figure 5
(overleaf). This is a little unconventional because
DOWNLOAD
THE FULL CODE:
magpi.cc/pibakery
Figure 7
R
epeated drawing of a petal function at different angles, the
centre being a smaller version of the outside
R = θ.sin(θ) r*th*maths.sin(th)
Things to try
Figure 8 The petal
function from N=2
11 Here are some functions in mathematical R = 1 + 4cos(5θ)
r + r*4.maths.cos
(5*(th + cTh))
to N=9 format, and how you should enter them.
SAVEUP
TO
35%
on the cover price
ISSUE #30
OUT NOW
hsmag.cc
TUTORIAL
Y
Why use a Sense HAT?
ou’ve probably noticed splashes of colour
appearing all over the place, particularly
01 The Sense HAT sits on top of your Raspberry
Rosie in people’s windows as they share Pi and adds the ability to sense and report details
MAKER
Hattersley joyful rainbow drawings and artwork. You can about the world around it. It can measure noise,
join in with this trend using a Raspberry Pi to temperature, humidity, and pressure, for example.
Rosie has been create your own amazing electronic display. All The Sense HAT can show readings on an 8×8 LED
writing about how
you need is a Sense HAT and just a few lines of matrix, but first needs to be instructed, using
to use tech longer
than the concept Python code. Python code, what sort of data it should look
of Googling By following our step-by-step guide, you for. The Sense HAT’s visual display can also be
has existed. will discover how to light up rainbow and heart programmed to show specific details including
@rosiehattersley images on the Sense HAT’s LED matrix, as well as simple images. In this tutorial we’ll look at how to
showing a custom scrolling message. If you don’t control the LED matrix. Don’t worry if you don’t
have a Sense HAT, you can still try out the code have a Sense HAT as you can use the Sense HAT
using the Sense HAT Emulator in Raspbian. Emulator and try out the code in Raspbian.
60 magpi.cc
TUTORIAL
X Figure 1
Open Thonny
03 We’re going to use a program called Thonny
to instruct our Sense HAT and tell it what to do.
When Raspbian loads, select Programming from
the top-left raspberry menu, then choose Thonny
Figure 1 Sense HAT uses a co-ordinate system to locate each LED on the matrix. The blue
Python IDE. Click the New icon to open a new, light is at (0, 2) and the red light is at (7, 4)
untitled window. We need to get our program to
recognise the Sense HAT module. To do this, type
these two lines of code into the Thonny window:
sense_hello.py DOWNLOAD
from sense_hat import SenseHat THE FULL CODE:
sense = SenseHat()
> Language: Python 3 magpi.cc/github
Click the Save icon and name your file rainbow.py.
001. from sense_hat import SenseHat
002. sense = SenseHat()
003.
Say something 004. sense.show_message("Hello Rosie")
04 From now on, Thonny will know to use the
Sense HAT whenever you type ‘sense.’ followed by
a ‘.’ and a command. Let’s get the Sense HAT to say
hello to us. Add this line of code to line 4 in Thonny: lick Run and the letters should scroll
C
sense.show_message("Hello Rosie")
across the LED display
Of course, you can use your own name. Click
Run and the letters should scroll across the LED
display. If you get an error in the Shell at the
sense_pixels.py
bottom of the Thonny window, check your code
carefully against the sense_hello.py listing. Every > Language: Python 3
letter has to match.
001. from sense_hat import SenseHat
002. sense = SenseHat()
003.
Choose your colours 004. sense.clear()
05 We are going to get the Sense HAT to light 005. sense.set_pixel(7, 4, 255, 0, 0)
up a rainbow and display a heart. We do this with 006. sense.set_pixel(0, 2, 0, 0, 255)
the set_pixel() function.
sense_rainbow.py
> Language: Python 3
www.UniPiCase.com
harder to navigate and had to be
completed within a time limit
wanted the marbles to have smiley faces
on them. The idea didn’t make it to the
game, but is reflected in the game logo
Source Code
Code a homage to
Marble Madness
Code the map and movement basics of
AUTHOR
MARK VANSTONE the innovative marble-rolling arcade game
H
itting arcades in 1984, Atari’s platform, and also boasted the first use of flats and slopes. We can produce the
Marble Madness presented an FM sound chip produced by Yamaha to background graphic using a 3D modelling
a rather different control create its distinctive stereo music. The game program such as Blender. The camera needs
mechanism than other was popular in arcades to start with, but to be set to Orthographic to get the forced
games of the time. The interest appeared to drop off after a few perspective look we’re after. The angle of the
original arcade cabinet provided players months – something Cerny attributed to the camera is also important, in that we need an
with a trackball controller rather than a fact that the game didn’t take long to play. X rotation of 54.7 degrees and a Y rotation
conventional joystick, and the aim was to of 45 degrees to get the lines of the terrain
guide a marble through a three-dimensional “The ball physics are correct. The heightmap can be derived from
course in the fastest possible time. This an overhead view of the terrain, but you’ll
calculated from the grey-
meant that a player could change the angle probably want to draw the heights of the
and speed of the marble as it rolled and shaded heightmap” blocks in a drawing package such as GIMP to
avoid various obstacles and baddies. give you precise colour values on the map.
During development, designer Mark Marble Madness’s popularity endured in the The ball rolling physics are calculated
Cerny had to shelve numerous ideas for home market, though, with ports made for from the grey-shaded heightmap graphic.
Marble Madness, since the hardware just most computers and consoles of the time We’ve left a debug mode in the code; by
wasn’t able to achieve the level of detail – although inevitably, most of these didn’t changing the debug variable to True, you
and interaction he wanted. The ground- support the original’s trackball controls. can see how the marble moves over the
breaking 3D display was one idea that made For our version of Marble Madness, we’re terrain from the overhead viewpoint of the
it through to the finished game: its pre- going to use a combination of a rendered heightmap. The player can move the marble
rendered, ray-traced isometric levels. background and a heightmap in Pygame left and right with the arrow keys – on a level
Marble Madness was the first game to Zero, and write some simple physics code to surface it will gradually slow down if no keys
use Atari’s System 1 upgradeable hardware simulate the marble rolling over the terrain’s are pressed. If the marble is on a gradient
Download
the code
IN THE PROCESS,
YOU’LL DISCOVER HOW TO:
Set up and use the free Create and texture 3D Make enemies that follow
software you’ll need character models and attack the player
W
hen we think of projects for the home, we often think
of IoT and/or home automation. These concepts tend to Getting started
interconnect, so we decided to have a look at instances of with IoT
both types with ten amazing projects. You can also combine these
Want to find out
with some of the recycling projects from our top ten list on page 80.
some of the basics
For now, though, grab your Raspberry Pi and let’s get building. of using the Internet
of Things with a
What is the Internet of Things? Raspberry Pi? Check
We’ll be the first to admit that the term ‘Internet of Things’ (IoT) out this blog from
is not very descriptive. The concept is defined many ways, but Raspberry Pi on
some ways you can
usually involves an internet-connected device that has some level of
get started:
automation or analysing that does not require human interaction. It magpi.cc/iotstart
can involve human interaction, though. Or be set up for you to then
walk away and never think about it again.
Many features of IoT devices can be found in smart devices – such
as smart lighting, smart fridges, smart heating, etc. Don’t get too
bogged down in descriptions and definitions like this, though – in the
case of this feature, let’s just have a bit of internet-connected fun!
e
idity levels in your hom
temperature and hum
View a graph of the
Raspberry Pi 3
Baby Monitor
magpi.cc/babycam
Internet Doorbell
magpi.cc/iotdoorbell
PiHue
magpi.cc/pihue
internet radio
A cool casing for this
Internet Monitor
magpi.cc/webmonitor
to life
Bringing an old pocket TV back
ZX Spectrum
Next Accelerated
SpecNext specnext.com £230 / $288
SPECS
PROCESSOR:
Z80 on Xilinx Raspberry Pi Zero adds audio and realistic loading to this
Spartan-6
XC6SLX16 FPGA reimagined ZX Spectrum computer. By Lucy Hattersley
MEMORY:
F
1MB RAM ollowing several years of development, of the device sits a full-size SD card slot and three
(expandable to
2MB internally)
The ZX Spectrum Next Accelerated – a buttons: Reset, Drive, and NMI. And the original
reimagining of the popular 1980s computer Expansion port provides compatibility with
AUDIO: – has finally arrived. Part of the Spectrum’s classic hardware.
3 × AY-3-8912
modernisation is a Raspberry Pi Zero acting as an The NMI button opens a menu that enables you
audio chips with
stereo output accelerator, melding the power of a 1980s classic to flick between turbo modes: 3.5MHz, 7MHz,
with the greatest computer of the modern age. 14MHz, and 28MHz. You can also enter POKE files,
WIRELESS: Inside the box you’ll find the ZX Spectrum Next browse memory banks, and adjust various sound,
ESP8266 WiFi
computer, a power supply, and a spiral-bound graphical, and memory settings. Some period
module
user manual which is pleasingly similar to the games become wonderfully playable when cranked
ACCELERATOR original but packed with information from BASIC up to 28MHz: Sentinel, originally an achingly slow
BOARD: programming to machine code. trudge, becomes a fast-paced and tense 3D puzzler.
Raspberry Pi The keyboard is a thing of beauty. The keys are
Zero W
responsive, although the layout is a bit weird after Z80 and beyond
years of muscle memory bonded to PC. The heart of the Spectrum Next is a Xilinx
It’s packed with connections: HDMI and VGA Spartan-6 XC6SLX16 FPGA (field-programmable
for video out; 3.5 mm ear and mic mini-jacks; PS/2 gate array, magpi.cc/spartan6). FPGA isn’t
for keyboard and mouse; plus the mini HDMI and
A range of modern micro USB ports of Raspberry Pi Zero; and two
and classic
9B9 joystick ports (compatible with Kempston,
ports make for a
versatile computer Cursor, and ZX Interface 2 Protocols). To the left
add oomph to a project Attached to the motherboard, a Raspberry Pi Zero acts as a sound
system, enabling files to be loaded as if they were tapes
Next is a lovely
piece of kit.
Well-designed
Alongside this sits a Raspberry Pi Zero, which We’re impressed. From a design and build and well-built:
enables you to load digital .tzx files as analogue quality perspective, ZX Spectrum Next has authentic to the
cassette tape (screeches, loading screen, and all). achieved all we wanted from a new Spectrum. original, and with
technology that
It also brings SID (Sound Interface Device) support And it’s a great example of using the power of
nods to the past
to the table, enabling better audio for games. Raspberry Pi to add oomph to a project. From a
while remaining
There are plans afoot for Raspberry Pi Zero’s licensing and business perspective, managing functional and
micro USB port to act as a digital joystick port, and to maintain this purity of focus while blending relevant in the
the mini HDMI output may be used down the line multiple open-source and proprietary software modern age.
9
to add a second display. Beyond that, Raspberry projects, all while juggling licensing owned by (to
Pi Zero adds a 1GHz CPU and 512MB of RAM to the our count) 15 separate organisations including
/10
hardware – plenty of extra headroom for ambitious Amstrad/Sky, is seriously impressive stuff. Bravo,
game developers. SpecNext, bravo!
CONNECTIONS:
3 × analogue Control your home automation projects
inputs,
3 × buffered with this tiny board. By Phil King
inputs,
S
3 × sinking
outputs, uperseding Pimoroni’s Automation pHAT,
1 × relay the Automation HAT Mini has the same
Zero-size form factor (but can be used
TOLERANCE:
Up to 24 V; up with any Raspberry Pi). Although a little more
to 500 mA (total expensive than its predecessor, it has the bonus of
for sinking coming fully assembled and adds a tiny full-colour There are plenty of
outputs), up to connections for inputs
LCD which provides useful status info on and outputs, and a
2 A (relay) tiny LCD can be used
connected inputs and outputs. Another nice
to show their status
DISPLAY: addition is the six-pin female header on the
0.96-inch underside, which has the same pinout as
IPS LCD
Pimoroni’s extensive range of I2C mini breakouts
BREAKOUT: (including numerous sensors), although you’ll
Six-pin female need an extender to connect one.
header The board’s main connections for inputs and
outputs are 3.5 mm screw terminals. As well as a
single relay, there are three analogue inputs, three
buffered inputs, and three sinking outputs. All of
these are tolerant to voltages up to 24 V – which is
fine for controlling a plethora of household devices
The underside of the board, showing the
that typically have a 12 V or 24 V control board. But female breakout header on the right
make sure you don’t use the board to switch
mains voltages! the three outputs. With a tolerance of up to 2 A, the
relay can be connected on the NC (normally closed)
T he LCD provides useful or NO (normally open) side, depending on whether
your device spends more time switched on or
Verdict status info on connected off respectively.
Although created for the original Automation
It’s ideal for most inputs and outputs HAT/pHAT, Pimoroni’s getting started guide
home automation (magpi.cc/automationguide) shows you how to
purposes, and Inputs and outputs use the board’s Python library – instead of using
we love the mini
Read via a 12-bit ADC, the analogue inputs have an the curl command, you’ll need to clone it from
LCD, although if
accuracy of ±2%, which is fine for most purposes GitHub (magpi.cc/automationgh) to get the up-
you need more
relays you might when you need to read a variable voltage. The to-date version. The relevant code examples show
prefer the full-size digital inputs are used to tell if a connected device the status of inputs/outputs on the LCD, including
Automation HAT. is on (signal above 3 V) or off (below 1 V). bar graphs for analogue inputs.
9
For turning devices on and off, you have a choice If you’re new to the world of home automation
of the three sinking outputs and the relay. For the and its terminology, you should also check out
/10
former, you connect your device load on the ground Tanya Fish’s excellent explainer on the Pimoroni
side; a maximum of 500 mA can be sunk between blog: magpi.cc/automationblog.
PC HARDWARE
ENTHUSIASTS
10 Best:
Cassette Pi
Tapeless technology
A ‘self-contained real-time
notification scroller’, according to
upcycling extraordinaire Martin
Upcycling
Mander – this Raspberry Pi Zero
stuffed inside a clear cassette tape
retrieves IoT connected notifications
using IFTTT.
projects magpi.cc/cassettepi
Have some old tech lying around your RetroPie NES controller
home? Get inspired to recycle it...
Console in a controller
R
ecycling stuff in your house shouldn’t just be We did this ourselves when Raspberry Pi Zero launched, albeit a bit more
limited to cardboard boxes and plastic bottles: crudely. This version is much neater and allows you to use it with an original
it can also involve reusing tech that may be NES controller – if you have one spare, that is.
a little past its sell-by date. Here are ten amazing magpi.cc/nespi
examples of reusing and upcycling some older tech.
Victorian
dresser magic
Tomy Turnin’ Turbo mirror
Dashboard Outrun Arcade
Antique wizardry
We featured this a long time ago in
Toy to life
The MagPi, but we love the idea of
Do you have any kids’ toys lying around? Then maybe you can taking the very cool magic mirror
do something like Circuitbeard (aka Matt Brailsford): turn a concept and putting in an antique
toy steering wheel into a mini Out Run cabinet, complete with dresser. An amazing melding of old
force feedback. and new.
magpi.cc/outrun magpi.cc/magicdresser
Brick case
Lego cases used to be all the
rage when Raspberry Pi was
released, and this Lego laptop
takes the concept to its logical
conclusion. Lego is great for
prototyping cases of all sizes and
types, though.
magpi.cc/pibook
Flash Cam
Analogue to digital
This very retro camera has had its flash completely upgraded with a
Raspberry Pi Zero, which allows it to take short video clips. The flash and
camera still don’t work, but it’s got a great aesthetic.
magpi.cc/flashcam
magpi.cc/emulatortv magpi.cc/pividbox
Learn JavaScript
with Raspberry Pi
JavaScript is one of the most popular languages out there. PJ Evans opens his code editor
Essential resources
Learning JavaScript and Node.js? You’re going to need these…
NPM amongst which you’ll find comprehensive
Node Package Manager is like Python’s pip documentation on all versions of JavaScript with
for Node. Literally thousands of libraries to examples and browser support information.
enhance your project can be installed in a magpi.cc/jsguide
single command. Always start here to avoid
reinventing the wheel. STACK OVERFLOW
npmjs.com Every developer’s little secret. A gigantic Q&A
site for many subjects including Raspberry
MDN WEB DOCS Pi, JavaScript, and Node.js. Chances are the
This free resource from Mozilla is like the answer to your question is here somewhere.
Library of Alexandria for internet development, magpi.cc/stackoverflowjs
NodeSchool
NodeSchool NodeSchool is an astounding tutorials available are installed
CREATOR
> Name Dane and Nicole > Community role YouTubers > Website magpi.cc/8bitsbyte
Y
ou can find a huge and a demonstration of the Raspberry Pi hobby project. He
variety of Raspberry Pi projects, whereas we share a loved the project, but he also
projects online. A lot of step-by-step guide and the code wanted to take it apart to be able
them are useful and cool, some on websites like Instructables build something else: his next
of them great for beginners, and and Hackster.” project. We thought it would be a
others are just extremely wacky. The name comes from a bit of shame to just take it apart and be
Dane and Nicole from 8 Bits and a pun on bits and bytes, and they done with it. Around the same
a Byte are on the wacky side. like to think of each other as time, Nicole had just finished a
“We build all kinds of stuff, both four bits half a byte. You video editing course. We were
including internet-controlled can probably do the maths able to borrow a camera and we
robots, wearables, talking yourself on that. thought we’d try to document
appliances, data visualisations, the project, but at this point it
A classic Monty Python and self-driving cows,” they tell How did the channel start? was just for ourselves. The video
sketch made into a
us. “On our YouTube channel we The idea of the channel started wasn’t too bad and we also
robot face that argues
with you. Poorly post montages of how we built it when Dane finished his first realised we would be making
more of these projects in the
future. That’s when we had the
idea that it could be fun to share
them with others.
From thereon it grew; we
indeed built more things,
although very infrequently at
8-bit projects
This Month in
Raspberry Pi
#MonthOfMaking
You’ve been making and sharing – here are some of our faves!
T
he #MonthOfMaking is now over, and it
was a lot of fun! People from around the 01
world shared their projects with us for
#MonthOfMaking and also #MagPiMonday! Here
are just some of the amazing things we saw...
01.
This Raspberry Pi laptop build seems to
have just about everything! When will it be
able to make tea?
02. This looks very handy for stargazing!
03.
We always love to see some ham radio
projects using a Raspberry Pi
04. We definitely think this new UI is cooler
05. Making sweet music with a lot of hacking
06. What clip would you use to wash your
hands? We like the song from OK K.O.! Let’s
Be Heroes
07. A useful device for darkrooms (do people
still have those?) or recording studios
08. The semaphore clock has been upgraded
with nicer fonts. It looks even snazzier now
09. This is a very cool way to upcycle an old
power supply!
86 magpi.cc #MonthOfMaking
THIS MONTH IN RASPBERRY PI
03
02
06
05
04
08
07
09
#MonthOfMaking magpi.cc 87
THIS MONTH IN RASPBERRY PI
Pi Wars Turkey
Pi Wars Prime may have had to go online, but the Turkish version managed to go ahead
W
ho doesn’t love a bit of friendly robot
battling? The organisers of Pi Wars
Turkey got in contact with us, asking if
we knew about them. We did! So they showed us
some excellent photos from the event.
01
01.
Prep work and coding
are an important
skill for building a Pi
Wars competitor
02.
The attendee count
was huge! We love
the variety of robots
on display at the front
as well
03. This obstacle course
has some classic
hazards, such as
the turntable and
03 05
some gravel
04.
Pi Noon is popular
everywhere
05.
As usual, robots had to
take part in multiple,
varied events
02
04
CROWD
A PROFJUNDING
ECT?
Raspberry Pi NFC/ If you
’velaunc
Power Pi
Raspb hed a
Audio Skirt
erry P
projec i-relate
t, let u d
magp s know
i@ras !
pberry
pi.org
If your Raspberry Pi is doing critical work that would not This cool little add-on gives Raspberry Pi a couple of
react well to a power outage, blip, or surge, then having extra features: an NFC/RFID reader, which is very cool,
an uninterruptible power supply is a great way to add and two 3.2 watt amplifiers for enhanced sound! We’ve
some level of security to its continued operation. This seen a couple of projects that meld both NFC and audio,
one could provide up to an hour of extra power. so it could be great for that!
kck.st/2JTul0F kck.st/2ViLRk0
EVENTS
POSSIBLE EVENT
CANCELLATIONS
Please follow local public health
advice and take decisions on
whether to cancel clubs or
events in consultation with the
05 07
venues that host them.
Raspberry Jam
Event Calendar
Find out what community-organised Raspberry
Pi-themed events are happening near you…
01. Medway Makers Tech Meetup 05. AWC/UA & STEDY Raspberry Jam
Sunday 3 May Friday 8 May
Online AWC San Luis Technology Institute, San Luis, AZ, USA
magpi.cc/OPTwTU magpi.cc/ZDtRuj
Workshops on building cool things with Arduino, how to For those interested in learning all about Raspberry Pi,
code for beginners, how to use a Raspberry Pi, and so on. AWC/UA is hosting workshops on how to get started.
02. Free Robotics Sunday Virtual Lesson 06. West Sound CoderDojo on Zoom!
Sunday 3 May Saturday 9 May FULL CALENDAR
Online Online
Get a full list of upcoming
magpi.cc/sgixR9 magpi.cc/jQ16dX events for May and
A virtual lesson from this free after-school robotics Ninjas, parents, mentors, and all are invited to join beyond here:
workshop that normally meets on Wednesdays/ West Sound CoderDojo for bi-weekly sessions of rpf.io/jam
Thursdays near Roppongi, Tokyo. coding and fun.
03. ONLINE: Music Creation Basics with Sonic Pi 07. Dallas Young Makers Club
Tuesday 5 May Saturday 23 May
Online J. Erik Jonsson Central Library, Dallas, TX, USA
magpi.cc/cM3fNs dallasyoungmakers.org
Learn the basics of Sonic Pi, a free, cross-platform code- Free mentor-led, hands-on projects for kids with
based music creation and performance tool! Raspberry Pi, Lego Mindstorm robots, and more.
FIND OUT
ABOUT JAMS
Want a Raspberry Jam
in your area? Want to
start one?
[email protected]
Activities
“S
omething like Astro Pi is a fantastic
thing to get involved in if you want to
really give children some focus and
direction. The idea of having your code run
on the International Space Station is a real
motivator for young kids.”
Your
Letters
Lens concerns
Are there any ways to add
proper lenses to a Raspberry Pi
Camera Module? I have some
nice lenses I’d like to use for
El Carrillon some more advanced projects.
will last for
another
several years Karl via Twitter
thanks to the
upgrades we
covered in There are a few 3D-printable
issue 92
mounts on Thingiverse for
specific lens makes (Canon,
Bells, bells, bells Nikkon, etc) and they seem to
work pretty well. Alternatively,
What a big surprise to see this here, I was looking for news about take a look at the new official
Raspberry Pi software and see this story. Immediately when I saw HQ Camera that can be used with
the Carillon, I was shocked! It was my father and an electric any C- or CS-mount lens.
engineer who worked on the original project and built the
The new HQ Camera has support for
Carillon. Also, I was 13 at that time and was involved too, loading interchangeable lenses and also features
the code with the notes and songs in a Commodore 64. The a higher-res 12.33MP sensor
program sends the signals to the parallel port of the machine and
a custom interface activates the switch of the bells. My father’s
name was Carlos Maria Morelli. He passed away in August 2014,
but it is really good to see his project is still alive and working!
Contact us!
> Twitter @TheMagPi
> Facebook magpi.cc/facebook
> Email [email protected]
> Online raspberrypi.org/forums
magpi.cc/freebook
Subscribe to The MagPi, HackSpace magazine, or Custom PC. Your first three issues for £10, then our great value rolling subscription
afterwards. Includes a free voucher for one of five fantastic books at store.rpipress.cc/collections/latest-bookazines
UK only. Free delivery on everything.
COMPETITION
Competition magpi.cc 95
Join us as we lift the lid
on video games
LEARN
Features Editor
Rob Zwetsloot
[email protected]
Sub Editors
Phil King and Nicola King
COMPUTING
ADVERTISING
Charlotte Milligan
[email protected]
+44 (0)7725 368887
DESIGN
& ICT
criticalmedia.co.uk
Head of Design
Lee Allen
Designers
Sam Ribbits, Harriet Knight,
Ty Logan
W I T H R A S P B E R R Y P I Illustrator
Sam Alder
CONTRIBUTORS
Mike Cook, David Crookes,
Frank Delporte, PJ Evans, Gareth
Halfacree, Rosemary Hattersley,
Nicola King, Mark Vanstone
PUBLISHING
Publishing Director
Russell Barnes
[email protected]
Director of Communications
Liz Upton
CEO
Eben Upton
DISTRIBUTION
Seymour Distribution Ltd
2 East Poultry Ave,
London EC1A 9PT
+44 (0)207 429 4000
SUBSCRIPTIONS
Unit 6 The Enterprise Centre
Kelvin Lane, Manor Royal,
Crawley, West Sussex, RH10 9PE
+44 (0)1293 312193
magpi.cc/subscribe
H
ave you ever tried working I often use it because it allows clarity computing tasks, but still has its
on a Raspberry Pi? It’s of focus. Linux is where I get things heart and soul in programmable
a surprisingly pleasant done. And the Raspberry Pi 4 with computing. You can’t hack
experience. Sure, you might not be 4GB RAM snaps and crackles along; electronics to the GPIO pins of a
able to run Microsoft Word or Apple there are no sluggish setbacks. tablet, no matter how touchable the
Mail, but Chromium, LibreOffice and We’re delighted that Raspberry interface is.
Claws Mail are excellent, and free, Pi, ‘the little computer that could’, A Raspberry Pi can become
alternatives. Plus you get beginner- is now very much ‘the big computer whatever you want it to be – even
friendly programming tools like that does’. if what you want it to be is a work
Scratch and Thonny.
There’s been a huge uptake in
Raspberry Pi recently, and we think Raspberry Pi can become whatever you
A
it’s because folks want to explore
low-cost computing.
want it to be – even a work tool
Gareth Halfacree, one of our
most trusted testers, tried out the Still, we’re all about hacking and tool. We’re lucky, because our work
Raspberry Pi 4 as a desktop solution making at heart. I’ve been having is Raspberry Pi. And we get to spend
when it first arrived, and it turns out fun lately with the Raspberry Shake our days making cool things and
to be a surprisingly versatile option. seismograph, building an outdoor writing about them. And I get to do it
I’m glad we asked him to look at how light display, and working with all on the same computer.
Raspberry Pi 4 shapes up as a remote robotics. I still dream of a Raspberry If you haven’t tried working
working option. Pi drone project that doesn’t take on Raspberry Pi then I hope this
There may still be shortcomings: your hands off. month’s The MagPi magazine has
we couldn’t get Zoom to work, Like most readers of The MagPi, I’m managed to change your mind. Give
although some would see this as a on the lookout for new projects and it another shot.
welcome bonus. But most tools – things to build.
such as Google Docs, LibreOffice, Lucy Hattersley
AUTHOR