[go: up one dir, main page]

100% found this document useful (2 votes)
717 views100 pages

RaspberryPi Magazine MagPi111

December 2021 of the Official Raspberry Pi Magazine MagPi111

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
717 views100 pages

RaspberryPi Magazine MagPi111

December 2021 of the Official Raspberry Pi Magazine MagPi111

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

BUY IN PRINT WORLDWIDE MAGPI.

CC/STORE

Issue 111 November 2021 magpi.cc The official Raspberry Pi magazine

GET
YOURS
FREE!
SEE PAGE 32

magpi.cc/store

Experiment Explore
with a different the world
operating system of sensors!

BUILD A RASPBERRY PI PICO STREAM DECK


WELCOME

WELCOME
to The MagPi 111

T
he story of Raspberry Pi Zero is intertwined with The
MagPi magazine. Zero was first introduced to the world in
The MagPi magazine issue #40. This fantastic single-board
computer is the entry point for many of our readers.
We’re impossibly proud to introduce Raspberry Pi Zero 2 W. Lucy

EDITOR
Thanks to a clever design technique, it packs a faster quad-core Hattersley
CPU into the same tiny footprint. You can use Zero 2 in your Lucy is editor of
The MagPi and it’s
current project (just swap out a Zero for a Zero 2 and get an months like this
that she wishes
instant speed boost), and Zero 2 is compatible with the vast array we’d done the issue
numbering in binary.
of kits and current home builds.
magpi.cc
Our Zero 2 feature (page 34) brings you all the information on
this exciting new computer. And every subscriber to The MagPi in
print will be getting a free Zero 2 in the post. We take great care
of our subscribers and routinely hand out free gifts, from the
original Raspberry Pi Zero to Google AIY Voice Kits, Raspberry Pi
OS installation CDs and cooling stands, and now, Zero 2.
It is worth subscribing to The MagPi. All new subscribers GE
RASPBT A
will also get a Raspberry PI ZER ERRY
O2W
Pi Zero 2 W (see page 32).
PAGE
On a personal note, a big 32
thank-you to everybody who
subscribes to The MagPi. You
keep this magazine alive.

Lucy Hattersley Editor

magpi.cc 03
CONTENTS

Contents
> Issue 111 > November 2021

Cover Feature

34 Raspberry Pi 34
Zero 2 W
Regulars
92 Your Letters
97 Next Month
98 The Final Word

Project Showcases
12 SPY-DER Robot
16 Automatic Guitar Tuner
18 Electronic Nose
22 Pico Light Arcade
24
24 Community Jams
26 Raspberry Pi Pico Robot
28 Oasis-grow

16

Automatic Guitar Tuner Community Jams

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

50 60
Tutorials
46 Sensory world – part 1
50 Build a stream deck
54 Retro MIDI on Raspberry Pi
Build a stream deck Ultimate home sever – part 4
60 Ultimate home server – part 4
64 Write your own game emulator
80
The Big Feature
72

TonyPi

Raspberry Pi operating systems 86

Reviews
80 TonyPi
82 10 amazing Pi Bakery projects
84 Learn circuit design

Community
86 Akkie interview
88 This Month in Raspberry Pi Akkie interview

WIN W AV E S H A R E E - I N K 95

1 OF 5 DISPLAY PHAT
06 magpi.cc
THE WORLD OF RASPBERRY PI

Raspberry Pi
Build HAT announced
Discover the new collaboration between LEGO®
Education and Raspberry Pi. By Lucy Hattersley

R
aspberry Pi and LEGO® have been
collaborating on a new product: the
Raspberry Pi Build HAT.
The Build HAT is designed to combine the
power of Raspberry Pi with the LEGO Maker Plate
included with the LEGO Education SPIKE™ Prime
expansion set.
Tom Hall, General Manager at LEGO Education,
said: “Combining SPIKE Prime with Raspberry Pi
Raspberry Pi Build HAT
will inspire students to explore more advanced provides four LEGO sockets
and a 5.5 mm barrel plug
creations and continue to nurture their interest
to power and control LEGO
in STEAM learning. This brings in even more motors and sensors
high ceiling learning opportunities that tap
into the maker space and encourage students to is included in the latest LEGO Education SPIKE
combine different products. The Raspberry Pi Prime portfolio (version 45681; £362 / $340;
Build HAT will be available through Raspberry Pi’s magpi.cc/spikeprime). With the Build HAT
authorised reseller network.” attached, Raspberry Pi can control up to four
LEGO motors and/or sensors using Python code.
Brick building
Build a remote The Build HAT is compatible with the most
control car with
Raspberry Pi
recent generation of LEGO Technic™ motors,  ombining SPIKE Prime
C
and sensors. An optional extra, the Maker Plate,
with Raspberry Pi will
and LEGO

inspire students
The Build HAT itself costs $25 and a compatible
48 W (8 V DC, 6 A) power supply is sold alongside
for $15. With the power supply attached, the
Build HAT powers both Raspberry Pi and LEGO
motors and sensors.
Build HAT is the second Raspberry Pi
product to feature the RP2040 microcontroller
designed by Raspberry Pi and first introduced with
Raspberry Pi Pico.
See magpi.cc/buildhat for more information.

08 magpi.cc Raspberry Pi Build HAT announced


THE WORLD OF RASPBERRY PI

The face on this


robot can be made
happy or sad using
Python code to
control motors

magpi.cc 09
THE WORLD OF RASPBERRY PI

Photo credit: ELBA


The kit comprises
a Raspberry Pi
400 Desktop Kit
and monitor

Leaving a legacy
IT veteran Gerry Fillery leaves a donation to help the next generation of coders

W  is generosity will help


H
hile Raspberry Pi was initially
developed for young people, folks of
all ages have picked up our favourite support the computer
microcomputer for fun and practical projects.
Gerry Fillery was one of those people. science and maker
Having retired from his career in IT ten years
ago, Gerry took an interest in Raspberry Pi, and
education of millions of
had projects set up around his house. “Each time young people
I would visit him he seemed to have acquired
more bits and pieces, he was quite an enthusiast,” part of the Stay Connected to School initiative,
recalls his friend. allowing them to stay connected to learning
Gerry’s interest in Raspberry Pi was so great that whilst schooling is disrupted.
he decided to leave a donation to the Raspberry Pi “Gerry is our first ever legacy donor,” said
Foundation in his will, and is the first person to Teresa Hicks, Director of Strategic Partnerships
have done so. His generosity will help support the at the Raspberry Pi Foundation. “We are
computer science and maker education of millions incredibly grateful for his generous gift. His
of young people all over the world. legacy lives on through helping us to bring maker
education to young people all over the world”.
Connecting people
A part of this donation has gone towards Vocal vocation
distributing free Raspberry Pi Desktop kits to Gerry grew up in Blackheath, London. As a
those who do not have a computer at home as youngster, he also had links to Fairlop and Seven

10 magpi.cc Leaving a legacy


THE WORLD OF RASPBERRY PI


The donation was able to
fund several kits for young
people. Partners like the
East London Business
Alliance (ELBA) have
supported kit distribution

Ideal for family


learning + clubs! �
ea � f or an
�d !
rr� P�

The kit comprises

Ideal GIFT and


a Raspberry Pi
400 Desktop Kit
sp b e
and monitor
Ra
starter project book!
Donate to the Learn to code SNAP!,
Raspberry Pi Foundation SCRATCH and PYTHON!
k
If you want to follow in Gerry’s footsteps ingbook.co.u
and help bring computers and computing Clear and easy-to-read
education to young people around the
large format (10"x 8")
getcod

world, you can donate to the Raspberry Pi


Foundation at rpf.io/donate.
Preview: lets

Raspberry Pi based
Kings, and was educated at Edinburgh University
where he studied as a Statistician and Actuary.
projects + mac/PC and
He worked as a techie throughout his career, Chromebook compatible
preferring a technological challenge. Full colour - 140 pages

F!
He would often talk of voice applications in
!’
WOW! � ��� ’� �� ��
Order: 20% OF
tech, a field he was very familiar with: he worked
on early bank telephone automation systems. Offer ends December 24th
He lived for the last 20 years of his days in
Frimley Green, Surrey. Thank you, Gerry, for all books or ebooks! tarquingroup.com/pi
you have done.

Leaving a legacy magpi.cc 11


PROJECT SHOWCASE

SPY-DER
Robot
A multi-legged surveillance robot combines AI and
Raspberry Pi. Rosie Hattersley learns some spidey-sense

T
hose of us with an aversion to the company
of spiders may find themselves a little
uncomfortable at the design of the latest AI
robot created by the Sparklers, a group of computer
science engineers in India. Not only does the robot
specialise in watching its object’s every move,
but it has multiple legs and the ability to move in
unexpected ways.
Arijit Das
MAKER

Team leader Arijit Das explains that SPY-DER


is so-named because of its ability to walk like an
Indian computer
science engineer arachnopod – much to the consternation of some
Arijit runs a group observers. The robot’s main purpose is for live video
of like-minded tech surveillance, streaming footage that can be viewed
enthusiasts called
Sparklers that
remotely via a dedicated web browser. SPY-DER
focuses on making can be controlled in two ways, either through voice
AI- and robotic- commands or from the web interface. Riffing on one
based projects
of the favourite items of prey for real-life spiders,
such as a Sudoku-
solving buddy. Arijit uses ‘bumblebee’ as the robot’s wake word,
prompting its LED eyes to light up.
magpi.cc/spyder
“Whenever I call it by its name, it starts listening
Servo motors are used to control
to me and then, based on my voice command, it
the legs, which wave majestically,
will act,” he clarifies. These commands cover both
just like a friendly spider
speech recognition and ‘intent detection’. “I can give
SPY-DER the same command in different ways, i.e.
‘Wave your hands’ or ‘Say hello’. Both commands
make it wave its legs,” says Arijit. The online
control panel, meanwhile, lets the user control all of
SPY‑DER’s actions. If such movements don’t make
you tense up, you can take a look at SPY-DER in
action at magpi.cc/spyderyt.

Evolutionary process
The first version of SPY-DER was an Arduino Nano-
based device, controllable via an Android smartphone

12 magpi.cc SPY-DER Robot


PROJECT SHOWCASE

Raspberry Pi Zero W enables the web


control interface and manages the
voice recognition and AI elements

Quick FACTS
> SPY-DER can
be built over the
course of a week

> Arijit’s version of


Don’t be alarmed, but on hearing the chassis is here:
the wake word, the SPY-DER magpi.cc/
robot’s LED eyes light up spyderprint

> He built his own


after seeing how
much commercial
robots cost

> Reactions from


friends and his
pet rabbit have
been extreme…

> Extreme delight or


extreme fright!

SPY-DER Robot magpi.cc 13


PROJECT SHOWCASE

S
 PY-DER mimics its near
namesake but operates
on just four legs

S
 PY-DER’s eyes light up
ominously in response
to the wake word

14 magpi.cc SPY-DER Robot


PROJECT SHOWCASE

I spy… spy spiders


To build your own spider robot, first follow Arijit’s
online instruction video: magpi.cc/spyderbuild.
The second YouTube video explains how to
incorporate Raspberry Pi in order to make use of AI
features: magpi.cc/spyderai.

or web browser, but lacking the voice recognition A


 rijit 3D-printed the
parts for the spider
aspect Arijit was keen to add. “Obviously I needed a robot’s chassis
small computer here,” he comments. Several of his
Download and 3D-print the spider body
previous projects, including the Sudoku‑solving 01 parts (magpi.cc/spyderprint). Then attach
robot we featured in The MagPi #98 (magpi.cc/98), the servo motors for the legs, and assemble the
were based around Raspberry Pi. Size constraints rest of the body.
led Arijit to choose Raspberry Pi Zero W this time.
Wireless connectivity and the ability to connect
to a Raspberry Pi Camera Module were also
critical features.
The limited RAM provision of Raspberry Zero W
presents a challenge for Arijit’s hope of eventually
implementing a local speech and intent recognition
system from scratch. The speech recognition
system would need to be highly optimised,
otherwise it will take a lot of time to recognise the
speech, he acknowledges. For now, SPY-DER uses
an amended version of Picovoice (picovoice.ai)
speech recognition, but in time Arijit also aims to Attach battery and charging cables, Arduino
add image processing and AI-based features, such
02 and Arduino IO shield, and install the Arduino
as object tracking and face recognition. code before inserting Raspberry Pi Zero W, USB
microphone, and Camera Module.

Building it
Rather than designing SPY-DER’s body from
scratch, and having recently got his first 3D
printer, Arijit adapted an existing spider robot
chassis (magpi.cc/spiderbot), changing its
dimensions to accommodate Raspberry Pi Zero W,
microphone, and the Camera Module. He tweaked
the spider robot’s Arduino code, but wrote the
Python code for Raspberry Pi to be able to control
SPY-DER. The web controls use a Flask framework
with a web page coded in HTML, CSS, and jQuery.
Download the project code from Arijit’s GitHub
“For the live video streaming, I used RPi-Cam- 03 repository (magpi.cc/spyder) along with
Web-Interface (magpi.cc/rpicamweb), due to Picovoice, amending the code as indicated. For video
the fact that the latency is very low here,” Arijit streaming, you’ll also need to install the RPi-Cam-
explains. Helpfully, he provides diagrams and code Web-Interface.
at magpi.cc/spyder.

SPY-DER Robot magpi.cc 15


PROJECT SHOWCASE

Automatic
Guitar Tuner
A Pico-powered automatic tool to tune your guitar?
Nicola King is inspired to start strumming

L
et’s face it, there’s no point in having pitch of the tone coming from the plucked string.
an ultra-cool guitar if you don’t have It then twists/adjusts the peg as necessary to
the means to make sure it stays in tune, ensure accurate tuning for sweet sounds.
especially if you’re pursuing a Springsteen-esque Guyrandy tells us that Pico is the brains of the
form of brilliance on the fretboard. entire tuner: “It samples an electret microphone
Guyrandy Jean-Gilles is a musical maker who at 4096 samples per second, computes an FFT
took Raspberry Pi Pico and created something (fast Fourier transform), finds the strongest
rather special. “The goal of the project was to make magnitude frequency in the audio, then turns a
Guyrandy
MAKER

a low-cost, automatic guitar tuner,” he tells us. DC motor clockwise or counter-clockwise until
Jean-Gilles
“I’d been meaning to do a project with Pico and the target frequency and the strongest frequency
Guyrandy is an there are few development boards as cheap and in the audio match.”
engineer and maker well-documented.”
from the US east
coast. He got his
Change your tune
bioengineering Pico power As with all electronic makes, this was a learning
degree from Guyrandy developed his idea over a two-month experience with a few bridges to be crossed, and
the University of period, and the result is a very useful device. The the trickiest part of the build was determining a
Pennsylvania, and
guitarist chooses whichever string they want to guitar string’s pitch from audio. “There’s a lot of
currently works
in the medical tune and then places the tuner on the appropriate academic research in the area that I wasn’t aware
device industry. tuning peg. A button on the automatic tuner is of before starting the project,” says Guyrandy.
magpi.cc/ held down by the user which then activates the “This version found the strongest magnitude in a
tunergitlab microphone, and the tuner begins to determine the fast Fourier transform, and assumed that was the
fundamental frequency.”

I’d been meaning to do a project with Pico In terms of accuracy, he found a few blips that he
had to even out. “The tuner’s frequency detection

and there are few development boards as is repeatable but inaccurate. It will mistakenly
think harmonics are the fundamental frequency
cheap and well-documented for almost all cases. I had to hard-code harmonic
frequencies into the firmware to make the tuner
work appropriately,” he explains.
That said, the tunings are reliably inaccurate so
they can be used to correctly tune a guitar. “For
example, the low E string is 82.4 Hz in standard
tuning, but the project repeatable thinks it’s 250 Hz.
Currently alternate tunings aren’t possible, but with
a firmware change, drop tunings can be achieved.”
Guyrandy has had plenty of suggestions from
other makers in terms of potential improvements,
including adding a vibration sensor so the tuner
can be used in a noisy setting, and also “to make
Guyrandy demonstrates his automatic a tuner that fits over all the tuning heads of the
guitar tuner, here using it to turn the
peg for the top E string guitar and tunes all the strings simultaneously.

16 magpi.cc Automatic Guitar Tuner


Quick FACTS
> Guyrandy was
inspired by
Hold the push-button on top
the Roadie 3
of the device to start listening,
guitar tuner:
then pluck the string you’ve
magpi.cc/roadie3
selected with the rotary knob
> To make your
own, you’ll need
a Pico, Adafruit
The LED of the selected string PowerBoost 1000…
lights up; two RGB LEDs below
indicate the current status – > ….plus tactile
green for correctly tuned buttons, mini metal
The tuning head fits over
gear motor, and
a guitar peg and turns
some LEDs
it automatically until it
reaches the correct pitch
> In 2017, Guyrandy
snappily decorated
his graduation cap
and gown…

> …with the official


7-inch display and
a Raspberry Pi 3:
magpi.cc/gradcap

Guyrandy designed
a slick-looking
case for the tuner
in CAD software
and 3D-printed the
parts for it

While this is cool, I’m not sure how I’d separate


two different fundamental frequencies from one
audio signal.”
He is currently working on a second
version of the tuner and will be trying the YIN
(magpi.cc/yin) algorithm to detect frequency, as
well as incorporating some piezo-electric sensors
to pick up vibrations, along with a stronger motor.
If you’d like to have a go at making your own
version of the tuner, Guyrandy has generously
made his code open-source, and information on
exactly what you need in order to build it can be
found on his GitLab page (magpi.cc/tunergitlab).
Why not dust off that old guitar and get making?

Automatic Guitar Tuner magpi.cc 17


PROJECT SHOWCASE

Electronic nose
Sniffing out your surroundings with this next step in sensor technology.
Rob Zwetsloot asks a Raspberry Pi to detect cheese or petrol

L
ight sensors, temperature sensors, humidity A 98 percent classification accuracy was achieved in
sensors, noises sensors (i.e. microphones) the testing process.”
are all fairly common, however gas sensors
are not something you see everyday. Using them Smell test
specifically to ‘smell’ your surroundings is even rarer. With only four types of gas sensors, extensive
Luis Rodriguez Mendoza is the creator of one of these testing and training of the model was required.
rare projects. “A training data set was created by taking
After learning about the different and weird things measurements of air, beer, and coffee
Luis Rodriguez
MAKER

dogs have been trained to identify by smell at the independently.” Luis explains. “Each sample was
Mendoza airport, Luis asked the question of whether he could do taken, on average, for 15 minutes at one second
A Geomatics something similar with low-cost gas sensors. intervals, producing over 900 sample readings per
Engineering “The purpose of the project is to show that low-cost test and the data was exported into CSV files. For
Master’s student sensors can be reliable in detecting odours and that classification purposes, an additional column was
at the University
they can possibly be used in clinical settings.” Luis tells manually added to label the sample (i.e., coffee,
of Calgary, he is
passionate about us. “Testing was done using samples of beer and brewed beer, air). The three datasets were imported and
health and science, coffee. A K-Nearest Neighbours (KNN) algorithm was combined in MATLAB. This data was used to create
and applications
used in MATLAB to create a classification model that a k-nearest neighbour model, k was selected to
of wearable
technology. was used to predict the aromas of beer and coffee, and be 5, this was determined by trial and error. A
was validated using a 10-fold cross validation (k-fold)... 10-fold cross-validation was used to validate the

The principal
component analysis
gives a more
accurate reading of
what data is being
collected

18 magpi.cc Electronic nose


PROJECT SHOWCASE

Using the Explorer HAT Quick FACTS


makes connecting all
the sensors very easy > The sensors
detect methane,
hydrogen, carbon
A variety of gas sensors monoxide, and
detect different types alcohol molecules
of scents
> The news article
that inspired it
was about dogs in
Finnish airports

> Luis likes to


develop wearables
that analyze
biomechanics...

> … like his


accelerometer
that determines
body position
The whole setup is while cycling
powered completely
by Raspberry Pi > Methane is part of
the coffee aroma,
however alcohols
can also be part
of it

Electronic nose magpi.cc 19


PROJECT SHOWCASE

T
 he full build is
fairly simple but
quite impressive
in what it does

20 magpi.cc Electronic nose


PROJECT SHOWCASE

Sniffing electronically

The sensors are calibrated when it turns on –


01 this is done by having the Python script run on
start up, and holding the sensors away from anything
you’d like to whiff. Once the sensors are calibrated to
neutral, a sensor reading will be displayed.

Professional electronic
model, and a Principal Component Analysis (PCA) noses are used in medicine
was used as an exploratory technique to verify the and engineering sectors
and can cost thousands
model and the results, similar to the work shown
Credit: CC BY-SA 4.0:
in past research. LukaszKatlewa
“A test dataset was gathered by taking 17 new
samples of two-minute readings at one second
intervals to assess the classification model. Each
sample was independent of each other (only air,
beer, or coffee was measured at a time), and they
were manually labelled accordingly, resulting in
over 2500 measurements. This data was imported,
combined, and randomly rearranged in MATLAB.
Using the classification model created from the
training dataset, the testing data was classified and Placing the e-nose on the sample will begin
the results from the classification model represent
02 a reading using the gas sensors, which will
be automatically logged in a CSV file for you to look
97.7% accuracy.”
at later.

I quickly realized how easy,


efficient, and capable
Raspberry Pi boards are
A near 98% accuracy is extremely impressive
for the three test subjects, and it’s all done on a
Raspberry Pi 3.
“Raspberry Pi was introduced to me in the fall
of 2020 during one of my university courses,” Luis The CSV file can be processed using MATLAB,
said. “I quickly realized how easy, efficient, and 03 and there are a couple of post-process scripts
capable Raspberry Pi boards are.” that Luis have created to output at confusion matrix
It’s a cool, working concept, so we hope to see with classifications, along with PCA and the raw data.
more like it in the future.

Electronic nose magpi.cc 21


PROJECT SHOWCASE

Pico Light Arcade


This inexpensive build was created in a single evening and
it’s set to provide hours of fun, as David Crookes discovers

A
trip to a seaside arcade is rarely complete ordered the arcade buttons and, once they arrived,
unless you’ve grabbed hold of a soft rubber I drilled 20 holes into a board I had lying around.”
mallet and exerted huge amounts of The holes were arranged so that each player
energy on a satisfying game of Whac-A-Mole. would have one button immediately in front of
Known as Mogura Taiji in Japan, where the game them, followed by a row of three and then a further
originated, it relies on speedy reactions to hit as five – making for nine each. Two buttons were
many small plastic moles as possible – and when placed in the centre: one to start the game and
Thomas Roth Thomas Roth had a go, he decided he had to create the other to select a playing mode. “I screwed in
MAKER

a version for himself. the buttons and wired them up in a 3×7 matrix,”
Thomas Roth is an IT
“It was a small arcade and my friend and I had Thomas says. “There was no soldering involved.”
security researcher
who lives in Germany so much fun with a game like this, I just knew I
and creates videos wanted to have one for our parties,” he says. In his Keeping score
about hardware case, the ‘moles’ he was bashing were a set of LED Once done, Thomas began to program the
hacking and
reverse‑engineering.
lights and Thomas reckoned it would be relatively game and he reckoned a Raspberry Pi Pico
easy to replicate. “I spent zero time planning microcontroller would be more than capable of
magpi.cc/
picolight it,” he continues. “I came back from the arcade, running it. “I really like the simplicity of Raspberry
Pi Pico,” he says. “Firmware updates are drag-
and-drop, it’s super-easy to code for, it’s really
cheap, and it boots up immediately, too.”
At first, he flexed his C programming skills to
code what he describes as “a high-speed Whac-A-
Mole” with the goal being to hit any buttons that
light up as fast as possible. “Whoever manages
to press the most buttons in 45 seconds wins,”
he smiles, adding that he then wanted a way of
displaying the score.
“I didn’t have a nice display lying around so I
built a Web Serial-based website that also shows a
scoreboard,” he says. “This is completely optional,
though, and the table will run happily without it.”

Mind games
Once the rules of Whac-A-Mole were established
and coded, he then moved on to create a second
As if to prove German has a word for mode: replicating a game of Simon. “The table
everything, Thomas refers to this messy array shows a sequence and both players have to
of wires surrounding Raspberry Pi Pico as
“kabelsalat” – or cable salad in English remember and repeat it. The sequence gets longer

22 magpi.cc Pico Light Arcade


PROJECT SHOWCASE

Each player has nine buttons to


press. These two in the centre
allow games to start and different
game modes to be played

Quick FACTS
> The build and
code took three to
four hours

> It cost roughly $45


to create

The table looks great with its retro-style There are 20 arcade buttons in total
> There are two
video game stickers, coloured circles but Thomas says they’re 3.3 V each and
game modes
surrounding the buttons, and a black darker than he’d like. “You might want to
tape finish around the edges change the resistor,” he suggests
> The scoreboard
uses the Web
Serial API

> You can choose


your own

T here was no soldering button layout

involved
and longer, and whoever first presses a wrong
button loses.”
He’s not ready to stop there, though. “I would
love to have more game modes and I’d also love to
see someone hook up a seven-segment display to Warning!
show the score,” he reveals. “I’m also designing a
This project requires use
PCB to make the underside a bit cleaner – as it is, of a drill. Be careful when
using electric tools.
there are 20 buttons with four wires to each and it
magpi.cc/drillsafety
looks messy.”
Even so, it also looks like a heap of fun. “It
A laptop is being used
certainly is, and it should be a great project for to display the score,
anyone to do with kids,” Thomas adds. “In fact, but it’s only acting
as a screen. Thomas
two friends of mine have already decided to build would prefer to use
a seven-segment
their own with their children, but adults will have a
display, but didn’t
fantastic time with it too.” have any to hand

Pico Light Arcade magpi.cc 23


PROJECT SHOWCASE

A Raspberry Pi sends out all the


info to the various tablets
Notes are fed to
the tablet screen
so everyone can
follow along

A projector was
experimented
with, but it was too
bright in the park

Community Jams
Bringing the jam sessions outside thanks to a Raspberry Pi broadcasting
notes and lyrics. Rob Zwetsloot grabs a seat and listens

W
hile reading The MagPi, you might think “Community Jams (communityjams.org)
that a reference to a Jam would be for couldn’t play music indoors using our
a Raspberry Jam. In this case you’d be web‑based chords and lyrics application
Bob Steele
MAKER

wrong, it’s about a community of musicians that (magpi.cc/musicapp),” says Bob Steele, a retired
A retired software like to play together. programmer and current Community Jams member.
developer currently Over the course of last year, the way they play “Outdoors, I put the app on a Raspberry Pi so we
living in Portland. He together had to change. Mainly, they had to move didn’t need an internet connection. Raspberry Pi
writes software for
the community jams outside and that caused some problems. had a web server to deliver the application from
and plays bass guitar Apache. Unfortunately, the projector was too weak
with them. in bright sunlight and was always subject to having
communityjams.org its screen blow over in the wind. I figured out that if
the app was delivered from [Apache] Tomcat, I could
create a web socket protocol that would share the
current song and position to many tablets. So now
the musicians are outside, masked, separated by a
good distance, and all able to share the same display
on their personal tablets.”

Early adopter
Although Bob has been programming and working
Who needs books of
with computers for several decades, he’s mainly
music when it gets
sent to your tablet? worked with software projects: “In the early 1980s

24 magpi.cc Community Jams


PROJECT SHOWCASE

Quick FACTS
> Bob used to work
in Silicon Valley

> Jam sessions can


be traced back to
1920s jazz

> Bassist Bob also


has a bass guitar
learning app on
his site

> Community
Jams spun off
from Portland
Casual Jams...

> …which was created


A very simple setup,
which allows for the 14 years ago and
group to play together has 3700 members

I designed or help design a number of internal


hardware projects for the video industry.
“I heard about [Raspberry Pi] from the internet
in the early days,” he says. “I’ve ended up buying

T he musicians are happy


that: 1) they get to play
music in the park and 2)
they know next to nothing
about how it works
The web app that Bob
at least one of every model. Don’t know why, but The whole setup is just a Raspberry Pi 3 with created, as seen on
they are good platforms for small projects. I first Bob’s software, an access point to connect to a several screen sizes

used UNIX in 1975 and my personal machine has local wireless LAN, and a battery to run it.
been Linux for many decades … so Raspberry Pi “I should have installed DNS instead of the fixed
seems like home. In fact, most of them never get IP address,” Bob ruminates. “The fixed IP address
connected to a keyboard, mouse, or display. SSH or helps when Raspberry Pi is not in the park. It gets
VNC is all I usually need.” plugged in, attaches to the local WiFi, and updates
itself using crontab jobs.”
Can’t beat it While its humble use as a way to get some
It’s a simple project with a simple goal – to display friends to play music together is great, we feel
music for musicians, and it works well in that the technology is simple yet powerful enough to
regard according to Bob: “The musicians are happy be expanded to larger groups. Check out Bob’s
that: 1) they get to play music in the park and 2) website, bsteele.com, for more about Community
they know next to nothing about how it works.” Jams and his other projects.

Community Jams magpi.cc 25


PROJECT SHOWCASE

Raspberry Pi
Pico Robot The smartphone’s accelerometer not
only picks up left and right movement,
but allows MohammadReza to tilt
forward and back to control the direction

Rather than use a standard controller, this robot is steered using


an Android phone’s accelerometer. David Crookes takes a look

R
obotics projects have long been popular using Raspberry Pi Pico, and I wanted to experience
among the Raspberry Pi community, but the challenge of working with the microcontroller.”
MohammadReza Sharifi’s outstanding To ensure that the robot could make use of
contribution definitely has a touch of va va a smartphone’s accelerometer, MohammadReza
voom about it. Powered by a Raspberry Pi Pico, needed to develop a custom app. He did
his four-wheel drive car is controlled using the so using the MIT App Inventor platform
accelerometer in an Android smartphone. “The idea (appinventor.mit.edu) – a blocks-based visual
suddenly came to my mind,” he tells us, “and it programming environment that makes it relatively
MohammadReza
MAKER

took me about three hours to build and program.” easy to create software for mobiles.
Sharifi
That itself is impressive, particularly given the
MohammadReza work needed to get things moving. It all began two
is a self-described
geek, gamer, writer,
months ago when MohammadReza was browsing T he biggest challenge was
Instagram. “I saw a promotional video about a toy
cinema lover,
YouTuber, and in which a coloured ball was being controlled by definitely building the
mobile gestures,” he says. “I thought to myself
engineer. He lives in
Khuzestan, Iran. that controlling a robot using mobile gestures mobile app
magpi.cc/ could also be an interesting project.”
picorobot From that point on, he quickly looked to gather “The main advantage of this platform is that
the equipment needed. To start with, he bought you don’t have to deal with coding challenges
an inexpensive plastic robot car chassis kit which because it lets you focus more on the main
came complete with four yellow wheels and four concept of a project,” MohammadReza explains.
DC gear motors. He then added a L298 motor driver That said, it wasn’t totally straightforward, as you
and an HC05 Bluetooth module. can perhaps imagine.

Speeding ahead Twists and turns


“I decided to connect these to a Raspberry Pi Pico The idea was to create an app that would send data
microcontroller,” he says. “I’d seen that a small from the accelerometer to Raspberry Pi Pico in
number of robotics projects had been implemented real-time via a Bluetooth connection. That way,

26 magpi.cc Raspberry Pi Pico Robot


PROJECT SHOWCASE

Raspberry Pi Pico processes


the movement data in
real-time, and sends the
information to the motor driver
Quick FACTS
When the smartphone is
titled, the app on the device > Tilting a
sends the movement details smartphone steers
to Pico via Bluetooth the robot

> A bespoke Android


controller app
was developed
The chassis was bought
online as an inexpensive
> A Python app
kit. A breadboard was
was created for
fixed to the top
Raspberry Pi Pico

> The project cost


MohammadReza could tilt his smartphone left, for about £40 to make
instance, and send information telling the robot to
move left. > See it in action
This is what took up much of the development at: magpi.cc/
picorobotyt
time. “The biggest challenge was definitely
building the mobile app,” he reveals. “It needed
to identify the co-ordinate axes and identify the
position of the accelerometer sensor in the mobile.
It also needed to perform trial and error to find the
amount of angular acceleration and the magnitude
of acceleration.”
Eventually, however, it began to work near-
flawlessly. He’s now considering creating a version
for iPhone, but although the MIT App Inventor web
application is free, open-source, and allows apps to
be made for iOS and Android, he’s decided to use a
different system for the Apple device.
“I will create an iOS app for the robot using
Kivy,” he says, referring to the free and open-
source Python framework and relishing a fresh
challenge. His priority first and foremost this time
around, he adds, was just getting it to work with
his Xiaomi Redmi Note 9 Pro Android smartphone
and he’s more than happy to see it going down well
The L298N motor driver is
with other makers online. “It makes me proud that inexpensive and popular
people are interested in my project,” he beams. among Raspberry Pi makers

Raspberry Pi Pico Robot magpi.cc 27


PROJECT SHOWCASE

Oasis-grow
Growing fruit and vegetables can be so frustrating, but a
Raspberry Pi-based smart agriculture project helps take the
uncertainty out of cultivation. Rosie Hattersley reports

P
lants, mushrooms, and other cultivated accept,” says Mike, explaining why he and his PhD
organisms don’t respond in linear ways,” student co-founder Aviel Stein set about improving
even when provided with supposedly the odds of a successful harvest. Their response,
‘ideal’ growing conditions, much to the Oasis-grow, is a ‘smart agriculture engine’
frustration and disappointment of those keen that runs on Raspberry Pi and collects detailed
to cultivate their own food, observes 25-year- information about whatever the user cares to grow
old entrepreneur and technology fan Mike Lee. in a bid for more predictable results.
Mike Lee and Such nonconformity “is a mindset that many The system provides visual and sensor data, plus
MAKER

Aviel Stein programmers and engineers find difficult to controls for heat, humidity, airflow, light, and
watering cycles. The selling point is a system that
Oasis-X co- “keeps your plants, mushrooms, and Petri dishes
founders Mike
and Aviel met at
happy, and remotely monitors the grow space so
a maker event you can identify and address problems before they
in Pennsylvania get serious.”
where self-
taught coder and
entrepreneur Mike Make room for mushrooms
was showing off Mike and Aviel met at the 2019 Pennsylvania
several Raspberry Maker Faire where, among other projects of his
Pi projects.
own devising, Mike presented his first Raspberry
oasis-x.io Pi project: a dashboard camera with buttons and
a remote, back-window LED screen for signalling
other cars. “It was very cool but perhaps a bit too
dangerous for the road (the other cars did not
react … well),” he admits. Nonetheless, the pair
decided to work together, and quickly formed
Oasis-X (magpi.cc/oasisx) having identified a
market for a smart agriculture monitoring tool.
Aware that DIY plant monitoring and sensor kits
 he temperature-
T
controlled incubation were already available, Mike and Aviel needed to be
tent has sensors to
sure they were offering something that fulfilled the
monitor humidity,
airflow, and light levels scalability promise it would need to be of interest

28 magpi.cc Oasis-grow
PROJECT SHOWCASE

Quick FACTS
Sensors attached to Raspberry > Mike has been
Pi 3 measure air humidity, light cultivating
levels, soil moisture; a time- mushrooms for
lapse camera is also used two years

> Aviel has a long-


term interest in
permaculture

> The project


attracted its first
potential customers
in August 2020

> From beta to


manufacturing took
Oasis-X a year

> Simplifying it
and making
improvements are
of course ongoing

Cultures could be cultivated in


bottles or jars, or the whole box used
to grow mushrooms and other crops

Remote monitoring means the


Oasis-grow setup can be located in
a basement or cupboard, but plant
progress is easily checked up on

Oasis-grow magpi.cc 29
PROJECT SHOWCASE

Warning!
Electrical Safety
Please be careful when
working with electrical
projects around the
home. Especially if they
involve mains electricity.

magpi.cc/
electricalsafety

 ime-lapse images
T
can be taken of the
contents in their Petri
dish habitat

to agriculture, and merit a commercial launch. Ploughing ahead


Mike explains it was important for Oasis-X to take Oasis-grow’s makers took inspiration from
an “open-source first approach” to developing older projects, and chose Raspberry Pi because
agriculture technology. “Technology vendor lock- of its multitasking capabilities and a file system
in is such a big issue for farmers,” he continues. that they found made organising and retrieving
complex data a much simpler task. Most of the
hardware they use for prototyping was bought
 asis-X is also keen to make the concept
O from the usual online retailers, with Raspberry

available for hobbyists and home Pi running Bash alongside Raspberry Pi OS and
Python. Their web interface was created in Python

horticulturists, providing source code and and uses AWS (Amazon Web Services).
“We’ve spent the last year nailing down the core
hardware architecture details via GitHub functionality and are in the process of making it
faster, more modular, and easier to use,” Mike
explains. The system went through more than 20
“Our systems must collect and store lots of iterations and was developed in close consultation
different information while communicating with with farmers and home horticulturists. This
the network and managing multiple independent process helped Mike and Aviel realise that the
processes, [so] a full-fledged operating system is vision, sensing, and environmental helper
close to required.” modules were valuable individually as well as

30 magpi.cc Oasis-grow
PROJECT SHOWCASE

Grow your own


Raspberry Pi 3B, a USB camera, and a power supply
are the basis of this project. Full setup instructions
can be found at magpi.cc/oasisgrowgit.

Download the Oasis-grow code from the


01 GitHub page (an installable operating
image is in development, take a look at the GitHub
instructions). Set up your incubation tent, or position
the camera to monitor it.

To start data collection, turn on the


02 Raspberry Pi camera, start Python, and run
main.py. If successful, the image loader will run on
bootup next time.

collectively. As a result, the pair are soon set to Impressive results


from their initial home
offer an open-source version of the GUI integrating growing chambers
machine learning, decision support, and smart
notification prototypes.
As an agri-business system, Oasis-grow had
to prove its worth and has undergone successful
long-term, large-scale field tests in farms in the
eastern US over the past year. These ‘turn-key
growing systems’ have recently been distributed
to the company’s early backers, with a Kickstarter
campaign fundraising towards its ‘smaller helper
modules’ currently running. However, Oasis-X
For more detailed monitoring, add a relay
is also keen to make the concept available for 03 board for AC control, GPIO buttons for a
hobbyists and home horticulturists, providing physical interface, environmental sensors, and LED
source code and hardware architecture details via status displays, as per Oasis-grow’s full configuration.
GitHub (magpi.cc/oasisgrowgit).

Oasis-grow magpi.cc 31
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 2 W with 12 Month upfront
subscription only (no Raspberry Pi Zero 2 W with
Rolling Monthly Subscription)

Subscribe by phone: 01293 312193


Subscribe online: magpi.cc/subscribe
Email: magpi@subscriptionhelpline.co.uk
32 magpi.cc
SUBSCRIPTION

JOIN FOR 12 MONTHS AND GET A

FREE Raspberry Pi Zero 2 W


WITH YOUR FIRST
12-MONTH SUBSCRIPTION

Subscribe in print
WORTH

$15
today and get a
FREE computer!

A full Raspberry
Pi desktop
computer

Learn to code and


build your own
projects

Make your own


retro games
console, media
player, magic
mirror and much, This is a limited
offer. Not included
much more with renewals. Offer
subject to change or
withdrawal at any time.

Buy now: magpi.cc/subscribe

SUBSCRIBE
on app stores

magpi.cc 33
FEATURE

Introducing
Raspberry Pi Zero 2 W
The smallest Raspberry Pi now packs a quad-core processor and
runs over five times faster. Raspberry Pi Zero is back in a big way.
By Lucy Hattersley

R
aspberry Pi Zero is one of the greatest
ever Raspberry Pi computers. This tiny
powerhouse has been given away free to
all The MagPi magazine subscribers ever since its
introduction in 2015.
It may be diminutive in size, but Raspberry Pi
Zero’s reputation is enormous. This month we’re
delighted to introduce you all to Raspberry Pi
Zero 2 W: it has a lot to live up to.
It comes in the exact same package you know and
love. Only now, Zero 2 packs a more powerful Arm
Cortex-A53 quad-core processor running at 1GHz.
Zero 2 sticks with the same form factor, so you
can take a Raspberry Pi Zero out of your current
project, and drop Raspberry Pi Zero 2 W straight
in its place and immediately benefit from the
improved speed. It’s also compatible with the
vast array of kits and innovative projects designed
around the small board.
At the heart of Raspberry Pi Zero 2 W sits an all-
new SiP (System-in-Package). An exciting new
approach by Raspberry Pi, that combines the usual
System-on-Chip with DRAM and enables a faster
CPU to sit in the same form factor.
It’s a new, and faster, day for Raspberry Pi Zero,
yet one that keeps the important heritage intact.
We can’t wait to see what you make with it.

34 magpi.cc Introducing Raspberry Pi Zero 2 W


FEATURE

Get your free


Raspberry Pi Zero 2 W
Raspberry Pi Zero 2 W is being given away free to
all our current and future subscribers. If you have
any print subscription to The MagPi magazine, you
will be getting a Raspberry Pi Zero 2 W in the post.
All new subscribers will get a Raspberry Pi Zero 2 W
with their subscription to our magazine (see Page 32,
magpi.cc/subscribe, for more details).
Raspberry Pi Zero 2 W costs $15 and is available
now from all major Raspberry Pi Resellers. You can
find a list of approved Raspberry Pi resellers at
magpi.cc/products.

Introducing Raspberry Pi Zero 2 W magpi.cc 35


FEATURE

Meet Raspberry Pi Zero 2 W


R
aspberry Pi Zero 2 W is designed to be
instantly swappable with Raspberry Pi
Zero in a current project, with an identical
form factor and most components in the same 2 SYSTEM-IN-PACKAGE
At the heart of Raspberry Pi Zero 2 sits
place. Dig a little deeper, and there are a host of
1 MINI-HDMI a System-in-Package (SiP) containing a
tweaks and improvements across the board. The Mini-HDMI port now has Broadcom BCM2710A1 quad-core Arm
winged edging that enables easier Cortex-A53 System-on-Chip (SoC) with
insertion of the HDMI cable. VideoCore IV and 512MB DRAM.

Specifications
SOC:
Broadcom BCM2710A1 quad-core
Arm Cortex-A53 (ARMv8-A) 64-bit
@ 1GHz

GPU:
Broadcom VideoCore IV

RAM:
512MB DRAM
5
NETWORKING:
802.11 b/g/n wireless LAN, Bluetooth
4.2 (Bluetooth Low Energy, BLE)
2
GPIO:
HAT-compatible 40-pin GPIO header,
unpopulated

STORAGE:
microSD

PORTS:
Micro SDCard slot, Mini HDMI, USB 1 6
On-The-Go, micro USB power;
composite video and reset pins
(via solder test points), CSI camera
connector

●POWER CONSUMPTION:
1 W (idle in Raspberry Pi OS GUI);
Max power, 3.8 W or 0.76 A (32-bit
mode); 5.5 W or 1.1 A (64-bit) mode
6 ANALOGUE VIDEO AND RESET
PRICE: Raspberry Pi Zero 2 W supports analogue
$15
video and reset connections. The pins are
moved to the rear of the board, alongside
DIMENSIONS: other test pins. In the bottom-right sits TV,
66 × 30.5 × 5 mm form-factor
while in the top-left, a Run pin can be used
(compatible with Raspberry Pi Zero)
to reset and restart Zero 2.

36 magpi.cc Introducing Raspberry Pi Zero 2 W


FEATURE

Meet the System


3 NEW POWER CIRCUIT
The enhanced power circuitry
in Package
from Raspberry Pi 3 has been
shrunk down and fitted onto One interesting new aspect of Raspberry Pi
Raspberry Pi Zero 2 W’s board. Zero 2 W is the System-in-Package approach
4 WIRELESS LAN to the chipset design.
The wireless LAN A Broadcom BC2710A1 SoC is placed on
and Bluetooth is now the substrate and 512MB of DRAM is placed
housed inside a module above, with an interposer placed between the
enclosure. This can two (to act as a ‘spacer’). This enables both
help with compliance, chips to connect neatly to the substrate using
enabling Raspberry gold wire. The whole thing is placed inside a
Pi Zero 2 W to have mould. This is the black chip you see on the
a smoother entry Raspberry Pi board.
to highly regulated
industrial environments.

3
4
X-ray images
The picture is a view of a 3 mm ×
2 mm section of the System-in-
Package. The black circles are
solder balls. The thick grey lines
are tracks on the substrate. The
thin black lines are gold wires, and
you can see them bonding to the
silicon (which is transparent to the
X-ray machine). Here, we can see
the 0201 (50 um × 25 um in size)
capacitors inside the package.
5 CAPACITORS
INSIDE CPU
Here is a top-down X-ray of the
There are now 18
System-in-Package that reveals
capacitors inside the
an Easter egg! Spot the Raspberry
SiP and fewer 0201
Pi logo shape in the ball map. This
capacitors on the board.
is possible because, while the
When the CPU demands
connections on the outside are
a surge in power, the
signals, the ones in the middle
capacitors inside can
are ground/power and can be
ensure that power is
arranged into any pattern.
there to meet demand.

Introducing Raspberry Pi Zero 2 W magpi.cc 37


FEATURE

Eben Upton and Simon Martin


on Raspberry Pi Zero 2 W
Raspberry Pi founder and CEO Eben Upton, and Principal Hardware Engineer
Simon Martin, walk us through the design of the new Zero 2

W
e caught up with Simon Martin, “Every part on that board pays for itself. It’s
Principal Hardware Engineer at a single-sided board, and it only has reflowable
Raspberry Pi and Eben Upton, founder components; it doesn’t have any through-hole
and CEO of Raspberry Pi. components. So it can all be manufactured simply
Simon: “Raspberry Pi Zero 2 W is all about how and robotically.
much power you can pack into such a tiny space. “So, coming up to the sixth anniversary, and
It’s about just how much can we get from such a how to use everything we’ve learned from those
small form factor. five years, there’s this whole question of ‘can
“Keeping that same form factor is important. we do it again?’ And we’re delivering most of
An original Raspberry Pi Zero can be removed Raspberry Pi’s 3 power for not much more than
from a project and Raspberry Pi Zero 2 W can half the price of a Raspberry Pi 3.
be plugged into its place. Any application that “The reality is that earlier this year people
was there beforehand will get a boost from the found out that Raspberry Pi knows how to make
processor performance. their own silicon [see, Raspberry Pi RP2040 in
“Instead of using the single-core processor Raspberry Pi Pico, magpi.cc/102 – Ed]. Raspberry
that’s in the Raspberry Pi Zero, we’ve got a quad- Pi Zero 2 W is not our own silicon, but we package
core Cortex-A53 processor, which is similar silicon in unusual ways
silicon to the original Raspberry Pi 3 when that
was announced.” Inside the package
Eben: “There’s this whole question of ‘can Simon: “It’s also known as a ‘stacked package’. It’s
we do it again?’ You can use Moore’s Law in two the concept of putting more than one monolithic
ways: you can take an amount of money and fill piece of silicon into a package to make a full system
[Raspberry Pi] with more and more computing and package device. There’s a BCM2710A1 SoC
power, or you can take the current amount of (system on a chip) in there and half a gigabyte of
computing power and deliver that at a lower and DRAM. These are both gold-wire stitched to the
lower cost. And that’s what we did with Raspberry substrate. That is then encapsulated to make the
Pi 1 – we took a ten-year-old PC’s processing package. And so, by doing this, we can get two chips
power and delivered it at around $30. And then into the space of one.
we launched Raspberry Pi 2 in 2015 and, lo and “Because the chips are similar sizes you need
behold, we’ve done the thing that everyone else to use a silicon interposer, or spacer, amongst the
does: we’ve picked a price point and filled it out centre of the processor. Then, when you put the
with six times as much computing power using memory on top, it doesn’t squash the gold wires
Moore’s Law. that connect the processor to the substrate. The
“Raspberry Pi Zero is really the result of going memory is very sensitive, so there’s less desire to
‘Aha! We should do the same thing as we did put anything on top of the memory, which is why
before.’ We should take a Raspberry Pi 1’s worth the SoC goes on the bottom and the memory on top.
of computing power and we should use Moore’s “The A53 was the highest performance chip
Law to squeeze the price down. that we’ve ever used that used wire bonding in

38 magpi.cc Introducing Raspberry Pi Zero 2 W


FEATURE

Know the numbers


Get to know what the numbers on the Raspberry Pi
Zero 2 W’s SiP mean:

RP30A0-AU: This is the SiP design number. The A0


refers to Raspberry Pi Zero, and the AU indicates
the use of gold wiring. The first models used copper

“ Because the wires but it was changed to more expensive gold


wiring to maximise long-term reliability).

chips are similar 2041: The week of manufacture (read right to left).

sizes you need to use Ours indicates the 41’st week in 2020.

a silicon interposer ”
200826: The date the batch was ordered (read right
to left). In this case, 26 August 2020.

the package, and Raspberry Pi Zero 2 W displays “The can [Wireless Lan enclosure] is a forward-
a considerable uptick in performance. Single- looking thing to the days where people want to
threaded performance is approximately 40% design this into things. We’ve got to be upfront:
faster than a normal Raspberry Pi Zero. Obviously, there’s not a huge amount of stock for the first
this is quite cool, but if you do a benchmark of the year because ‘hey, there’s a global semiconductor
single-core on a Raspberry Pi Zero and compare it shortage.’ Looking ahead, this is a product that’s
to the quad-core of Raspberry Pi Zero 2 W, you get going to be around for a long time, and we hope
more than five times the performance. Real time people will put it into product designs for OEMs.”
performance is around three times the speed. A
Raspberry Pi Zero takes around 90 seconds to boot
into the GUI, whereas Raspberry Pi Zero 2 W takes
around 30 seconds.
“It’s a small board, and if you are willing to help
out by putting a heatsink on it, or if you put it in
some sort of metal case where the heat can be
drawn away from the chip, then it is possible to
add voltage to the device so you can run it faster.”
A Raspberry Pi Zero 2 W with a cooling solution
can generally sustain 1.2GHz performance.”
Eben: “We use thick copper inside the board.
So, effectively, we dissipate the heat throughout
the board. So if you look at Raspberry Pi Zero 2 W
with a thermal camera, you’ll see that it gets hot
throughout the board. That’s because we’re using
copper to move heat away from the CPU.

Introducing Raspberry Pi Zero 2 W magpi.cc 39


FEATURE

Raspberry Pi Zero 2 W
Starter Projects
Here are some great ideas for things to
make with your Raspberry Pi Zero 2 W Handheld camera
Raspberry Pi Zero 2 W has the CSI (camera
serial interface) port found on most Raspberry Pi

Handheld console computers, enabling you to connect a Raspberry


Pi Camera Module to the device. And the official
case has a cover with a pin-hole space for the
There are many retro gaming projects for Raspberry camera. Many makers have taken things further with
Pi, and Raspberry Pi Zero lends itself extremely well 3D-printed cases and LCD screens. Take a look at
to small, handheld consoles. Attach a screen, battery, PolaPi-Zero for inspiration, and a guide to make your
consoles, and a 3D-printed case, and you’re good to own Raspberry Pi Zero 2 W camera.
play handheld classics. magpi.cc/polapi
There are some handy kits you can get to help build
your handheld console, like this RetroFlag GPi Case.
magpi.cc/retroflaggpi

Heart monitor
Practice checking on your ticker with this simple heart
rate monitor using the Enviro pHAT from Pimoroni, as
well as a Pulse Sensor Amped. Put together by Jon
Witts, it measures live heartbeats and displays the
results on a Scroll pHAT HD.
magpi.cc/heartratemonitor

40 magpi.cc Introducing Raspberry Pi Zero 2 W


FEATURE

Make a mood light


Make a dashcam The Mood Light is a Raspberry Pi Zero project kit
from Pimoroni. It uses the GPIO pins on Raspberry
Pi Zero to connect to a Unicorn pHAT with 32 RGB
Dashcams can be attached to your car to record NeoPixel LEDs. You can set these to a single colour,
video in case of an incident. ZeroView is a mount or fade them through all the colours of the rainbow.
with suction cups designed to house Raspberry magpi.cc/moodlight
Pi Zero. It includes a mount for your Raspberry Pi
Camera Module. The cups enable it to be attached
to a car windscreen, or any other type of window.
magpi.cc/zeroview

“ ZeroView is a mount with


suction cups designed to
house Raspberry Pi Zero”

Smart
Calendar
Raspberry Pi Zero 2 W is great
for powering an e-ink display,
which draws less power than an
LCD. The combination is perfect
for presenting this always-on
calendar that updates once an
hour, or at the press of a button.
Zonglin Li has infused the front-
end with numerous widgets and
an LED lights up when the screen
is being refreshed.
magpi.cc/einkcalendar

Introducing Raspberry Pi Zero 2 W magpi.cc 41


FEATURE

Raspberry Pi Zero 2 W
QuickStart Guide
Setting up and using Raspberry Pi Zero 2 W is pretty straightforward

C What you need


ongratulations on becoming a Raspberry
Pi Zero 2 W owner. We’re sure you’ll enjoy
discovering a whole new world of computing All the bits and bobs you need
and the chance to handcraft games, control robots, to set up a Raspberry Pi computer
build machines, and share your experiences with
other Raspberry Pi fans.
Getting started won’t take long: just corral the 8GB microSD card
extra bits and bobs you need on our checklist. To You’ll need a microSD card with a
get set up, use Raspberry Pi Imager to set up a card capacity of 8GB or greater. Raspberry Pi
and connect all the cables. This guide will lead you Zero 2 W uses it to store the operating
through each step. You’ll find Raspberry Pi OS, system and store programs and files.
including coding programs and office software, If you want to reuse an old card, you’ll
all available to use. After that, the world of digital need a card reader: either USB or a
making with Raspberry Pi awaits you. microSD to full-sized SD (pictured).

42 magpi.cc Raspberry Pi Zero 2 QuickStart Guide


FEATURE

Power supply
Raspberry Pi Zero 2 W uses
the same type of micro
USB power connection as
many old electronic devices.
So you can recycle an old
USB to micro USB cable
Linux, Mac, or Windows computer and a smartphone power
You’ll need a Linux PC (such as another Raspberry supply. Raspberry Pi also
Pi), Windows Linux PC, or Apple Mac computer, sells official power supplies
to run Raspberry Pi Imager to download and write (magpi.cc/products), which
Raspberry Pi OS onto a microSD card for Raspberry provide a reliable source
Pi Zero 2 W. of power.

USB keyboard
Like any computer, you need the means to
type commands, create code and documents,
and otherwise control Raspberry Pi. You can
use a Bluetooth keyboard, but the initial setup
process is much easier with a wired keyboard.
Raspberry Pi sells an official Keyboard and Hub. Display and HDMI cable
magpi.cc/keyboard A standard PC monitor is ideal, as the screen will
be large enough to read comfortably. It needs to
have an HDMI connection, as that’s what’s fitted
on your Raspberry Pi board. Raspberry Pi Zero 2 W
needs a mini HDMI to HDMI cable (or adaptor).
magpi.cc/minihdmi

perform the setup with a wired mouse. Raspberry Pi USB mouse


sells an Official Mouse (magpi.cc/mouse). A tethered mouse that physically attaches to
your Raspberry Pi via a USB port is simplest
and, unlike a Bluetooth version, is less likely
to get lost just when you need it. Like the
keyboard, we think it’s best to perform the
setup with a wired mouse. Raspberry Pi sells
an Official Mouse (magpi.cc/mouse).

Raspberry Pi Zero 2 QuickStart Guide magpi.cc 43


FEATURE

Set up
Raspberry Pi Zero 2 W
Set up your microSD card and connect
all the accessories before powering up

A HDMI cable, such as


one used by most modern
televisions, is used to connect
Zero 2 to a TV or display. You’ll
need a mini-HDMI to HDMI
cable (or adaptor)

A wired mouse or keyboard is connected to the micro


USB socket. Most devices use a USB-A connection,
and you may need a micro USB to USB-A adaptor
(magpi.cc/usbadaptor).
Get it connected
01 As you’re setting up a Raspberry Pi Zero
2 W, you’ll need to use a USB-A to micro USB-B
cable (or adaptor) to connect a keyboard to the then connect the keyboard to the micro USB socket
smaller connection on a Raspberry Pi Zero W. One (via the micro USB-A to USB-B adapter). Connect
is included with the official keyboard, which also your mouse to one of these if possible. If not,
has additional USB-A ports to accept the mouse you’ll need a USB HUB so you can connect both the
and other accessories. Or you can use a cable with keyboard and mouse to the single USB-B socket.
your own keyboard.

More connections
Mouse and keyboard 03
02 You can either connect your mouse to a
Now connect your full-sized HDMI cable
to the mini-HDMI to HDMI adapter, and plug the
USB socket on your keyboard (if one is available), adapter into the mini-HDMI port in the middle of

44 magpi.cc Raspberry Pi Zero 2 QuickStart Guide



You may need a
micro USB to USB A
adaptor and mini-
HDMI to HDMI
adaptor to connect
devices such as a
mouse, keyboard
and display

your Raspberry Pi Zero 2. Connect the other end of


the HDMI cable to an HDMI monitor or television.
“ When Raspberry Pi OS
first loads, you will need to
set a few preferences ”
Set up the software
04 Assemble your Raspberry Pi
Now you’ve got all the pieces together,
it’s time to install an operating system on your
06 Now it’s time to physically set up your
Raspberry Pi so you can start using it. Download Raspberry Pi. Plug your PC monitor into the mains.
Raspberry Pi Imager from magpi.cc/imager. This Remove the microSD card from the SD card adaptor
utility is available for Windows, macOS, and Linux and slot it into the underside of your Raspberry Pi
computers, so choose the relevant version for Zero 2 W.
your system.

Power up
Write the OS to 07
05 the microSD card
Plug in your Raspberry Pi power supply
and, after a few seconds, the screen should
Attach your microSD card to your PC or Mac come on. Raspberry Pi OS will boot up. When
computer, and launch Raspberry Pi Imager. Click Raspberry Pi OS first loads, you will need to set a
the ‘Choose OS’ button to select which operating few preferences. Click Next, when prompted, then
system you would like to install. The top option select your time zone and preferred language, and
is Raspberry Pi OS (32-bit). With an OS selected, create a login password. You’re now ready to get
click the ‘Choose SD card’ button and select online. Choose your WiFi network and type any
your microSD card (typically there will be just required password. Once connected, click Next to
one option). allow Raspberry Pi OS to check for any OS updates.
Finally, click the ‘Write’ button and wait while When it’s done so, it may ask to reboot so the
the utility writes the selected OS to your card and updates can be applied. You’re all set to start
then verifies it. When complete, you may remove enjoying computing with your very own Raspberry
the microSD card. Pi Zero 2 W.

Raspberry Pi Zero 2 QuickStart Guide magpi.cc 45


TUTORIAL

Sensory world:
Part 01

Build a fire
and gas leak
alarm system
Enable Raspberry Pi to detect flames and gas leaks to raise an alarm

H
Connect flame sensor
umans experience the world through a
range of senses. This enables us to be aware
01 For this tutorial, we’re using the
of whatever’s happening in our environment flame sensor from the Waveshare Sensors
so that we can react to it. Pack, available in the UK from The Pi Hut
So, it makes sense (no pun intended) that your (magpi.cc/wavesensors), and also sold separately,
Phil King
MAKER

Raspberry Pi would also benefit from being able to but any similar sensor should work in a similar
sense things. Fortunately, this is made possible way. It uses PIR (passive infrared) to detect a
Longtime contributor
to The MagPi, Phil is using a wide variety of electronic sensors. In this change in temperature nearby. While the sensor
a freelance writer series, we’ll explore some of the most commonly has pins for both analogue and digital outputs,
and editor with a
available sensors and their use cases. we only need the latter for our alarm, as a nearby
focus on technology.
To start off, we’ll build a simple fire and gas leak flame will set the digital output to high.
@philkingeditor alarm system using a couple of sensors. When With the power turned off, connect the flame
either hazard is detected, a visual and audible alert sensor to Raspberry Pi, as in Figure 1 (where it’s
will be triggered. at the bottom). We’re powering it from Raspberry
Pi’s 3V3 pin, grounding it with a GND pin (both via
the breadboard side rails), and the digital output

Figure 1 The wiring diagram for the complete alarm system,
Figure 1 including two sensors, LED, and buzzer (marked DOUT on the sensor) is going to GPIO 21.

Flame test code


02 With the flame sensor wired up, turn on
Raspberry Pi. You should see the sensor’s red
power LED light up if it’s connected correctly.
To start with, we’ll create a simple Python
program, as in the flame_test.py listing, to
read the sensor and print out a message when
triggered, to check that it’s working correctly.
From the desktop menu, go to Programming and
open the Thonny IDE to start coding.
To simplify the setup, we’re using the GPIO
Zero library rather than RPi.GPIO; at the top of

46 magpi.cc Sensory world: Build a fire and gas leak alarm system
TUTORIAL

The MQ-5 gas sensor can detect


butane, methane, propane, and
other noxious gases

The passive infrared flame DOWNLOAD


sensor detects any nearby
fire within its scope
THE FULL CODE:
magpi.cc/github

our code, we import the Button method from it.


We’ll use this to sense when the digital output
from the sensor is high, in effect the equivalent
flame_test.py Top Tip
of a push-button being pressed. As it’s connected
Analogue out
to GPIO 21, we assign the flame object to this with > Language: Python
flame = Button(21). For simplicity,
In an infinite while True: loop, we check 001. from gpiozero import Button we’ve used the
whether the pin is high (if flame.value == 1) 002. digital outputs
and set the message (msg1 variable) that we’ll be 003. flame = Button(21) to trigger our
alarm. To use the
printing to the Thonny Shell area accordingly. 004. msg1 = ""
analogue outputs,
In our print statement, we add the end = "\r" 005.
you’ll need to
parameter so that the message is always printed 006. while True: add an ADC chip
on the same line, which is a lot neater than using 007. if flame.value == 1: (e.g. MCP3008) to
a new line each time. 008. msg1 = "Fire! " convert them to
009. else: digital readings.
010. msg1 = "No fire"
011. print(msg1, end = "\r")
Flame on!
03 Now it’s time to test our sensor by putting
You’ll Need
a flame near to it to see if it triggers our alarm > Flame sensor
Add a gas sensor
message. We used a disposable lighter for this, but
you could just light a match. Always be careful with
04 So, we have our flame sensor working
magpi.cc/
flamesensor
fire, though, and don’t get the flame right next to correctly. Now it’s time to add the gas sensor to > MQ-5 gas sensor
the sensor as it’s not fire-proof! our setup. We’re using a Waveshare MQ-5 sensor magpi.cc/
Run your flame_test.py Python code and then for this, as featured in the Sensors Pack, but other gassensor
move the flame towards the sensor. Ours triggered similar gas sensors are available. The tin oxide > LED
at around 30 cm distance, but the sensitivity can be layer inside the sensor has a high sensitivity to
> Active piezo buzzer
altered by using a small crosshead screwdriver to the presence of gases such as butane, methane,
adjust the screw on the sensor board – other flame and propane. > Jumper wires
sensors may have a potentiometer rotary knob on The sensor has pins for analogue and digital
board for this purpose. outputs, but we only need the digital output for
When the flame is close enough to trigger the our alarm. We connect that pin (DOUT) to GPIO14,
sensor, another red LED lights on ours to indicate and the VCC and GNC pins to 3V3 and GND (shared
this. The message printed in the Thonny Shell area with the flame sensor via the breadboard side
should change from ‘No fire’ to ‘Fire!’. rails), as in Figure 1 (gas sensor at the top).

Sensory world: Build a fire and gas leak alarm system magpi.cc 47
TUTORIAL

gas.value == 1), then the message will be set to


‘Gas leak!’; if not, it’ll be ‘No gas’.
We add msg2 to our print statement, after msg1,
again including the parameter end = "\r" so the
message is always printed on the same line.

Turn on the gas


06 Now it’s time to test our gas sensor to
check it’s wired up and working correctly. As
before, we’re using a disposable lighter for this,
pressing the button to release a little gas without
T
 esting the flame
igniting it for the flame. You could use gas from a

flame_gas_test.py
sensor with a lighter.
Be careful not to hob or cylinder, but you only need a tiny amount
move it too near
the sensor or other to trigger the sensor, so be sure to turn it off again
components!
after a couple of seconds.
> Language: Python Run your flame_gas_test.py Python code

Top Tip 001. from gpiozero import Button


and then release a little gas in the vicinity of
the sensor. As with the flame sensor, the gas
002. sensor’s sensitivity can be altered by using a small
Off board 003. flame = Button(21) crosshead screwdriver to adjust the potentiometer
004. gas = Button(14) screw on the sensor board.
We’ve placed our
005. msg1 = "" When the presence of gas is detected and the
sensors on the
breadboard, but 006. msg2 = "" sensor is trigger, another red LED lights on ours to
you could keep 007. indicate this. The second message printed in the
them separate 008. while True: Thonny Shell area should change from ‘No gas’ to
from the other 009. if flame.value == 1: ‘Gas leak!’.
components and 010. msg1 = "Fire! "
wire them up from
there, with the
011. else: T he gas sensor’s sensitivity
012. msg1 = "No fire "
digital outputs
wired directly to 013. if gas.value == 1: can be altered
the GPIO pins. 014. msg2 = "Gas leak!"
015. else: Let there be light
016. msg2 = "No gas "
07 If your sensors and code are working
017. print(msg1, msg2, end = "\r") correctly, and the correct messages are shown
when they’re triggered, it’s time to move on to
the next part. Printed messages are all very well,
Add gas to code
05 While we could create a new program to
but for a proper alarm you need a visual and/or
audible alert.
test the gas sensor separately, we’ll add it in to our For the visual side, we’ll add a standard red
previous code as it will then be simpler to rework it LED to our setup – ours is 5 mm, but you can use
into our final alarm code later. any size. As always when using LEDs, a resistor
In the flame_gas_test.py listing, we assign the is required to limit the current to make sure it
gas object to GPIO 18 with gas = Button(14). As doesn’t receive too much and potentially burn out.
before, we’re using the Button method to detect With the LED placed in the breadboard, with legs
when the pin is triggered and thus set to high. in different unconnected rows, we connect a 330 Ω
We add a new msg2 variable, which we’ll set to resistor between the negative (shorter) leg and the
the message we want to print in the Shell area. ground rail of the breadboard. The positive (bent,
This is done by adding some extra lines to our while longer) leg is connected to GPIO 16 on Raspberry Pi
True: loop. If the gas sensor pin is triggered (if (as in the Figure 1 wiring diagram).

48 magpi.cc Sensory world: Build a fire and gas leak alarm system
TUTORIAL

T
 he Waveshare flame sensor has both analogue and digital
outputs. Sensitivity can be adjusted with the screw The MQ-5 gas sensor can detect several noxious gases in the air
and is highly sensitive

Get a buzz
08 For our audible alert, we’re using a small buzzer (e.g. magpi.cc/towerlight). You could also
active piezo buzzer to make a beeping noise. The send an email or push notification alert to your
buzzer will have a longer positive leg and a shorter phone whenever the alarm is triggered.
negative one; their positions may also be marked Next time we’ll create an intruder alarm using
on top of the buzzer itself. Connect the negative noise and laser sensors. See you then.
pin to the breadboard’s ground rail and the Warning!
positive pin to GPIO 25 (as in Figure 1). Fire and gas

fire_gas_alarm.py Never play with fire! Be


careful when testing
your alarm and don’t

Alarm code position the lighter flame


09 With everything wired up as per Figure 1, > Language: Python
too close to the sensors
or other components.
Only release a small
you’re now ready to program your fire and gas amount of gas and do
it in a well-ventilated
alarm. In the final code, fire_gas_alarm.py, we 001. from gpiozero import Button, LED, Buzzer area. Do not rely on
add LED and Buzzer to the gpiozero imports at the 002. from time import sleep this DIY alarm for your
safety. In the event
top. We also import sleep from the time library, to 003. of a real fire or gas
use as a delay. 004. flame = Button(21) leak, call the relevant
emergency service.
We create two functions, one for each type of 005. gas = Button(14)
magpi.cc/firesafety
alarm: fire_alarm and gas_alarm. Each uses a for 006. led = LED(16) magpi.cc/gassafety
loop which toggles the LED and buzzer on and 007. buzzer = Buzzer(25)
off a set number of times, with a 0.5 sleep delay 008.
each time. 009. def fire_alarm():
Finally, in a while True: loop, we check the pin 010. print("Fire! ", end = "\r")
values and trigger the relevant alarm when the 011. for i in range (10):
pin receives a signal from the sensor. If neither 012. led.toggle()
is triggered, we show the default message and 013. buzzer.toggle()
ensure the LED and buzzer are turned off. 014. sleep(0.5)
015.
016. def gas_alarm():
017. print("Gas leak!", end = "\r")
Sound the alarm 018. for i in range (10):
10 Now to test the alarm system. As before, try 019. led.toggle()
positioning a flame near the fire sensor to check 020. buzzer.toggle()
that the alarm is triggered, in which case the LED 021. sleep(0.5)
will blink and the buzzer will beep. Do the same 022.
for the gas sensor by releasing a small amount 023. while True:
of gas; the alarm will sound again. Each time, an 024. if flame.value == 1:
appropriate message will show in the Shell area. 025. fire_alarm()
026. elif gas.value == 1:
027. gas_alarm()
028. else:
Taking it further 029. print ("All OK ", end = "\r")
We now have a simple working fire and gas alarm. 030. led.off()
To make the alert more obvious, you could add 031. buzzer.off()
a relay switch to turn on a 12 V tower light with

Sensory world: Build a fire and gas leak alarm system magpi.cc 49
TUTORIAL

Turn Keybow
2040 into a
stream deck
Reprogram the RP2040 auxilliary keyboard into a
powerful macro keyboard for streaming and more

S
Basic Keybow 2040 usage
treaming is fun. Whether you’re doing
art, playing games, or just chatting with
02 Plugging your newly built Keybow 2040 into
followers, it can be great to interact with your PC will activate the pre-installed code that
folks while doing something else. turns it into a numpad using a basic HID (human
It is also quite complex to stream. Starting with interface device) script. The LEDs in the keys are
a complicated OBS setup to stream your game, turned off, but go green as they are pressed.
and ending up with loads of extra tabs and audio As well as being usable while plugged in,
mixers thrown in, there can be a lot to control you can also access the storage inside and find
Rob Zwetsloot
MAKER

and maintain while you’re live, and even more different examples in the examples folder. To use
to do if you want to use silly audio effects or one, merely copy it to the top Keybow directory
Rob is amazing. He’s
zooms, etc. This is where a stream deck comes and change the file’s name to code.py.
also the Features
Editor of The MagPi, in, allowing for short cuts for various functions
a hobbyist maker, at the press of a button. A lot of dedicated stream
cosplayer, comic
book writer, and
deck products can be pretty expensive, though,  lot of dedicated stream
A
extremely modest. so let’s make something a lot cheaper and far
more customisable.
deck products can be
magpi.cc
pretty expensive
Construct Keybow 2040 Customise your code
You’ll Need 01 The Keybow requires some building
03 The code.py file is what tells the Keybow
before you use it – it’s fairly simple though. 2040 how to operate. Looking through the
> K
 eybow 2040 You attach some standoffs, a middle layer, examples, you’ll be able to see how a lot of the
magpi.cc/ add the switches to the final plate, add the individual parts work together. A full list of the
keybow2040
keycaps, and then sandwich it all together. functions can be found on the Keybow GitHub
> O
 BS There are some illustrated instructions here: here: magpi.cc/keybowgit.
obsproject.com
magpi.cc/keybowbuild. You should be done As it runs on CircuitPython, based on
> V
 oiceMod before an episode of The Simpsons is over. MicroPython, a lot of Python knowledge and
voicemod.net For stream deck use, we also have a 3D-printed skills are transferable while writing any custom
> U
 SB-C to switch stand that it fits onto nicely, keeping the code. With one caveat though – using sleep is not
USB-A cable keys in eyesight (which is important, as we’ll recommended by Pimoroni, and it did not work
explain later). with this build either. Still, there’s a lot you can do.

50 magpi.cc Turn Keybow 2040 into a stream deck


TUTORIAL

Control your streaming


with hotkeys activated
Make quick changes that affect your from the stream deck
stream without having to fumble
with all the open applications

LED colours
It’s very quick to prototype and test your custom
code as well – opening, editing, and then saving
05 We’ve opted for all the keys to be lit up Top Tip
the code.py file will immediately reset Keybow while the stream deck is connected, and this can be
2040 so that you can test out your handiwork. done using a simple keybow.set_all() command, Manual
where an RGB code is placed in the brackets. combos
For our code we’re using green (0, 255, 0),
The key combos
yellow (255, 255, 0), and red (255, 0, 0), and you
you’ve set up
Keyboard shortcuts
04 The basic keys used by the default code
can easily add or modify the colours as you see fit.
All the keys light up green when the Keybow is on
can also still be
done on your
should be altered if you plan to use this as a (mostly to remind us that it is), and keys will turn regular keyboard,
stream deck. They function as a numpad, and yellow once activated. The red is used for the mute in case you need
a backup way to
while they will work as hotkeys, they may also be and voice change button when activated, just to
use a hotkey.
used normally by the software you’re running. differentiate them.
Luckily, the Arduino key library allows for For other colours, blue is a good one (0, 0, 255),
multiple keys to be sent at once: as well as white (255, 255, 255). If you need another
shade, simply enter the name of it followed by
keyboard.send(Keycode.LEFT_CONTROL, Keycode. ‘rgb’ into your search engine of choice.
KEYPAD_ZERO)

In our code, we’re still using numpad keys, but


When pressed
we’ve added the left CTRL key to the combo. You
could easily use a different key, such as the scroll
06 One of two most important parts of our
lock, or multiple keys. Just check to make sure code is the press_handler function. As the code
the key combos you’re planning on using aren’t cycles, it waits for a key to be depressed before
being used in other programs – we don’t want any it starts doing anything. It gets told which key is
ALT+F4 incidents while streaming games. being depressed, finds out which part of the key

Turn Keybow 2040 into a stream deck magpi.cc 51


TUTORIAL

VOICE
CHANGER
0 1 2 3
Here’s how the
keys are laid out on
Keybow 2040 related
to the code
SOUND
EFFECTS
4 5 6 7
USB CABLE

AUDIO
CONTROL
8 9 10 11
OBS
CONTROL
12 13 14 15

combo it should use, and then sends that as a colours’; however, one of them treats a series of
Top Tip key press.
We also have an if statement so that a specific
three keys differently: elif key.number >= 1 and
key.number <= 3. Only one may be lit yellow at a
key turns to yellow when depressed, as all this time, and we’ll be using this to select a type of
OBS focus
button does is stop any sound effects from voice modification.
You may find playing – it can easily be applied to other keys by The and here also works as a Boolean operator,
some difficulties modifying this if statement. where AND means only if it satisfies both
using hotkeys with requirements, and OR means if it satisfies at least
OBS – make sure one requirement.
the window is in
focus for them.
When released
07 By having separate press and release
Planning your layout
functions, we save the code treating a button-
press as multiple events. We can also define what
08 For the code in this tutorial, we’ve set up
happens when the button is released; in this case the keys in categories, as shown in Figure 1. Keys
we change the colour of the key to indicate that 0-3 on the top line handle voice changing, the
it’s been used, as well as updating the keytoggle second row we use for sound effects, the third line
list, which we use to remember the state of the for muting and stopping sound effects, and the
key (on or off, 1 or 0) last line for OBS hotkeys.
Adding hotkeys to As we have many different buttons doing Remember, the keys go from 0 to 15 only when
OBS is very easy, and different things, we’ve racked up a long if the Keybow is orientated with the USB cable
it can control just
about every aspect statement – most are simply ‘change between two sticking out of the right side.
Depending on your stream deck uses, you can
make your own layout; however, be aware of the
placement when programming.

Special keys
09 Our mute key and voice change key both
turn red when activated. These are both important
keys in the setup and if you’re a bit forgetful, like
us, you may not realise that the voice change key
is still on until a helpful member in chat points
out that you sound like a robot.
They broadly function the same as any other key
pressed; however, the differing colours do help

52 magpi.cc Turn Keybow 2040 into a stream deck


TUTORIAL

DOWNLOAD
THE FULL CODE:
magpi.cc/streamdeck

The free version of


VoiceMod offers many
features, and they all
work with hotkeys

when you’re trying to quickly bump a key while It will not only set the hotkey but also tell you
drifting a Ferrari around LA. what it is – a good way to check that your code
worked properly.

Toggle keys
10 VoiceMod hotkeys
The keys 1, 2, 3 we are treating as toggle keys,
as explained above. Here is how the code works:
12 VoiceMod is a great piece of software
for doing fun voice changers, playing sound
key.set_led(*rgb2) effects, and generally controlling the entire
keytoggle[key.number] = 1 audio input for your stream. Selecting a
modifier, you’ll see a button to add a hotkey -
This part sets the key to yellow, and changes the click that and use the desired Keyboy 2040 key.
keytoggle list to on/1 for that key. The same is true for any sound effects or clips
you upload.
if key.number != 1: In the Settings, you can also add other
Elevating and angling
keys[1].set_led(*rgb1) hotkeys – for the code we’ve used, key 0 is for a stream deck can
keytoggle[1] = 0 voice changer toggle, key 8 for mute/unmute, make it easier to
press buttons… and
and key 9 for stopping any sounds. remember it’s there
This part checks to see if key 1 was not pressed,
and the following two statements check for keys 2
and 3. If those keys were not pressed, the colour is
returned to green, and the keytoggle is set to off/0.

 ur mute key and voice


O
change key both turn red
when activated

OBS hotkeys
11 Just about every element in your OBS setup
will be able to have a hotkey attached – whether
it’s simply changing to a scene, showing and
hiding an image, or to stop streaming. From OBS,
click Settings and then select the Hotkeys tab.
Click on the bar next to the function you’d like
to hotkey, and then press the desired Keybow key.

Turn Keybow 2040 into a stream deck magpi.cc 53


TUTORIAL

Connect retro
Part 01

MIDI hardware
to Raspberry Pi
External MIDI sound cards like the Roland MT-32 were the peak of computer
music in the 1980s and 1990s. They still work just as well today

E
K.G.
MAKER

xternal MIDI sound cards were the pinnacle Connect the MIDI OUT plug on the lead to the
Orphanides
of 1980s and early 1990s computer music MIDI IN port on your audio interface. The MIDI IN
K.G. holds that production and playback. We’ve used a plug on the cable goes into the MIDI OUT port on
digital audio Roland MT-32 and SC-55 in this tutorial, but you the sound card. Power up your external audio device
hardware peaked can use most external MPU, MT-32, GM, GS, or and make sure you’ve connected headphones or
in the 1990s
and is prepared
XG MIDI devices from the era. Although some speakers – audio connections vary. Our MT-32 rev 0
to die on this current hardware MIDI sequencers are marketed has only a pair of 1.4‑inch TRS outputs, so make sure
preposterous hill. to musicians, modern consumer audio interfaces you have appropriate cables and adapters. On some
@KGOrphanides usually lack integrated MIDI voices, and even early devices, you should keep the MIDI device volume
2000s implementations can suffer variable General low to avoid crackling. Similarly, if you accidentally
MIDI sound bank quality. However, the Serda attach the MT-32’s right output to your speaker’s
3XMA (magpi.cc/x3m) is a well-regarded and, at left channel and vice versa, your sound will be
€79 (£68), relatively inexpensive modern USB MIDI overwhelmed by static upon playing anything.
interface with sound banks designed for backwards
compatibility with the SC-55.

Power me on
02 Connect the USB-to-MIDI cable to a USB
Hook me up
01 If you’re using original 1980s or 1990s
port on Raspberry Pi and power on. Raspberry Pi OS
should detect it as an ALSA device. We’ll check that
hardware, start by connecting your MIDI-to-USB it’s there and then run a couple of tests to make
cable. This has a standard USB Type-A plug on one sure it’s plugged in, discover its port number, and
end, and a pair of 5-pin DIN MIDI plugs on the other. play a MIDI file. Open a Terminal and enter:

amidi -l
You’ll Need sudo apt install pmidi
wget wiki.ultimacodex.com/images/8/80/
> U
 SB to 5-pin MIDI Stones.mid
cable pmidi -l
> A
 n external MIDI pmidi -p 20:0 Stones.mid
sound card

> S
 cummVM The port number after -p should be whatever
magpi.cc/ pmidi -l reports your device as. If pmidi doesn’t
scummvm list any devices, reboot Raspberry Pi. We’re going
> D
 OSBox-X to need MIDI sequencer software next, so let’s

Above Here, we’re using Jack’s Connect interface to connect
magpi.cc/dosboxx grab Qtractor and Jack right away. At the Terminal,
Qtractor to our MIDI interface, and our Vortex Wireless MIDI
keytar to Qtractor. Think of the lines as patch cables enter: sudo apt install qjackctl qtractor.

54 magpi.cc Connect retro MIDI hardware


TUTORIAL

Uniquely, the Roland MT-32’s


display can be programmed to
display a message, which some
games take advantage of, like
Sierra’s Quest for Glory II


Above Qtractor is a simple but effective Digital Audio Workstation
(DAW) capable of handling MIDI files and composition

Jack in
03 To minimise latency, we’re going to be using
the Jack Audio Connection Kit, which should have
been fully installed as a dependency of qjackctl. At
the Terminal, type:

qjackctl

Now click Setup and, at the right of the screen,


set MIDI Driver to seq from the pull-down. Leave
the Advanced tab at default settings - if you’ve
previously edited your Jack profile, you may need
to reset the Output and Input Device fields to
‘(default)’. Do not select your USB MIDI interface This £10 5-pin DIN MIDI to USB adapter
here, as Jack is looking for PCM audio support and works perfectly, but name-brand models
will crash without it. like the £35 Roland UM-ONE-MK2 are worth
From Raspberry Pi’s applications menu, go to getting if you need guaranteed support for
on-screen messages
Sound and start Qtractor.

Import to DAW
04 Time to try our Digital Audio Workstation.
In Jack’s main window, select Connect and click
the ALSA tab. Select Qtractor from the left column
(Output ports) and USB MIDI Interface from the
right (Input ports), then click Connect. A line
should appear between them. instrument, create a new Qtractor file, and go back
In Qtractor, in a new project, go to the to the ALSA tab in Jack’s Connect window – restart
Track menu > Import tracks > MIDI. Select the Jack if your MIDI instrument doesn’t show up.
Stones.mid file we were using earlier. This should Connect your MIDI instrument on the left to
open several tracks in Qtractor. Click the <| button Qtractor on the right, and Qtractor on the left is
to make sure the play head is at the beginning, connected to your USB MIDI Interface on the right.
then hit play. You should be able to hear and see
our MIDI file.

Your own composition


06 Go back to Qtractor, right-click in the
How about MIDI input?
05 You can manually use Qtractor’s piano roll
left-hand pane, and select Add Track. Select Type:
MIDI, Channel: 2, and Program: 17 for an MT-32
to create and edit music. But if you have a MIDI harpsichord – or Program: 7 for GM hardware.
instrument with either a USB connection or another Click OK and play. If that works, make sure you’re
5-pin DIN and USB adapter, you can use that as at the start of the track, press record, play, and you
a control surface to record or play music directly can now record real-time MIDI input. Give each
through your retro MIDI device. Plug in your track its own channel - the MT-32 supports up to

Connect retro MIDI hardware magpi.cc 55


TUTORIAL


Above The MT-32 defaults to receiving MIDI on channels 2–9;
press the MASTER VOLUME and 5 buttons at the same time, then
tap 1 to switch it to a more conventional channel 1–8 configuration

eight simultaneous channels, plus percussion. The


SC-55 and other General MIDI cards support up
to 16. You’ll notice that Qtractor doesn’t display a
patch map with instrument names. You can find
an MT-32 list at magpi.cc/mt32 and a list of the
GM GS instruments used by the later devices on
Wikipedia (magpi.cc/midievents).

Add real MIDI to ScummVM


07 ScummVM allows you to play a wide

Above More readily available than the MT-32, the Roland
range of retro and even modern games, from the SC-55 and its successors use a particularly lovely-sounding
General MIDI sound bank
classic LucasArts titles it was first designed for,
to adventures by Sierra, RPGs by SSI, and modern
AGS adventures. synth, Roland GS device. Click OK to return to the
Go to magpi.cc/scummvmdownloads and main screen.
download the ‘Raspberry Pi 3/4/400 with Raspberry Select Add Game, navigate into the directory
Pi OS 32 bits (armhf)’ AppImage. Then download where you extracted Beneath a Steel Sky, and click
Beneath a Steel Sky - Freeware Floppy Version Choose. Select the game’s entry and click Start.
from magpi.cc/scummvmgames and extract it The theme music should play through your MT-32,
somewhere convenient. while SoundBlaster-compatible sound effects will
In your file manager, right-click on the come through Raspberry Pi’s PCM output.
ScummVM AppImage, select Properties, click the
Permissions tab, and set the Execute pull-down
to Anyone. Click OK, then double-click the file to
Do it in DOSBox-X
launch it.
09 ScummVM can’t play everything from that
era, so we’ll configure DOSBox-X to use our MIDI Top Tip
device, too. Open a Terminal and type:
MIDI configuration for ScummVM SC-55 in
08 ScummVM uses ALSA to output to your MIDI sudo apt install automake libncurses-dev nasm
software
device. Although they can work together, stop Jack libsdl-net1.2-dev libpcap-dev libfluidsynth-
If you want GM
to avoid potential conflicts during configuration. In dev ffmpeg libavdevice58 libavformat-* sounds without
ScummVM, click Options. In the Audio tab, select libswscale-* libavcodec-* hardware
your USB MIDI Interface as your preferred output git clone https://github.com/joncampbell123/ tinkering,
device. In the MIDI tab, select it as your GM device. dosbox-x.git download
FluidSynth and
Finally, in the MT-32 menu, select your MIDI cd dosbox-x
direct your MIDI
interface as the device and, depending on what ./build
output through
hardware you have, tick either True Roland MT‑32 sudo make install that via Jack.
or, if you’re using an SC-55 or similar GM/GS dosbox-x

56 magpi.cc Connect retro MIDI hardware


TUTORIAL

MIDI jargon buster

MIDI Musical Instrument Digital Interface, an electronic music communication standard

SysEx System Excclusive messages, used to send instrument patches, messages, and control signals to MIDI devices

MPU Roland's MIDI Processing Unit range. The most famous was 1984's MPU-401

MT-32 This famous Roland MIDI synth became a byword for PC MIDI audio before the GM standard

GM General MIDI, a 1991 standardised spec for MIDI-controlled sound generators

GS General Standard/General Sound, a Roland standard that expands GM with extra sounds

XG Yamaha's 1994 EXtended General MIDI standard, with up to 480 instruments

At DOSBox-X’s Z: prompt, type exit. This will cmake .. See midi.org/


specifications
create the DOSBox-X config directory, Now we make for more specs
can export a config file for easier customisation. sudo make install and standards

Restart DOSBox-X and, at the Z: prompt, type:


Now cd to the directory containing the Martian
CONFIG.COM -all -wcd Dreams installer and type:
exit
innoextract 'setup_ultima_worlds_of_
adventure_2_-_martian_dreams_1.0_cs_(28044).
exe'
Configure your MIDI settings.
10 Restart DOSBox-X again. Click on the Main Copy the MARTIAN folder to a new /dos/games
menu at the top left of DOSBox-X’s menu bar and directory in your home. Go to that directory and type:
select Configuration Tool. Next to mididevice, type
alsa. For midiconfig, type the device identifier dosbox-x INSTALL.EXE
pmidi gave us earlier - 20:0 in our case. If you’re
using a rev 0 Roland MT-32, you may need to add Press ENTER to progress through the options
20:0 delaysysex to prevent buffer overflow issues. until you get to audio settings. Select Roland
Save this to the config file we set up earlier and MT‑32 or LAPC-1, then select Yes to save and exit.
we’re ready to try out a game. Exit DOSBox and, back at the command line, type:

dosbox-x MARTIAN.EXE

Obtain and extract


11 Martian Dreams
Tell me more
Top Tip
Go to magpi.cc/ultima2 and grab the free version
of Martian Dreams - you’ll need to create a GOG
12 Although a number of external MIDI
account if you don’t already have one. The supplied sound cards had LCD screens, most just display
Make your
own MT-32
file requires innoextract to use on Raspberry Pi, so instrument, volume, and similar data. The
open a Terminal and type: exception is the MT-32, which could display any If you can't get
text sent as a SysEx (MIDI system exclusive) an external MIDI
sudo apt install build-essential cmake message to its tiny screen. A number of games, device, turn a
libboost-all-dev liblzma-dev including titles by Sierra and LucasArts, used this spare Raspberry
Pi into one with
wget https://constexpr.org/innoextract/ to display references to the on-screen action.
the MT32-pi
files/innoextract-1.9.tar.gz For more MT-32 utilities and documentation, check operating system:
tar xzf innoextract-1.9.tar.gz out magpi.cc/mt32resource. Roland also continues magpi.cc/
cd innoextract-1.9 to distribute software and documentation for its mt32pigit.
mkdir -p build && cd build older audio hardware at magpi.cc/rolandtools.

58 magpi.cc Connect retro MIDI hardware


SUBSCRIBE AND

SAVEUP
TO

35%
on the cover price

ISSUE #48

OUT NOW
hsmag.cc
TUTORIAL

Ultimate home
Part 04

server: enhance
your network
Make your ultimate server a network genie with these apps

I
n the previous parts of this tutorial, we’ve forward. The easiest way to do this is to ask your
PJ Evans taken a Raspberry Pi 4 and turned it into a router to reserve an IP address for your ultimate
MAKER

file sharing, media streaming powerhouse. server. We recommend you look at doing this
PJ is a writer, Next we’re taking on your network. There are before proceeding. Sorry for the vagueness, but
software developer
so many ways to enhance your home (or office) every router does this differently.
and tinkerer. His
server has just told network that we can’t hope to fit them into a few
him it’s time for pages. However, these steps will point you in the
lunch. This might be right direction and hopefully inspire you to make
getting out of hand.
Home control the easy way
twitter.com/
your home network smarter, faster, and more
convenient to use. Follow along and we’ll automate
02 Want to automate your home? Fancy being
mrpjevans
your home, allow you to access your data securely able to control lights or check a home webcam
from anywhere in the world, and automatically from anywhere in the world? How about if that
protect you from nefarious websites. software cost you absolutely nothing? Home
Assistant is an incredible package that integrates
a wide range of inexpensive smart devices such as
Philips Hue, Ikea Trädfri, and many more. Best of
Settle on an address
01 A key aspect for any server is that you
all, it’s open enough that you can create your own
activities and integrate your own projects relatively
should know where it is. It seems obvious, but easily. Installation on an existing server requires
a typical home network will assign IP addresses a few steps, but a great guide has been written by
dynamically (a system known as DHCP) and the HA team – magpi.cc/hacore – that we have
there’s a fair chance they will change from time summarised here: magpi.cc/hasummary.
Home Assistant can
control hundreds to time. We normally get around this by using
of IoT devices
zero-config domain names like ‘.local’, but we’re
with customisable
dashboards like this going to need a set IP address for our server going
Getting started with
03 Home Assistant
The first time you run Home Assistant, it’ll take
a few minutes or so to get its act together as it
installs everything it needs. HA will also scan
your network for any existing devices you have.
Once running, you can access the dashboard at
http://ultimate.local:8123 (change the name if
you didn’t call your server ‘ultimate’). You may
be surprised to see what is already detected and
available. If not, there are hundreds of plug-ins
to extend HA’s capabilities. Home Assistant is a
massive topic, so you may want to have a read of
our tutorial in The MagPi #99 (magpi.cc/99).

60 magpi.cc Build the ultimate home server with Raspberry Pi


TUTORIAL

The Home Assistant app


allows you to monitor and
control all kinds of IoT devices

Our ultimate server now hosts a whole


suite of network features in a tiny case

Add an MQTT broker


04 We will absolutely forgive you if this title
sudo apt install mosquitto mosquitto-clients
You’ll Need
sounds like gibberish. MQTT is a very simple This will install Mosquitto and make sure it’s
> Raspberry Pi
protocol for sending messages from device running as a service at all times. To test it’s
Ultimate Server as
to device. It is loved by the home automation working, open two Terminal windows and run built in The MagPi
community, so it’s no surprise it’s well supported these commands, one in each: #108, #109, & #110
by Home Assistant. The principle is simple: any
device can publish its data (e.g. a temperature mosquitto_sub -t "test"
reading) to an MQTT ‘topic’ (a label to describe mosquitto_pub -m "message from mosquitto_pub
the data stream). Then, any other device can client" -t "test"
‘subscribe’ to the MQTT topic and receive updates
in real-time. It makes brewing your own sensors If all is working, you will see a window ‘talking’
or switches so much easier as you don’t have to to the other. Now anything that generates MQTT
know about the target. messages can connect with you and your Home
Assistant server. Just add the MQTT integration in
HA and you can create graphs, alerts, and more.

 key aspect for any server


A
is that you should know 06 Adding remote access
Previously, we’ve configured our server to
where it is stream audio and video and now we can switch
lights, check the living room, feed the cat, and
more. So, if you’re not home, how do you do
A nice kind of mosquito
05 One of the most popular MQTT brokers (a
this? Remote access to your home network is
not something to take lightly, as if you can get
server that receives and broadcasts MQTT events) access, what stops someone else? The answer is
is Mosquitto. Installation is very straightforward: PiVPN, a script that installs a VPN (virtual private

Build the ultimate home server with Raspberry Pi magpi.cc 61


TUTORIAL

A virtual private network) that you can connect to securely from a port mapping. Your router needs to forward all
network such as
Wireguard creates a anywhere in the world. Previously PiVPN only traffic to port 51820 (default) over UDP to your
secure encrypted link supported OpenVPN, which can be difficult to server. How to do this varies from router to router,
to your home devices
from anywhere work with, but now the much simpler Wireguard so search for your particular router’s instructions.
protocol is supported. To create users that can access the network,
run this command:

Top Tip Installing Wireguard


pivpn add

07 For lots of information on PiVPN and Give a username when prompted and a config file
Building
your Home Wireguard, head over to The PiVPN Project at will be created. Copy that config file to the device
Assistant pivpn.io. To get started with installation, run the you want to use to access the network and import
setup following command from a Terminal: it using the free Wireguard client software. Now
you can access your home network from a laptop
The Home curl -L https://install.pivpn.io | bash or smartphone from anywhere in the world.
Assistant
community
maintains a list of The installer will take you through a series of
compatible smart questions. An important point is to ensure you
Add a web server
devices. These
either work ’out
have a static IP address as your router will need
to know where to find your Wireguard server.
09 The fun thing about web servers is they
of the box’ or with When asked what type of server to install, are actually very simple things. You can place
a free plug‑in:
answer ‘Wireguard’. Continue through the a text file in the home directory and the server
magpi.cc/
installer, accepting the default answers. If you will happily serve it anywhere in the world. If
haplugin
don’t have a static IP address for your router, you you would like to be able to access files through
may need to consider a dynamic DNS service such a web browser, you can combine Wireguard and a
as DynDNS (account.dyn.com) so you can easily web server to make access both easy and secure.
reach your Wireguard service. As an example, we’re going to configure access
to the media library we have previously created.
First, install a web server:

Using Wireguard
08 Before you can use Wireguard to get secure
sudo apt install apache2

remote access to your network, you need to allow After that single line, you would be able to access
the internet to ‘see’ it. This is done by creating a simple welcome page at http://ultimate.local.

62 magpi.cc Build the ultimate home server with Raspberry Pi


TUTORIAL

Adding directories to
10 your web server
It has a maintained blacklist of DNS servers
that are for advertising and intercepts any such
What a web server can provide you with is only requests. To do this, Pi-hole must be your DNS
limited by imagination. Let’s get simple access server. Here things get complicated. For best
to our music and videos, which are stored in results, your new Pi-hole server should also
/mnt/huge/Media. Apache has a complex be your network DHCP server (the server that
configuration system, but we’re going to play a allocates IP addresses to your local devices). This
little UNIX trick to make things easier: a symbolic requires some additional setup and we recommend
link. This allows us to map one part of the file you have a read of The MagPi #104 (magpi.cc/104).
system to another, creating a kind of short cut.

sudo ln -s /mnt/huge/Media /var/www/html/


Careful with those ports
media
13 A final warning. In this tutorial we’ve
Now you should be able to go to http://ultimate. talked about opening ports to the internet using
local/media/ and browse your files. It isn’t your router’s port forwarding features. You may
pretty, but it’s a start! Now you can connect to be tempted to just directly open ports to the
your network securely and access files easily. various services we’ve installed so you can get
access wherever you are. One tip: don’t. The
reason that services such as Wireguard exist is
 i-hole can protect your
P to ensure that bad actors can’t find any easy way
to access your stuff. Wireguard uses state-of-
entire network, even the-art encryption. So long as your config file
is not compromised, you’re more than likely
your smartphone completely safe. If you open your web server
to the planet, we guarantee you will have bots
sniffing around trying to find access within
minutes. VPN isn’t easy, but it’s worth the time.
Avoid the dodgy advertising
11 One of the most popular Raspberry
Pi applications is Pi-hole (pi-hole.net), a
Next time
clever system designed to ‘sink’ internet
advertisements, leaving your browser clear of
14 Well, we’ve built a pretty impressive
noise. While we strongly recommend supporting server. File sharing, media streaming,
your favourite sites by allowing adverts, many remote access, network protection, and home
sites contain ads that are not only scams, automation. Next month we will look at how Pi-hole is a network-
wide ad blocker
but can lead to tricking you into downloading to protect all this hard work, and your precious that’s effective and
malware that can compromise your data. data, from unexpected loss. easy to use
Pi‑hole can protect your entire network, even
your smartphone. To install it, simply run this
command from a Terminal:

curl -sSL https://install.pi-hole.net | bash

The installer will ask several questions, but is


well-designed and you’re probably going to be
OK to answer every one with the default answer.

Starting off with Pi-hole


12 Pi-hole works by looking at DNS requests.
These are requests to servers that map domain
names such as raspberrypi.com to actual servers.

Build the ultimate home server with Raspberry Pi magpi.cc 63


TUTORIAL

How to write your own


Download
the code
emulator in Python
from GitHub:
wfmag.cc/ Ever wanted to create your own computer? Here’s how to do
wfmag54
just that – and even get it to run some classic games

AUTHOR
EDWIN JONES
A software engineer at video game developer Mediatonic, Edwin Jones
has been working in the games industry for around 16 years. Find out
more about him here: edwinjones.me.uk

H
ow can we make our own computer simple specification to implement. The CHIP-8
with Python? Don’t computers need only has 35 opcodes, which is low compared
lots of physical things like circuit to other computers. You still have all the usual
boards and electronics? Normally problems to solve – loading binary files, parsing
yes, they do, but we’re going to opcodes, and then running them on virtual
create something known as a ‘virtual machine’ – a hardware – but not the other baggage that comes
computer defined completely by software, not with trying to write emulators for other systems.
hardware. You’ve probably used virtual machines You also get to finish the project by playing some
many times without realising it. Many modern classic games – what’s not to like?
games consoles run older, classic games via We’ll be using Python 3 and Pygame for the
virtual machines, also known as emulators. project because CHIP-8 isn’t very demanding
There are many kinds of emulator, but one and can be easily emulated. This means it’s a
of the most fun to start with is the CHIP-8. The good fit for Python, as we don’t need to worry
CHIP-8 was never a real computer, but that’s so much about performance and can use a
what makes it fascinating: long before most other language that makes solving the problems at
games systems, it existed as a program for 8-bit hand a bit easier – we don’t need to focus as
computers in the 1970s. This means there’s no much on smaller details.
hardware to attempt to emulate and quite a A simple way to build such a device in code
is with a class representing the CPU, so let’s go
ahead and create a Cpu class. Create a folder
called pychip8 on your machine and save our
code below there with the file name cpu.py. We’ll
be using this folder for every module we create.

"this module defines the chip 8 cpu"

class Cpu:
"""this class represents the CHIP 8 cpu"""

# game ram begins at address 0x200 / 512


PROGRAM_START_ADDRESS = 0x200
 All being well, your pychip8
# the chip 8 works with 16 bit/2 byte opcodes
folder should look like this
when you’re finished. WORD_SIZE_IN_BYTES = 2

64 magpi.cc How to write your own emulator in Python


TUTORIAL

# V[15/0xF] is used as a carry/no borrow flag


for certain ops
ARITHMETIC_FLAG_REGISTER_ADDRESS = 0xF
FRAME_BUFFER_WIDTH = 64
FRAME_BUFFER_HEIGHT = 32

def __init__(self):
# 4k of RAM
self.ram = [0] * 4096
self.program_counter = self.PROGRAM_START_  here are all kinds of simple
T


games available for CHIP-8,
ADDRESS from puzzlers to dinky
for us to use later. You can see how this works in Space Invaders clones. You’ll
find a good selection at
self.index_register = 0 the code below – save this into your folder with wfmag.cc/chip-roms.
self.general_purpose_registers = [0] * 16 the file name rom_loader.py.

self.delay_timer = 0 import os

self.stack = [] def get_rom_bytes(rom_name):


self.stack_pointer = 0 """This method loads the bytes from a rom from
the roms folder"""
self.keys = set() folder = os.path.dirname(os.path.realpath(__
file__))
self.frame_buffer = [[bool()] * 32 for i rom_folder = os.path.join(folder, "roms")
in range(64)] rom_file_path = os.path.join(rom_folder,
rom_name)
self._load_font()
with open(rom_file_path, "rb") as file:
self._current_word = 0 file_bytes = file.read()
self._current_operation = None return file_bytes

Can you see how we’ve defined the registers Here we’re opening and reading the file in binary
and buffers from the system’s specification into mode with the "rb" options string from the given
simple Python types and collections? Don’t worry file path and returning it from the get_rom_bytes
about understanding all this code right now, as method as a bytes object. This means we can
we’ll be plugging in more parts of the computer then iterate over each byte in turn to decode
as we go. This is just the ‘heart’ of the machine each instruction for the CHIP-8.
and where our core logic will run. How can we parse the raw binary from a file
Wireframe
The CHIP-8, like almost all computers, works and turn that into instructions for the CPU? The
This tutorial first appeared
by following a sequence CHIP-8 has a strange in Wireframe, our sister
of instructions. We’re “There are many emulators, opcode definition, in magazine that lifts the
going to load up files that each opcode is a lid on the world of video
representing these
but one of the most fun 16 bit / 2 byte value that games. Every issue includes
instructions in a binary to start with is CHIP-8” contains the instruction
tutorials and in‑depth
interviews, along with news
format (called ROMs) and and the data for that and reviews of the latest
process each instruction one by one in our CPU. instruction. This would be simple enough were it indie and triple-A games.
The name for such an instruction is sometimes not for the fact that apart from the first four bits, To find out more, visit their
known as – you guessed it – an opcode! each following nibble can be part of an instruction website at wfmag.cc.
The problem we face now is how can we get or data – depending on the instruction in Check out their
the data from a file into memory so our code can question. For instance, the opcode 0x00E0 means subscription offers at
wfmag.cc/subscribe.
work with it? We can do this with a simple ‘ROM ‘clear the screen’, but opcode 0x1234 means
loader‘ module that reads all the binary into a list ‘jump to memory address 0x234’. A nibble might

How to write your own emulator in Python magpi.cc 65


TUTORIAL

self.word = word & 0xFFFF

# we just want the most significant bits/


nibble
# here so we bitshift right
self.a = (word & 0xF000) >> 12

self.nnn = word & 0x0FFF


self.nn = word & 0x00FF
self.n = word & 0x000F

# Where don't use the lower nibbles,


bitshift
# right to get just the raw value
self.x = (word & 0x0F00) >> 8

# Eg. we want 0x4 not 0x40


 e sure to get the
B

full CHIP-8 code from self.y = (word & 0x00F0) >> 4


wfmag.cc/wfmag54,
where you’ll find the
sound strange, but it’s just half a byte. A byte is
operations.py module, 8 bits and can be represented with two hex digits, Don’t worry if you don’t understand all this
and more detailed
comments that we so 0xFF means 255. A nibble can be represented code at once. The important thing to know is
couldn’t fit in here. with one hex digit (e.g. 0xF for 15). This will come that we’re parsing a 16-bit value and storing it
in handy later when we’re manipulating our in different fields of the class. opcode.a is the
opcode data. One way leftmost nibble, x the
to solve this problem is “Don’t worry if you next one along, y the
to abstract it into a class, one after that, and n
which is exactly what
don’t understand all the very last. You can
we’re going to do. this code at once” remember this with the
Our next piece of hex-like pattern 0xAXYN.
Python code is going to be an Opcode class, as opcode.word, opcode.nn, and opcode.nnn are ways
shown below. Again, save this into your folder, of accessing these nibbles in groups. This will
this time with the file name operation_code.py. come in handy later on.
Now we have a way to read the ROM and parse
class Opcode: the contents of it, but what can we actually do
"""This class represents the instructions and with all this data? The CHIP-8 has 35 opcodes,
data of an opcode""" but we shall only be using 33 of them. For
simplicity, we're ignoring sound and any machine
def __init__(self, word): code operations. You can find a list of them on
""" Wikipedia at wfmag.cc/opcode.
This class takes in a 2 byte value/word First, let’s define a module that turns
and parses the bytes these opcodes into readable functions we
to store them in different attributes for can reference. Hex is fun, but it’s not easy to
later use understand what the raw numbers mean at
times. The following bit of code is too long to
Args: run in full here, but you’ll find it on our GitHub
word: a 2 byte/16 bit value that at wfmag.cc/wfmag54. It’s the file named
represents an opcode. operations.py – here’s a small snippet:
"""
def add_to_x(opcode, cpu):
# We use bitwise AND with a mask to pass
extract specific nibbles.
def add_x_to_i(opcode, cpu):
# a word should be no more than 16 bits pass

66 magpi.cc How to write your own emulator in Python


TUTORIAL

def add_y_to_x(opcode, cpu):


pass

Don’t worry that all these functions contain a pass


statement at the moment; the important thing is
that each one has the same signature and a clear
name. Now we need to make another module,
called operation_mapping.py, that lets us map
the raw binary/opcode to one of the functions
we’ve defined above. Modelling code without
a full implementation like this is often known  nce it’s complete, you can
O


run CHIP-8 straight from
as stubbing, and can be a useful approach to your command line, like this.
working on a problem when you aren’t entirely return operations.set_x_to_y
sure what the solution will be, but do need to if opcode.n == 0x1:
have some idea of the interface you’ll be using to return operations.bitwise_or
solve it. if opcode.n == 0x2:
return operations.bitwise_and
from operation_code import Opcode if opcode.n == 0x3:
import operations return operations.bitwise_xor
if opcode.n == 0x4:
def find_operation(word): return operations.add_y_to_x
opcode = Opcode(word) if opcode.n == 0x5:
return operations.take_y_from_x
if word == 0x00E0: if opcode.n == 0x6:
return operations.clear_display return operations.shift_x_right
if opcode.n == 0x7:
if word == 0x00EE: return operations.take_x_from_y TECH SPECS
return operations.return_from_function if opcode.n == 0xE: The CHIP-8 has the following
return operations.shift_x_left specifications:
if opcode.a == 0x1:
• 4 kB of memory
return operations.goto if opcode.a == 0x9:
return operations.skip_if_x_y_not_equal
• 1 6 general-purpose 8-bit
registers (the 16th is
if opcode.a == 0x2: also used as a special
return operations.call_function if opcode.a == 0xA: arithmetic flag at times)
return operations.set_i
if opcode.a == 0x3:
• A 64 pixel-wide by 32 pixel-
high frame buffer
return operations.skip_if_equal if opcode.a == 0xB:
return operations.goto_plus
• A stack that stores return
addresses for function
if opcode.a == 0x4: calls and nothing else
return operations.skip_if_not_equal if opcode.a == 0xC:
return operations.generate_random
• S ome way to store
the pressed state of a
if opcode.a == 0x5: 16-button keypad (0–F)
return operations.skip_if_x_y_equal if opcode.a == 0xD:
return operations.draw_sprite
• A n 8-bit index register
if opcode.a == 0x6: • A n 8-bit program counter
return operations.set_x if opcode.a == 0xE: • A n 8-bit stack pointer
if opcode.nn == 0x9E: • A n 8-bit delay timer register
if opcode.a == 0x7: return operations.skip_if_key_pressed • A n 8-bit sound timer
return operations.add_to_x if opcode.nn == 0xA1: register (when above zero,
return operations.skip_if_key_not_pressed a beep is made)
if opcode.a == 0x8:
if opcode.n == 0x0: if opcode.a == 0xF:

How to write your own emulator in Python magpi.cc 67


TUTORIAL

if opcode.nn == 0x07: screen, loading fonts, and input handling, so we


return operations.set_x_to_delay_timer need to define code that can manage this logic
if opcode.nn == 0x0A: for us. Let’s start with the internal font of the
return operations.wait_for_key_press machine. The CHIP-8 has a single font that is
if opcode.nn == 0x15: hard-coded into memory, and usually stored in
return operations.set_delay_timer the first 512 bytes of memory (0x000–0x200). The
if opcode.nn == 0x18: font is basically a pattern of bits that describes
return operations.set_sound_timer the dots that make up each letter. Let’s make a
if opcode.nn == 0x1E: module with this pattern as shown below, and
return operations.add_x_to_i save it as font.py.
if opcode.nn == 0x29:
return operations.load_character_ """
address Chars are 4x5. Each line must be a byte wide so
if opcode.nn == 0x33: each line value is padded with 0x0.
return operations.save_x_as_bcd Eg:
if opcode.nn == 0x55: 0:
return operations.save_registers_zero_ #### = 1111 = F0
to_x # # = 1001 = 90
if opcode.nn == 0x65: # # = 1001 = 90
return operations.load_registers_zero_ # # = 1001 = 90
to_x #### = 1111 = F0
"""
raise KeyError(f"Opcode {word:#06x} not
present in list of valid operations") # each char is 5 bytes long, so to get
# char 'B' you'd use DATA[CHAR_SIZE_IN_BYTES *
Now we’re cooking! This code will take a block of 0xB]
16 bits we load from a ROM file, parse this into CHAR_SIZE_IN_BYTES = 5
our custom Opcode class and use the properties
of that class to figure out what corresponding DATA = [0xF0, 0x90, 0x90, 0x90, 0xF0, # 0
functionality the opcode is referencing. If you 0x20, 0x60, 0x20, 0x20, 0x70, # 1
refer to the table from wfmag.cc/opcode, you 0xF0, 0x10, 0xF0, 0x80, 0xF0, # 2
should be able to see exactly what our functions 0xF0, 0x10, 0xF0, 0x10, 0xF0, # 3
are going to actually do by looking up the 0x90, 0x90, 0xF0, 0x10, 0x10, # 4
related opcode. 0xF0, 0x80, 0xF0, 0x10, 0xF0, # 5
Before we can wire this up further, we’re going 0xF0, 0x80, 0xF0, 0x90, 0xF0, # 6
to need to add some extra functionality. There 0xF0, 0x10, 0x20, 0x40, 0x40, # 7
 es, it’s a bit blocky, but
Y

it’s a tiny, functioning are a few opcodes that handle drawing to the 0xF0, 0x90, 0xF0, 0x90, 0xF0, # 8
version of Space Invaders.
0xF0, 0x90, 0xF0, 0x10, 0xF0, # 9
Pretty neat.
0xF0, 0x90, 0xF0, 0x90, 0x90, # A
0xE0, 0x90, 0xE0, 0x90, 0xE0, # B
0xF0, 0x80, 0x80, 0x80, 0xF0, # C
0xE0, 0x90, 0x90, 0x90, 0xE0, # D
0xF0, 0x80, 0xF0, 0x80, 0xF0, # E
0xF0, 0x80, 0xF0, 0x80, 0x80] # F

The code above is a layout of a series of nibbles


in a list format that we can access, and each
5 bytes represents the raw pixels of a character.
Each “1” equals a lit pixel for each character; each
character is 4 bits across and consists of 5 rows.
As we only use a nibble, only the most significant
bits of each byte are used – that is why each
value ends with 0.

68 magpi.cc How to write your own emulator in Python


TUTORIAL

Next, we’re going to need some way to handle


input. The CHIP-8 had a very simple input
mechanism – 16 keys from 0–F. This fits exactly
into a nibble. Let’s define a module to map our
keyboard keys to those values. Save the following
as keyboard_input.py:

"""This module contains the keyboard input


handling logic"""

import sys CHIP-8 Noughts and


Crosses. Perfect if you
import pygame don’t have a pen and
if event.key in keys: piece of paper handy.

keys = {} cpu.key_up(keys[event.key])
keys[pygame.K_0] = 0x0
keys[pygame.K_1] = 0x1 This code defines a dictionary to map keyboard
keys[pygame.K_2] = 0x2 input into and a function we can use to check
keys[pygame.K_3] = 0x3 which keys are pressed. We then pass that data
keys[pygame.K_4] = 0x4 into our CPU. Handy!
keys[pygame.K_5] = 0x5 The last missing part of our emulator is the
keys[pygame.K_6] = 0x6 renderer. A renderer is simply some code that
keys[pygame.K_7] = 0x7 can take raw data and instructions and turn
keys[pygame.K_8] = 0x8 those into some form of visible output. We’ll use
keys[pygame.K_9] = 0x9 Pygame Zero to draw to our screen and we can
keys[pygame.K_a] = 0xA define our renderer like so, remembering that
keys[pygame.K_b] = 0xB the CHIP-8 was limited to a 64×32 resolution with
keys[pygame.K_c] = 0xC black and white output. The following needs to be
keys[pygame.K_d] = 0xD saved with the file name renderer.py:
keys[pygame.K_e] = 0xE
keys[pygame.K_f] = 0xF """This module defines the renderer object and
related methods"""
def handle_input(cpu=None):
""" import pygame
This function handles control input for this
program. WHITE = pygame.Color(255, 255, 255)
""" BLACK = pygame.Color(0, 0, 0)
for event in pygame.event.get():
SCALE = 10
# quit if user presses exit or closes the
window # The CHIP-8 display ran at only 64 * 32 pixels.
if event.type == pygame.QUIT: # this value scales the framebuffer
sys.exit() # so it's easier to view the emulator on modern
displays
# check cpu registers and inject key input screen = pygame.display.set_mode((640, 320))
if cpu:
if event.type == pygame.KEYDOWN: def render(frame_buffer):
if event.key == pygame.K_ESCAPE: """This method draws everything to the screen"""
sys.exit()
screen.fill(BLACK)
if event.key in keys:
cpu.key_down(keys[event.key]) for x in range(64):
for y in range(32):
if event.type == pygame.KEYUP: if frame_buffer[x][y]:

How to write your own emulator in Python magpi.cc 69


TUTORIAL

"This method sets a key as released"


if key in self.keys:
self.keys.remove(key)

def move_to_next_instruction(self):
self.program_counter += Cpu.WORD_SIZE_IN_
BYTES

def move_to_previous_instruction(self):
 igure 1: If the bc_test.ch8
F self.program_counter -= Cpu.WORD_SIZE_IN_

ROM shows this message,


then congratulations: you BYTES
have a functioning CHIP-8 pygame.draw.rect(
emulator, and you’re ready
to play some games! screen, def load_rom(self, rom_bytes):
WHITE, for i, byte_value in enumerate(rom_bytes):
(x * SCALE, y * SCALE, SCALE, self.ram[Cpu.PROGRAM_START_ADDRESS +
SCALE)) i] = byte_value

# Go ahead and update the screen with what def set_arithmetic_flag(self):


we've drawn. self.general_purpose_registers[self.
# This MUST happen after all the other drawing ARITHMETIC_FLAG_REGISTER_ADDRESS] = 1
commands.
pygame.display.update() def clear_arithmetic_flag(self):
self.general_purpose_registers[self.
The code above takes the frame buffer of the CPU ARITHMETIC_FLAG_REGISTER_ADDRESS] = 0
and iterates through it, drawing a 10×10 white
square for every pixel that should be set. This gives def emulate_cycle(self):
us a larger window to see the emulator running, self._current_word = self.fetch_word()
and will be easier to use on a larger, modern
display. A frame buffer is just a section of memory opcode = Opcode(self._current_word)
that stores things you want to show on a display self._current_operation = operation_
monitor or TV. In our case, it’s just a 2D list of mapping.find_operation(self._current_word)
Boolean values representing ‘on’ or ‘off’ for a pixel
that we defined in our Cpu class earlier. self.move_to_next_instruction()
We’re getting closer to having something self._current_operation(opcode, self)
work as all the core components of our system
are now wired in. There’s a bit more code we def fetch_word(self):
need to add to our CPU now we’ve defined all its word = self.ram[self.program_counter] << 8
dependencies. Let’s go back and add some extra | self.ram[self.program_counter + 1]
imports to the top of our CPU module, cpu.py:
return word
from operation_code import Opcode
import operation_mapping def update_timers(self):
import font if self.delay_timer > 0:
self.delay_timer -= 1
Now append the code below to the end of the
CPU module: def _load_font(self):
offset = 0x0
def key_down(self, key): for item in font.DATA:
"This method sets a key as pressed" self.ram[offset] = item
if key not in self.keys: offset += 1
self.keys.add(key)
If you read through the code above, you should
def key_up(self, key): be able to understand what each method is doing

70 magpi.cc How to write your own emulator in Python


TUTORIAL

as there is a comment in each one to help you 480, which is close enough.
understand the code. We’ll need this for the next for _ in range(8):
step as we’re going to revisit our operation class cpu.emulate_cycle()
and fill in the blanks we left earlier. This is going
to be quite a lot of code – as before, it's too much cpu.update_timers()
to print here, so download the file operations.py renderer.render(cpu.frame_buffer)
from our GitHub at wfmag.cc/wfmag54. Don’t
worry too much about what each method does; # delay until next frame.
focus more on what opcode it relates to and what clock.tick(60)
functionality it achieves for our emulator. There
are several comments to help you understand The code above sets up all the dependencies,
each opcode, if you’re interested. loads the ROM data, and runs the core loop of
We only need to write one more module to get the CHIP-8 CPU, which will read and evaluate
our emulator working and to see our hard work instruction by instruction. Don’t worry about
pay off. We need an entry point to our code that “running out”, as almost every ROM loops; they're
initialises and runs it in the right order. Let’s go not designed to terminate without user input.
ahead and create a file called __main__.py (NB: The last thing we’ll need is a ROM to test this
there are two underscores either side of the out with. First, let’s use a debug ROM – the best
word ‘main’) that will handle all this for us. I’ve found is called bc_test created by BestCoder.
Create a folder called roms in your working
"""This is the main entry point for the program""" directory and copy bc_test.ch8 into it from this
repository: wfmag.cc/chiptest.
import argparse With the ROM in place, open the directory that
import keyboard_input contains your pychip8 folder in your terminal
import renderer of choice and run the command python pychip8
import rom_loader --rom="bc_test.ch8". You should see something
import pygame like the output in Figure 1. If you do, have a round
of applause – you have a working emulator! If you
from cpu import Cpu see nothing on the screen, the error’s likely in
the renderer module; if you see a screen like the
if __name__ == "__main__": one in Figure 2, then you’ll be able to work out
what’s gone wrong by checking the error codes at
parser = argparse.ArgumentParser() wfmag.cc/error-codes.
parser.add_argument("-r", "--rom", Once you’re sure the test passes, it’s time for
required=True, type=str, help="the name of the rom real games! There are plenty of ROMs available
to run in the emulator") for the CHIP-8 – you’ll find several at wfmag.cc/
args = parser.parse_args() chip-roms. Just copy the files into your roms
folder and run the command, replacing the test
cpu = Cpu() ROM name with the name of the ROM you want
clock = pygame.time.Clock() to run, and bingo: you’re playing games on a
rom_bytes = rom_loader.get_rom_bytes(args.rom) computer that you wrote yourself!
cpu.load_rom(rom_bytes)

pygame.display.set_caption("pychip8")
pygame.init()

# main loop
while True:
keyboard_input.handle_input(cpu)
 igure 2: If running the
F

bc_test.ch8 ROM gets you a


# The CHIP-8 is reported to run best at message like this, then you
can troubleshoot your
around 500 hz
emulator with the error list
# The update loop runs at 60 fps. 60 * 8 = at wfmag.cc/error-codes.

How to write your own emulator in Python magpi.cc 71


FEATURE

Raspberry Pi
Operating Systems
Whatever you want to do with Raspberry Pi, there’s an
operating system for that, as Phil King finds out

B
ased on Debian, a flavour of Linux, the Other Raspberry Pi operating systems are aimed
official Raspberry Pi OS is an excellent, at particular use cases. For media playback, there’s
easy‑to‑use operating system, but it’s not the LibreELEC and OSMC: both based on Kodi, they
only show in town. offer a slick interface for navigating your music and
You might want to give an alternative general- video collections, as well as streaming media. Retro
purpose OS a go, such as the popular Ubuntu with its gaming fans are also well catered for with a choice
slick interface and large software catalogue, or the of RetroPie, Recalbox, and Lakka for emulating old
user-friendly and accessible Manjaro. If you’re feeling consoles and computers. Then there are specialist
adventurous, there’s also RISC OS: an evolution of the OSes such as OctoPi (3D printing) and Home
Acorn Archimedes operating system dating back to Assistant (smart home).
1987, it’s super-fast and offers a fascinating insight Trying out a new operating system is as easy as
into how desktop OSes used to look and work. writing it to a microSD card with the Raspberry Pi
Imager tool (magpi.cc/imager), which has many OS
options already built-in, so why not give it a go?

72 magpi.cc Raspberry Pi operating systems


FEATURE

Ubuntu Desktop
Type: General-purpose

Available: Raspberry Pi Imager, ubuntu.com/raspberry-pi

Works on: Raspberry Pi 4 (4GB+), 400, CM4 (4GB+)

Minimum card size: 16GB

P
eople have been using Raspberry Pi as a
cost-effective PC alternative for years,
but you don’t have to stick to the official
Raspberry Pi OS: Ubuntu is a popular flavour of
Linux used on millions of PCs around the world.
While Ubuntu is also available in more
lightweight Server and Core versions, the new
Desktop edition is the fully-fledged version of the
Linux distro. So if you’ve used it before, it’ll all be
very familiar in how it looks and works.
Available in the menu of the Raspberry Pi
Imager tool (magpi.cc/imager), it’s a pretty large
download and takes a little while to write to a 16GB
or larger microSD card. Boot it up on Raspberry Pi
and it starts with a system configuration welcome
wizard where you can set up the keyboard type,
WiFi connection, and add a new user. It then takes
a few minutes to configure everything.
The GNOME desktop environment is
aesthetically pleasing with an applications sidebar, One of the main advantages of Ubuntu is its
launcher, and search facility. The downside is that huge software library. Pre-installed apps include
it’s rather sluggish to use: there’s a slight delay the Firefox web browser, Thunderbird email client,
whenever you open or do anything on the desktop. Rhythmbox music player, and LibreOffice suite.
Not everything works out of the box, either: you More can be installed via the Ubuntu Software tool
may well get a message saying you need to install – or, a little confusingly, also from the Snap Store,
some extra packages to do something such as Synaptic Package Manger, or Terminal. You may
playing MP4 videos. well find more recent versions of some software
than in Raspberry Pi OS, such as
Python 3.8. The GPIO pins can
be used by installing the LGPIO
Python library.
If you want to stay on the
cutting edge, Ubuntu gets a major
update twice a year, although
this can sometimes cause issues
with stability.

• Fully-fledged desktop OS
• Slick, modern GUIL
• Large software catalogue
• Can be a bit sluggish and flaky

Raspberry Pi operating systems magpi.cc 73


FEATURE

RISC OS Pi
Type: General-purpose

Available: Raspberry Pi Imager

Works on: All models

Minimum card size: 2GB

“It’ll N
ow this one takes us back. RISC OS was first Once you get the hang of it, this can prove very
developed by Acorn to run on its 32-bit effective. If you only have a two-button mouse, you
ARM-based Archimedes home computer can always assign a keyboard key as the third button.

even run in 1987. Since Raspberry Pi also uses an ARM CPU,


it seems only fitting that the OS is available for it.
Bundled software includes the primitive NetSurf
web browser, PipeDream office suite, and a selection

on the A community of enthusiasts continues to develop


RISC OS, including a special version tailored for
of basic games (called ‘diversions’). Using the
StrongEd text editor, it’s possible to program in

original Raspberry Pi 400 (available from riscosopen.org).


The first thing you’ll notice when installing
languages such as BBC BASIC, Lua, and Python.
Extra software can be installed using the !Store and

Model B” RISC OS is how compact it is. This is an ultra-


lightweight OS that only requires a 2GB microSD
PackMan package managers.
The biggest downside is that Raspberry Pi’s
card – there’s no advantage in using a larger one, on-board wireless LAN is not yet supported, so
since the OS can only use the first 2GB. Amazingly, you’ll need to use a wired Ethernet connection or a
it’ll also work on any Raspberry Pi model, even the special WiFi HAT to get online. In addition, the GPIO
original Model B from 2012. pins on more recent Raspberry Pi 4 models aren’t
The old-school GUI is a world away from recognised, while the USB 3.0 ports only work at USB
Raspberry Pi OS or Ubuntu. It looks very retro and 2.0 speeds.
applications are grouped together in folders rather Still, it’s well worth a look for the nostalgic and
than in a main menu. The other aspect you’ll notice the curious and could prove useful for learning how
is that it runs like lightning, even though it only computers work under the bonnet.
operates on a single core of the CPU.
An intriguing aspect is that it’s based around • Ultra-lightweight OS
using a three-button mouse: the left button is select, • Extremely fast to use
middle (or scroll wheel) displays a contextual menu, • Looks very old-fashioned
while right is ‘adjust’ (a modified version of select). • No support for on-board WLAN

74 magpi.cc Raspberry Pi operating systems


FEATURE

Manjaro ARM Linux


Type: General-purpose

Available: Raspberry Pi Imager, manjaro.org

Works on: Raspberry Pi 3, 4, 400, CM3/3+/4

Minimum card size: 8GB

M
anjaro aims to be a simpler, more
user‑friendly version of Arch Linux while
providing all the benefits of cutting-edge
software – it boasts its own large repository
alongside the Arch User Repository.
You can install Manjaro with one of four

Kali Linux
desktops – KDE Plasma, GNOME, Xfce, MATE – or
the lightweight Sway window tiling manager, or a
minimal version with no desktop.

Type: Security testing


• Based on Arch Linux
• Highly customisable Available: kali.org
• Good choice of desktops
Works on: All models
• Large software repository
Minimum card size: 16GB

LibreELEC
Type: Media centre
K
ali is a specialist distro for information security tasks such as
penetration testing. Once installed on Raspberry Pi, you can use
it to audit the security of other devices on your network.
There’s no configuration wizard, so you’ll need to set up a few
Available: Raspberry Pi Imager, libreelec.tv things manually. You do get a desktop (Xfce), though, and a set of
built-in security apps, plus the Firefox web browser.
Works on: All models
• Specialist security distro
Minimum card size: 16GB
• Good range of OS versions
• Set of built-in testing tools

B
ased around the • Some manual configuration needed
Kodi media player
software, LibreELEC
is a lightweight single-
purpose distro that’s
simple to set up and use. The menu system is
slick and easy to navigate, with sections including
movies, TV shows, and music. You can also stream
media by installing add-ons for services such
as YouTube, BBC iPlayer, and Disney+. With a
Raspberry TV HAT attached, you can even use it as a
personal video recorder.

• Slick, easy-to-use interface


• Supports most media files
• Highly customisable with add-on
• Watch and record live TV (with TV HAT)

Raspberry Pi operating systems magpi.cc 75


FEATURE

OSMC RetroPie
Type: Media centre Type: Retro gaming

Available: Raspberry Pi Imager, osmc.tv Available: Raspberry Pi Imager, retropie.org.uk

Works on: All models Works on: All models

Minimum card size: 16GB Minimum card size: 8GB

B B
ased around the Kodi media player, OSMC uilt on top of Raspberry Pi OS, RetroPie
is a fully-fledged OS, enabling you to install brings together a suite of emulators for
other applications. So it may prove more over 50 retro consoles and computers.
versatile if you need to also use your Raspberry Pi Running it on a Raspberry Pi 4 or 400 gives you
for anything else, such as a web server. the most power, enabling better emulation
When using it for Kodi media playback, OSMC of later systems such as the PlayStation 2,
works very similarly to LibreELEC with an easy- GameCube, and even the Wii.
to-use menu system to navigate media categories Use it in a standard setup with a monitor or, for
such as movies, TV, and music. a more authentic experience, a bartop or full-size
arcade system.
• Fully-fledged operating system
• Versions for different models • Emulates over 50 systems
• Kodi media playback • Works on all models
• Versatile and customisable • Customisable menus and settings
• Large community to offer advice

Raspberry Pi OS versions
The official operating system for Raspberry Pi is based on Debian Linux.
There are several versions available…

With Desktop (32-bit): The default option in Raspberry Pi Imager, it features the Pixel
GUI and includes core applications such as the Chromium web browser and VLC
media player.

Lite: This is a minimal version of the OS with no desktop installed, just a command-line
interface. Quick to boot, it’s ideal for a headless setup, typically on a Raspberry Pi Zero.

Full: Identical to the default option, with a GUI, but with additional recommended
software pre-installed such as the LibreOffice suite and various programming IDEs.

64-bit: Not yet available in Raspberry Pi Imager, this is a beta test edition that only
works on 64-bit models (3, 4, 400, or CM4) to unleash their full power. Download it
from magpi.cc/rpios64.

76 magpi.cc Raspberry Pi operating systems


FEATURE

Lakka
Type: Retro gaming

Available: lakka.tv

Works on: All models

Minimum card size: 8GB

L
akka is another solid option for retro
gaming. Each game is implemented as
a libretro ‘core’, while RetroArch takes

MotionEyeOS
care of the inputs and display. So, while it
doesn’t support quite so many systems as its
rivals, it offers a single, unified, and consistent
configuration for all its emulators. Controllers
typically work as soon as you plug them in, too.
Type: Security camera

Available: magpi.cc/motioneyeos
• Versions for all models
• Download from website Works on: All models
• Painless configuration
Minimum card size: 1GB
• Samba sharing for ROMs

T
his OS turns your Raspberry Pi into a
video surveillance system using a Camera
Module and/or USB camera. You can even
set up a network to cover different rooms of your
home, monitoring all the camera feeds in a web
interface. It can be set to capture photos and video
whenever motion is detected on a camera, and
send you email/push alerts.

• CCTV security system


• Options for multiple cameras
• Can monitor several rooms

Recalbox
• Download from website

Type: Retro gaming

R
ecalbox offers a wide range wide of
emulators for retro gaming – if not Available: Raspberry Pi Imager, recalbox.com
quite so many as RetroPie. It does Works on: All models
come with the Kodi media player built-in,
though, so it’s ideal if you’re look for an all- Minimum card size: 8GB
in-one entertainment system.
Recalbox also adds a share partition on • Versions for every model
the microSD card so you can easily remove • Wide range of emulators
it from Raspberry Pi to add game ROMs on • Kodi media player built-in
another computer. • Share partition for ROMs

Raspberry Pi operating systems magpi.cc 77


FEATURE

info-beamer
Type: Digital signage

Available: Raspberry Pi Imager, info-beamer.com

Works on: Raspberry Pi 2, 3, 4, Zero W, CM3/3+/4

Minimum card size: 8GB

D
igital signage installations are typically
found in shops, restaurants, cinemas,
museums, etc. To create your own, all
you need is a Raspberry Pi with info-streamer

Home
installed and a monitor or TV.
Sign up for a free account and you can monitor
and control your device(s) from a web dashboard.

Assistant
With multiple screens and Raspberry Pi boards,
you can even set up a video wall.

• Digital signage solution


• Cloud dashboard Type: Smart home
• Monitor multiple devices Available: Raspberry Pi Imager, home-assistant.io
• Build your own video wall
Works on: Raspberry Pi 3, 4, 400

OctoPi
Minimum card size: 4GB

H
ome Assistant is an open-source
ecosystem for smart home automation and
Type: 3D printing boasts a helpful worldwide community of
enthusiasts. Easy to set up and use, it features
Available: Raspberry Pi Imager, octoprint.org
‘Integrations’ (plug-in modules) to support over
Works on: Raspberry Pi 3, 4, 400, CM3/3+/4 1,000 smart devices; you can even program your
own in Python. Little wonder PJ Evans opted to
Minimum card size: 8GB
use it for his tutorial series on home automation
starting in The MagPi issue 99 (magpi.cc/99).

O
ctoPi contains the OctoPrint software for monitoring and
controlling a 3D printer remotely from a web browser. It adds • Over 1,000 devices supported
WiFi to any 3D printer with • Sophisticated web dashboard
a USB port, for easy file dropping • Powerful automations
and remote control via a web • Google or Alexa voice control
dashboard. You can also add a
camera to the setup for a live video
stream of the 3D printing process,
and to record time-lapse videos.

• Control a 3D printer
• Access via web interface
• Live camera stream
• CuraEngine slicing

78 magpi.cc Raspberry Pi operating systems


FEATURE

Homebridge
Type: Smart home

Available: Raspberry Pi Imager, homebridge.io


“Your Homebridge setup
Works on: All models can be controlled via a
Minimum card size: 4GB
web-based interface”

A
pple’s HomeKit is great for controlling
your smart home, but it’s not compatible
with all devices. Homebridge offers a
Raspberry Pi-based solution, enabling you to
integrate other devices such as Nest thermostats,
Ring video doorbells, Philips Hue light-bulbs, and
Sonos speakers.
Your Homebridge setup can be controlled
via a web-based interface, including
installing or removing plug-ins – there are
over 2,000 available.

• Use other devices with HomeKit


• Over 2,000 plug-ins
• Web-based interface
• Voice control with Siri

Other OSes
We didn’t have space in this feature to cover every available operating system for Raspberry Pi.
Here are a few others to consider…

Alpine Linux (alpinelinux.org): Lightweight OS emteria.OS (emteria.com): Full build of piCorePlayer (picoreplayer.org): Minimal OS
with an emphasis on security. Android, aimed towards industry use. designed for remote music playback.

ALT (altlinux.org): Russian language OS, Fedora ARM (arm.fedoraproject.org): ARM Pi MusicBox (pimusicbox.com): Stream music
version of Fedora Linux, only works on
available in Raspberry Pi Imager under ‘Other or play locally stored tracks and podcasts.
Raspberry Pi 2 and 3.
language-specific OS’.
FreeBSD (freebsd.org): UNIX-like operating Slackware ARM (sarpi.penthux.net):
Arch Linux ARM (archlinuxarm.org): Lightweight system, an alternative to Linux. Slackware is one of the oldest Linux distros.
and flexible OS, the basis of Manjaro.
FydeOS (fydeos.io): Customised version of SliTaz (slitaz.org): Compact OS that works
CentOS (centos.org): Robust Linux distro, Chromium OS for Raspberry Pi 4 and 400. completely in memory from an attached
popular for running web servers. USB stick.
Gentoo (gentoo.org): Highly customisable
Linux distro, not easy to install.
Chromium OS (magpi.cc/chromiumos): The TLXOS (thinlinx.com): A ‘thin client’, available
open-source basis for Chrome OS, as used in as a 30-day trial in Raspberry Pi Imager, it’s a
Lubuntu (lubuntu.net): Lightweight Linux OS
Chromebooks. based on Debian, with minimal LXDE desktop. compact OS that’s useful for kiosk displays.

DietPi (dietpi.com): Extremely lightweight NetBSD (netbsd.org): Fast and secure UNIX- Void Linux (voidlinux.org): Independent
Debian-based OS with a simple interface. like OS based on BSD. general-purpose Linux distro.

Raspberry Pi operating systems magpi.cc 79


REVIEW

Hiwonder TonyPi
Hiwonder hiwonder.hk £380 / $519
SPECS

DIMENSIONS:
186 × 113 × Raspberry Pi 4-powered humanoid robot with built-in smarts
373 mm; 1.7 kg
and options to set up bespoke behaviours. By Rosie Hattersley
COMPONENTS:

T
Raspberry Pi 4
4GB, 11 V battery, onyPi is a 37 cm-tall humanoid robot so the fun here is all about controlling him. He’s
3MP camera with plenty of personality to keep you a solidly built fella, with angular joints and broad
(480×800 pixel)
engaged as you learn fun ways to interact lower arms and hands primed for scooping up
14 × LX-824HV
servos, on-board with him. He can either be controlled via an iOS coloured balls on command. We rather liked his
lithium-ion or Android app, or you can use a Raspberry Pi, all-white finish, which contrasts with his 14
battery pack with Windows PC, or Mac. deliberately visible LX-824HV servos. Agility-
DC charging point Containing a Raspberry Pi 4, TonyPi comes wise, TonyPi can walk, shimmy, wave, bow, get
(US adapter),
power level
preassembled (aside from the connectable head), up, and turn his head – all from the smartphone
indicator or tablet app, while more advanced controls
can be added as custom list items via Python
ACCESSORIES: and OpenCV.
3 × Tag cards, 3 ×
colour balls, servo
wire, screwdriver
 e tried to fool him with
W
posters of people and
various charming but
inanimate objects, but
TonyPi was unmoved
Swiping a finger in the window section of the
Hiwonder app moves TonyPi’s head. You’ll need
to swipe several times to get TonyPi to move
much, though. Body movements can be initiated
using the step controls at the top of the on-
screen control panel, or by tapping within the
circular control area. The upper control section
causes TonyPi to step forwards and backwards
With 14 servos, TonyPi and turn gently to one side, while the circular
is both powerful and
control section sees him jump peremptorily
responsive to
user commands whichever way he’s instructed.

80 magpi.cc Hiwonder TonyPi


REVIEW

TonyPi is a great-
looking robot that can
be easily controlled via
Android or iOS apps

Clear vision codes and have your robot do something else,


TonyPi’s object recognition ability is great. One having programmed a different action in Python
neat trick is his ability to recognise faces, waving using the instructions provided.
in response. We tried to fool him with posters Be aware that switching user modes causes
of people and various charming but inanimate
objects, but TonyPi was unmoved.
TonyPi to revert to his initial position, as we
inadvertently discovered. If TonyPi is lying Verdict
‘Colour tracking’ was also impressive: select down, you’re likely to have one heck of a shock
a colour and move the corresponding ball gently when you switch him back on and tap the ‘get TonyPi is an
impressively
in front of his 3-megapixel camera and TonyPi’s up’ instruction on the Hiwonder app. TonyPi
designed robot
head will follow the ball’s movements. He will launched himself backwards as he automatically
with solid object
also nod when shown an object that’s red, green, tried to stand upright from the prone position recognition
or blue – our orangey-red sofa was an easy win – we’d left him in. Luckily, your reviewer caught features. For
but he doesn’t always get it right. him just as he was about to disappear off the longer-term
Line following was largely successful: TonyPi edge of the kitchen table. entertainment, be
strode along confidently on straight stretches, Instructional PDFs really help in getting prepared to log in
remotely and
slowing but still following the line round gentle the most from using TonyPi, but using a PC or
use Python to
bends. It’s best to set his head to point down so Raspberry Pi as a control via SSH and a smartphone access his more
he is able to follow the trail; if not, he may veer hotspot is extremely fiddly, more than pi‑top’s advanced features.

8
off unexpectedly at an angle. Three QR codes are Robotic Kit with its built-in IP address-displaying
included in the box: place these against a light OLED [magpi.cc/108]. Once set up, though,

/10
background and TonyPi will wave, shimmy, or possibilities such as adding a microphone and
shuffle his feet. You can also create your own QR trying voice recognition come into play.

Hiwonder TonyPi magpi.cc 81


REVIEW

10 Amazing:
Mike Cook F
 idget Spinner Maze Runner

projects
Spin to escape
This project tests your fidget-spinning skills to see just how fast you can get out
of the maze determined by how fast you spin.

magpi.cc/60

A look back at some of Mike Cook’s


C
 ut-out theatre
best builds in The MagPi
Interactive story time

Y
ou may have read last month that Mike
Use a tablet to control this wonderful,
Cook, legendary tech writer and author of
old-school storytelling method that
our monthly Pi Bakery since issue 33, has will be sure to impress and entertain
decided to retire from regular tutorials in The MagPi. many kids, young and old.
While we’ll see him again in the future, we wanted
to highlight ten very cool things that he made over D
 anse Macabre magpi.cc/57
nearly 80 issues. Thank you, Mike!
A skeleton dance
Perfect for the spooky season, these
scary skeletons can be made to
deviously dance by your own hands,
while classical music is played
of course.

magpi.cc/50

T
 rill guitar
Mini MIDI guitar
This guitar uses a mixture of Raspberry Pi Pico and Trill touch sensors to create
a very customisable MIDI guitar. We love the case for it as well.

magpi.cc/102

S
 anta’s Drop
Deliver The MagPi magazines festively
A fun holiday game to make and play, where you take the reins of
Santa’s sleigh to deliver The MagPi magazines to kids everywhere.
Unfortunately, the real Santa is too expensive to use monthly.

magpi.cc/101

82 magpi.cc Mike Cook projects


REVIEW

T
 he Story Train
Trolley problem solved
Wooden train sets are irresistible. You have to play with them.
Linking them up to an e-book allows you to turn pages using the
train, a great way to keep kids engaged with reading.

magpi.cc/41

T
 he Large Head ‘N Ron Collider
Halloween games
Meet Head and Ron, glowing spooky creatures that are used as part of the
Collider game, where you try and match the lights at the right moment.

magpi.cc/62

P
 ico-Voice
Voice modulation
Use various knobs and dials to change your voice using this
Raspberry Pi Pico project in a very cool box.

magpi.cc/106

R
 aise a Glitch Storm
Noise corruption
Using some rotary encoders, you can interact with an oscilloscope to create
weird and wonderful noises, for fun and scary movies.

magpi.cc/95

H
 ex-a-Pad
Six-sided sounds
This cool little instrument is one of RASPBERRY PI PROJECTS FOR DUMMIES
many that Mike has made, with sides
you can tap for sound. This two-part
tutorial starts in issue 90. Mike is also the author of Raspberry Pi Projects for
Dummies, which you can grab at magpi.cc/mikecook.
magpi.cc/90

Mike Cook projects magpi.cc 83


RESOURCES

Learn circuit design


with Raspberry Pi
Discover how to design your own electronic
circuits with these resources. By Phil King

Getting Started
in Electronics
Forrest M Mims Who better to teach you the Starting with the basics of
AUTHOR

fundamentals of electronic electricity, it takes you on a


circuits than Forrest M Mims, tour of digital and analogue
Price:
the designer of the original components and how they work.
£24.99 / $20
Altair 8800 home computer? It moves on to integrated circuits
magpi.cc/
Billed as a complete electronics and digital logic gates using
electronicsmims
course in 128 pages, this classic switches and transformers.
tome is all the more remarkable Linear circuits are also
for its handwritten text and covered; responding to a wide (i.e. on a breadboard) and
hand-drawn diagrams! While range of voltages, they have permanent circuits. There are
there are more in-depth many applications. 100 tried and tested circuit
electronics books around, this Of most interest to us is the designs to explore, arranged
one will certainly give you a section on using electronic into categories such as basic,
solid grounding. components to make temporary photonic, digital, and linear.

Online courses
Study circuit design with these CRASH COURSE as students are encouraged to
ELECTRONICS & PCB DESIGN try things out, ask questions,
interactive courses This Udemy course is aimed and share ideas with each other as
at those learning electronics a community.
from the ground up who wish to magpi.cc/tinkeringcircuits
leverage that knowledge to build
actual PCBs. ADVANCED DIPLOMA IN
magpi.cc/crashcoursepcb BASIC ELECTRONICS
This free Alison course covers the
TINKERING FUNDAMENTALS: principles of electronics and some
CIRCUITS of the theorems guiding the design
Participation is essential in of electrical circuits.
Coursera’s hands-on workshop magpi.cc/alisonelectronics

84 magpi.cc Learn circuit design with Raspberry Pi


RESOURCES

An Introduction
to Electronics
Open University This OpenLearn course is ten hours at your own pace, it
Books
AUTHOR

to read
an adapted extract from the starts with the basic theory of
Price: Open University course T212 electrical circuits, including
Free Electronics: sensing, logic and Ohm’s law, Kirschoff’s laws, and
magpi.cc/ actuation. Just sign up for a free series and parallel circuits.
openlearnelectronics
Check out these
account to enrol. Taking around It then goes on to cover some
fundamental circuits – including
info-packed books
voltage dividers, the Wheatstone
bridge, operational amplifiers,
and sensors – before exploring
the concept of signal processing
using sounds.
Each section features videos
and/or interactive elements, By
the end of the course, you should
be able to use basic components
to design simple electronic SIMPLE ELECTRONICS
circuits, as well as having learnt WITH GPIO ZERO
a lot more about the general Build breadboard-based
concepts involved. electronic circuits connected
to Raspberry Pi and control
them with Python programs
and the easy-to-use GPIO
Zero library.

HackSpace
magpi.cc/gpioessentials

Magazine #48 MAKE: ELECTRONICS


A great primer for general
electronics, it’s full of
The ultimate achievement interesting facts and runs
Ben Everard
AUTHOR

in circuit design is to create you through 36 ‘experiments’


Price: your own printed circuit board building circuits using
£6 / $8 (or free PDF) (PCB), but it may seem a standard components.
hsmag.cc/issue48 daunting prospect. The latest magpi.cc/
issue of our sibling magazine, makeelectronics
HackSpace, demystifies the
process with a 12-page feature
showing you how to get started. it takes you through all the steps ELECTRONIC CIRCUIT
As the article explains, “If of designing a PCB to work with DESIGN IDEAS
you can build electronics on a Raspberry Pi Pico. Starting Aimed at the more advanced
a breadboard, you can design with a schematic, various user, this weighty compendium
a PCB. There’s no magical components are added, along covers over 170 circuit types
difference. Instead of wires, you with custom artwork and copper and explains them in great
just have traces of copper.” traces for connections. Finally, detail with diagrams.
Using the EasyEDA online you can send your board design magpi.cc/
software (easyeda.com/editor), off to be manufactured. circuitdesignideas

Learn circuit design with Raspberry Pi magpi.cc 85


INTERVIEW

Akkie
Can you be a maker without knowing electronics?
Akkie was before Raspberry Pi

> Name Akira Ouchi > Occupation Infrastructure engineer


> Community role Maker > Website github.com/Akkiesoft

“I
had no electronic skills sticking a pen into an old mouse by [moving] the tray of the
at all before I learned to create a sort of tablet, or optical drive,” Akkie tells
and started playing with making use of an optical disc us. “It is quieter, easier, and
Raspberry Pi.” drive to look after his hamster. smarter to implement similar
Not the kind of thing you’d “Although the term ‘IoT’ functions with a Raspberry Pi,
expect to hear from one of the was not common in 2009, I server monitor, and infrared
best-known members of Japan’s combined the optical drive, LED nowadays.”
wonderful maker community, cardboard, and springs to create
This optical drive Akira Ouchi, or Akkie as he’s a thing that could feed the When did you learn about
would take care
best known. He had been doing hamster or control the power Raspberry Pi?
of Akkie’s hamster
while he was away little projects though, like switch of the air conditioner I discovered Raspberry Pi on
the RS Components’ website
on 12 March 2012 – I found this
from my Twitter [Ed, see photo].
At that time I used a Linux
netbook for my optical drive IoT
project to demonstrate at some
events. I thought Raspberry
Pi could make it compact the
demo stuff. After replacing the
netbook with Raspberry Pi, I
created a wearable optical drive
attached on the top of a helmet,
and Raspberry Pi built-in
optical drive.

What are your favourite


things that you’ve made with
Raspberry Pi?
My fave is a Plarail (Japanese
train toy for kids) project
that can be controlled from a
smartphone. A Raspberry Pi
Zero and camera are mounted
to the carriage, [along with

86 magpi.cc Akkie
INTERVIEW

I think it’s amazing the sense of unity


a community can feel when they get
their hands on a junk part
a] built-in motor driver and Furthermore, Japan has its
LiPo battery. own certification system for
I enjoyed using the motor power supplies and radio waves,
driver to control acceleration and it often takes a long time
and deceleration, and the design for foreign products to become
of the web UI. available in Japan. Sometimes
they cannot be used in Japan
What differences have you because the manufacturer often
noticed in the Japanese maker does not obtain certification
community compared to in Japan. Compared to the
the USA/UK? certification system in US or a 640×48 pixel LCD that was A
 kkie’s first
Raspberry Pi, as
I don’t know much about UK, I assume it makes things built into a children’s toy and posted to his Twitter
overseas maker communities (or less flexible for Japanese analyse it. No matter if they account in 2012

Japanese communities even), makers’ projects which use knew each other or not, makers
but when I saw maker events in radio waves… brought information they had to
US or the UK, I found there were Apart from our country’s Twitter and GitHub, and made
more huge (literally!) projects system, I think it’s amazing the controlling the LCD possible
than in Japan. It might be hard sense of unity a community can in a few weeks. That was really
for us to create huge projects in feel when they get their hands amazing. It is available for
Japan because, in many cases, on a junk part. In early 2021, it Raspberry Pi as well. I followed
there is not enough space in our was very popular for Japanese those instructions, bought the
Translation
house to work in. makers on Twitter to take out toy, and made it work too. by Satoka Fujita

See Akkie’s work

“[Over the last year], there has


been no online event for Open
Source Conference ( OSC:
ospn.jp). I usually exhibit and
introduce Raspberry Pi projects,
and give a presentation as
Japanese Raspberry Pi Users
Group at the OSC’s events. I
also showed projects at Japan’s
Maker Faire events.
“I post about projects and
[the] making process on my
blog (magpi.cc/akkieblog) and
This train set is controlled by
Raspberry Pi Zero and a smart Mastodon (magpi.cc/akkie).”
phone. There’s a Camera Module
stuck to the front as well

Akkie 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. 
Pet-cam number one this month, with a
cute dog to keep track of
02. 
A useful range sensor! And a clever way to
solve a voltage problem
03. 
Chickens count as pets, right? A great use of 02
a simple automated Raspberry Pi project
04. Pet-cam the third, with a small cat napping
in the corner and tweeting in private
05. Litter collection of the future maybe?
06. This would not look out of place on the
robot that Sly is cutting from Rocky IV
07. This is a very cool upcycling project. Be
careful working with a big computer
PSU, though!
08. Robot mower updates are always fun – this
one keeps getting better
09. A great start to Halloween decorations from
early October
10. This is a very impressive synth idea brought
to life!
11. Using some clever code, CycOb has
managed to create virtual bumpers so that
this robot knows when it has hit an obstacle
by how much power the motor is using

88 magpi.cc MagPi Monday


THIS MONTH IN RASPBERRY PI

03 04

05

09

06

08

11
07

10

MagPi Monday magpi.cc 89


THIS MONTH IN RASPBERRY PI

Best of
the rest!
Other amazing things
Amazing projects that from the community
we were
contacted about this month

PIHUNTER
magpi.cc/pihunter

We got an email from Gabriel Simches, a cyber


security analyst, about his Raspberry Pi threat-
hunting device, which he has excellently called
piHunter. He reckons it will work at home and in Here are the tools it runs:
a “small to mid-sized office” as well.
“Set up a Raspberry Pi to collect full-packet Arkime
Suricata Zeek (Bro) Elasticsearch Kibana
captures on your network, then index, normalise, (Moloch)
and search through your data to find anomalies,”
Filebeat Winlogbeats (TBD) RITA Run-RITA-Run tcpdump
Gabriel writes on GitHub. “All the data and tools
needed to deep-dive into any irregularity or weird
tshark prads strings yara python
activity is ready to go! A good threat-hunting
device has both GUI tools and multiple Living off
scapy PowerShell foremost Nmap
the Land (LotL) tools.”

INTERACTIVE BOOKSHELF
magpi.cc/iotlibrary

“The Internet of Things landscape is riddled


with commercial companies that want to gather
as much data as they can, while I think a library
thrives on privacy,” writes Willem Jan in his blog
about his interactive bookshelf idea. Using a series
of sensors and LEDs, Willem thinks he can make
finding and discovering books more fun.
The blog goes into his research on sensors,
microcontrollers, and microcomputers, before
giving a practical build for your bookshelf.
“Although this blog is very technical, I will try to
inform a general audience about the possibilities
that the Internet of Things has to offer.”

90 magpi.cc Mondays
Coolest
Best of the
Projects
are
rest
for Pico
online!
THIS MONTH IN RASPBERRY PI

TERMINATOR HUD
magpi.cc/termhud

Ever wanted to see like the Terminator? Maybe not


but it’s a cool idea for a video filter that looks great
as well. It’s all written in Python for Raspberry Pi
Camera Modules, and works best on Raspberry Pi 4
as it needs a bit of oomph to get it working.

TRACKING PLANES IN BRAZIL


magpi.cc/coffeeradiopod

We got an email from Martin Butera who hosts a podcast


in Brazil’s capital, Brasilia, about radio and coffee. While
talking to Thiago Pereira Machado, he mentioned how he
used Raspberry Pi to track aircraft, a cool and common
project for English speakers but not one we’ve seen in
Portuguese before.

Crowdfund this! Raspberry Pi projects you


can crowdfund this month

CROWD
Mini Pupper Little Hackers A PROFJUNDING
ECT?
If you
’ve launc
A cute quadrapedal robot based on Raspberrry Pi, it’s Raspb hed a
erry P
perfect for learning about robotics with it’s incredible 12 Learning to code with less screen time was something projec i-relate
t, let u d
degrees-of-freedom and open source software including Google Engineer Brandon Tory was worried about, so he magp s know
i@ raspb !
the Robot Operating System, OpenCV for computer created a book to allow you to do just that with help from errypi.
c om
vision, and SLAM for mapping its surroundings. his six-year-old son

kck.st/3zVVaZA kck.st/3zOfvQr

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


YOUR LETTERS

Your
Letters

 aspberry Pi Zero 2
R
is here, and we
gave one to all
current subscribers.
Get yours with a
new subscription

Subscriber gifts
I was wondering if you were still doing a Raspberry Pi Zero with your
subscriptions? Do subscribers get anything else as well with their
subscription? I’ve been meaning to get one for ages.

Christof via Twitter

As you may have noticed by now, the subscription offer has been
upgraded to include a Raspberry Pi Zero 2. You can find more info
about that on page 32. As for gifts, current subscribers also received a
Zero 2 in the post. Subscribing is the best way to make sure you get
any of the special items we give away!

92 magpi.cc Your Letters


YOUR LETTERS

 lot of people love to share what


A
they’re working on via Twitter

Make sure to check


Project submissions Nightmare before Christmas out our spooky project
upgrades feature in
issue 110 for some last-
If I have a Raspberry Pi project Will you be showing off Halloween projects again this year from the minute ideas
I’d like you to see, where is the community? I’ve got some really fun plans and I was wondering
best place to send it? whether I should send them to you! I hope you like being scared…
I think it would be a great fit
for The MagPi. Phil via Facebook

Daisy via email We absolutely will if you share it with us! Due to the peculiarities of
creating a magazine, this November issue will come out a few days
We’re more than happy to look at before Halloween, and the issue after Halloween has happened will be
any Raspberry Pi, Raspberry Pi the December issue – which will have Christmas stuff in it. Don’t
Pico, or RP2040 projects that you worry, though: we’ll print them any time of the year.
may have done, and emailing is Speaking of which, don’t forget to send us your Christmas projects
the best way to show us. too! Although they’ll probably end up in the February issue.
Otherwise, contacting us on
Facebook, or showing us on
#MagPiMonday on Twitter is a
good start! Sometimes, if we see Contact us!
it online, we’ll also contact you
about it. Whether it becomes a > Twitter @TheMagPi
project showcase, a mention in > Facebook magpi.cc/facebook
This Month in Raspberry Pi, or a > Email magpi@raspberrypi.com
retweet, we love to see and share > Online forums.raspberrypi.com
what you’re making!

Your Letters magpi.cc 93


Join us as we lift the lid
on video games

Visit wfmag.cc to learn more


COMPETITION

WIN ONE OF FIVE


WAVESHARE
E-INK DISPLAY PHATS
WITH 20 HEATSINKS FOR RUNNERS-UP!
IN ASSOCIATION
WITH THE PI HUT

This 2.13” E-Ink display is perfect


for the Raspberry Pi Zero 2 W
that you can get free with your
twelve-month subscription to
The MagPi. We have five to give
away, and 20 runner-up prizes
of a heatsink for Zero 2 as well.

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

Terms & Conditions


Competition opens on 27 October 2021 and closes on 26 November 2021. Prize is offered to participants worldwide aged 13 or over, except employees of the Raspberry Pi Foundation,
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
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


NEXT MONTH
EDITORIAL
Editor
Lucy Hattersley
lucy@raspberrypi.com

Features Editor
Rob Zwetsloot
rob@raspberrypi.com

Sub Editor
Nicola King

ADVERTISING
Charlotte Milligan
charlotte.milligan@raspberrypi.com
+44 (0)7725 368887

DESIGN
criticalmedia.co.uk

Head of Design
Lee Allen

Designers
Lucy Cowan, Sam Ribbits

Illustrator
Sam Alder

CONTRIBUTORS
David Crookes, PJ Evans, Satoka

CHRISTMAS
Fujita, Rosemary Hattersley,
Edwin Jones, Nicola King,
Phil King, KG Orphanides

PUBLISHING
Publishing Director
Russell Barnes
russell@raspberrypi.com

Director of Communications

Incredible makes for


Liz Upton

CEO
Eben Upton

the festive season!


DISTRIBUTION
Seymour Distribution Ltd
2 East Poultry Ave,
London EC1A 9PT
+44 (0)207 429 4000

SUBSCRIPTIONS
Unit 6 The Enterprise Centre
Kelvin Lane, Manor Royal,
Crawley, West Sussex, RH10 9PE
+44 (0)1293 312193
magpi.cc/subscribe

THE MAGPI #112 magpi@subscriptionhelpline.co.uk

ON SALE 25 NOVEMBER 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

Raspberry Pi
Raspberry Pi (Trading) Ltd., Maurice Wilkes

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

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

Upgrade a Super @TheMagPi


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

8 Camera magazine. Except where otherwise noted,


content in this magazine is licensed under
fb.com/MagPiMagazine a Creative Commons Attribution-
Build an intruder NonCommercial-ShareAlike
3.0 Unported
magpi@raspberrypi.com
alarm (CC BY-NC-SA 3.0).
ISSN: 2051-9982.
THE FINAL WORD

Tapping into tech


Intriguing early encounters with computing led to
Rosie Hattersley’s career writing about them

I
first encountered the concept information studies so I could get at than the Smith Corona typewriter
of computers when my visiting the Acorn computers in the commerce with the three-page text memory that
aunt reached into her bag and suite. Unfortunately, I had to spend I would write my university essays on.
triumphantly produced lengths of stiff the first half-term learning to touch- My first computer was a second-
cardboard with seemingly random type – anathema for an impatient and hand Mac, so I could brush up the
bits punched out. Whereas my mum less than dextrous teenager. QuarkXpress and Photoshop skills I
had been one of the earliest female used in my first job in publishing,
students of cybernetics, her sister Commodore coding indirectly taking me to a writing role
had gone into teaching maths. Both Thankfully, a brilliant Commodore 64 at home computing title PC Advisor
were perfectly placed to encounter made it into our home. I spent hours where I got to try out, review, and
programming 1970s-style, and my learning to play a musical keyboard write about using hundreds of
mum spent two happy years as a gadgets, games, apps and programs
Fortran programmer.
School meant Casio watches and
The arrival of two and, eventually, learn about an
intriguing product known as
LED displays; sometimes built into BBC Micros in the Raspberry Pi and its aim to put
pleasingly flexible, twangable rulers; computers and computing skills in the
sometimes embedded into the shaft of school library reach of the world. The global success
a pen. Resetting the time and date was of maker faires, Raspberry Jams, Pi
the ideal excuse to linger in a caused a stir Wars, Code Clubs and dojos, as well as
classroom while chatting to (aka the dozens of individual projects that
flirting with) nerdy, but nice, which sat above the computer’s own I’ve been lucky enough to learn about
schoolmates. Almost without fail, an keyboard, and typing in game code first hand and write about for The
overlooked friend would interject with from books. I taught myself BASIC and MagPi, show that Raspberry Pi has
a rude word spelled out on their fancy set up modest databases to organise brilliantly delivered.
scientific calculator screen. my growing record collection, but was
The arrival of two BBC Micros in the often ousted from the C64 by my
Rosie Hattersley
AUTHOR

school library caused a stir. As a games-hungry brother, keen to thrash


wannabe journalist, I became the another joystick in the service of Daley Rosie Hattersley has been writing about
editor of the newspaper we put Thompson’s Decathlon. the joy of tech for the past two decades
together as a class. Getting to use one Our Dad spent an apocryphal £3000 and (occasionally) still misses QuarkXpress.

at school meant taking business and on a Elonex 386 laptop, heavier even @RosieHattersley

98 magpi.cc Tapping into tech


Design

Code

Configure

Analyze

PR O FES S I O N A L CO N T R O L SYS T E M D E V E LO PM E N T TOO 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 • info@cdptech.com
CDP Technologies AS // Hundsværgata 8, 6008 Ålesund, Norway
HIGHPI PRO
The new case from the HiPi.io team

Rapid tool-free assembly and disassembly Secure microSD card cover


Large internal volume for HATs VESA mount support
Compatible with Pi 2/3/4 Molding-configurable output ports
Multiple lid options customizable for volume orders
Passive & Active Cooling options Printed logo for your branding

Available at these great Pi stores:

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

You might also like