RaspberryPi Magazine MagPi111
RaspberryPi Magazine MagPi111
CC/STORE
GET
YOURS
FREE!
SEE PAGE 32
magpi.cc/store
Experiment Explore
with a different the world
operating system of sensors!
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.
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
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
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.
magpi.cc 09
THE WORLD OF RASPBERRY PI
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
The donation was able to
fund several kits for young
people. Partners like the
East London Business
Alliance (ELBA) have
supported kit distribution
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.
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
Evolutionary process
The first version of SPY-DER was an Arduino Nano-
based device, controllable via an Android smartphone
Quick FACTS
> SPY-DER can
be built over the
course of a week
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
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.
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.
Guyrandy designed
a slick-looking
case for the tuner
in CAD software
and 3D-printed the
parts for it
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
T
he full build is
fairly simple but
quite impressive
in what it does
Sniffing electronically
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.
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
Quick FACTS
> The build and
code took three to
four hours
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
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
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
Quick FACTS
> Bob used to work
in Silicon Valley
> Community
Jams spun off
from Portland
Casual Jams...
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.
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
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.
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
> Simplifying it
and making
improvements are
of course ongoing
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
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
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
Subscribe in print
WORTH
$15
today and get a
FREE computer!
A full Raspberry
Pi desktop
computer
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.
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.
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.
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
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.
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
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
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
Raspberry Pi Zero 2 W
QuickStart Guide
Setting up and using Raspberry Pi Zero 2 W is pretty straightforward
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
Set up
Raspberry Pi Zero 2 W
Set up your microSD card and connect
all the accessories before powering up
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
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.
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.
46 magpi.cc Sensory world: Build a fire and gas leak alarm system
TUTORIAL
Sensory world: Build a fire and gas leak alarm system magpi.cc 47
TUTORIAL
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
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
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.
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)
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
DOWNLOAD
THE FULL CODE:
magpi.cc/streamdeck
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.
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.
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.
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
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.
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
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
GS General Standard/General Sound, a Roland standard that expands GM with extra sounds
dosbox-x MARTIAN.EXE
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).
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:
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.
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.
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.
class Cpu:
"""this class represents the CHIP 8 cpu"""
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
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
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:
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
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]:
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_
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
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?
Ubuntu Desktop
Type: General-purpose
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
RISC OS Pi
Type: General-purpose
“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.
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.
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.
OSMC RetroPie
Type: Media centre Type: Retro gaming
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.
Lakka
Type: Retro gaming
Available: lakka.tv
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.
Recalbox
• Download from website
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
info-beamer
Type: Digital signage
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.
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
Homebridge
Type: Smart home
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.
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.
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.
TonyPi is a great-
looking robot that can
be easily controlled via
Android or iOS apps
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.
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
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
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
Getting Started
in Electronics
Forrest M Mims Who better to teach you the Starting with the basics of
AUTHOR
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
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
Akkie
Can you be a maker without knowing electronics?
Akkie was before Raspberry Pi
“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.
86 magpi.cc Akkie
INTERVIEW
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
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
03 04
05
09
06
08
11
07
10
Best of
the rest!
Other amazing things
Amazing projects that from the community
we were
contacted about this month
PIHUNTER
magpi.cc/pihunter
INTERACTIVE BOOKSHELF
magpi.cc/iotlibrary
90 magpi.cc Mondays
Coolest
Best of the
Projects
are
rest
for Pico
online!
THIS MONTH IN RASPBERRY PI
TERMINATOR HUD
magpi.cc/termhud
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
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.
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!
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!
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
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
CEO
Eben Upton
SUBSCRIPTIONS
Unit 6 The Enterprise Centre
Kelvin Lane, Manor Royal,
Crawley, West Sussex, RH10 9PE
+44 (0)1293 312193
magpi.cc/subscribe
Plus!
system which has been assessed as
conforming to ISO 14001.
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
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
at school meant taking business and on a Elonex 386 laptop, heavier even @RosieHattersley
Code
Configure
Analyze
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