100% found this document useful (1 vote)
732 views

MagPi110 Raspberry Pi Magazine Oct 2021

Leading Magazine for the Raspberry Pi Issue 110

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
732 views

MagPi110 Raspberry Pi Magazine Oct 2021

Leading Magazine for the Raspberry Pi Issue 110

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

SPOOKY PROJECT UPGRADES FOR HALLOWEEN!

Issue 110 September 2021 magpi.cc The official Raspberry Pi magazine

R A S P B E R RY P I
SMART GADGETS Hack home devices with super small computers!

H
ea
ter c ue
M eter B arbe Sno
Dog re D e t e c to r
Translator

Sm
ar t Bar tender

Ca er
t Spe
G u it a r P e d a l edo m et

USE
magpi.cc/store

GPIO
PINS

WIN! AIR QUALITY KITS UP FOR GRABS!


QHD or Full HD?
Go CURVED!

G-Master GB3266QSU G-Master G2466HSU


Red Eagle Red Eagle

Immerse yourself in the game with the new Red Eagle #monitors4gamers.
Choose the height adjustable GB3266QSU with a 2560x1440 resolution or the G2466HSU
with 165Hz refresh rate and enjoy stutter-free gameplay on these 1500R curved VA panels.

Find your match at gmaster.iiyama.com


WELCOME

WELCOME
to The MagPi 110

A
s time goes on, I’m increasingly becoming a militant 'right
to repair' advocate. I think it’s right to fix and improve things,
rather than chucking them in the bin and buying afresh.
It makes financial sense to build your gadgets or repair them,
and you can improve classic kit with Raspberry Pi technology. With Lucy

EDITOR
Hattersley
Raspberry Pi, you can make an outrageous idea work. You can’t buy a
dog translator, cat speedometer, or snore detector. With Raspberry Pi, We love our
subscribers and
your ideas – or the wild ideas of other makers – become reality. shower them with
free gifts. I suggest
And, it makes sense to know how something works. Build you take out a
subscription right
something with your own hands and it’s truly yours. away so the next
issue lands on
Your Smart Gadgets feature (page 30) has all the information you your doorstep.

need to transform classic devices into super-smart widgets, and build @LucyHattersley

your crazy gadgets for the home. And while you’re in a creative mood,
don’t forget Halloween is coming. Your spooky upgrades feature
(page 68) is packed with ideas for entertaining local kids
with electronics. GET A
I hope you enjoy this issue. RASPBERRY PI
It’s packed with great ideas and ZERO W KIT
fun makes. Let us know what
you repair, improve, or create
PAGE 28
for yourself.
Lucy Hattersley Editor
SPOOKY PROJECT UPGRADES FOR HALLOWEEN!
Issue 110 September 2021

Issue 110 September 2021 magpi.cc The official Raspberry Pi magazine

R A S P B E R RY P I
SMART GADGETS
Raspberry Pi Smart Gadgets

Hack home devices with super small computers!

H e
ea cu
ter
M eter B a r b e Sno
Dog re D e t e c to r
Translator

Sm
ar t Bar tender

Ca er
t Spe
G u it a r P e d a l edo m et

USE
GPIO
PINS
magpi.cc

WIN! AIR QUALITY KITS UP FOR GRABS!

magpi.cc 03
3 ISSUES FOR £10
+
FREE BOOK

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

Contents
> Issue 110 > October 2021

Cover Feature

30
30 Raspberry Pi
Smart Gadgets

Regulars
08 World of Raspberry Pi
92 Your Letters
97 Next Month
98 The Final Word

Project Showcases
12 miniLIGO
16 Package Thief Deterrent
18 ML Prosthetic Arm 20
20 Solar System Display
22 Cyberdeck
26 Zippy

16

Package Thief Deterrent Solar System Display

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.

magpi.cc 05
CONTENTS

Tutorials 38 62
38 Make retro noises
43 Ultimate home server - part 3
48 Surrogate TV project streams
52 Code Gradius Volcanos
55 Create GUIs in Python - part 10
Make retro noises Build an Android tablet
62 Build an Android tablet
The Big Feature 76
68

Keybow 2040
Spooky project upgrades

Reviews 86

76 Keybow 2040
78 PoE USB Hub HAT
80 Electronic clock for Pico
82 10 amazing instrument projects
84 Learn networking
Community
86 Matt Gray interview
88 This Month in Raspberry Pi Matt Gray interview

WIN A I R Q UA L I T Y K I T S FO R 95

1 OF 10 RASPBERRY PI
06 magpi.cc
THE WORLD OF RASPBERRY PI

The next
generation of
documentation
Raspberry Pi introduces a new documentation hub. By Lucy Hattersley and Alasdair Allan

R
aspberry Pi has launched the next restructured, and a great deal of non-Raspberry
generation of its documentation Pi specific documentation needed to be removed,
that can be viewed today while other areas were underserved and needed
(magpi.cc/documentation). to be expanded.”

The page is built Writing on the Raspberry Pi blog
automatically
following a push to
(magpi.cc/bringondocs), Alasdair Allan, Head Replacing Markdown
the master branch of Documentation at Raspberry Pi, says: “The The new documentation design “comes from
on the GitHub page, documentation repository itself had been left to the same team of folks that built the excellent
where anybody can
issue a pull request grow organically. When I arrived, it needed to be PDF-based documentation for Raspberry Pi Pico
and RP2040.”
The PDF documentation for RP2040 and
Raspberry Pi Pico was built off an Asciidoc-based
toolchain, and “we knew from the outset that
we’d want to migrate the current Markdown-
based documentation to Asciidoc. It’d offer us
more powerful tools going forwards, and a lot
more flexibility,” says Alasdair.

Get involved
The Asciidoc source for the new
documentation site is hosted on GitHub
(magpi.cc/documentationgit), and the
Documentation site is built and updated
automatically using GitHub Actions when
someone pushes to the master branch.
“However, we’ll mostly be working on the
develop branch in the repository, which is the
default branch you’ll now get when you take a
fresh checkout, and also the branch you should
target for your pull requests,” says Alasdair (see
magpi.cc/documentationpullrequest).

08 magpi.cc The next generation of documentation


“We’ve always taken pull requests against the If you’re already a 
The new
documentation page
Markdown-based source behind our documentation
site. Over the years, as the documentation set has contributor, the easiest is built with Asciidoc
and is more focused
on Raspberry Pi
grown, there have been hundreds of community
contributors, who have made over 1200 individual
thing to do is to take a fresh
pull requests, ranging from fixing small typos to checkout of the repository
contributing whole new sections.
“With the introduction of the new site, “I’m hoping that everyone that has
Raspberry Pi will continue to take pull requests contributed to the documentation over the years
against the new Asciidoc-based documentation. will see the new site as a big step towards making
“However, we’re going to be a bit more targeted our documentation more accessible – and, as
around what we’ll accept into the documentation, ever, we accept pull requests. However, if you’re
and will be looking to keep the repository focused already a contributor, the easiest thing to do is to
on Raspberry Pi-specific things, rather than having take a fresh checkout of the repository, because
generic Linux tutorial content,” writes Alasdair. things have changed a lot.”

The next generation of documentation magpi.cc 09


THE WORLD OF RASPBERRY PI


The new Astro Pi looks similar
to the original, although the
camera gives it away

New Astro Pi in space


for a new mission
The next series of Astro Pi missions have begun, and will have a hardware upgrade as well

M
ission Space Lab and Mission Zero are teams to investigate plant health with the higher
back once again: the challenge where quality optical filter used in conjunction with the
teams of students send code to the ISS IR-sensitive camera. Using the Coral machine
(International Space Station) to be run on a learning accelerator, teams will also be able to
couple of Raspberry Pi systems that are installed develop machine learning models that enable
on the station. These Astro Pi were launched in high-speed, real-time processing.”
2015, though, and are long due an upgrade.
Not only will the new Astro Pi computers use Taking part in Astro Pi
a Raspberry Pi 4, they’ll also receive a powered- There are two Astro Pi missions to choose from:
up Sense HAT and more sensors and features Mission Zero and Mission Space Lab. Young people
for students to use. This includes a High Quality can participate in one or both of the missions, and
Camera, Coral machine learning accelerator, entry is completely free.
colour and luminosity sensor, and a passive
infrared sensor. This joins the current sensors of Mission Zero
a gyroscope; an accelerometer; a magnetometer; In Mission Zero, young people write a simple
and humidity, temperature, and pressure sensors. Python program that takes a sensor reading and
“The new hardware makes it possible for displays a message on the LED screen. This year,
teams to design new types of experiments,” participation in Mission Zero also gives young
the Astro Pi team says. “With the Raspberry people the opportunity to vote for the names of
Pi High Quality Camera they can take sharper, the two new Astro Pi units being sent to the ISS.
more detailed images and, for the first time, Mission Zero can be completed in around an hour,
teams will be able to get full colour images of the and is open to anyone aged 7 to 19 years old. Every
beauty of Earth from space. This will also enable eligible entry is guaranteed to run on board the ISS

10 magpi.cc New Astro Pi in space for a new mission



Team Jupiter took this photo of
Lake Balkhash in Kazakhstan

T
 he Coral hardware
is a little add-on
that can be used
with Astro Pi.

T here are two Astro Pi 


A beautiful ocean photo by

Upgrade in Numbers
Team Mechabot - with the

missions to choose from: HQ camera, future photos


will be awesome

Mission Zero and Mission COMPUTER: COMPUTER:


Space Lab Raspberry Pi B+ - Raspberry Pi 4B -
700MHz processor Quadcore 1.5 GHz
and participants will receive an official certificate
with 512 MB RAM processor with 8GB
with the exact time and location of the ISS when
RAM
their program ran.
MACHINE LEARNING
Mission Zero runs until 18 March 2022, and you
can read more here: magpi.cc/missionzero. ACCELERATOR: None MACHINE LEARNING
ACCELERATOR: Coral
Mission Space Lab CAMERA: Raspberry
Mission Space Lab is for teams of young people Pi Camera Module - CAMERA: High Quality
who want to run their own scientific experiments 5MP sensor, 2592 x Camera - 12.3 MP,
on the Astro Pi units aboard the ISS. It runs over 1944 resolution 4056 x 3040 resolution
eight months in four phases, from idea registration
to data analysis. SENSORS: SENSORS: Gyroscope,
Have a look at the winning teams from last
Gyroscope, accelerometer,
year (magpi.cc/astropi21) for amazing examples
accelerometer, magnetometer,
of what teams have investigated in the past. But
magnetometer, temperature,
remember – the new Astro Pi units offer exciting
new ways of investigating life in space and on temperature, humidity, pressure,
Earth. Mission Space Lab team mentors just need humidity, pressure colour, luminosity,
to send their team’s experiment idea by 29 October passive infrared
2021: magpi.cc/missionspacelab.

New Astro Pi in space for a new mission magpi.cc 11


PROJECT SHOWCASE

m
 iniLIGO fires lasers at a
beamsplitter to create an
interferometer used for
subatomic analysis

miniLIGO
gravitational
wave detector
A Nobel-prize winning concept inspired PhD students to make their own
gravitational wave tracker using Raspberry Pi. Rosie Hattersley explains

A
fter hearing about the science prize- how LIGO works. miniLIGO is designed to be a
winning LIGO (Laser Interferometer “simplistic and affordable” prototype mimicking
Gravitational-wave Observatory, the laser-interferometer gravitational wave
magpi.cc/ligo) six PhD students at Carnegie observatory experiment that won the Nobel Prize
Husni
MAKER

Mellon University in Pittsburgh decided to see in physics in 2017.


Almoubayyed whether they could emulate the idea.
Syrian-born PhD LIGO detects the gravitational waves in space Sensitive subject
student Husni caused by celestial objects colliding and predicted by The team had an advantage because Husni had
uses code and Albert Einstein in his General Theory of Relativity. worked on the original LIGO project when he was
data to study the
Understanding space has always interested studying at Glasgow University as part of a scientific
universe and often
combines them Husni Almoubayyed, so he was attracted to the idea collaboration. “While I mostly worked on data
with his Raspberry of something that can monitor gravitational effects analysis at that time, I wanted to experience some of
Pi maker projects
“stretching and contracting space around us on a LIGO’s engineering challenges,” he says, of which
magpi.cc/miniligo very tiny scale”. While there was no expectation of one is creating an interferometer (magpi.cc/ligoifm)
building their own LIGO device, not least because for highly detailed analysis work. For example,
of the expense involved, Husni and fellow students CalTech’s LIGO interferometers can measure a
wanted to help communicate to a wide audience distance 1/10,000th the width of a proton!

12 magpi.cc miniLIGO gravitational wave detector


Raspberry Pi 3B provides the
processing power to analyse signals
received and displays them on screen
and, thanks to Python code, as sound

Quick FACTS
> The $1,000
budget was set by
Carnegie Mellon
University

> miniLIGO was


created for its
A luminosity sensor analyses the Build18 event
‘fringes’ of the object to discern
A beam splitter divides a laser minute details or phenomena, such > The first LIGO
beam into two, with mirrors used as tiny distortions detector was
to bounce and merge them to launched two
create an interference pattern decades ago...

> The first


gravitational wave
was detected
in 2015

T
 eam miniLIGO – Oshadha > A space-based
Gunasekara, Aileen Zhai, version of LIGO –
Husni Almoubayyed, Alisa
Chang, Elliot Tuck, and LISA – is currently
Anirudh Mani – demonstrate being planned
their device at Build18,
Carnegie Mellon University

miniLIGO gravitational wave detector magpi.cc 13


PROJECT SHOWCASE

Schematic of the
interferometer used
for miniLIGO

The base is made


of 2-way mirrored
acrylic and laser-cut
with annotations to
indicate where the
3D-printed parts
should fit

“LIGO is an extremely expensive and large-


scale experiment,” says Husni, and some major
decisions were needed about how to create a
prototype cost-effectively. With the aim of
building the miniLIGO project for less than $1000,
it was clear that some compromises would be
needed, while mimicking the original LIGO concept
as closely as possible.
“LIGO has an extremely accurate damping
system that works to shield it from vibrations
and seismic changes,” Husni explains. “We
considered using a six-axes motion sensor as a
low-cost alternative, and to correct the signal
computationally using the sensor, but ultimately
decided to leave it out as we deemed that it would
L IGO has an extremely accurate damping not be a good use of time and resources as stronger
sources of noise would still dominate the signal.”
system that works to shield it from Having used microcontrollers and Raspberry Pi
for wearable computing and music-based projects,
vibrations and seismic changes the possibilities of single-board computers were
clear. (One of the other projects you’ll find on
Putting together
miniLIGO ahead of its the husni.space website is a graphical tablet
public demonstration
that makes music with a corresponding artistic
visualisation.) “Raspberry Pi allows us to easily
connect all the pieces of the project, and has
enough processing power to do signal processing
in real time,” he says. Raspberry Pi provides easy
interaction with the light sensor, while also having
plenty of processing power to analyse and process
wave signals in real-time. It also meant the project
could be portable – the team successfully ran
miniLIGO from a battery pack.

Getting set up
A Raspberry Pi 3B, connected to a portable battery
and a Bluetooth speaker, and a GPIO library
are at the heart of miniLIGO. The team used an
Adafruit High Dynamic Range Light Sensor and

14 magpi.cc miniLIGO gravitational wave detector


PROJECT SHOWCASE

L
 ayout additions will
see Pico controlling the
automatic running of
multiple locomotives Make it mini
To make your own miniLIGO, you’ll need a Raspberry
Pi 3B powered by a portable battery pack. The code
can be found at: magpi.cc/miniligogit.

A high distance laser and a 50:50 beam


01 splitter splits the laser into the two arms of an
interferometer. You’ll need two mirrors and two 75:25
beamsplitters to create two Fabry-Perot cavities.

optical equipment, including the lenses and laser T


 he two perfectly
reflective mirrors are used
from Edmund Optics, then added a monitor and a to build the Michelson
speaker. Access to the university 3D printing lab interferometer
Use an acrylic board as the base for the
meant they were able to 3D-print their own case. 02 interferometer, and 3D-print or attach holders
When it came to writing software for miniLIGO, to it at exactly equal heights. Use an Adafruit High
they decided to use Python code, largely because Dynamic Range Sensor or a Raspberry Pi HQ Camera
of the “mature and easy-to-use” Python library, to capture movements.
from which they chose some of the common
scientific computing libraries such as numpy,
scipy, and matplotlib.
When miniLIGo’s sensors detect a signal, its
software analyses it, visualises it in real-time
and plays a sound representation of it in Python.
The team also wrote the software to simulate a
gravitational wave signal whenever the red button
on the device is pressed. Warning!
Husni explains: “miniLIGO is based on a Laser pointer
Michelson interferometer setup that has several
applications in physics and astronomy. Although Attach a screen to show visualisations and a
it is nowhere near precise enough for gravitational
Be careful when using
laser pointers in your 03 Bluetooth speaker to alert you to any waves
projects and don’t aim
wave detection, miniLIGO can be used to detect a laser pointer at a detected. You could also add a trigger button to
person’s head. initiate demo visualisations.
sources of noise that LIGO encounters, such as when
lightning strikes nearby.” magpi.cc/lasersafety

miniLIGO gravitational wave detector magpi.cc 15


PROJECT SHOWCASE

Package
Thief Deterrent
Here’s a decidedly tongue-in-cheek make that is an extremely
humorous take on a home security system. Nicola King stands well clear

M
any of us are increasingly ordering Armed with a Raspberry Pi 4, a security camera,
goods online, with the consequence and various other ingredients, he set about
that more and more parcels and boxes making something that certainly caused a stir in
are landing on doorsteps everywhere. From a the neighbourhood, as his must-watch YouTube
security aspect, it can be a little worrying when video demonstrates (magpi.cc/packagetheft). “I
our precious new purchases are left in plain sight built the project more for entertainment value
waiting for us to return home. A fun and light- than actual use (since I’ve only ever had one
hearted project by Canadian maker Ryder shows package stolen), but I consider it a success either
Ryder,
MAKER

one unique way of handling it. way,” he tells us.


aka ‘Ryder So, how does the alarm system work? Using a
Calm Down’ Flour power security camera pointed at Ryder’s door, images
Ryder is a software Following the theft of a package from his porch from the camera are pulled by his Raspberry Pi
engineer who likes earlier in the year, Ryder decided to take action. and processed by a custom machine learning
to build ridiculous “It had never happened to me before and I was model to detect if there is or isn’t a package.
inventions in his
spare time and
a little frustrated,” he recalls. “I’d been doing “If a package has been taken unexpectedly,
document them on some image classification work at the time, and Raspberry Pi sends signals to a relay (via its GPIO
his YouTube channel figured this would be a great opportunity to build pins) to activate a variety of alarms to entice the
Ryder Calm Down.
something to deter people from stealing packages ‘thief’ to drop the package,” Ryder explains.
magpi.cc/ryderyt from my porch.” Those surprises for thieves include a sprinkler, a
loud truck horn, and a flour shower.

It’s great at detecting whether there is or “This is definitely a great project if you’re
looking to get your feet wet into machine learning
is not a package, but it also sometimes – though I don’t recommend you implement the
sprinkler, flour, or air horn components,” he says.
recognises my cats as packages! “All the participants in my video were friends and
neighbours of mine, and implementing the exact
same setup for the public will likely get you into
some sort of trouble,” he cautions. However, he
does suggest that you can modify the project to
send you an email when a package arrives, or has
been taken unexpectedly, which may be a more
prudent route to take!

Averting a cat-astrophe
Computer vision is central to Ryder’s project,
and he used Google Cloud AutoML to train the
machine learning model. “I wanted something
to include in my video that was easiest for those
getting started with machine learning to use,”
A Raspberry Pi 4 runs the software, with a
relay board used to control 12 V components
he reveals. “Training a model yourself can be
such as the flashing light, siren, and sprinkler quite intimidating.”

16 magpi.cc Package Thief Deterrent


PROJECT SHOWCASE

Warning!
Don’t Assault
You may get into trouble
if you attack innocent
porch visitors with flour,
or anything else for that
matter. Do not deploy
that aspect of the
project in a real-
world environment.

A garden sprinkler is
activated via a relay Quick FACTS
to spray the offender
> This project took
with water
Ryder around a
month to complete.
When a package theft is
detected by the camera and
> You’ll need quite
computer vision, a red flashing
a few items to
light and siren are triggered
make this…

> “A combination


of Python,
TensorFlow,
and the last of
my sanity!”

> Find the code on


GitHub: magpi.cc/
Ryder also added a packagetheftgit
flour blaster using
compressed air and > He’s working
a solenoid on a Raspberry
Pi-powered
autonomous car

It wasn’t plain sailing to get this system working


as he wanted. Ryder originally had all alarms and
sprinklers go off at the same time, but decided
to move them to separate threads with separate
timings in order to best soak his very obliging
friends and neighbours. “The model [is] great at
detecting whether there is or is not a package,” he
says “but it also sometimes recognises my cats as
packages!” He also sensibly trained the system to
disarm when he arrived to pick up his parcels.
Many co-operative friends and neighbours have
embraced his undertaking, “though I did buy my
neighbours a few boxes of chocolate afterwards
to say sorry for the noise”, Ryder admits. For
the time being, he has dismantled this project,
“since I don’t really have the need for it, but I’m
brainstorming some version two ideas – one of
With a camera pointed down at the porch, Ryder trained
which involves a net.” Any future front-step felons a machine learning model to spot when a package was
may be in for a shock! present – and recognise known faces to disarm the alarm

Package Thief Deterrent magpi.cc 17


Machine Learning Wiring up the capture
suit components

Prosthetic Arm
This intelligent arm learns how to move naturally, based
on what the wearer is doing, as Phil King discovers

K
nown for his robotic creations, popular the suit’s Raspberry Pi Zero using AOgmaNeo
YouTuber James Bruton is also a keen Iron (magpi.cc/aogmaneo), a lightweight C++
Man cosplayer, and his latest invention software library designed to run on low-power
would surely impress Tony Stark: an intelligent devices such a microcontrollers.
prosthetic arm that can move naturally and “AOgmaNeo is a reinforcement machine
autonomously, depending on the wearer’s body learning system which learns what all of the data
posture and limb movements. is doing in relation to itself,” James explains.
“It’s a project I’ve been thinking about for a “This means that you can remove any piece of data
James Bruton
MAKER

while, but I’ve never actually attempted properly,” and, after training, the software will do its best to
James tells us. “I thought it would be good to have replace the missing piece with a learned output. In
Former toy
designer, current
a work stream of something that could be useful.” my case, I’m removing the right arm and using the
YouTube maker, learned output to drive the prosthetic arm, but it
and general Motion capture suit could be any limb.”
robotics, electrical
To obtain the body movement data on which to While James notes that AOgmaNeo is actually
and mechanical
engineer, James base the arm’s movements, James considered meant for reinforcement learning,“in this case
is a fan of doing using a brain computer, but this would be we know what the output should be rather
it yourself and unreliable without embedding electrodes in than it being unknown and learning through
innovation by trial
and error. his head! So, he instead opted to train it with binary reinforcement.”
machine learning. To train the model, James used distinctive
magpi.cc/
jamesbruton For this he created a motion capture suit from repeated motions, such as walking, so that the
3D-printed parts to gather all the data from his prosthetic arm would later be able to predict what
body motions: arms, legs, and head. The suit it should do from incoming sensor data. He also
measures joint movements using rotating pieces spent some time standing still so that the arm
with magnetic encoders, along with limb and would know what to do in that situation.
head positions – via a special headband – using
MPU-6050 inertial measurement units and New model arm
Teensy LC boards. With the machine learning model trained,
Collected by a Teensy 4.1, this data is then Raspberry Pi Zero can be put into playback mode to
fed into a machine learning model running on control the backpack-mounted arm’s movements

18 magpi.cc Machine Learning Prosthetic Arm


PROJECT SHOWCASE

Part of the motion capture


suit, the headband is
equipped with an IMU to
gather movement data

Equipped with three heavy-duty


servos, the prosthetic arm moves
naturally based on the data from IMU
sensors on the wearer’s other limbs

The data gathered during training mode


is fed into a machine learning model on
a Raspberry Pi Zero; in playback mode, it
controls the robotic arm

Quick FACTS
The motion capture suit comprises 3D-printed
parts, each equipped with a magnetic rotary
encoder, MPU-6050 IMU, and Teensy LC
> T
 he project took
James a few
months to create
 aspberry Pi Zero can be put into playback mode to control
R
> H
 e designed and
the backpack-mounted arm’s movements intelligently 3D-printed the
robot arm parts
intelligently. It can then duplicate what the James admits that the project is highly
wearer’s real right arm was doing during training experimental and currently an early work in > It uses three high-
depending on the positions and movements of progress. “I’d like to develop this concept further,” torque XM540-
other body parts. he says, “although the current setup is slightly W270-T servos
So, as he demonstrates in his YouTube video overambitious and impractical. I think the next step
> T
 he arm is
(magpi.cc/mlarmyt), if James starts walking on will be to have a simpler set of inputs and outputs.”
mounted on
the spot, the prosthetic arm swings the opposite While he generally publishes his CAD designs
2020 aluminium
way to his left arm as he strides along, and moves and code, the arm “doesn’t work all that well, so
extrusions
forward as raises his left leg. If he stands still, the I haven’t this time. AOgmaNeo is open-source,
arm will hang down by his side. The 3D-printed though (free for personal use), so you can make > T
 hese are fitted to
hand was added purely for aesthetic reasons and something similar if you wished.” What would you a standard
the fingers don’t move. do with an extra arm? frame backpack

Machine Learning Prosthetic Arm magpi.cc 19


PROJECT SHOWCASE

Solar System Display


Dmytro Panin has taken one small device and one giant leap towards
creating a near-perfect digital orrery, as David Crookes explains

Dmytro considered using a Raspberry Pi


Zero, but eventually opted for a Pico

F
or centuries, astronomers have used positions based on the current time and date. It
orreries to simulate the motion of the then presents the planets revolving around the
planets around the sun. These mechanical sun, showing their relative circular orbits.
models of the Solar System originated around
150 BCE, but they gained their name when English
nobleman Charles Boyle, the Fourth Earl of Orrery, T he cool part is that no
commissioned his own planetarium in 1713 based
on a design by clock makers George Graham and external data is needed
Dmytro Panin
MAKER

Thomas Tompion.
Dmytro Panin would love to have one. “They’re “The cool part is that no external data is
a bit on the bulky side, but I may attempt to build needed,” Dmytro says. “The positions of the
Dmytro is a
programmer based an orrery one day,” he says. In the meantime, planets are calculated on board and the only
in Kyiv, Ukraine, and he has produced a digital version that is equally thing that the system knows is the current time,
he wrote his first
captivating and useful, powered by a Raspberry which comes from the RTC module.” It makes the
line of code aged
eight. He works for Pi Pico microcontroller. “Astronomy has always build a relatively straightforward one to replicate
a large provider of fascinated me, and I wanted something that I could and Dmytro has been more than happy to make
nearshore software look at and see the planets in the Solar System it open-source. He even shares his design for a
engineering services.
progress over time,” he continues. “So I built a 3D-printed case.
magpi.cc/ visual reminder.” But why choose the Raspberry Pi Pico for this
picosolar
project? “Microcontrollers are amazing: you have
A star build a tiny object which can execute your commands
His project is out of this world. As well as Pico, it and do virtually everything with extremely low
uses two other main components: a Waveshare power consumption. When I found out about the
Precision RTC expansion module with an on-board new RP2040 microcontroller and checked the
DS3231 chip and a Pimoroni Pico Display Pack. specs, I knew it could became part of my next
This allows the device to calculate the planets’ build,” he says. “I was particularly interested

20 magpi.cc Solar System Display


PROJECT SHOWCASE

By pressing these buttons (A and B), you


can browse dates in the past and future
to see the positions of the planets at
that particular moment. “It’s like time
travel,” Dmytro says. Pressing both
together brings you back to the present

Quick FACTS
> It depicts the
relative positions of
the planets

> The software


is written in
These two buttons (X and Y ) are used to MicroPython 1.15
change the brightness of the In-Plane
Switching (IPS) screen because Dmytro > It took six weeks in
When it’s set for the present time, says it can be a bit too bright at night total to create
the device can be used as a clock
too. Pluto has the job of tracking > The main parts cost
seconds. “Let’s call it a small about $30
consolation prize for being demoted
to dwarf planet,” Dmytro says > All the files are on
GitHub: magpi.cc/
picosolar

in using MicroPython instead of C to program


a microcontroller.”

Space to think
Dmytro has also added some neat flourishes to his
creation. To start with, he wanted to figure a role
for Pluto – the celestial body demoted to the status
of dwarf planet by the International Astronomical
Union in 2006. “I decided to represent the seconds
by having Pluto bounce, starting from the full
amplitude to just rolling at the bottom of the
screen when a minute is about to end,” he says.
He also made use of the Pico Display’s tiny
buttons so that past and future planetary positions
can be viewed on the screen. Most of the time,
however, it just sits on a shelf in his line of sight,
allowing him to keep track of the current positions.
“It means I can always see it,” he says. “But the
downside is that I can end up mindlessly staring at
With just three main components and a
Pluto jumping around without realising how much 3D-printed case, the Solar System Display
time has passed.” is a simple, yet very effective, project

Solar System Display magpi.cc 21


PROJECT SHOWCASE

Cyberdeck portable
entertainment system
Action adventurers and sci-fi tales inspired a Raspberry
Pi-concealing portable box of tricks. Rosie Hattersley peers inside

T
hough more of a wordsmith than a tech
expert, Justin Forsythe had enough of an
interest in technology to take a master’s
degree focusing on our relationship with it. “I’ve
Justin
MAKER

always been interested in how things work,” he says


Forsythe simply. The maker community caught his attention
Tennessee-based and, starting with soldering, he began to investigate
Justin’s forays into the uses of PCBs and Raspberry Pi. Inspiration for
making sparked what would become the Cyberdeck soon arrived.
his MA in media
Encouraged by the success of his first electronics
psychology,
investigating project in which he revived and added capacity to
the relationship the HDMI ports of his Onkyo audio receiver, Justin
between people
began to cast around for what to make next. “The
and technology.
versatility, affordability, and size of Raspberry Pi
really made it a smart buy during a time when I
wasn’t sure what my next project would be,” he
says. He knew it was to be something practical. He
also found the entertainment factor of RetroPie
and other retro gaming emulators intriguing, and
had seen examples in portable cases.

Electric dreams El Wire colour-changing


light strips enhance the
“Somewhere around this time” he began reading gaming experience
the novel Neuromancer, “which elicited images
of clandestine hackers whipping out cases that of Raspberry Pi OS, and to combine that with a
contain computers with powerful capabilities. gaming pad inside a ruggedised case. “A self-
I’ve always been a fan of James Bond and Mission contained system with wireless access also has
Impossible. This definitely helped put my head in the value in an emergency situation,” he reasons,
right place for making something fun and useful.” suggesting it’s a practical option to take on a
Not content building a ‘toy without a real- camping, fishing, or sailing trip. What would
world application’, he decided to make use of the make his idea less like reinventing the laptop was
word processing and internet access possibilities having the game station and PC parts sit alongside

22 magpi.cc Cyberdeck portable entertainment system


PROJECT SHOWCASE

Kodi TV streaming
software provides on-
the-go entertainment

A separate control
panel is used to
adjust the neon
lighting scheme
Quick FACTS
> Justin was
reading William
Gibson’s
Neuromancer
when inspiration
struck…

> and the idea for a


briefcase-based
device was born

> In a further sci-fi


nod, Cyberdeck
Justin chose a classic wood-effect boasts Tron-like
enclosure to hide the built-in fan LED trim
which cools the adjacent Raspberry
Pi 4 when the Cyberdeck is in use >  A hidden
lighting panel
controls crafty
colour changes

> All the better to


amuse his kids!

Cyberdeck portable entertainment system magpi.cc 23


PROJECT SHOWCASE

each other, plus some serious attention to the


Cyberdeck’s aesthetics.
Raspberry Pi’s size offers perfect portability for
a project in which space management was critical:
“The challenge [was] to arrange the components
in such a way that they are attractive and
conveniently oriented in relation to one another.”

Case study
He sourced a Nanuk 910 waterproof case from
C4Labs, which has a fan inside and pins to connect
to Raspberry Pi, “so that when the board receives
power, it’s also being cooled”. Furthermore, the
The bespoke decal hints case design meant “I could throw this entire project
at something intriguing
inside, despite the case’s
in the river, pull it out and open it, and the setup
deliberately subtle colour would be dry and ready for use.”

J ustin began reading the novel Neuromancer, “which elicited images of


clandestine hackers whipping out cases that contain computers”
The plethora of
downloadable gaming
ROMs inspired the idea of
a dual entertainment and
practical project

24 magpi.cc Cyberdeck portable entertainment system


PROJECT SHOWCASE

xxxxxxxxxxxxx

On the case
A sturdy, ideally waterproof case, a handheld
gaming pad, a power pack, and a small screen to
connect to Raspberry Pi 3 or 4 form the basics of the
Cyberdeck setup.

Prepare SD cards with RetroPie (and any


01 additional entertainment apps you wish) and
Raspberry Pi OS , then place it in the case along with
the battery, screen, mini keyboard, and the gamepad.

Measure and cut foam to fit inside the case


02 and cushion the components, strapping the
Next, Justin decided his Cyberdeck would look “so The Cyberdeck provides
plenty of fun for the family screen and Raspberry Pi in place with Velcro. Add
much cooler” with a keyboard. The Rii K12 model optional LED strips to enhance the Cyberdeck’s
he chose, along with a 10.1-inch 1080p screen and visual appeal.
30,000 mAh portable battery left room for a “small
framing” of protective foam and a little wriggle
room, if needed, to adjust the position of the cables.
To his delight, there was even room for a control
board for the funky light strip he’d got his eye on.
This adds to the atmosphere when the
Cyberdeck is being used in retro game emulation
mode to play the legal ROMs he acquired online.
Since he’s largely satisfied with its look and its
practical, portable qualities, Justin says any future
refinements are likely to be along the lines of small
solar panels to boost the battery power even further, Check everything works by booting up
and a possible new version with a Faraday cage
03 Raspberry Pi. Reassemble in the case,
inside. “As to Raspberry Pi, itself, I do have a couple connecting Raspberry Pi to the case’s internal fan,
of ideas in the works, but I’ll keep quiet for now!” then hooking up all the other components to it.

he tantalises.

Cyberdeck portable entertainment system magpi.cc 25


PROJECT SHOWCASE

Zippy
Tomasz Burzy aimed for the stars with his latest project but reality brought his ambition
back down to earth. The result is no less impressive, as David Crookes discovers

S
ince February this year, NASA’s Raspberry Pi Zero W computer. “It’s helped me
Perseverance rover has been trundling become acquainted,” he says – although his dream
across the surface of the Red Planet as of replicating the rover is still very much in mind.
part of the space agency’s Mars 2020 mission. Its
cameras have taken many amazing photographs Game on
of a barren landscape and eerie sky, attracting Since starting the project, Zippy has evolved
millions of viewers and inspiring a new generation and the latest version – 3.0 – is an impressive
Tomasz Burzy of scientists and engineers. build. It makes use of a printable modular
MAKER

Tomasz Burzy is among those enthralled by tank model designed by Nahuel Taibo


Tomasz says he NASA’s endeavour. “I became interested in (magpi.cc/roverplatform). It also uses an L298N
has ADHD: “I don’t robotics a while ago and love seeing the work of H-bridge motor driver to operate 12 V high-torque
have the attention
span for everyday NASA’s Jet Propulsion Laboratory and Boston metal gear motors, powered by an 11.4 V lithium
tasks, yet somehow Dynamics,” he says. “The Mars rovers quickly polymer battery.
I have the focus to became my favourite pieces of engineering One version of his code uses a web server to
design, engineer,
and when I saw Perseverance, I wanted to access Zippy remotely; another allows the tank
program, and
produce solutions build a replica.” to be controlled using an Xbox One gamepad. The
to those problems.” decision to use Raspberry Pi Zero W was primarily
magpi.cc/zippy I only learned Python at driven by the small amount of available room
inside the plastic model, but Tomasz found it works
the start of 2020 perfectly well.
“Zippy doesn’t have a lot of space inside of
Unfortunately, Tomasz had no experience of him after you put in the motors – once the motor
making a remote-control vehicle, so his partner driver and the battery are in there, it gets pretty
The components,
including the suggested he should work on something a little cramped,” he explains. “But Raspberry Pi Zero W
L298N motor driver,
smaller first. This led to the creation of a tinier fits in perfectly and it’s a powerful enough
fit snugly inside
Zippy’s casing tank called Zippy which he based around a computer to allow me to add features later on.”

The original motor gears were grinding on grass, so they were


replaced with an improved set

26 magpi.cc Zippy
PROJECT SHOWCASE

The waterproof Osmo Action


camera is capable of filming 4K HDR
video and taking Ultra HD images

Tomasz’s brightly coloured,


3D-printed case contains a
Raspberry Pi Zero W running a
script that listens for inputs before
turning its GPIO pins on and off

Quick FACTS
Zippy is an agile tank that’s easy
to control thanks to the integration > The components fit
of an Xbox One gamepad into the centre of
the tank

> Tomasz designed


parts to hold them
in place
To get things moving, Tomasz had to spend
time writing the code. “I only learned Python > It took hours
at the start of 2020, but I’ve been working to get the
with electronics on and off for a while,” he controller working
tells The MagPi. He used a Python library called
> An RGB LED
approxeng.input to get the Xbox One controller
indicates what’s
working. “It lets me connect almost any control to
happening in
Raspberry Pi and use its inputs,” he says. the script

Room for a view > All the files are on


To top things off nicely, a camera has been placed GitHub: magpi.cc/
onto Zippy. “I mounted an action camera because zippyos
Zippy has an interesting low-to-the-ground
point-of-view,” Tomasz explains. “During one of
the test drives, a fox became interested in Zippy
and we got some great close-ups. Sadly, that
footage was lost when my NAS failed.”
Despite such a setback, Tomasz hasn’t lost heart
and he intends to continue to persevere with his
Perseverance-inspired build by making future
improvements. As it stands, Zippy struggles to ride
over sand, rocks, and long grass, but it makes light
work of carpets and flat ground and can zip around Zippy struggles
with some terrain,
at a fair old speed. “I’d like to add headlights or a but Tomasz says
it trundles across
first-person-view camera,” Tomasz reveals. The
pebbles “with
sky really is the limit for a project such as this. determination”

Zippy magpi.cc 27
SUBSCRIPTION

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

Rolling Monthly Subscription


Low monthly cost (from £5)
Cancel at any time
Free delivery to your door
Available worldwide

Subscribe for 12 Months


£55 (UK) £90 (USA)
£80 (EU) £90 (Rest of World)
Free Raspberry Pi Zero W Kit with 12 Month upfront
subscription only (no Raspberry Pi Zero W Kit with
Rolling Monthly Subscription)

Subscribe by phone: 01293 312193


Subscribe online: magpi.cc/subscribe
Email: [email protected]
28 magpi.cc
SUBSCRIPTION

JOIN FOR 12 MONTHS AND GET A

FREE Raspberry Pi
Zero W Starter Kit
WITH YOUR FIRST
12-MONTH SUBSCRIPTION

Subscribe in print
today and you’ll
receive all this:

Raspberry Pi Zero W
Raspberry Pi
Zero W case with
three covers
USB and HDMI
converter cables
Camera Module
connector
This is a limited offer. Not
included with renewals.
Offer subject to change or
withdrawal at any time.

Buy now: magpi.cc/subscribe

SUBSCRIBE
on app stores

magpi.cc 29
FEATURE

R A S P B E R RY P I

SMART
GADGETS Transform an ordinary object into a smart thing
by putting a Raspberry Pi in it - by Phil King

S
mart gadgets are everywhere these days, but
p33 you don’t need to buy them ready‑made. Using
Raspberry Pi as a brain makes it easy to transform
existing appliances and devices into smart ones. Or, you can
p33
even use it to build your own custom products from scratch,
to suit your own precise requirements.
Here we present a range of amazing projects to create
smart devices for every aspect of your life. We hope they
inspire you to make your own – let us know if you do!

Dog
Translator
p35 p34

p32 p32

G u it a r P e d a l

H
ea
ter c ue
M eter B arbe
30 magpi.cc Raspberry Pi Smart Gadgets
FEATURE

Home appliances
S
mart home appliances are really taking
off, but you don’t need to trash that old
washing machine or fridge. Make it smart
with a Raspberry Pi.

Washbeary Pi “ Rick was


Washing machines contain a microcontroller to manage determined
their various actuators (such as the motor, heater, and
drain pump) and sensors. So why not control one with Refrigerator/ to create a
Raspberry Pi instead? This way, you can create your
own custom washing programs. YouTuber askDrAlex
Freezer Monitor smart alert
demonstrates his work in progress in a couple of videos,
with Raspberry Pi controlling an old machine’s motor. A
After his wife’s carefully preserved breast milk was ruined
by a freezer failure, along with three racks of ribs, Rick
system for
similar project by tom-2015, Washberry Pi, is detailed on
GitHub: magpi.cc/washberrypi.
was determined to create a smart alert system for his
fridge. Costing around $30, it uses a BME280 sensor to
his fridge ”
monitor the fridge or freezer’s temperature, linked via a
Maker: askDrAlex flat cable to a Raspberry Pi Zero W outside the appliance.
url: magpi.cc/washbearypi Data is reported to a web dashboard, and a high- RELATED
temperature alert text can be sent to a phone. PROJECTS
• Raspberry Pi baby
Maker: Rick Kuhlman
monitor magpi.cc/
url: magpi.cc/fridgemonitor
babycam

• Uber Home
Automation
Water Dispenser magpi.cc/uberhome

After calculating that he spent 15 hours a year filling water • Smart Waste Bin
bottles from his fridge’s painfully slow dispenser, Chris magpi.cc/smartbin

ThermOS Smart set about building an intelligent water dispenser. With a


Raspberry Pi 4 controlling a solenoid switch for a water • KDE Plasma

Thermostat pump, connected to the kitchen sink supply via a long


tube, it can automatically fill three sizes of water bottle.
Bigscreen TV
plasma-bigscreen.org
While smart thermostats are useful for controlling Housed in a sleek black 3D-printed casing, dubbed the
your central heating system remotely, they have a few ‘Hydrobot 5000’, it looks really cool too.
limitations and can be expensive. Needing a new smart
thermostat to replace the six old thermostats controlling Maker: Chris Courses
his complex home heating system, Joe opted to build url: magpi.cc/waterdispenser
his own powered by a
Raspberry Pi 4. Using the
HAP-Python HomeKit
Warning!
framework, he can control
Electrical Safety
his system’s six heat zones
for different rooms from his Please be careful when
working with electrical
iPhone. How cool, or hot, projects around the
is that? home. Especially if they
involve mains electricity.

magpi.cc/
Maker: Joe Truncale electricalsafety
url: magpi.cc/thermos

Raspberry Pi Smart Gadgets magpi.cc 31


FEATURE

Food and drink


I
f you want your Raspberry Pi to help you cook
a raspberry pie, or other dishes and beverages,
there’s a smart project for that.

HeaterMeter Barbecue “Hack a


If you want to be a true ‘pitmaster’, you’ll want to know
all about this open-source controller for your barbecue. standard
Thermistor, or thermocouple probes, are used to monitor
the grill, food, and ambient
fridge to
temperatures and adjust
the blower to maintain
convert it
the perfect cooking heat. into a smart
Raspberry Pi adds a
web interface and alarm fermentation
chamber ”
notifications, so you can sit
back and relax. You can buy
a ready-made HeaterMeter
OnionBot Sous Chef
board, or build your own Keen cook Ben found himself pondering how to
using the comprehensive automate simpler kitchen tasks, such as softening
online guide. onions, to save time and enable him to focus on
RELATED culinary creativity. His solution is a robot sous chef with

Maker: Bryan Mayland PROJECTS a Raspberry Pi brain. With a suspended thermal sensor
array to detect the temperature of the pan below, and a
url: magpi.cc/heatermeter • Picrowave Camera Module to help monitor cooking progress using
magpi.cc/picrowave machine learning, a servo motor controls the dial on the
induction stove.

BrewPi
• Tea-Pi magpi.cc/teapi

• Voice-Controlled
Maker: Ben Cobley
The key to successful beer brewing is to carefully control Coffee Machine
url: magpi.cc/onionbot
the fermentation temperature. The documentation on magpi.cc/voicecoffee
the BrewPi site shows how to hack a standard fridge to
convert it into a smart fermentation chamber by adding
a heater and sensors. A ready-made BrewPi Spark unit
• Chamber Sourdough
Incubator Smart Bartender
monitors and controls the temperature, connected to magpi.cc/chamber For the ultimate in luxury, you could hire your own
a Raspberry Pi which logs data and provides a web personal bartender. But it’s far cheaper to just make a
interface, but it’s possible to build your own DIY version. robotic one using Raspberry Pi. With the ability to mix up
You could even use BrewPi for sous vide-style cooking. to six ingredients together
at the same time, this one
Maker: Elco Jacobs can serve you anything from
url: brewpi.com a rum and coke to a Long
Island iced tea. You could
customise the device to
change ingredients and add
more drinks, or even link it up
to a voice assistant.

Maker: Hacker Shack


url: magpi.cc/bartender

32 magpi.cc Raspberry Pi Smart Gadgets


FEATURE

Pets and critters


W
hat could be better for your next pet project
than making a project for your pet? Or
maybe one to catch unwanted critters.

Cat Speedometer
These giant hamster wheels for cats are brilliant for
indoor exercise, but have you ever wondered how fast
your cat can run on one, and how far? Shawn decided to

Tweeting Cat Flap find out by fitting his wheel out with a Raspberry Pi Zero
and a reed switch base to sense the six magnets around
Cat flaps are ideal for letting your furry feline friend the wheel passing it. From this, distance, speed, and top
wander in and out of the house as it pleases – which, let’s speed can be calculated and logged. Shawn discovered
face it, is what cats do. But what if a flap could do more? his cats were running 4–6 miles a night, at up to 14 mph.
Since Daphne was already active on social media, mainly
to complain about her ‘staff’ Kate Bevan. Bernie Sumption Maker: Shawn Nunley
thought she deserved a more tech-savvy cat flap. The url: magpi.cc/catspeedo RELATED
result is a portal that tweets a photo and message every
time Daphne passes through it (@DaphneFlap).
PROJECTS
• Hamster Fitness
Maker: Bernie Sumption & Kate Bevan Tracker magpi.cc
url: magpi.cc/tweetcatflap /hamsterfitness

• RaspiTrap humane
mousetrap

Dog Translator magpi.cc/raspitrap

• Dog Treat Dispenser


Ever wondered what your dog is trying to tell you by
magpi.cc/dogtreat
barking? YouTuber NerdStoke has come up with the
solution (allegedly): a Dog Translator. His pet pooch • Cat Prey Detector
Nugget wears a harness with a microphone to pick up magpi.cc/catprey
his barks. A Raspberry Pi Zero then converts them into
human speech to be played back over speakers. OK, • BLE Cat Door
so the speech comprises prerecorded phrases played magpi.cc/blecatdoor
based on the time of day, but it’s a fun project and
easily customisable.

Maker: NerdStoke
url: magpi.cc/dogtranslator
IoT Kitteh “ The cat flap
Cats may wander miles around their neighbourhood. To tweets a
find out the location of his puss Lily, Jeremy invented a
vest to track her position using GPS. For communication photo and
purposes, he fitted it with a cellular connection. After
realising that a cat wouldn’t be able to answer the phone message
when called, he opted to send a message to the device
via AWS IoT and have it call him back automatically, as
every time
well as (perhaps more useful) sending GPS co-ordinates. Daphne
Maker: Jeremy Wall passes
url: magpi.cc/iotkitteh
through it ”

Raspberry Pi Smart Gadgets magpi.cc 33


FEATURE

Health and fitness


F “ It uses computer vision and machine learning
rom Fitbits to Peloton bikes, the world is
awash with smart gadgets to help you stay fit
and well, but why not exercise your mind by
making one?
to help track your HIIT workout progress ”

HIIT Personal Trainer


High-intensity interval training is a popular way to keep fit,
and James has created a clever system and web app to
enable you to train at home. It uses computer vision and RELATED
machine learning on Raspberry Pi to help track your HIIT
workout progress in real-time (at around 30 fps). It acts as
PROJECTS
an electronic referee, tracking the user’s detected poses • YogAI Smart Personal
and movements, and then scoring them. There’s even a Trainer magpi.cc/yogai
leaderboard so multiple users can compete.
• Smart Bottle

Shareable Smartbike Maker: James Wong


url: magpi.cc/hiitpi
magpi.cc/smartbottle

• SmartEdge Gym Buddy


Keanu wanted to track his cycling routes using GPS and
magpi.cc/gymbuddy
log his speed and ride length data. Rather than buying a
standard bike computer, he decided to create his own
• Gymnasticon
which would also turn the lights on and off automatically, Smart Bike
as he kept forgetting. It features a Raspberry Pi, Arduino, magpi.cc/gymnasticon
and lots of wiring. Since he wanted to be able to share
the bike without interfering with his own ride data, he also
added an RFID scanner to identify the rider.

Maker: Keanu Dav


url: magpi.cc/smartbike

RIoT Brick Run Tracker Smart Snoring Correction


Wanting to log his progress in the Brecon Beacons 10
Peaks ultramarathon, Alan created his own GPS run An estimated 25% of adults snore regularly, which
tracker in a 3D-printed case. As showcased in The MagPi can be a problem for them or their partner. Bryan and
magazine issue #93 (magpi.cc/93), the RIoT Brick Brayden have come up with a solution: a DIY device
enabled family and friends to access a web dashboard based around a Neosensory Buzz bracelet, normally
to track how he was used to alert people with hearing difficulties to doorbells
doing in the gruelling and alarms. A sound
endurance race. Powered inference base running on
by a 20,000 mAh battery Raspberry Pi recognises
pack, the Brick was also snoring sounds from a mic
equipped with numerous and sends a signal to the
sensors to log temperature, Buzz bracelet to wake the
humidity, pressure, altitude, user temporarily so they
and light level readings stop snoring.
along the route.
Maker: Bryan and
Maker: Alan Peaty Brayden Staley
url: magpi.cc/riotbrick url: magpi.cc/snoring

34 magpi.cc Raspberry Pi Smart Gadgets


FEATURE

Clothing and accessories


I
f you want to show off your new project, what
better way than to wear it? Or you may want a
better way to organise your clothes.

RELATED
Smart Wardrobe
Some people are
PROJECTS predicting that smart
• Pi Camera Cap wardrobes (aka closets)

Raspberry Pi Zero Prism magpi.cc/picameracap will be the next big thing


for the home, but Tan
While the original Google Glass never really took off, • Sock Matcher See Youu explored the
smart glasses are still a thing. Instead of forking out big magpi.cc/sockmatcher concept back in 2015 using
money for ready-made ones, however, it’s possible to a Raspberry Pi. The project
make your own. One inspiring example is Ricardo’s Prism, • CNC Embroidery includes an RFID reader to
Machine
which fits a Raspberry Pi Zero, Camera Module, and detect tags the user has
magpi.cc/cncembroidery
micro LCD into a 3D-printed wearable case, with a beam placed into every item of
splitter and convex lens to focus the HUD image. It can clothing in the wardrobe.
• Social Media without
do facial, image, and optical character recognition, as well the Internet (smart Once an item is registered,
as internet browsing. suit) magpi.cc it can be recognised and
/socialmediasuit the system will tell you, via
Maker: Ricardo Ferro an Android smartphone
url: magpi.cc/pizeroprism app, when you last wore it.

Smart Watch
“ F or the Maker: Tan See Youu
url: magpi.cc/smartwardrobe
ultimate
Smartwatches are incredibly popular and the swankier
in one-
models are often worn as a status symbol. For the
ultimate in one-upmanship, however, you could be
upmanship,
Multi-effects Guitar Pedal
wearing your own custom-created, one-of-a-kind watch. For those who like to wear an electric guitar, a DIY effects
That’s what Tyler did, creating his Smart Watch to impress you could pedal will make it sound even better. We’ve seen a
a friend at work. It comprises a Raspberry Pi Zero W
and LCD screen, housed in a 3D-printed case that he be wearing few based on Raspberry Pi, but Raphaël’s is incredible,
featuring a touchscreen and offering serious sonic
designed. With the addition of a tiny joystick and buttons,
it can even play Minecraft!
your own capabilities with an innovative method for combining
effects. It is able to digitally create a complex parallel
custom- signal chain: “Something like the modular synth version
Maker: Tyler Suard
url: magpi.cc/smartwatch created, of guitar pedals,” he says. No off-the-shelf pedal can do
anything like it.
one-of-a- Maker: Raphaël Isvelin
kind watch url: magpi.cc/guitarpedalyt

Raspberry Pi Smart Gadgets magpi.cc 35


Learn to Write Fast and Run Fast on Arm
Join Arm DevSummit
Virtual Event Live on October 19-21, 2021

OVER 140 AGENDA ITEMS ACROSS THESE SEVEN TRACKS:

• Cloud Native for the Endpoint, Edge and the Cloud

• The Future of Mobility is Software Defined

• Developing Interactive Consumer Experiences

• Practical Software Development for a Productive IoT

• AI in the Real World: From Development to Deployment

• Hardware Design Methodology

• Optimizing Arm Technology for PHC, Cloud and 5G Infrastructure

DON’T MISS THESE HOT WORKSHOPS FOCUSING ON PRACTICAL


SOFTWARE DEVELOPMENT FOR A PRODUCTIVE IOT:

• Introducing Keil® Studio and Cloud-based Development for IoT and


Embedded Applications

• Containers Over-The-Air: Building Your First Edge AI Device the Easy Way

• Ultra-Low Power Wi-Fi Made Easy – Develop a Battery Powered


Wi-Fi Sensor in Hours

Visit devsummit.arm.com to Register


TUTORIAL

Make retro noises


with Raspberry Pi
Recreate the sounds of the 16-bit computer
era with authentic vintage audio chips

T
he Yamaha OPL2 FM synthesis chip – also Raspberry Pi’s Serial Peripheral Interface (SPI)
known as the YM3812 – was a powerhouse to be active. Open a Terminal and type sudo
of 1980s and early 1990s digital audio. raspi‑config. Select option 3 ‘Interface options’,
Released in 1985, it appeared on the classic AdLib, then ‘P4 SPI’. Select Yes to enable it, then Finish.
K.G.
MAKER

Game Blaster, and early Sound Blaster cards, as You’ll also need the WiringPi library, but this
Orphanides
well as Yamaha’s own keyboards. These relatively comes installed by default on current versions
K.G. makes, writes inexpensive OPL2 sound cards soon found favour of Raspberry Pi OS and will be pulled down
about and helps to among PC game developers keen to make up for automatically during installation if it’s not found.
preserve unusual the limitations of the timer-controlled internal
gaming software
and hardware. PC speaker. In this project, we’re going to relive
the heady days of 1980s computer music by
@KGOrphanides
Install and test the software
connecting Cheerful Electronic’s OPL2 Audio
Board to Raspberry Pi’s GPIO, playing classic
03 Open a Terminal window and type:
game soundtrack files and programming a simple
controller to play your own tunes. git clone https://github.com/DhrBaksteen/
You’ll Need ArduinoOPL2.git
cd ArduinoOPL2
> O
 PL2 Audio Board sudo ./build
magpi.cc/opl2
Connect your OPL2 Audio Board
 PL2 board libraries
> O 01 Use a jumper cable to connect VCC on the If all dependencies are met, you’ll be asked to
magpi.cc/opl2lib OPL2 board to board pin 2 (5 V) of Raspberry Pi’s choose which of Cheerful’s boards you’re using.
> 3
 .5 mm to 3.5 mm GPIO. Connect GND to pin 6, A0 to pin 16 (GPIO 23), Select option 2 for the OPL2. Once built, the
stereo audio cable Data to 19 (GPIO 10), Latch to 15 (GPIO 22), Shift installer will show you a connection diagram. We’ve
 peaker with
> S to 23 and Reset to pin 13 (GPIO 27). The pins have
3.5 mm input changed through various iterations of the OPL2
> 7
 × female-female
board’s software, so check the documentation.
Dupont jumper Finally, use the 3.5 mm audio output on the board to
cables connect speakers or headphones. Powered speakers
are the best choice, as they’re less susceptible to
audible interference, but we’ve had no trouble using
headphones. For the sake of your ears, make sure
the board’s physical volume control is at minimum
before you start testing.

Set up Raspberry Pi
You can buy the OPL2
board as a kit to solder
02 We strongly recommend using a fresh install
together yourself of Raspberry Pi OS for this hardware project.
or, like us, as a fully
assembled item The OPL2 board controller software requires

38 magpi.cc Make retro noises with Raspberry Pi


TUTORIAL

Pin names are clearly


silkscreened on the OPL2
Audio Board’s PCB

The OPL2 board can be powered via a


3.3 V pin, but you’ll get more volume if you
connect it to 5 V, such as you’ll find on pin 2.

already wired up our board, but double-check that mousepad ~/.bashrc


against the pin numbers shown to make sure you’ve
used the ones it expects. Then paste that export PATH line in at the end of the
Make sure your speaker is connected and switched file and save.
on; enter Y to play the test tune. If you don’t
hear anything, check your volume control and GPIO
connections, then run the demotune executable in
Get ready to code
Top Tip
ArduinoOPL2/examples_pi/demotune/ to re-test.
05 The examples_pi directory contains handy
MIDI input
tools, libraries, and code examples that are worth
Play some tunes
04 The OPL2 board’s accompanying tools
looking at and playing with. They’re written in C++
and use the WiringPi library.
To receive input
from USB MIDI
include a command-line player for id Software’s Make a directory and copy the /examples_pi/ devices, RtMidi
IMF AdLib audio format, the VGZ and VGM formats demotune/midi_instruments.h file into it. This (magpi.cc/rtmidi)
is worth a look.
used to encode audio for AdLib cards, as well as the is a General MIDI instrument library based on one
OPL2 relatives in Sega’s consoles, and the DOSBox created by The Fat Man for the original AdLib card.
Raw OPL (DRO) audio format created to record OPL2 We’re going to write an extremely simple controller
and OPL3 output from DOS games. Some example application so we can play a monophonic tune live
files are included; others can be found online. using Raspberry Pi’s number keys. We’ll use ncurses
To try the player out with the Jill of the Jungle to detect key presses, so open a Terminal and type:
theme, open a Terminal and enter:
sudo apt-get install libncurses5-dev
cd ArduinoOPL2/examples_pi/opl2play libncursesw5-dev
./opl2play tunes/jill.vgz

If you want to be able to run the player from


anywhere, add it to your path by typing the
Make your own synth
following in the Terminal:
06 You can download the extended source
export PATH="$PATH:$HOME/Software/ code for this micro-project at magpi.cc/inputcpp.
ArduinoOPL2/examples_pi/opl2play/" Following along will guide you through key interface
documentation for the OPL2 board and some of its
To make that permanent, run: core features.

Make retro noises with Raspberry Pi magpi.cc 39


TUTORIAL

DOWNLOAD
THE FULL CODE:
input-print_version.cpp magpi.cc/opl2git
> Language: C++

001. #include <ncurses.h> /* remember to sudo apt-get 031. while (1) {


002. install libncurses5-dev libncursesw5-dev */ 032. if (kbhit()) {
003. #include <OPL2.h> 033. int key = getch();
004. #include <stdio.h> 034. if (key==49){
005. #include <wiringPi.h> 035. opl2.playNote(0, 5, NOTE_C);
006. #include "midi_instruments.h" 036. // Play note C-5 on channel 0
007. 037. } else if(key==50){
008. OPL2 opl2; 038. opl2.playNote(0, 5, NOTE_D);
009. 039. } else if(key==51){
010. int kbhit() 040. opl2.playNote(0, 5, NOTE_E);
011. { 041. } else if(key==52){
012. int ch = getch(); 042. opl2.playNote(0, 5, NOTE_F);
013. if (ch != ERR) { 043. } else if(key==53){
014. ungetch(ch); 044. opl2.playNote(0, 5, NOTE_G);
015. return 1; 045. } else if(key==54){
016. } else { 046. opl2.playNote(0, 5, NOTE_A);
017. return 0; 047. } else if(key==55){
018. } 048. opl2.playNote(0, 5, NOTE_B);
019. } 049. } else if(key==56){
020. 050. opl2.playNote(0, 6, NOTE_C);
021. int main(int argc, char **argv) { 051. } else if(key==57){
022. opl2.begin(); 052. opl2.playNote(0, 6, NOTE_D);
023. 053. } else if (key==48){
024. // Load a harpsichord instrument and assign 054 opl2.playNote(0, 6, NOTE_E);
it to channel 0. 055. }
025. Instrument harpsichord = 056. delay(500); // Hold the note for 500ms
opl2.loadInstrument(INSTRUMENT_HARPSIC); 057. opl2.setKeyOn(0, false); // Release
026. opl2.setInstrument(0, harpsichord); the note
027. 058. }
028. initscr(); 059. }
029. cbreak(); 061. }
030. scrollok(stdscr, TRUE);

We’re going to include the opl2 library and playNote function to specify the channel we wish to
instruments header file, capture keyboard input, set play a note on (0 in this case), its ISO octave number
an instrument, and associate specific keys on the (5), and the note we wish to play. Useful examples
keyboard with notes to be emitted by the sound card. and explanations can be found in the Working with
Open Geany (or your preferred syntax- Instruments (magpi.cc/workingwithinstruments)
highlighting text editor) on Raspberry Pi’s desktop entry in the OPL2 board’s documentation and
and create a file called input.cpp in the same the indepth.md file that comes with its libraries.
directory that you copied midi_instruments.h to. These include instructions for creating your
own instruments and setting sustain – download
input_sustain.cpp (at magpi.cc/inputsustaincpp)
to see how this could work with our sample code.
Find your voice
07 To see which instruments are available for
you to use, open midi_instruments.h and take
Cutting keys
a look through it. In our example code, we load a
harpsichord voice from midi_instruments.h and
08 We’re going to handle key press detection
set it to a channel. We then use the OPL2 library’s with a popular, if limited, approach to keyboard

40 magpi.cc Make retro noises with Raspberry Pi


TUTORIAL

OPL2 Audio Board to Raspberry Pi wiring guide

VCC
OPL2 board pin GND A0 Data Latch Shift Reset
(5V/3.3V)

Raspberry Pi GPIO pin


2 (5V) 6 16 19 15 23 13
(Board Numbering)

Raspberry Pi GPIO pin


5V GND 23 10 22 11 27
(BCM Numbering)

Ready to compile
character capture using getch() from the
ncurses library. It works here because we
10 With your code in place, it’s time to Top Tip
only want to play one note at a time and will compile input.cpp. The online version of the file
be fixing the duration of each note in code. A includes an extra routine to display which note Take it to
more sophisticated control application would you’ve played. the bank
benefit from the SDL library (magpi.cc/sdllib), Open a Terminal in the directory containing
particularly its handling of KEYUP events. midi_instruments.h and input.cpp. Raspberry Pi To create and
Once a keystroke has been captured, it’s OS comes with the GCC compiler already installed. import OPL2
instruments,
written to a variable called key. We’ve then used We’ll tell it to use the OPL2, WiringPi, and ncurses
try Wohlstand’s
a short series of if/else statements to have each libraries. Type: OPL3BankEditor
keycode invoke a note from the OPL2. magpi.cc/
gcc -std=c++11 -Wall -o input input.cpp opl3bank
-lOPL2 -lwiringPi -lncurses

Cracking the (key)code


09 We’ve used the number keys to provide
Then type ./input to try it out and make some
(slightly beepy, monophonic) music with
a control surface of just over an octave, not your number keys. Press CTRL+C to exit when
including semitones, on a standard Raspberry Pi you’re done.
keyboard. These tend to be the same across all
layouts, but other keys do not.
That’s because keycodes are based on
Further projects
character, not physical position, so an AZERTY
keyboard user will have trouble if software is
11 If you have an Arduino microcontroller,
hard-coded to use the WASD keys for movement. you can connect the OPL2 Audio Board to it to
To check the key numbering for your keyboard, transform the board into a DOSBox-X compatible
see the list at magpi.cc/javakeycodes or Sound Blaster 1.0 clone, which you can then
download, compile, and run keycheck.cpp (from connect to Raspberry Pi via USB. Connection
magpi.cc/keycheckcpp) to display the keycodes. and configuration instructions are provided
This is useful if you wish to increase the range at magpi.cc/opl2dosbox and you can find our
of your Raspberry Pi-powered instrument by comprehensive guide to running retro DOS games
assigning notes to more keys. using DOSBox-X at magpi.cc/dosemulation.

Make retro noises with Raspberry Pi magpi.cc 41


TUTORIAL

Ultimate home
Part 03

server: add sound


and vision
Turn your server into a media powerhouse with Plex and Mopidy

PJ Evans
MAKER

PJ is a writer,
software engineer,
and tinkerer. His
ambient music
collection has
been described
as “inspiring” (PJ
Create as many Plex provides a beautiful
Evans) and “just libraries as you like playback experience and
a load of random by dividing media won’t say a word about
noise” (Mrs Evans, into directories your musical taste
music teacher).

twitter.com/
mrpjevans

S
ound and vision is where we’re at for our (magpi.cc/109). We want to be sure our external
ultimate server project this month. Sure, drive is mounting on startup. Reboot and then issue
serving files is all very well (see The MagPi this one simple command in the terminal:
magazine issue #109, magpi.cc/109) but what
about a decent media interface? Luckily we’re spoilt df -h
for choice. We’re going to add two media serving
solutions, Plex and Mopidy, to our server. Plex is a The ‘df’ command is short for ‘disk free’ and
great choice for playing back your media anywhere shows you a summary of disk usage. If all is well,
in the world and Mopidy can turn your server into you’ll see the external drive (partition sdb1) mounted
a jukebox as well as a multi-room audio streaming to /mnt/huge (or whatever you decided to call the
system. We’ll also look at how to create your file mount point). If /mnt/huge does not appear in the
You’ll Need structure and how to add content from different list, refer back to the previous tutorial and make sure
sources. Let’s hit the play button. the entry in /etc/fstab is correct.
>R
 aspberry Pi
ultimate server
magpi.cc/108

Check, check, and check again Set up your library


01 02
>  Plex magpi.cc/plex

> Mopidy Before we plunge into the world of media Media streaming tends to involve a lot of
magpi.cc/mopidy streaming, let’s make sure your ultimate server is files. Before you find yourself in a mess, take some
correctly configured as per last month’s tutorial time to consider how you would like to structure

Ultimate home server: add sound and vision magpi.cc 43


TUTORIAL

your Raspberry Pi media system without issues. If


you want to get the best quality possible, consider
The command buying in FLAC format (no lossy compression)
df -h shows that the
from services such as HDTracks (hdtracks.com) or
external drive has
correctly mounted Qobuz (qobuz.com).

all your media. How you do this is up to you, but


when it comes to ripping CDs, many encoders such
Going to the movies
as abcde (A Better CD Encoder, magpi.cc/abcde)
will automatically rip to a given structure, so it can
04 Adding mainstream movies can be a bit
be helpful to plan this out now. See Figure 1 for challenging as there are no legal vendors of DRM-
an example of a well-laid-out file structure. Don’t free movies. However, you can use Plex’s own free
feel that you have to follow this – if you would streaming service to access content with a wide range

Top Tip prefer more complex (or simple!) divisions, that’s


completely up to you.
of (sometimes cheesy) movies to watch, as well as
video podcasts. You can also use plug-ins to access
all of YouTube. Of course, if you have a collection of
Quickly copy home movies, it’s a great way to get them up on the
your media big screen.
Add some sounds
Moving a lot of
media files over
03 Now we have lots of fast USB 3.0 space to
the network can play with, we can add some media that we’d like to
Let’s Plex!
be very time-
consuming. Luckily,
stream. This is a massive topic in itself, so we’ll just
give you some pointers here. You can now legally
05 We’re going to install Plex, one of the most
our USB drive
buy MP3s from many sources such as Amazon and popular media streaming services available. It
can be mounted
Apple. These are free from DRM (Digital Rights supports a dizzying array of file formats for both
onto the source
machine for super- Management), meaning you can play them back on audio and video. Plus, clever built-in transcoding
fast copying. systems mean it can compress on-the-fly to ensure
Remember, the the smoothest of playbacks. All with a very friendly,
host operating Figure 1 good-looking user interface. Installation takes a few
system will need steps, so follow the commands in the install_plex.sh
a driver that
listing to add Plex’s repository, update, and then
can understand
ext4 partitions. install and configure Plex. Once complete, we can
check Plex is running using this command:

sudo systemctl status plexmediaserver

You should see that Plex is ‘loaded’ and ‘active


(running)’. Press Q to exit and you’re ready
to configure!

First-time Plexing
06 When we installed Plex, it started a web
server on port 32400. So all you need to do is open a
web browser on another machine (or the server itself
if you’ve installed a desktop) and go to:

http://ultimate.local:32400/web
Figure 1 Here’s an
example of a sensible (Replace the server name if you didn’t use
directory structure
for your media files. ‘ultimate’ when setting it up in part 01 of this series.)
Remember to create What you should see now is the Plex welcome
it on your external
mounted drive screen. Be patient: it can take a few seconds on

44 magpi.cc Ultimate home server: add sound and vision


TUTORIAL

the first run. To get the best out of Plex, create a


free account as prompted using an authentication
provider such as Google or just your own
email address.

Initial setup
07 Plex will take you through a short wizard to
get things set up. Start by giving your Plex server
a name; we’ve chosen ‘ultimate’ to be consistent.
You can also opt for access to your Plex library from
anywhere on the internet. Plex will attempt to open
a port on our home router so you can access your
media from the plex.tv website. If you don’t want
to do this, ensure the checkbox is clear. Click ‘Next’
to start adding your libraries. One-by-one, select a
library ‘type’ (music, movies, etc.) when navigating
to the corresponding folder on your external drive;
Streaming to headless devices O
 nce Plex is installed,
e.g. for ‘Music’, use /mnt/huge/Media/Music.
10 One restriction of Plex is that it requires
you need to add
each directory and
specify what type of
a device with some kind of interface to work and media it contains
plays audio to that interface. If we wanted to play
Library management
08 Plex will now start scanning your folders for
audio on the ultimate server itself, or stream to
another Raspberry Pi computer that is connected to
content. It will also access online databases to add speakers, we need to use Mopidy, a purpose-built
metadata to its library to make your collection as audio streaming solution. Luckily, Plex and Mopidy
complete as possible. Depending on the size of your can live side-by-side and even share libraries. To
collection, this process will take anywhere between install Mopidy and its user interface, Iris, follow the
seconds and hours. It’s a background process though, commands in the install_mopidy.sh listing. Once
so you can start using Plex right away as your media complete, you can access the user interface here:
appears. You’ll also notice that Plex will also offer
you online content – you can disable this if you wish http://ultimate.local:6680/iris/
or sign up for a ‘Plex Pass’ for a lot more features. If
you don’t like what Plex has ‘found’ for your media
types, you can always click the pen icon and edit the
metadata; Plex doesn’t always get it right. install_plex.sh DOWNLOAD
THE FULL CODE:
> Language: Bash magpi.cc/installplexsh

Access it anywhere 001. #!/bin/sh


09 One of the great things about Plex is the
002.
003. # Plex's repository uses HTTPS as the transport, so we need to
availability of its client applications. Not only is there install support
a rock-solid web-based interface (which works great 004. sudo apt update
on Raspberry Pi OS’s Chromium) but support for a 005. sudo apt install apt-transport-https ca-certificates curl
wide range of devices including PlayStation, Xbox, 006.
007. # Get Plex's public key and add the Plex repo
Apple TV, Amazon Fire devices – and for mobile, iOS
008. curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt
and Android. If you created an account earlier, all you key add -
have to do is install the app and log in. Your ultimate 009. echo deb https://downloads.plex.tv/repo/deb public main | sudo
server will be detected and added. Now you can tee /etc/apt/sources.list.d/plexmediaserver.list
access and stream your media collection from any
010. # Install the server
location on the internet. 011. sudo apt update
012. sudo apt install plexmediaserver

Ultimate home server: add sound and vision magpi.cc 45


TUTORIAL

Mopidy is an
alternative to Plex,
designed for
local playback
and streaming

Warning!
Adding media to Mopidy
The laws covering the
ripping of CDs, DVDs
11 In the previous step we installed the
Add the following at the end of the file:

and Blu-rays vary from ‘local’ plugin, which allows Mopidy to access local [local]
country to country.
The private copying of file systems for media. One restriction is that it can media_dir = /mnt/huge/Media/Music
copyrighted material only support a single directory. Start by editing the
is illegal in the United
Kingdom. Check what config file: Remember to change this path if you’re using a
you want to do is legal different naming system or structure. Save the file
before proceeding!
sudo nano /etc/mopidy/mopidy.conf (CTRL+X), and instruct Mopidy to scan the contents,
magpi.cc/ripping
then restart:

sudo mopidyctl local scan


install_mopidy.sh DOWNLOAD sudo systemctl restart mopidy
THE FULL CODE:
> Language: Bash magpi.cc/installmopidysh Reload Mopidy in your web browser and the media
should be available. Now you can play music using
001. #!/bin/sh your server as the audio source should you wish.
002.
003. # Add Mopidy repo and install Advanced Mopidy
004. wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key 12 Now you have Mopidy installed, you can
add -
005. sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https:// upgrade to a few special features. Mopidy supports
apt.mopidy.com/buster.list a wealth of plug-ins and one of the most popular is
006. sudo apt update mopidy-spotify, which, you guessed it, turns Mopidy
007. sudo apt install mopidy
into a Spotify client (although you need a premium
008. sudo adduser mopidy video
009. account for this). Also, you can install Snapcast
010. # Configure (be careful with this line!) to create a synced multi-room audio system for a
011. printf "[http]\nhostname = 0.0.0.0" | sudo tee -a /etc/mopidy/ fraction of the price of solutions such as Sonos. For
mopidy.conf more detail and tutorials on all of this, check out The
012.
MagPi issues #96, #97, and #98.
013. # Install user interface
014. sudo apt install python3-pip
015. sudo pip3 install Mopidy-Iris
016. sudo pip3 install Mopidy-Local
017. sudo sh -c 'echo "mopidy ALL=NOPASSWD: /usr/local/lib/
python3.7/dist-packages/mopidy_iris/system.sh" >> /etc/sudoers'
Next time
018. In the fourth part of this series, we’re going to look at
019. # Enable and start service how Raspberry Pi OS can be put to work to make your
020. sudo systemctl enable mopidy network a better place. Access your files securely
021. sudo systemctl start mopidy from anywhere in the world, protect yourself from
tracking ads, and more.

46 magpi.cc Ultimate home server: add sound and vision


TUTORIAL

Stream viewer-
controlled projects
with Surrogate.TV
Want a new level of interaction in your livestreams? Add Surrogate.TV
to your Raspberry Pi projects for super low-latency audience control

I
f you cast your mind back many years, you use. If you’re using a Raspberry Pi Camera
you’ll remember the craze of Twitch Plays Module or HQ Camera, plug it in the usual way
Pokémon. Using inputs from the user chat, via the CSI port, with the silver connectors on the
Rob Zwetsloot a computer would play through the video game connector ribbon facing in the direction of the SD
MAKER

Pokémon Red, often with chaotic results. card slot.


Rob is amazing. He’s The popularity of these streams has resulted in For a USB webcam, Surrogate.TV recommends
also the Features
many similar ideas, whether directly or indirectly, using a USB 3.0 port if possible, which are the blue
Editor of The MagPi,
a hobbyist maker, and Surrogate.TV is one of these. Not only does ones in the middle of a Raspberry Pi 4.
cosplayer, comic it allow viewers to control what they see, what Before connecting it all up to your Raspberry Pi
book writer, and they see can be a full-on Raspberry Pi contraption projects, it’s a good idea to run through the basics
extremely modest.
like a painting robot or little fighting robots in in the rest of this tutorial first.
magpi.cc real life, with negligible latency. The features are
much more rich than in the past as well, so let’s
explore how to set up your own fun interactive
Flashing Surrogate image
projects on Surrogate.TV.
02 We’re going to use Raspberry Pi Imager
to create our SD card, which you can grab from
magpi.cc/imager. Once that’s installed on your
Y
 our game, as seen
Assemble your surrogate
from the dashboard,
when a Raspberry 01 A camera is essential for this project;
computer, download the Surrogate image (a .gz
file) from magpi.cc/surrogateimg, and then finally
Pi is set up and
switched on however, it doesn’t matter what kind of camera open the Imager application.
Click on Choose OS and select ‘Use custom’ from
the bottom of the list. From here, select the image
file you just downloaded. Now click on Choose
Storage and select the SD card you’d like to use.
Click on Write, then just wait for it to complete.
Don’t worry about starting it up yet, as we’ll
need to create a game for it to connect to first.

Starting with Surrogate.TV


03 You need to create an account at surrogate.tv
on another computer – we’ll trust you understand
how to set up an online account. Once that’s done

48 magpi.cc Stream viewer-controlled projects with Surrogate.TV


TUTORIAL

Games are interactive (and


very low-latency!) and can be
controlled using a queuing system

If your project already works in real life, it’s


easy to add code to hook it up to Surrogate

and you’re logged in, it’s time to create a ‘game’ – of your wireless network. Enter the SSID and
the kind of thing you’ll have viewers interact with password of your home network and leave the rest You’ll Need
via Raspberry Pi. Click on ‘Create a game’ and it will of the options. Click Connect; you will be kicked
> Raspberry Pi 4
give you a checklist of stuff you’ll need – make sure off Raspberry Pi as it turns the hotspot off and
you have your wireless details to hand, like it says, attempts to connect to your wireless network. > Surrogate image
file: magpi.cc/
and then press Start. Reconnect to your own home wireless network
surrogateimg
Give your game a temporary name and URL – from your computer. Go back to surrogate.tv and
these can be changed later, but for now it will help click ‘Skip to dashboard’, where you should be able > Raspberry Pi
Camera Module:
us get all set up. Click Next. to find and control your ‘game’/Raspberry Pi.
magpi.cc/camera

> Or a USB webcam

> Another computer


Connecting to Raspberry Pi If all is working, a yellow
04 Now you can plug in your Raspberry Pi -
with WiFi

you won’t need it connected to a monitor in this light should be showing next
part. From your other computer, copy the token
it displays, and then open your wireless settings to the controller name
and look for the hotspot that Raspberry Pi has
created – the SSID should be surrogate-rpi, and
Game testing
the password is surrogatetv.
When you’re connected to the hotspot from
06 If your Raspberry Pi doesn’t show up as a
Raspberry Pi, click Continue on your other controller in the Sets category, reboot Raspberry Pi Top Tip
computer. You will now be taken to a web page on and wait a few minutes. If that still doesn’t work, go
Raspberry Pi. back, reflash, and try again, double-checking your Compatibility
WiFi details.
If all is working, a yellow light should be showing The Surrogate
next to the controller name. If you click Preview, the image is based on
Raspberry Pi OS,
Set up Raspberry Pi
05 You should see a field to enter the token
camera you connected to Raspberry Pi should start
up and the feed will be displayed on screen.
so it should be no
problem to port
you copied in the previous step – paste it in and So far so good; now we need to check if the full your projects to it.
click Continue, and it will ask you to add the details system works and streams.

Stream viewer-controlled projects with Surrogate.TV magpi.cc 49


TUTORIAL

T
 he game loop allows Stream testing
you to see how the
game is working in
07 On the game we set up, there’s a toggle you
everything, there’s nothing really to do right now;
however, you can see how it will work by going
real time
can click labelled Enabled. Do that and the yellow back to the dashboard in a separate tab and see
icon should turn green. Toggle the Game Online how it shows the current state of the stream.
setting above this as well, and then click on ‘Go to
game’ on the left and it will give you the stream
interface, hopefully with your camera feed.
Game templates
This feed is the watcher stream, which has
some delay; however, if you click ‘Play now’ you’ll
09 Included in Surrogate.TV are some
be momentarily allowed into the game. This in- templates for games to check out, including
game stream is very low-latency – saving that a simple robot using a fairly cheap robot kit.
bandwidth for when you need it. Change your Raspberry Pi settings by going to
the dashboard and clicking on its name under
Controller. Change it from Simple Game to ‘bot’
from the drop-down list.
Going for a loop
08 You may have heard the term ‘game loop’ in
Following the instructions here, you can build
the robot and wire it up to the GPIO on Raspberry
regards to game design – breaking the interactive Pi in the correct way. Mount your Raspberry Pi to
part of the game down to its core. In this instance the robot, turn it on with a mobile power supply,
it’s fairly similar, but with audience participation and you’ll be immediately be able to play with the
it’s showing what a viewer will do when controlling robot from your computer.
a game. As we’ve set up a simple game to just test

Y ou can build the robot 10 Custom game setup


You can also create custom code for
and wire it up to the GPIO custom games that can control your own projects
(or different robots). It’s a good idea to get SSH
on Raspberry Pi started up on your Surrogate Raspberry Pi, so

50 magpi.cc Stream viewer-controlled projects with Surrogate.TV


TUTORIAL

hook up a monitor and keyboard to it. Login with you can link to other Python code to pass on C
 ontrolling simple
servos over
username pi and password creator1337, and then controls via the stream interface. the internet is
straightforward
type sudo raspi-config to open the command Otherwise, check out the handy tutorial with the right
line configuration tool. Go to Interfaces, SSH, and from Surrogate.TV (magpi.cc/customgame) bits of code and
Surrogate integration
enable it. for the basics you need on getting a fresh
Now is also a good time to change your script running. There’s also documentation
password by using sudo passwd pi. Before you for diving deeper in how to use Surrogate here:
disconnect the monitor and keyboard, type in magpi.cc/surrogatedocs.
hostname -I to get the IP address so you can SSH
in from your other computer.

Examples to try
12 If you don’t have a project in mind to hook
Custom game coding
11 In the case of the robot code from the
up, you can find some examples that might spark
your imagination at hackster.io/surrogatetv.
template, you’ll find it in games/bot/game.py in There’s some neat stuff involving robots and servos
the file structure of Raspberry Pi. Here you can to get you started. You can also check out some of
play around with the example code to see how it the games the Surrogate.TV folks stream on their
works. Of note is the Python library surrotg which website, as well as other users of the platform.

Top Tip
Playability
Make your game
engaging to
viewers by giving
them a high score
to go for!

T
 his simple robot can
be entirely controlled
via Surrogate using a
template code

Stream viewer-controlled projects with Surrogate.TV magpi.cc 51


TUTORIAL

Wireframe
This tutorial first appeared in
Wireframe, our sister magazine
that lifts the lid on the world of
video games. Every issue includes
tutorials and in‑depth interviews,
along with news and reviews of
the latest indie and triple-A games.
To find out more, visit their website
at wfmag.cc.
Check out their subscription offers
at wfmag.cc/subscribe.

Source Code

Recreate Gradius’s
AUTHOR
rock-spewing volcanoes
MARK VANSTONE Code an homage to Konami’s classic shoot-’em-up

R
eleased by Konami in 1985, to provide the variations of trajectory that updated, we move the rock upwards by its
Gradius – also known as we need our rocks to have. We’ll need an speed and then reduce the speed by 0.2.
Nemesis outside Japan – actor created for our spaceship and a list This will make it fly into the air, slow down,
brought a new breed of to hold our rock Actors. We can also make and then fall to the ground.
power-up system to arcades. a bullet Actor so we can make the ship fire From this code, we can make rocks
One of the keys to its success was the way lasers and shoot the rocks. We build up the appear just behind both of the volcanoes,
the player could customise their Vic Viper scene in layers in our draw() function with a and they’ll fly in a random direction
fighter craft by gathering capsules, which star-speckled background, then our rocks, upwards at a random speed. We can
could then be ‘spent’ on weapons, speed- followed by the foreground of volcanoes, increase or decrease the number of rocks
ups, and shields from a bar at the bottom and finally the spaceship and bullets. flying about by changing the random
of the screen. In the update() function, we need to numbers that spawn them. We should
A seminal side-scrolling shooter, Gradius handle moving the ship around with the be able to fly in and out of the rocks, but
was particularly striking thanks to the cursor keys. We can use a limit() function we could add some collision detection to
variety of its levels: a wide range of hazards to make sure it doesn’t go off the screen, check whether the rocks hit the ship – we
were thrown at the player, including waves and the SPACE bar to trigger the bullet to may also want to destroy the ship if it’s
of aliens, natural phenomena, and boss be fired. After that, we need to update our hit by a rock. In our sample, we have an
ships with engine cores that had to be rocks. At the start of the game our list of alternative, ‘shielded’ state to indicate
destroyed in order to progress. One of the rocks will be empty, so we’ll get a random that a collision has occurred. We can also
first stage’s biggest obstacles was a pair of number generated, and if the number is check for collisions with the bullets: if a
volcanoes that spewed deadly rocks into 1, we make a new rock and add it to the collision’s detected, we can make the rock
the air: the rocks could be shot for extra list. If we have more than 100 rocks in and the bullet disappear by moving them
points or just avoided to get through to our list, some of them will have moved off-screen, at which point they’re ready to
the next section. In this month’s Source off the screen, so we may as well reuse be reused.
Code, we’re going to have a look at how them instead of making more new rocks. That’s about it for this month’s sample,
to recreate the volcano-style flying rock During each update cycle, we’ll need to but there are many more elements from
obstacle from the game. run through our list of rocks and update the original game that you could add
Our sample uses Pygame Zero and the their position. When we make a rock, we yourself: extra weapons, more enemies, or
randint function from the random module give it a speed and direction, then when it’s even an area boss.

52 magpi.cc Recreate Galaxian's iconic attack patterns


TUTORIAL

Download

Vulcan Venture the code


from GitHub:
wfmag.cc/
Here’s Mark’s volcanic code. To get it working on your system, you’ll need to install Pygame Zero – wfmag52
full instructions are available at wfmag.cc/pgzero.

# Gradius if rocks[r].y < 800:


import pgzrun rocks[r].y -= rocks[r].speed
from random import randint rocks[r].x += rocks[r].dir
rocks[r].speed -= 0.2
jet = Actor(‘jet’,(400,300)) if jet.colliderect(rocks[r]):
bullet = Actor(‘bullet’, center=(850, 0)) shieldsUp = True
rocks = [] if bullet.colliderect(rocks[r]):
rocks[r].y = 800
def draw(): bullet.x = 850
screen.blit(“background”, (0, 0)) if shieldsUp == True:
drawRocks() jet.image = “jet2”
screen.blit(“foreground”, (0, 0)) else:
bullet.draw() jet.image = “jet”
jet.draw()
def getOldRock():
def update(): for r in range(0, len(rocks)):
if keyboard.up: jet.y = limit(jet.y-5,50,550) if rocks[r].y >= 800:
if keyboard.down: jet.y = limit(jet.y+5,50,550) return r
if keyboard.left: jet.x = limit(jet.x-5,10,790)
if keyboard.right: jet.x = limit(jet.x+5,10,790) pgzrun.go()
if keyboard.space :
if bullet.x >= 850 : bullet.pos = (jet.x,jet.y+5)
if bullet.x < 850: bullet.x += 20
updateRocks()

def limit(n, minn, maxn):


return max(min(maxn, n), minn)

def drawRocks():
for r in range(0, len(rocks)):
rocks[r].draw()

def makeRock(pos):
r = len(rocks)
if r < 100:
rocks.append(Actor(‘rock’+str(randint(1,3)), center=pos))
else:
r = getOldRock()
rocks[r].pos = pos
rocks[r].speed = randint(6,12)
rocks[r].dir = (randint(0,60)-30)/10

def updateRocks():
if randint(0,10) == 1: makeRock((215,480))
if randint(0,10) == 1: makeRock((540,480))
shieldsUp = False
The Gradius volcanoes spew rocks at the player just before

for r in range(0, len(rocks)): the end-of-level boss ship arrives.

Recreate Galaxian's iconic attack patterns magpi.cc 53


EoN
Pi NAS

VENTED
TUTORIAL

Create GUIs with Python:


Part 10

Stop-frame animation
Build your own stop-frame animated GIF creator

T
his project uses a Raspberry Pi Camera app = App(title="Stop frame animation")
Module and guizero to make a stop-frame
animation application (Figure 1). take_next_picture = PushButton(app,
To complete this project, you’ll need a Raspberry text="Take picture", command=capture_image)
Pi with an official Camera Module (or High Quality viewer = Picture(app)
Camera). If you need help connecting up the Camera
Module, take a look at the ‘Getting started with the app.display()
Camera Module’ guide at rpf.io/picamera.
Laura Sach
MAKER

You will need guizero installed with the optional Note that the higher the resolution, the greater the
Laura leads the ‘images’ functionality, which you can install by processing time. 400×400 is small but really quick
A Level team at running this command in the terminal: to process.
the Raspberry
The GUI contains a PushButton and Picture.
Pi Foundation,
creating resources pip3 install guizero[images] When the button is pressed, the capture_image
for students function is called. The function uses the camera
to learn about This project is broken down into stages: to capture an image and save it as frame.jpg. The
Computer Science.
picture is then displayed in the Picture widget.
@CodeBoom 1. Taking a picture with the camera and displaying Test the program (stopframe1.py, overleaf). When
it on a GUI you click the ‘Take picture‘ button, the image
2. Taking multiple pictures and saving them to a GIF should be displayed on the GUI (Figure 2).
3. Allowing the user to change the GIF
4. Tidying up the GUI Figure 1

Take a picture
Start by creating this program.

# Imports ---------------
Martin
MAKER

O’Hanlon from guizero import App, Picture, PushButton


from picamera import PiCamera
Martin works in
the learning team # Functions -------------
at the Raspberry
def capture_image():
Pi Foundation,
where he creates camera.capture("frame.jpg")
online courses, viewer.image = "frame.jpg"
projects, and
learning resources.
# Variables -------------
@martinohanlon camera = PiCamera(resolution="400x400")

# App ------------------- Figure 1 A simple stop-frame animation

Create GUIs with Python: Stop-frame animation magpi.cc 55


TUTORIAL

DOWNLOAD  n animation is made of


A
THE FULL CODE: multiple pictures, known
stopframe1.py magpi.cc/guizerocode
as frames
> Language: Python 3

001. # Imports --------------- Each time a new image is captured, you will need to
002. open it and append it to your list of frames:
003. from guizero import App, Picture, PushButton
004. from picamera import PiCamera
def capture_image():
005.
006. # Functions ------------- camera.capture("frame.jpg")
007. viewer.image = "frame.jpg"
008. def capture_image():
009. camera.capture("frame.jpg") frame = Image.open("frame.jpg")
010. viewer.image = "frame.jpg"
frames.append(frame)
011.
012. # App ------------------- total_frames.value = len(frames)
013.
014. app = App(title="Stop frame animation") The len (length) of the frames list is then used to
015.
update the text in total_frames.
016. camera = PiCamera(resolution="400x400")
017. take_next_picture = PushButton(app, text="Take picture", Your program should now look similar to
018. command=capture_image) stopmotion2.py. Test it and make sure the number
019. viewer = Picture(app) of frames increases each time you take a picture.
020. .
021. app.display()
Save as a GIF
You can PIL to save all the frames as one animated
GIF. Create a new save_animation function to save
Take multiple images and save to a GIF the frames as animation.gif.
An animation is made of multiple pictures,
known as frames. Each frame in the animation def save_animation():
will be slightly different to the last and when if len(frames) > 0:
played together at speed, the animation will viewer.show()
appear to move. frames[0].save(
In this step, you will change your GUI to keep a "animation.gif",
list of all the frames taken and use PIL (Python save_all=True,
Imaging Library) to save the frames as an animated append_images=frames[1:])
GIF which will be displayed in the viewer. viewer.image = "animation.gif"
At the top of your program, import the Image else:
module from PIL: viewer.hide()

from PIL import Image There is a lot happening here, but by breaking
down the code you see how this works. If the
Create a list to store the frames of your animation: number of frames in the list is greater than 0, then
the viewer is shown, otherwise it is hidden.
frames = []
if len(frames) > 0:
To keep track of how many frames have been viewer.show()
taken, import a Text widget, add it to your app, ...
and set it to 0. else:
viewer.hide()
from guizero import App, Picture,
PushButton, Text The frames are then saved to a file called
animation.gif. The first frame (frames[0]) is saved,
total_frames = Text(app, text="0") the remaining frames (frames[1:]) are appended,
and all are saved to the animated GIF.

56 magpi.cc Create GUIs with Python: Stop-frame animation


TUTORIAL

Figure 2

frames[0].save(
"animation.gif",
save_all=True,
append_images=frames[1:])

The animation.gif is then shown on the viewer.

viewer.image = "animation.gif"

Call the save_animation function at the end of


the capture_image function to create and display
the animation.

def capture_image():
camera.capture("frame.jpg")
viewer.image = "frame.jpg"

save_animation()

Figure 2 Take a picture


Your code should now be similar to stopframe3.py

stopframe2.py
(overleaf). Test it out.

Delete the last frame


> Language: Python 3 At the moment, if you make a mistake while
creating your animated GIF, you have to start again
001. # Imports --------------- from the beginning.
002.
You should modify your GUI to allow the last
003. from guizero import App, Picture, PushButton, Text
004. from picamera import PiCamera frame taken to be deleted, so if a mistake is made
005. from PIL import Image you can undo the change.
006. Create a new function which will remove or
007. # Functions ------------- pop the last frame from the list, save the changed
008.
animation and then display it.
009. def capture_image():
010. camera.capture("frame.jpg")
011. viewer.image = "frame.jpg" def delete_frame():
012. if len(frames) > 0:
013. frame = Image.open("frame.jpg")
frames.pop()
014. frames.append(frame)
015. total_frames.value = len(frames) total_frames.value = len(frames)
016.
017. # Variables ------------- save_animation()
018.
019. frames = []
The length of the frames list is checked before
020.
021. camera = PiCamera(resolution="400x400") attempting to pop the last item. An error would be
022. raised if you tried to pop an item from an empty list.
023. # App ------------------- Add a PushButton to the GUI to call the
024.
delete_frame function, by inserting this code:
025. app = App(title="Stop frame animation")
026.
027. total_frames = Text(app, text="0") delete_last_picture = PushButton(controls,
028. take_next_picture = PushButton(app, text="Take picture", align="left", text="Delete last",
029. command=capture_image) command=delete_frame)
030. viewer = Picture(app)
031.
032. app.display() Note: You could also modify the GUI to allow you to
delete any frame, not just the last one.

Create GUIs with Python: Stop-frame animation magpi.cc 57


TUTORIAL

stopframe3.py
> Language: Python 3

001. # Imports --------------- 024. save_all=True,


002. 025. append_images=frames[1:])
003. from guizero import App, Picture, PushButton, Text 026. viewer.image = "animation.gif"
004. from picamera import PiCamera 027. else:
005. from PIL import Image 028. viewer.hide()
006. 029.
007. # Functions ------------- 030. # Variables -------------
008. 031.
009. def capture_image(): 032. frames = []
010. camera.capture("frame.jpg") 033.
011. viewer.image = "frame.jpg" 034. camera = PiCamera(resolution="400x400")
012. 035.
013. frame = Image.open("frame.jpg") 036. # App -------------------
014. frames.append(frame) 037.
015. total_frames.value = len(frames) 038. app = App(title="Stop frame animation")
016. 039.
017. save_animation() 040. total_frames = Text(app, text="0")
018. 041. take_next_picture = PushButton(app, text="Take
019. def save_animation(): 042. picture", command=capture_image)
020. if len(frames) > 0: 043.
021. viewer.show() 044. viewer = Picture(app)
022. frames[0].save( 045.
023. "animation.gif", 046. app.display()

Changing the timing E ach frame is displayed


Each frame is displayed for the default duration
time of 100 milliseconds. Include a Slider widget
in your GUI to allow the duration to be changed.
for the default duration
Add it to the list of imports. time of 100 milliseconds
from guizero import App, Picture,
PushButton, Text, Slider Figure 3

Then create the widget in the app.

Text(app, text="Duration")
duration = Slider(app, start=100, end=1000,
command=save_animation)

The start and end parameters will be the


minimum and maximum times you can set for the
frame duration.
Each time the slider is changed, the
save_animation function will be run.
Update the save_animation function to use the
duration value when saving the GIF.

frames[0].save(
"animation.gif",
save_all=True,
append_images=frames[1:],
duration=duration.value) Figure 3 Controls stacked at the top

58 magpi.cc Create GUIs with Python: Stop-frame animation


TUTORIAL

stopframe4.py
> Language: Python 3

001. # Imports --------------- 031.


002. 032. def delete_frame():
003. from guizero import App, Picture, PushButton, Text, 033. if len(frames) > 0:
004. Slider 034. frames.pop()
005. from picamera import PiCamera 035. total_frames.value = len(frames)
006. from PIL import Image 036.
007. 037. save_animation()
008. # Functions ------------- 038.
009. 039. # Variables -------------
010. def capture_image(): 040.
011. camera.capture("frame.jpg") 041. frames = []
012. viewer.image = "frame.jpg" 042.
013. 043. camera = PiCamera(resolution="400x400")
014. frame = Image.open("frame.jpg") 044.
015. frames.append(frame) 045. # App -------------------
016. total_frames.value = len(frames) 046.
017. 047. app = App(title="Stop frame animation")
018. save_animation() 048.
019. 049. total_frames = Text(app, text="0")
020. def save_animation(): 050. take_next_picture = PushButton(app,
021. if len(frames) > 0: text="Take picture", command=capture_image)
022. viewer.show() 051. delete_last_picture = PushButton(app,
023. frames[0].save( text="Delete last", command=delete_frame)
024. "animation.gif", 052. Text(app, text="Duration")
025. save_all=True, 053. duration = Slider(app, start=100, end=1000,
026. append_images=frames[1:], command=save_animation)
027. duration=duration.value) 054.
028. viewer.image = "animation.gif" 055. viewer = Picture(app)
029. else: 056.
030. viewer.hide() 057. app.display()

Your code should now resemble stopmotion4.py. Aligning widgets to the left inside the box will
Try it out. make them stack up next to each other.
Repeat this for rest of the controls so they are
Align the controls all put into the top box and lined up next to
At the moment, the controls are taking up a lot of each other.
room stacked at the top of the GUI (Figure 3). Your complete program should look similar to
Create a Box and align it to the top of the GUI to 11-stop-motion.py (overleaf).
hold the controls, first adding it to the imports.
Create Graphical User
from guizero import App, Picture, Interfaces with Python
PushButton, Text, Slider, Box
For further tutorials on how
controls = Box(app, align="top") to make your own GUIs with
guizero, take a look at our
book, Create Graphical User
Modify the widgets so that they are in the
Interfaces with Python. Its
controls box and set the align parameter to 156 pages are packed with
"left". For example: essential info and a range of
exciting projects.
total_frames = Text(controls, text="0", magpi.cc/pythongui
align="left")

Create GUIs with Python: Stop-frame animation magpi.cc 59


TUTORIAL

11-stopmotion.py
> Language: Python 3

001. # Imports --------------- 032. def delete_frame():


002. 033. if len(frames) > 0:
003. from guizero import App, Picture, PushButton, Text, 034. frames.pop()
004. Slider, Box 035. total_frames.value = len(frames)
005. from picamera import PiCamera 036.
006. from PIL import Image 037. save_animation()
007. 038.
008. # Functions ------------- 039. # Variables -------------
009. 040.
010. def capture_image(): 041. frames = []
011. camera.capture("frame.jpg") 042.
012. viewer.image = "frame.jpg" 043. camera = PiCamera(resolution="400x400")
013. 044.
014. frame = Image.open("frame.jpg") 045. # App -------------------
015. frames.append(frame) 046.
016. total_frames.value = len(frames) 047. app = App(title="Stop frame animation")
017. 048.
018. save_animation() 049. controls = Box(app, align="top")
019. 050. total_frames = Text(controls, text="0", align="left")
020. def save_animation(): 051. take_next_picture = PushButton(controls, align="left",
021. if len(frames) > 0: text="Take picture", command=capture_image)
022. viewer.show() 052. delete_last_picture = PushButton(controls,
023. frames[0].save( align="left", text="Delete last", command=delete_
024. "animation.gif", frame)
025. save_all=True, 053. Text(controls, align="left", text="Duration")
026. append_images=frames[1:], 054. duration = Slider(controls, align="left", start=100,
027. duration=duration.value) 055. end=1000, command=save_animation)
028. viewer.image = "animation.gif" 056.
029. else: 057. viewer = Picture(app)
030. viewer.hide() 058.
031. 059. app.display()

Laura Sach
Create graphical

60 magpi.cc Create GUIs with Python: Stop-frame animation


Robotics & rapid prototyping
with your Raspberry Pi
Power your projects with computer vision and applied AI
pi-top [4] Robotics Kit comes with electronic components such as a wide-angle
camera, servos and motors, all of which plug and play with the pi-top [4]
Complete or pi-top [4] DIY Edition†.
pi-top Robotics Kit with Expansion Plate
£187.90 / $199.90

Gesture Obstacle Autonomous


Control Avoidance Driving

Object Emotion Line


Recognition Mapping Recognition
Verdict:

10/10
Face
Interaction
Tracking

pi-top.com/MagPi
Raspberry Pi is a trademark of the Raspberry Pi Foundation. †pi-top [4] and Robotics Kit with Expansion Plate sold separately. © CEED Ltd. 2021

Raspberry Pi made simple, robust and modular.


TUTORIAL

Build an Android
tablet with Raspberry Pi
Emteria.OS is a version of Android for Raspberry Pi. Let’s use
it in its natural, portable environment, and use it for development

A
Build your tablet – part 1
ndroid on Raspberry Pi has been a topic
of discussion for years in specific spaces,
02 To make sure everything is working
and while there have been attempts in before fully committing to our build, we suggest
Rob Zwetsloot
MAKER

the past to port Android, emteria.OS has been just connecting Raspberry Pi 4 to the display at
the best way to use Android on Raspberry Pi for first. You may need to construct your screen,
Rob is amazing. He’s a few years now. With some recent great updates, however that is quite simple and there are full
also the Features
Editor of The MagPi, we’re revisiting this great OS to get it working as instructions here: magpi.cc/screenbuild.
a hobbyist maker, an Android tablet, and see how it can be used for You do not need to add the jumper wires between
cosplayer, comic Android dev. the control board and Raspberry Pi though, as you
book writer, and
will need to power Raspberry Pi and the display
extremely modest.
separately. You can use the special USB splitter
magpi.cc
cable that came with the SmartiPi Touch 2 case if
Raspberry Pi hardware
01 you wish to make it easier down the road, however

Top Tip You’ll need a Raspberry Pi 4 for this


project so that you can make the most out of your
you will at least need a micro USB power supply
and a USB C power supply.
custom tablet, although you can use a Raspberry
Installer issues
Pi 3B+, Raspberry Pi 400, and Compute Module
Run the installer 3 with emteria. Emteria also supports HDMI on
emteria.OS Installer
as Administrator
if you’re having
Raspberry Pi so you can connect it to a monitor,
TV, or other kind of small display depending on if
03 You’ll need to create an account for emteria.
issues, and check you want to use it as a tablet for development. OS, which you can do at emteria.com. Once you’ve
if the SD card runs,
With an official touchscreen, you can cut down done that, you can head to the download page
even if the final
on some wires and have it work in a traditional at magpi.cc/emteriainstaller and download the
checks fail.
Android way. installer. Run the program once it’s downloaded to

62 magpi.cc Build an Android tablet with Raspberry Pi


TUTORIAL

Emteria is a version of Android


that can run on Raspberry Pi
and other hardware

Using a touchscreen and


case, you can create your own
Android tablet using emteria

install – you may need to tell Windows to ‘run the and keyboard if you want to run through the
software anyway’ if a warning window pops up. process a little quicker. After setting your time You’ll Need
Once this is done, open the Emteria installer app, zone time, and date, you then need to select your
and you will be asked to login using the account WiFi network to connect to. Once again, if you’ve > Raspberry Pi 4

details you created earlier. From there, select your used Android this should be familiar. > Raspberry Pi Official
hardware (Raspberry Pi 4), choose the right SD card Now you need to activate your install (although Touchscreen
if you have multiple plugged in, and then click flash you can test it out for eight hours before doing Display magpi.cc/
officialdisplay
for the installer to do its job. this). We logged in via our account, but you can
enter a key if that’s easier for you. Skip the next > SmartiPi 2
Touch Case
two steps, agree to the EULA, and hit reboot for
magpi.cc/smartipi2
everything to be applied.
Initial emteria.OS boot > emteria.OS
04 Once the install has finished, plug your
emteria.com

SD card into your Raspberry Pi connected to the > Mobile battery


Build the tablet – part 2
touchscreen. Put the power in for the screen (the
micro USB on the controller board), and then plug
06 If installation and setup went fine, you
the power into Raspberry Pi 4. can install your Raspberry Pi and screen into the
It will cycle through the boot a few times before SmartiPi case. Once again there is a handy build
finally showing the emteria logo pulsing – after a guide on how to do this: magpi.cc/smartipibuild.
while this will transition to a grey screen and do At this point you can add a Raspberry Pi Camera
some set up before allowing you to click on next, Module to the whole case build, however at the
where you’ll perform the classic Android setup.

It will cycle through the


Initial emteria.OS setup boot a few times before finally
05 The touchscreen will be working at this
point, however you can always connect a mouse showing the emteria logo

Build an Android tablet with Raspberry Pi magpi.cc 63


TUTORIAL

A
 ffixing Raspberry Pi to time of writing it is not supported in the OS. The for this stage), along with other settings for remote
the back of the official
touchscreen requires emteria team are working on it though, and some work, Ethernet connections, launching apps at
only screws and a DSI USB webcams are supported right now, so if you’re boot, etc.
ribbon cable
desperate to take photos there are ways.

One of the great features


Top Tip Install extra software of emteria is its ability to
07
Sideloading
As emteria is not an official version of
Android, you’ll not have access to the standard
act as a kiosk
Sideloading is Play Store. You can still sideload APK files if you
when you install download files to the device though, and there is
an Android app F-Droid which is a free and open-source app store
from its standard Other Android differences
APK file – you’ll
for Android. Opening up this app will prompt you
to do an update before installing any apps, just
09 While many parts of emteria work like
have to switch on
like you would on the Play Store. You will have to stock Android, there are a few differences that are
a setting to allow
installing apps allow it to install third-party apps from the system worth noting. First of all, as there is no dedicated
this way though. settings, which it will help you do. off button on a Raspberry Pi, you’ll find there is a
shutdown app in the library that allows you to turn
off, reboot, and head to recovery. The browser is
not Chrome, and other default apps are swapped
Advanced settings
08 You’ve probably noticed that the tablet is
with non-Google based ones. You can still login
to Google services using the browser though, and
currently set to landscape. With no gyro inside, there are other browsers you can try as well.
you cannot automatically change the orientation.
Bringing up the emteria settings allows you change
the orientation to portrait (90 degrees), or even
Kiosk mode
flip the entire screen over (180 degrees). You’ll also
notice there are a load of the developer settings
10 One of the great features of emteria is its
sitting in here, such as keeping the screen awake ability to act as a kiosk – a terminal with limited
(useful if you have it plugged into a power supply functions that you set yourself. It’s meant for more

64 magpi.cc Build an Android tablet with Raspberry Pi


TUTORIAL

A
 ndroid Studio is the
development suite
for Android apps

C
 hoosing specific
apps that can only be
used in Kiosk mode
can be great for kids
or cafés

public places that might require people to sign


up to a service, or get directions in a large area.
To turn it on, go to the emteria settings and
toggle Kiosk state. Set a password so you can
turn it back off, and then select Kiosk or Web
launcher. In Kiosk launcher you can choose
‘approved apps’, which will be the only apps
the users can use. Similarly, web launcher sets
a selection of bookmarked websites that are
the only ones that can be visited. Tapping ten
times on the screen will bring back the Kiosk
settings menu.

Portability
11 As well as a portable battery, taking a
power supply with you can also work in case
you stop in a place with power. SmartiPi Touch
2 also has a stand, making it easier to use on
the go as well, however it does mean it’s not E
 mteria uses a specific
program, much like Imager,
quite as slim when folded up – the stand part to burn the latest version of
can actually be removed with a screw to cut the OS to an SD card
down on this size, making the whole thing a
little easier to take with you.

Development tips
12 Emteria is based on the latest version
of Android – Android 11 – making it a great
development environment for Android apps.
Even just connecting it to a monitor, or using
the VNC functions, will allow you to test out
apps you’re creating.
Heading to developer.android.com will give
you some great beginner tutorials and sample
code on how to start, as well as the tools
needed to build apps.

Build an Android tablet with Raspberry Pi magpi.cc 65


200 PAGES OF RASPBERRY PI
QuickStart guide to setting up The very best projects built by
your Raspberry Pi computer your Raspberry Pi community

Updated with Raspberry Pi Pico Discover incredible kit and


and all the latest kit tutorials for your projects

Buy online: magpi.cc/store


FEATURE

p o ok
S up your
Rasp berr y P i
r a d e s f o r your
pg
Unnervinegsturian projects
ped

A
s dusk draws nearer and the days get
colder, we approach the most frightful
night of the year, where ghouls and
ghosts come out to play and witches and
werewolves can be heard in the distance. While
we can’t help you repel these repugnant ruffians,
we can enable you join them with some blood-
curdling builds.
This year we’re going to help you take your
regular projects and make them scary, allowing
you to save some time and put on the perfect
Halloween party. Read on, if you dare…

68 magpi.cc Spook up your Raspberry Pi


FEATURE

Malic ious
ag ic M irror
M
Add a serious scare to your
smart mirror – visitors beware!

M
agic mirror projects are very cool and
very practical, and also completely
terrifying if you program them to give
jump scares. When we first covered them in the
December 2016 issue, creator Bradley Melton
was already adding scary pictures to replace the
inspirational quotes.
Sadly, this module was never released for the
Magic Mirror system (magicmirror.builders), but
you can get a nice little module that adds seasonal
lights here: magpi.cc/mmlights.
If you do want to add something truly scary to
your existing magic mirror, though, look no further
than Charles Gantt’s ‘spooky surprise’ tutorial
here: magpi.cc/spookymirror. It has details on
how to add your own PIR sensor, and instructions
on how to program your mirror to do the scares.

Mirror in motion
How the motion sensing works in practice

Spook up your Raspberry Pi magpi.cc 69


FEATURE

Sho ck ing
nt a Detector
Sa
Go from ho ho ho to no no no
with this motion-sensing trap
– give it a go!
A new look
Instead of jolly old Saint Nick, we want a scary photo. We found this picture

T
he Santa Detector is a classic project from of a skull on black that is sure to give anyone the heeby jeebys. You can use
the Raspberry Pi Foundation, making use any other picture you like, or draw one yourself. To add a picture to Scratch,
of a PIR motion sensor hooked up to some go to the costumes tab, hover over the circle ‘Choose a Costume’ button at
Scratch code so you can find out when Big Red the bottom, and select upload costume. Delete the other costumes.
has arrived. Instead of Santa, though, what if it
just detected any passer-by to give them a fright?
Upgrading this project for our uses is fairly
simple. Instead of flashing a picture of Santa, we
can replace it with a scary picture. We can also add
a scream sound effect to Scratch to go with the
picture. Lastly, we’ll have to camouflage it so it can

1
reach the maximum number of people for a scare.

magpi.cc/santadetector

We all
scream
From our repository of spooky upgrades,
you will find a file called Wilhelm_scream.
mp3. In the Sounds tab, hover over the round
button at the bottom, and click Upload File
to upload this new scary scream to your
project. In the code, replace ‘whoop’ in the
play sound block with ‘Wilhelm_scream’.
2
70 magpi.cc Spook up your Raspberry Pi
FEATURE

Similarly spooky
Possessed portrait
This seemingly normal painting is actually a
monitor in a frame with a little PIR motion sensor,
activating an animation of the portrait screaming
at passers-by. It’s the same concept as the Santa
detector on a grander scale.
D ow n l o a
i m ag e s a d n e w magpi.cc/possessedpic
n
from ma d code
g
spookyu pi.cc/
pgrades

Hidden
from sight
When hiding your PIR sensor, you can go simple or advanced. We
like the simple method of secreting ours on a shelf nestled among
3
figures or DVDs. Make sure the monitor is visible to anyone who will
be passing by your hiding spot. If you want to go advanced, there are
some nice PIR cases you can print from Thingiverse. Haunted Jack in the Box
Instead of a PIR motion sensor, this project uses
a Raspberry Pi Camera Module to detect when
someone is specifically looking at it, setting off
an automated Jack-in-the-box with variable
speeds and sounds for maximum frights.

magpi.cc/hauntedjack

Spook up your Raspberry Pi magpi.cc 71


FEATURE

Frigh ten in g D ow n l o
i m ag e s a d n e w
a
from m nd code

h
s p o o k y ag p i . c c /

o ot
upgrad

o B
es

Ph ot
Create eerie images with these
cunning code tweaks – fun for Awful accessories
all ages! It’s quite simple to switch out the overlays for spooky props – simply add
any images you have (or ones from our repository) to the overlays folder of

A
familiar sight at official Raspberry Pi your All-Seeing Pi code. They should be PNG files with transparency. Give
events, the All-Seeing Pi is a fun photo them simple file names and then head to overlay_functions.py and change
booth that lets you add stickers to photos the contents of the overlays list to the names of the new images; e.g.,
of yourself and tweet them out into the world.
It’s a fun thing to replicate at parties and other overlays = ['witchhat', 'fangs', 'catears'].
kinds of events, including perhaps an upcoming
Halloween party of your own.

1
To make this appropriately alarming, a first
step will be to change the overlays from fun
sunglasses and wigs to fangs and witches’ hats.
We can add an extra, basic overlay filter with a
little trick as well.

magpi.cc/allseeingpi

Similarly spooky
Creepy Face Stomach shot
Tracking Portrait Freak out your friends by
making your camera and screen
Using a camera and a screen in a
portable so that you can see
much different way – to change
through yourself for the perfect
a creepy face so that it’s always
zombie costume.
looking at you. Always.

magpi.cc/stomachshot
magpi.cc/trackingportrait

72 magpi.cc Spook up your Raspberry Pi


FEATURE

Fearful filters
We’re going to cheat a bit here to make some filters. Draw or
find some photo borders with a clear centre and open them in a
photo editing program. Add a layer below the border and fill it in
with a light green or a light brown colour. Reduce the opacity of
the coloured layer to 30% and voilà, instant filter. Test it with a
photo on the layer below the border and colour to make sure it’s
2
what you want, and then save it to the overlays folder as before,
updating the list in overlay_functions.py. Alternatively, we’ve
created some you can use.

“I t ’
c
s
a
a
t e
f u
a
n
t
thing to
pa r t i e s
3
rep l i
kinds
and other
of events “ Double trouble
If you add an extra button to your All-Seeing Pi, you can have both the filters
and props show up at once. Create a separate folder for the filters called
filters and then copy the overlay_functions.py file to this folder, renaming it
filter_functions.py. Update the code inside with the new folder location name,
and change the overlays list to filters. Update allseeingpi.py by adding:

from filter_functions import *

Follow the steps in the All-Seeing Pi tutorial to add the extra filters to the
images you take. There’s also a version of that code in our repository.

Spook up your Raspberry Pi magpi.cc 73


FEATURE

Das ta r dl y
p l ay Li ghting
Dis
Go from everyday LEDs to
haunted Halloween colours –
hang them from trees!

T
he amazing temperature-controlled
stair lights by Lorraine Underwood
(@LmcUnderwood) are a great way to set up
decorative lights anywhere – they don’t just need
to be on stairs. They also don’t have to be a rainbow.
We have a couple of options here to make it a
little more Halloween-themed, and that’s mainly
down to the colour palettes of the lights. Think
oranges, greens, and purples, classic colours for this
spooky time of the year.

magpi.cc/tempstairs Eerie RGB


NeoPixel lights use an RGB colour scale, assigning the red, green,
and blue elements an intensity value from 0 to 255. For example, a
ghastly green would be (0, 255, 0). For purple and orange, we need a
specific mix: purple is (128, 0, 128) and orange is (255, 140, 0). You
can also cheat for black by setting some LEDs to (0, 0, 0)
1
Terrifying
temperatures
The original aim of the project was to help you figure out the
temperature. You can still do that with this version if you wish,
switching out the original colours for our spooky ones. We
suggest orange for a colder colour, then green, and finally purple
2
for a warmer temperature.

74 magpi.cc Spook up your Raspberry Pi


FEATURE

“ Go all out an
d e c o r at e y o u r
d
h o m e w it h
l ig h t s a n d m u
s ic p o w e r e d
by Raspberry
Pi

Mysterious
music
You can have music dictate how your lights
move using LightShow Pi from Adafruit
(magpi.cc/lightshowpi). Even if you’re not going to
play the music, you can still use some tracks to help
randomise and animate your display – quicker than
programming it yourself.
3
Similarly spooky
Poplawski’s Holiday Lights
With an evergrowing selection of decorations, the
Poplawskis not only make their front porch spooky, they let
you control it over the internet.

magpi.cc/poplawski

Raspberry Pi Halloween
Lights and Music Show
Go all out and decorate your home with lights and music
powered by Raspberry Pi. We’ve also seen people hack
cheap projectors in recent years for this as well...

magpi.cc/hallolightsmusic

Spook up your Raspberry Pi magpi.cc 75


REVIEW

Keybow 2040
Pimoroni magpi.cc/keybow £50 / $57

An RP2040-based auxiliary keyboard for macros, samples,


and streams. Rob Zwetsloot gives them a tickle

E
ver since the release of Raspberry Pi swap them out for others if you’d like. There’s
SPECS Pico, we’ve been interested in its ability also a cheaper base kit for which you’ll need to
to power keyboards, both standard and provide your own switches and keycaps.
KEYS: custom. We’ve seen a couple of DIY projects
16 RGB LED
swappable
doing just this, and Pimoroni even released Lock on
keys in a 4×4 an add-on with a soft keys (RGB Keypad: Some construction is required, but it’s very
grid with magpi.cc/rgbkeypad) for Pico at its launch. It minimal – add the switches, sandwich the layers
mechanical, was only a matter of time before the RP2040 – together, and then put the keys on. We were
linear, and
the chip that powers Pico – would be used on done in a couple minutes, at which point you can
tactile key
options its own dedicated keypad with real keys. This actually start using the Keybow as a number pad
inevitable product ended up being another by plugging it in.
MICRO Pimoroni product: Keybow 2040. Unlike a standard Pico, the Keybow is
CONTROLLER: It comes with one of three sets of key switch connected via a USB-C cable to your computer of
RP2040 with
2MB of flash types depending on your preference: mechanical choice. There doesn’t seem to be any technical
memory (clicky-clacky), linear (silent), and tactile (silent

DIMENSIONS:
with some resistance). All versions have an LED
in the switch which is fully programmable, and
 uch cheaper and more
M
76 mm × 76 mm
× 30 mm (L × W the keys are standard sized so you can easily hackable than some of the
× H, including
switches,
keycaps
commercial alternatives
and feet)

Each key is individually


programmable, with
customisable RGB
LEDs as well Everything you get in the box – it seems a lot, but it’s a quick build

76 magpi.cc Keybow 2040


REVIEW

It works just


fine with a
Raspberry Pi

advantage to having USB-C; however, it does that change when pressed, and passing along a
mean the basic design has some forward specific combos of keys for when they’re pressed
compatibility for Pimoroni. Also, it’s nice to have rather than a single numpad key. Due to the way
more stuff making use of USB-C. A couple of it loads scripts, you can immediately test out
hardware buttons are also included: one to reset
the Keybow, and one to hold down to do the boot
your edits, making for very quick prototyping
and bug fixing.
Verdict
selection if you want to tinker with the code. We’ve been using a linear version for weeks
A premium-
now during streams as a custom stream deck, feeling product
Custom combo and it works perfectly with our custom setup (the that is easily
The code itself is written in CircuitPython, which code for which we’ll drop on magpi.cc/github). customisable and
is derived from the MicroPython – both can be It’s sturdy, turns on quickly, the LEDs are bright, priced much more
used on a regular Pico and they’re largely similar and we’ve had no noticeable lag on a button fairly than less-
open alternatives.
as well. Whatever changes you need can be press. With the removable caps, you can add

10
gleaned from the abundant example programs custom ones with specific labels like a mute icon
that are installed on Keybow 2040. or specific scene modes, etc., making it perfect

/10
With little effort we were able to change the for this, and much cheaper and more hackable
way the keys work – with constantly lit buttons than some of the commercial alternatives.

Keybow 2040 magpi.cc 77


REVIEW

PoE USB Hub HAT


for Raspberry Pi Zero
The Pi Hut magpi.cc/poeusbzero £22 / $25

Add Power over Ethernet and three USB


ports to Raspberry Pi Zero. By Phil King

T
he PoE USB HAT for Raspberry Pi Zero
SPECS
not only adds an Ethernet port, but
POWER OVER enables you to power everything via the
ETHERNET: same standard RJ45 cable. A nice bonus is the
IEEE 802.3af- inclusion of three full-size USB Type A ports to
compliant PoE, connect peripherals.
37 V ~ 57 V DC
This double-decker HAT features the Ethernet
input, 5 V 2 A
output port and fully isolated SMPS (Switch Mode Power
Supply) on the bottom board, with a second board
CONNECTIVITY: stacked on top holding the three USB ports.
10M/100M RJ45
Ethernet port, Coming already assembled, the two boards are
3 × USB-A ports held together by hex pillars.
With Raspberry Pi Zero mounted on top, the double-decker HAT
Extra pillars and screws are supplied to mount adds three USB ports on the top board and PoE on the bottom
DIMENSIONS: your Raspberry Pi Zero on the top – maybe this
23.1 × 65 mm
should be called a HAB (Hardware Attached on
Bottom) rather than a HAT!
L eaves Raspberry Pi
Zero’s GPIO header free
Free header
Four pogo pins on The USB board has four pogo pins that connect to to connect other boards
the upper USB board
test pads on the underside of Raspberry Pi Zero,
connect to test pads
on Raspberry Pi Zero so you need to ensure it’s mounted tightly and underneath Raspberry Pi Zero is that it leaves the
accurately to make solid connections. latter’s GPIO header free to connect other boards
An obvious advantage of or electronic components.
mounting the HAT One caveat is that you’ll need an 802.3af
compatible router for Power over Ethernet to

Verdict
work. If not, you could always add a PoE switch
or injector between the router and HAT. With an
input voltage of 37 to 57 V DC and output of 5 V 2 A,
Adds both up to around 13 W of power can be supplied, which
PoE and extra
should be plenty for most uses. Alternatively,
USB ports to
Raspberry Pi Zero if you don’t need PoE, you could simply power
without using the Raspberry Pi Zero normally via micro USB, which
GPIO header. will in turn power the HAT.

8
While we’ve seen DIY solutions for adding PoE
or standard Ethernet connectivity to Raspberry Pi

/10
Zero, and USB ports via a hub, this HAT offers a
neat all-in-one solution.

78 magpi.cc PoE USB Hub HAT for Raspberry Pi Zero


SunFounder Basic starter kit for
Raspberry Pi Pico
Based on Raspberry Pi Pico
Quickly learn embedded programming and electronic circuits
Comes with 283 items, 18 projects
Detailed online tutorials
Quick-response technical support

Available at: sunfounder.com/


products/pico-starter-kit

SunFounder Pico Car Kit


Completely Open-Source

Obstacle Avoidance Object Tracking


Speed Measurement Mileage Calculation
Line Following Cliff Detection

Available at: sunfounder.com/products/


raspberrypi-pico-car
REVIEW

Electronic Clock for


Raspberry Pi Pico
The Pi Hut magpi.cc/picoclock £24 / $27

A large LED clock powered by Pico and


with customisable functions. By Phil King

T
he size of this Electronic Clock by
SPECS
Waveshare is impressive. At 21.9 by 7.9 cm,
it’s a chunky device and its 22×7 green LED
DISPLAY: display with large pixels is readable from a
22×7 pixel
green LED, fair distance.
plus status Lifting off the rear panel reveals the electronics
A Raspberry Pi Pico flashed with the software can
sidebar and and two female headers to mount your Raspberry be slotted into the clock’s rear female headers
top weekday
Pi Pico (not included). First, however, you’ll need
display

FEATURES:
to flash Pico with the software. The online manual
(magpi.cc/picoclockguide) is confusing, as
T he USP of this clock is
DS3231
RTC with
there’s no need to compile anything with terminal
commands if using a Raspberry Pi: just drag the
the ability to customise
temperature
sensor, backup downloadable UF2 across to the mounted Pico. the example code to
battery, You can then mount Pico onto the rear headers,
photosensor, close the rear panel (securing it with the supplied add extra functions
buzzer, 3 × screws), plug it in, and the clock will start working.
push-buttons,
the correct time even if disconnected from 5 V
DIMENSIONS: Customisable clock power (via the supplied USB to micro USB cable),
216 (W) x 79 (H) With settings adjusted using three push-buttons although you’ll lose any custom settings. There’s
x 25 mm (D) on the side, standard clock functions include two also an option to automatically adjust the LED
alarms, a timer, and an hourly chime option, all brightness based on the built-in photoresistor.
using the on-board piezo buzzer. There’s also the The unique selling point of this clock is the
option of scrolling the display every three minutes ability to customise the example code and add
to show the date and temperature (in °C or °F, read extra functions, which is done solely in the
Verdict from the on-board RTC chip’s built-in sensor). C/C++ programming languages - there’s no
That RTC (real-time clock), along with a CR2032 official MicroPython support.
Solidly built with a coin cell battery, means the clock will remember
large display, it’s
a cool clock, and
the demo code
is customisable
– although you’ll
need to know
your C++.

8 /10 The chunky LED display is impressive and has rear panel holes for
wall mounting

80 magpi.cc Electronic Clock for Raspberry Pi Pico


Design

Code

Configure

Analyze

P R O FES S I O N A L CO N T R O L SYS T E M D E V E LO P M E N T TO O L

Home projects made easy.


CDP Studio, a great software development tool for your home projects. Build
systems for Raspberry Pi, use C++ or NoCode programming, open source libraries,
out of the box support for GPIO, I2C, MQTT, OPC UA and more. Create beautiful user
interfaces. Built for industrial control system development, FREE for home projects.

cdpstudio.com
Tel: +47 990 80 900 • [email protected]
CDP Technologies AS // Hundsværgata 8, 6008 Ålesund, Norway
REVIEW

10 Amazing:
Raspberry Pi
instruments Soundfighter
A new challenger
Get musical with these Raspberry Pi-
What do you do once you’ve mapped piano keys to a PS2 controller? You build
powered musical creations a second, identical piano and duke it out in Street Fighter. Go home and be a
piano man.

R
aspberry Pi is an incredible piece of hardware for
magpi.cc/soundfighter
audio, and we know many people that use it for
amazing sound systems. Did you know you can
also create music on it? Not just with code either, as these
projects show! Piano stairs
Up the scale
You don’t just have to make music
with your hands – with a little
inspiration from Big, you too can
turn a little fun stair workout into a
musical experience.

magpi.cc/pianostairs

Hex Keys
Trill MIDI Guitar
Isomorphic keyboard
New electric guitar
One of the great instruments designed by Mike Cook, this laser-
cut keyboard is quite different to a traditional piano keyboard, but Another invention from Mike Cook, this excellent MIDI guitar uses special Trill
can still make amazing tunes. touch sensors and a little display to create a cool, customisable guitar.

magpi.cc/pibakery magpi.cc/trillguitar

82 magpi.cc Raspberry Pi instruments


REVIEW

LED piano visualiser


Sound to light
These kind of visualisers are really popular on YouTube for pianos, giving them
a rhythm game vibe. Create one for your own piano.

magpi.cc/pianovisualiser
MIDI Trumpet Robot
Automated jazz
This trumpet is played by robotic fingers depressing the
valves, with MIDI sound actually playing from a speaker at the
mouthpiece. It’s controlled over the web.

magpi.cc/miditrumpet

Pedal Pi
Effects via Raspberry Pi
Ultrasonic theremin
This amazing project isn’t an instrument per se, but it is part of one – a guitar
Spooky tunes
effects pedal with a huge amount of customisation.
With an ultrasonic distance
sensor, you can control notes
magpi.cc/pedalpi
on Sonic Pi to create eerie
tunes, perfect for a 1950s alien
invasion B-movie vibe.

magpi.cc/theremin

Raspberry Pi Guitar Rig


One-man band
Building an amp into an
Self-playing xylophone acoustic guitar was only
the first step. Adding
a Raspberry Pi and
Robotic glockenspiel
touchscreen to control
With as few wires as possible, Stéphane was able to create this automated it on the fly to change
xylophone that uses many solenoids to play out a MIDI file on the synthesizer settings
classic instrument. makes this extra-special.

magpi.cc/xylophone magpi.cc/guitarrig

Raspberry Pi instruments magpi.cc 83


RESOURCES

Learn networking
with Raspberry Pi
Discover more about computer networking
using these resources. By Phil King

An Introduction
to Computer
Networking
for Teachers
Raspberry Pi Computer networking gives around six hours to complete, of networking. Week one,
AUTHOR

Foundation us access to the internet and over three weeks, although ‘Creating Connections’,
allows us to communicate with you can work at your own pace. covers the basics of computer
Price:
people all over the world, but Signing up for a free account network connections; week two,
Free
how many of us know how it gives you five weeks’ access ‘Packets & Protocols’, explores
magpi.cc/
really works? to the course, but there’s IP address and packets, along
introtonetworking
Aimed at computer science the option to upgrade for with protocols such as TCP/IP,
GCSE teachers, this foundation continued access and to receive DHCP, and NAT. The final week,
course is a useful starting a certificate of achievement. ‘The Net as a Network’, covers
point for anyone curious about The self-guided course the World Wide Web, cloud
computer networks. It takes teaches you the fundamentals computing, and cybersecurity.

Online courses
Study networking with LINUX NETWORKING AND the use of sockets in network
ADMINISTRATION (LFS211) programming, including methods
these interactive courses Aimed at IT professionals, this for testing applications.
self-paced course from the magpi.cc/flpythonnetwork
Linux Foundation is pricey
($299) but offers 50 hours of A TO Z LINUX
course material including videos NETWORKING CONCEPTS
and assignments. This Udemy course (£59.99) aims
magpi.cc/lfs211 to improve your Linux network
administration skills by learning
NETWORKING WITH PYTHON to build, maintain, and secure a
Another free course from the computer network.
Raspberry Pi Foundation, it covers magpi.cc/azlinuxnetwork

84 magpi.cc Learn networking with Raspberry Pi


RESOURCES

Raspberry Pi
Networking
Cookbook
Rick Golden For a Raspberry Pi-specific
AUTHOR

take on networking, this 352-


Price:
£29 / $45
page book features a collection
of server-side recipes to
Free web
magpi.cc/
rpinetworking
get you started and develop
your knowledge and skills.
resources
From basics such as remote of Things projects (using a
access using SSH, it goes on to GrovePi board) and setting up a
Check out these online
cover file sharing with Samba, Raspberry Pi cluster. networking resources
configuring a static IP address, While this Second Edition,
generating a firewall with ufw, released in 2016 when we
setting up an Apache web server, were running Raspbian Jessie
creating a wireless access point on Raspberry Pi, is a little
with hostapd, and monitoring dated in some aspects, it
network traffic with Wireshark. does contain a fair amount of
Bonus chapters cover Internet useful knowledge.
DEBIAN REFERENCE
Since Raspberry Pi OS is based
on Debian, the networking
section of the online Debian

Mastering
Reference manual is ideal
for learning a host of

Python
useful commands.
magpi.cc/
debianrefnetwork

Networking RASPBERRY PI FORUMS


Fully updated for Python 3, For troubleshooting Raspberry
Eric Chou
AUTHOR

the 576-page Third Edition Pi-specific networking issues,


Price: explores using the power of the ‘Networking and servers’
£38 / $50 Python libraries to master section of the official forums is
magpi.cc/ network engineering tasks, a good place to go for help
pythonnetworking covering topics such as network the Python-based Ansible magpi.cc/
automation, programmability, automation framework, network networkingforum
and data analysis. It’s aimed at security and testing, and
IT professionals and operations network monitoring.
engineers, and at least a Later chapters tackle building LINUX KERNEL ARCHIVES
basic knowledge of Python network web services with The networking section of
programming and networking is Flask, AWS and Azure cloud the Linux Kernel Organization
required to make the most of it. networking, network data archives is packed with
After an overview of the TCP/IP analysis with Elastic Stack, information on just about every
suite and Python, followed by working with Git, and using aspect of Linux networking.
low-level device interactions, Jenkins to automatically create magpi.cc/
it moves on to cover APIs, operations pipelines. kernelnetworking

Learn networking with Raspberry Pi magpi.cc 85


INTERVIEW

Matt Gray
A YouTuber with a penchant for making, with an
amazing Raspberry Pi-powered Game Boy Camera

> Name Matt Gray > Occupation Broadcast Engineer


> Community role YouTuber > Website magpi.cc/mattgray

M
The Fast WiFi Adapter is att Gray has been making
a modern way to interact
with classic tech for years – both in terms
of cool projects and
also cool YouTube videos. He’s
recently been in the spotlight
for a great hack of a Game Boy
Camera; however, he deserves a
bit more fanfare than that for all
he does.
“I’m a Broadcast Engineer
by day, but I’ve been making
videos on YouTube for over a
decade now!” Matt explains to
us. “I’ve also helped organise
Electromagnetic Field Festival, a
non-profit UK camping festival
for those with an inquisitive
mind or an interest in making
things: hackers, artists,
geeks, crafters, scientists,
and engineers.
“I’ve been making bits and When did you learn about Boy like a game, but converts
bobs for years, the bigger Raspberry Pi? it into a camera. The photos it
projects generally being ones I found out about Raspberry Pi takes are really low resolution
that make me laugh: The when it very first came out, and (128 × 112 px) and greyscale but,
Webcycle, an exercise bike that I used the original Raspberry considering that, I’m always
only lets you use the internet Pi as part of the Freddie surprised by how clearly the
when you’re pedalling. Mercury Thermometer. photos can come out
“The Freddie Mercury It was only ever designed to
Thermometer, because it Where did the Game Boy take 30 photos, print them using
seemed like no-one had made Camera hack idea come from? the Game Boy Printer, then
that joke yet. I’ve had my Game Boy Camera delete them to make space for
“[And] the Hoverpub, where since the 1990s: it was my first more. But after years in a box, I
we converted a small hovercraft digital camera, and I love it! It’s a wanted to use it again, and after
into a pub!” cartridge that goes into the Game some searching online, I found

86 magpi.cc Matt Gray


INTERVIEW

We’re
 fans of the very
clean insides of the adapter

a long-winded way to get photos charger and a switch. I’ve Testing out various
functions of BMOctoprint
off the camera around 2013, and programmed [this] Raspberry
was able to start using it again Pi so that when you turn it on
to not only take photos, but also with the camera plugged in, it
share online. automatically runs the cartridge
Its 30-photo limit was getting reader’s software to extract
annoying after a while, and I photos from it, and save them
didn’t want to also have to lug a onto Raspberry Pi. Then it hosts
laptop and bunch of cables and a WiFi network, so you can
adapters around with me to be connect to it and download the
able to clear it off. Then it hit photos from its web page.

I didn’t want to also have to lug


a laptop and bunch of cables and
adapters around with me
me. A Raspberry Pi Zero is a tiny For more details and to
computer I could take with me… see it in action, please watch
With my newly arrived 3D printer, my YouTube video on it:
I could combine [Raspberry] Pi magpi.cc/gbcam.
and all the other bits needed into
one compact unit to take with me! What else do you vlog about?
This isn’t my first escapade
How does the Game Boy with the Game Boy Camera. A
Camera hack work? few years ago I worked out how
Inside the custom 3D-printed to take colour photos with it
case, there’s a USB Game Boy (magpi.cc/gbcamcolour), even
cartridge reader (gbxcart.com) though it’s only greyscale! And
plugged into a Raspberry Pi Zero you might know me from my
W, which are powered by a LiPo previous project, ‘Will it soft Taking photos of
beautiful things with
battery via an Adafruit MicroLipo serve?’ (magpi.cc/wiss). a beautiful classic

Matt Gray magpi.cc 87


THIS MONTH IN RASPBERRY PI

MagPi
Monday
Amazing projects direct from our Twitter! 01

E
very Monday we ask the question: have you
made something with a Raspberry Pi over
the weekend? Every Monday, our followers
send us amazing photos and videos of the things
they’ve made.
Here’s a selection of some of the awesome things
we got sent this month – and remember to follow
along at the hashtag #MagPiMonday!!

01. 
This is a very neat project, and we do
appreciate it being able to monitor multiple
tanks at a time
02. 
Hopefully it still retains some of that
Raspberry Pi 400 power though
03. 
Sensors like this are slightly harder to make
than you’d think, so we appreciate this build
02
04. A companion rabbit robot – a rabbot?
Robbit?
05. More excellent use of weight sensors
with Hexabitz
06. This cute case has a secret surprise
07. A very fun project to do with people of
all ages!
08. ‘Robot chaos’ is what we call our drawer
with robots we’ve reviewed
09. The Model D looks very swish
10. We hope the fish appreciate their high-tech
living space
11. The full Planets Suite by our new
favourite orchestra

88 magpi.cc MagPi Monday


THIS MONTH IN RASPBERRY PI

03 04

05

09

06

08

07
11

10

MagPi Monday magpi.cc 89


THIS MONTH IN RASPBERRY PI

Raspberry Pi
Computing Education
Research Centre
The new University of Cambridge department will make learning better

I
f you’ve been paying attention to the work of Foundation and the invention of the Raspberry Pi Gender studies are
among those that have
the Raspberry Pi Foundation, you’ll have seen computer. More recently, we have collaborated on been commissioned
all the studies into how different backgrounds Isaac Computer Science, an online platform that from the Raspberry Pi
Foundation
effect the way people learn and interact with is already being used by more than 2500 teachers
computing. With this new initiative, this research and 36,000 students of A level Computer Science in
will be able to be applied to new learning. England, and that we will shortly expand to cover
“With computers and digital technologies GCSE content.
increasingly shaping all of our lives, it’s more “Through the Raspberry Pi Computing
important than ever that every young person, Education Research Centre, we want to increase
whatever their background or circumstances, understanding of what works in teaching and
has meaningful opportunities to learn about how learning computing, with a particular focus
computers work and how to create with them.” on young people who come from backgrounds
Philip Colligan, CEO of the Raspberry Pi Foundation, that are traditionally under-represented in
wrote in a blog (magpi.cc/rpcercblog). “That’s our the field of computing or who experience
mission at the Raspberry Pi Foundation.” educational disadvantage.
“The Research Centre will combine expertise
New research from both institutions, undertaking rigorous
“The new Research Centre is a joint initiative original research and working directly with teachers
between the University of Cambridge and the and other educators to translate that research
Raspberry Pi Foundation,” Philip continues. into practice and effect positive change in young
“[It] builds on our long-standing partnership peoples’ lives.”
with the Department of Computer Science and If you’d like to get involved, you can
Technology. That partnership goes all the way subscribe to the research newsletter here:
back to 2008, to the creation of the Raspberry Pi rpf.io/research-update.

90 magpi.cc Mondays
Coolest
This Month
Projects
are
in for
Raspberry
Pico
online! Pi
THIS MONTH IN RASPBERRY PI

Best of the rest!


Other amazing things from the community

ARGON EON HOME AUTOMATION HAT

The folks at Argon make great cases, and this four-bay NAS box for “Home Automation HAT is a home monitoring and automation controller
Raspberry Pi 4, that they’re crowdfunding, looks like an amazing HAT for the Raspberry Pi that can control up to two appliances/devices
piece of kit. This case will be made from aluminium with a triangular on a load of 250 VAC/7 A, 30 VDC/10 A, photo-coupling isolation
design, and will also be used for cooling. It even has a cute little Optocoupler EL357NC, allowing users to safely control high voltages or
OLED display. current devices.”
kck.st/3BR153B kck.st/3ksMnbY

Crowdfund this! Raspberry Pi projects you


can crowdfund this month

Pallet Town
What-If machine Stock ticker sequencer
A 3D-printed Futurama prop that you can We always love a nice e-ink display project, Similar to our favourite digital orchestra,
ask any What If question, which it will and this one is a cool, simple one that this sequencer plays the Pallet Town music
answer with a random episode of Futurama. tracks your favourite stock. from the original Pokémon games.

magpi.cc/whatiftv magpi.cc/stockticker magpi.cc/pallettown

Best of the rest! / Crowdfund this! magpi.cc 91


YOUR LETTERS

Your
Letters
Universal projects
Now that Raspberry Pi 4 is out, what about an article about some
great projects for the old Raspberry Pi 3A+? I have a Raspberry Pi
3A+, and am having a hard time finding good projects to use it for.
Maybe a WiFi radio? Digital photo frame (though it might not have
enough RAM)? Anyway, just thought it might be a fun article.

Wesley via email

Thanks for the suggestion! This


is definitely something we’ve
thought of doing. A lot of
projects that use a Raspberry Pi 4
will work fine with a Raspberry Pi
3A+, though: even with lower
power, not all projects use that
CPU speed or RAM, so the only
thing you might struggle with is
having the right ports – and
again, you can work around that.
For something like a digital
photo frame, a Raspberry Pi 3A+
is also perfectly fine! As a rule of
thumb, if it can run on a
Raspberry Pi Zero, it can pretty
much run on any Raspberry Pi.

Raspberry Pi 3A+ is
still a great computer
that can be used for
amazing projects

92 magpi.cc Your Letters


YOUR LETTERS

Punch cards are a


fascinating part of
computer history,
representing data
simply with holes in
a piece of card

Credit: Pete
Birkinshaw CC BY 2.0

Astro Pi upgrades Seeing our place in history, again


I’m hoping to enter the next I read Lucy Hattersley’s article ‘Our place in history’ in issue 108 of
Astro Pi competition, if there is The MagPi magazine. As an 85-year-old retired programmer, I can
one, and I was wondering about relate to her in-laws’ computer experience. I got into the computer
the tech specs of the two Astro field in the 1960s after a career change from teaching high school
Pi up on the ISS. Are they physics and math. I have used punched cards, punched paper tape,
Raspberry Pi 3? I’d like to test magnetic tape, floppy disks, etc. to store programs and data. I now
my idea before submitting! have about a dozen Raspberry Pi [boards] for various projects. My
latest project was to build a robot car with my nine-year-old great-
Lottie via Facebook grandson. I used a Raspberry Pi Zero W for that project. It’s
controlled with the Blue Dot Android App. My first computer build
Currently, it’s a Raspberry Pi B+ was based on the Motorola 6800 processor (SWTPC 6800). I built
inside Ed and Izzy Astro Pi. that in the late 1970s. The basic kit had 400 bytes of RAM and used
However, you’ll be pleased to an audio cassette unit for storage. I later upgraded to 32kB of RAM
know that Astro Pi is not only and an 8-inch floppy drive. It had no operating system. The
getting a new mission, but also a firmware that it booted into was called MIKBUG. Most of my
huge upgrade to Raspberry Pi 4, programming was done in assembly language. My favourite
along with some extra sensors computer to program was DEC’s PDP/11. I retired in 1998, but I have
and such. You can find out more tried to keep up with technology.
details about the new computers
on page 8. William via email

Wow, that is a long history with computers. Thank you for sharing
your story with us! We hope your great-grandson enjoyed his first
steps with Raspberry Pi, and will have fun making projects with one
for years to come.

Contact us!
> Twitter @TheMagPi
> Facebook magpi.cc/facebook
> Email [email protected]
The new Astro Pi are much more powerful > Online raspberrypi.org/forums
than the previous ones

Your Letters magpi.cc 93


SUBSCRIBE AND

SAVEUP
TO

35%
on the cover price

ISSUE #47

OUT NOW
hsmag.cc
COMPETITION

WIN ONE OF TEN


AIR QUALITY
KITS FOR
RASPBERRY PI
We reviewed the Air Quality
Kit for Raspberry Pi last
issue, and said it was a
“great kit for experimenting
with monitoring air quality.
Very easy to set up and
start using, and with some
good coding examples and
excellent tutorials.” We have
ten up for grabs!

Head here to enter: magpi.cc/win Learn more: magpi.cc/airqualitykit

Terms & Conditions


Competition opens on 29 September 2021 and closes on 28 October 2021. Prize is offered to participants worldwide aged 13 or over, except employees of the Raspberry Pi Foundation
and Raspberry Pi Trading, the prize supplier, their families, or friends. Winners will be notified by email no more than 30 days after the competition closes. By entering the competition,
the winner consents to any publicity generated from the competition, in print and online. Participants agree to receive occasional newsletters from The MagPi magazine. We don’t
like spam: participants’ details will remain strictly confidential and won’t be shared with third parties. Prizes are non-negotiable and no cash alternative will be offered. Winners will be
contacted by email to arrange delivery. Any winners who have not responded 60 days after the initial email is sent will have their prize revoked. This promotion is in no way sponsored,
endorsed or administered by, or associated with, Instagram or Facebook.

Competition magpi.cc 95
T H AT M A D E

OUT
“The Computers That Made Britain
is one of the best things I’ve read NOW
this year. It’s an incredible story of
eccentrics and oddballs, geniuses and
madmen, and one that will have you
pining for a future that could have been.
It’s utterly astonishing!”
- Stuart Turton, bestselling author
and journalist

Available on

Buy online: wfmag.cc/ctmb


NEXT MONTH EDITORIAL
Editor
Lucy Hattersley
[email protected]

Features Editor
Rob Zwetsloot
[email protected]

Sub Editor
Nicola King

ADVERTISING
Charlotte Milligan
[email protected]
+44 (0)7725 368887

DESIGN
criticalmedia.co.uk

Head of Design
Lee Allen

Designers
Lucy Cowan, Sam Ribbits

Illustrator
Sam Alder

CONTRIBUTORS
Alasdair Allan, Mike Cook,
David Crookes, PJ Evans, Tom
Hadfield, Martin O’Hanlon,
Rosemary Hattersley, Nicola
King, Phil King, KG Orphanides,
Laura Sach, Mark Vanstone

PUBLISHING
Publishing Director
Russell Barnes
[email protected]

RASPBERRY PI
Director of Communications
Liz Upton

CEO
Eben Upton

DISTRIBUTION

OPERATING SYSTEMS
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

THE MAGPI #111 [email protected]

ON SALE 28 OCTOBER This magazine is printed on paper sourced


from sustainable forests and the printer
operates an environmental management

Plus!
system which has been assessed as
conforming to ISO 14001.

DON’T MISS OUT! The MagPi magazine is published by

Walk a Spider
Raspberry Pi (Trading) Ltd., Maurice Wilkes

magpi.cc/subscribe
Building, St. John’s Innovation Park, Cowley

Robot
Road, Cambridge, CB4 0DS. The publisher,
editor, and contributors accept no
responsibility in respect of any omissions

Learn circuit @TheMagPi


or errors relating to goods, products, or
services referred to or advertised in the

design magazine. Except where otherwise noted,


content in this magazine is licensed under
fb.com/MagPiMagazine a Creative Commons Attribution-
Build a Pico NonCommercial-ShareAlike
3.0 Unported
[email protected]
light game (CC BY-NC-SA 3.0).
ISSN: 2051-9982.
THE FINAL WORD

A life in electronics
Who knows where the time goes? By Mike Cook

I
t was all a mistake, I was meant these were the only lessons I had in When Raspberry Pi took over the
to be a chemist. Back when I was programming, but I was hooked! running of The MagPi magazine, I was
five-years-old I knew I wanted to After graduation, I worked on a approached to see if I could write for
be a scientist, and by ten, various form of audio compression called it. Previously I had one article
science toys convinced me it was adaptive delta, pulse code published in The MagPi magazine
chemistry. But I was dyslexic, which modulation or ADPCM, later to be issue #5 (magpi.cc/5), which made
was not recognised in those days. used by Microsoft and Apple. the front cover. However, ‘Mike’s Pi
This caused my teachers to predict I was in the right place at the right Bakery’ began in The MagPi issue #33,
low-level manual work to my parents time. In 1976 I built my first and ran all the way to issue #109.
when I was five. Also dyslexia computer from just the information Having reached the grand old
resulted in me going to a Secondary in the data sheet of the Signetics age of 70, I felt it was time to catch
Modern school, but they had no 2650 microprocessor. I got a up on all those projects I had been
Chemistry Lab. So when it came to wanting to do for years but never
picking a science subject at the age of
thirteen, it was Physics.
I was in the had the time. The first one is to
convert all the Sony 8 videotapes of
I left school at the age of 16 and got right place at my children growing up into a digital
a job as an apprentice technician at a format. However, I am not going
small electronics company in the right time for good, I expect to return for the
Oldham, being paid the princely sum occasional ad-hoc article.
of £5.50 a week. They allowed me to lecturing position at Manchester It has been an absolute privilege to
do a day release where I took an ONC Polytechnic’s Physics department, write in The MagPi magazine, and
(Ordinary National Certificate) and one day I was contacted out of attending various Raspberry Pi
course in Electrical Engineering. the blue by Mike Bibby. He had been events, and shows, meeting some of
This, in turn, enabled me to take a asked to start a magazine about my readers. Thanks for having me.
combined Physics & Electronics home computers and an ex-student
degree at Newcastle upon Tyne had told him about me. I agreed to do
Mike Cook
AUTHOR

Polytechnic. When I went for an four articles, convinced the magazine


interview, my first encounter with a would not go further. Well, it did go
Despite, and maybe because of, his
strong Geordie accent did leave me further: 210 issues in total with my dyslexia Mike Cook has inspired and
wondering where the hell I was. The articles under the titles of ‘Body educated many people over the years in
maths module had three lectures Building Course’ (BBC), and ‘Run what is now known as physical computing.

about programming in Fortran II, the RISC’. magpi.cc/theBox

98 magpi.cc A life in electronics


Available at these great Raspberry Pi stores:

Contact your favorite Raspberry Pi store if it’s not listed here

You might also like