MagPi108, MagPi Magazine August 2021
MagPi108, MagPi Magazine August 2021
CC/STORE
magpi.cc/store
WELCOME
WELCOME
to The MagPi 108
E
verybody likes to get a gold star. I remember hosting awards
and no matter how cool they try to play it, getting a shiny
gong always puts a smile on somebody's face.
And sometimes it feels right to say ‘well done!’ That’s why this
month we’ve gathered together the best Award-Winning Makes
(page 30). These are the projects that have won shiny statues,
Lucy
EDITOR
gathered plaudits, and impressed some judges. Hattersley
These builds are worth your time. They deliver ideas for your next
Lucy is editor of
make and stand as glittering examples of Raspberry Pi making the The MagPi and is
back on the train
world a better place. to Cambridge with
a smile behind
If you want something more down-to-earth and buildable ‘right the mask.
now’, then I suggest PJ’s new ‘Ultimate Home Server’ tutorial @LucyHattersley
(page 38). This is the first in a new series of using Raspberry Pi in the
home to manage all of the digital files in your life.
And if you’ve ever fancied yourself making visual entertainment,
then check Make Games with Raspberry Pi (page 71). In this article, GET A
Mark Vanstone reveals Raspberry RASPBERRY PI
Pi software designed to help your ZERO W KIT
digital dreams become reality.
There is a lot to discover in this
PAGE 28
month’s edition of The MagPi.
Dive in and discover the idea for
that project that will one day,
perhaps, win you an award.
magpi.cc 03
3 ISSUES FOR £10
+
FREE BOOK
magpi.cc/freebook
Subscribe to The MagPi, HackSpace magazine, or Custom PC. Your first three issues for £10, then our great value rolling subscription
afterwards. Includes a free voucher for one of five fantastic books at store.rpipress.cc/collections/latest-bookazines
UK only. Free delivery on everything.
CONTENTS
Contents
> Issue 108 > August 2021
Cover Feature
Regulars
92 Your Letters
97 Next Month
98 The Final Word
Project Showcases
08 Callisto II
12 Humane Mousetrap
16 Bop It Minecraft Controller
18 PrivacyMic
20 Campervan LAN
24 Air Quality Traffic Light 26
26 Kenbak-2/5
08
Callisto II Kenbak-2/5
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
38 66
Tutorials
38 Ultimate home server - part 1
42 Build an arcade machine - part 5
48 Create GUIs in Python - part 8
Ultimate home server - part 1 Isomorphic keyboard
56 Custom Pico USB controllers
60 Raspberry Pi Pico data logger
66 Isomorphic keyboard
80
86
Make games with Raspberry Pi
Reviews
80 pi-top Robotics Kit
82 10 Amazing: Wearables
84 Learn Visual Studio Code
Community
86 Zack Freedman interview
88 This Month in Raspberry Pi Zach Freedman interview
WIN
A MARTY THE 95
ROBOT V2
06 magpi.cc
Robotics & rapid prototyping
with your Raspberry Pi
Power your projects with computer vision and applied AI
pi-top [4] Robotics Kit comes with electronic components such as a wide-angle
camera, servos and motors, all of which plug and play with the pi-top [4]
Complete or pi-top [4] DIY Edition†.
pi-top Robotics Kit with Expansion Plate
£187.90 / $199.90
Integrated
with Microsoft
Face
Interaction
Tracking
pi-top.com/MagPi
Raspberry Pi is a trademark of the Raspberry Pi Foundation. †pi-top [4] and Robotics Kit with Expansion Plate sold separately. © CEED Ltd. 2021
Callisto II
A retro gaming fan gave his Raspberry Pi a 1980s
makeover. Rosie Hattersley is on the case
I
n his spare time, games developer and maker
Kevin loves to tinker with all things retro: “I like
to design new NES games using 6502 Assembly”
he tells us, deftly setting the scene for how his
Callisto II retro computer design came about. A
hardware-based project, Callisto marries Kevin’s
enjoyment of 3D design and printing and his abiding
love of retro gaming.
Kevin Solar
MAKER
Tricky curves
Despite his experience with 3D printing to date, Kevin
says the trickiest part of the design was modelling the
curves, as he’d not done this before. He persevered,
knowing the curves would set his design apart from
others. It was also a challenge to find a true 4:3 LCD
screen that was inexpensive and readily available,
he says, but rarer still to find a retro computer that
used the 16:9 aspect ratio of modern displays. He was
eventually able to source an 8-inch Pimoroni display
to give Callisto that all-important 1980s look.
08 magpi.cc Callisto II
PROJECT SHOWCASE
Quick FACTS
> Kevin set up a
retro website
to accompany
Callisto’s launch
Callisto II magpi.cc 09
PROJECT SHOWCASE
Easy ethos
Kevin tried to use readily available parts from
online retailers for most of the project. “Not only
did I want this to be super-easy to print and put
together, I wanted it to be easy to find the parts
[and be] something you could put together for an
easy weekend project (assuming you spent the
previous week printing all the parts),” he says.
You don’t even need glue as all the parts have
been designed to snap together, but you should
allisto II is the third
C
ensure all the electronics have room to breathe,
3D-printed retro computer
Kevin has designed he cautions.
trio of Callisto
A
II computers
10 magpi.cc Callisto II
PROJECT SHOWCASE
Callisto II magpi.cc 11
PROJECT SHOWCASE
Humane mousetrap
Safely catching mice is a better way of fixing a problem, and using
Raspberry Pi means it needs less supervision. Rob Zwetsloot takes a look
W
ith some IoT projects, it’s the little
things that help. For example, take
Andrew Taylor, who did the good thing
of setting up a humane mousetrap. However,
checking it to see if any mice had been caught in it,
while necessary, was getting a little boring.
“If a mouse had gone in and I did not check
it, the mouse would quickly run out of food and
Andrew Taylor
MAKER
Quick FACTS
> The whole setup
costs roughly £28
Catching mice
Beat a path
There’s always room for improvement, as
Andrew explains: “I intend to improve the code
so that it can record running averages and give
an indication as to whether it believes there has
been a significant spike that might necessitate me
checking it out.”
“After 24 hours, it triggers a message containing
Whilst the aim of the project was to keep costs 03 the number of hits over that period by sending
down, Andrew is tempted to experiment by adding a HTTP request to IFTTT which is hooked up to
a camera, and possibly a light, so he can have a Pushbullet,” says Andrew. “This then sends this
peek remotely when there has been a spike in the message as a notification to my phone. The counter is
readings and to see if it is a false alarm. Which, as then reset ready for the next day.”
he admits, is “a new height in laziness!”
Bop It
Minecraft
Controller
Why play Minecraft with a keyboard and mouse when
you can use an electronic toy modified with Raspberry
Pi Pico? Nicola King appreciates the twist
Minecraft is a little
trickier, but perfectly
O
ne of the world’s favourite electronic playable using the
toys, Bop It has been around for 25 years. customised Bop It
Normally, you press, pull, flick, spin,
and twist its buttons and knobs according to the
spoken instructions given. Great fun, if noisy and
annoying for parents. Seth Altobelli, however,
opted to refit his Bop It with a Raspberry Pi Pico to
turn it into a USB controller for Minecraft.
Seth Altobelli
MAKER
Quick FACTS
> Seth has offered
to send his
custom Bop It to
Technoblade to
try out
> Combinations of
buttons are used
for some actions in
the game
PrivacyMic
A device that listens to noises in your home but
doesn’t hear your conversations? David Crookes tunes in
M
ore than 320 million smart speakers above the range of human hearing, the system
have been sold across the world, filters out speech and audible sound, yet can still
allowing us to use our voices to play understand what’s happening in our environment.
music, ask questions, and discover information.
A growing number of Internet of Things Sound of silence
(IoT) devices are also being embedded with PrivacyMic is built around Raspberry Pi and it
microphones, but there are concerns they’re works with ultrasonic sounds – that is, those
capable of eavesdropping on our conversations with a frequency of 20 kilohertz or higher. Many
Yasha “It’s hard to tell what an IoT device is doing objects and actions emit ultrasound waves,
MAKER
Iravantchi with its microphone beyond an LED signifying including compact fluorescent bulbs, dishwashers,
its microphone is in a muted or unmuted state,” computer monitors, flushing toilets, and electric
Yasha Iravantchi is
a PhD candidate says Yasha Iravantchi, a graduate student at the toothbrushes. “It’s a frequency that’s inoffensive to
at the University University of Michigan. “In the future, these humans, but can be annoying to dogs,” says Yasha.
of Michigan. He devices are going to perform more tasks than just Most traditional audio equipment won’t capture
researches novel
listening for speech commands and there is the ultrasonic sounds. “Devices are tuned to focus on
sensors that
operate in a privacy- possibility that a lot of audio will be captured, the range of human speech or hearing and they
preserving way. recorded, and stored.” often actively remove the sounds outside of these
magpi.cc/ For this reason, Yasha has been leading a team ranges as ‘noise’ from the environment,” Yasha
privacymic developing PrivacyMic, a research project ensuring explains. By creating a HAT for Raspberry Pi Zero W
private conversations cannot be recorded and using an analogue ultrasonic microphone and a
stored. By only gathering sound at frequencies filter to remove speech and audible frequencies,
however, PrivacyMic can do the opposite.
“The ‘noise’ that these systems throw away
is a valuable signal we can use to recognise
and classify daily-use objects,” Yasha says. It
means PrivacyMic can hear when a light bulb
or microwave is turned on, determine when a
toothbrush is being used, or when a toilet is
flushed, without capturing any conversations.
“We’ve also been using Raspberry Pi 3 to explore
ways of performing all tasks – from capture to
classification – on the computer itself to ensure no
data ever leaves Raspberry Pi.”
Listen up
So how does it work? “Analogue filters remove
the audible frequencies and only allow ultrasonic
frequencies to pass through to the analogue-to-
This laptop is running the team’s own open- digital converter (ADC),” Yasha explains. “These
source app T4Train which can connect to
signals are passed to a machine learning model
PrivacyMic and train a model on the spot using
incoming data, or load a pre-trained model to recognise these daily-use objects in ultrasound
18 magpi.cc PrivacyMic
In a demo, PrivacyMic was shown to
recognise finger snaps and use the
ultrasonic component of the sound to
unmute an Echo’s speech microphone
using a small servo that physically
presses the button, allowing for
normal verbal commands
Quick FACTS
> PrivacyMic
only listens for
frequencies
of 16kHz+
PrivacyMic magpi.cc 19
PROJECT SHOWCASE
Campervan LAN
Needing to travel to several countries for work, one
maker chose to kit out his campervan as a mobile office.
Rosie Hattersley was intrigued
C
ampervans are all the rage right now, since
they offer a chance to escape the home in
favour of fresh air and a change of scene.
Enrico Miglino’s job often needs him to pitch up
in Germany, Spain, or Belgium where his software
development architect consultancy is in demand,
so it made sense for him to take the digital nomad
concept literally, and adapt a campervan to create a
Enrico Miglino
MAKER
mobile office.
Although most campsites and caravan parks
Enrico designs and
develops multi- offer WiFi to guests, such connections are often
platform software unsecured, limited to only a couple of hours’ free
projects for clients use, and require each device to log in separately.
across Europe
Enrico needed a setup that was far more robust.
(and occasionally
India). He’s been His vehicle, Jan The Van, sports a secure mobile
using and helping LAN, is powered by three Raspberry Pi computers,
road-test Raspberry
and allows Enrico to use a single login to provide
Pi since its first
Linux prototype. internet access to any devices on his network. The
whole setup cost less than 500 euros, meaning he
we-are-borg.
com could also afford to add a solar panel.
Quick FACTS
More Raspberry Pi
Internal devices on Jan The Van’s network could
only be connected to the Ethernet port, which
wouldn’t work for iPads, iPhones, and other mobile
devices that lack the necessary port. To overcome
this, Enrico added an Ethernet switch and a second
Raspberry Pi 4B configured as a bridge to which
adapt the modules the ESP3266 modules attached to the sensors. The
screen orientation is corrected in configuration.
Air Quality
Traffic Light
Worried about the effects of poor air in his home city, Dmytro Panin
has created a unique alert system, as David Crookes explains
K
yiv in Ukraine is one of Europe’s most of code to account for inaccuracies which varied
polluted cities. It has high smog levels, drastically based on the environment temperature.”
which can cause health problems. “It also
occurred to me that, in summer, the air quality Good to go
in our area can deteriorate due to peat deposits Instead, he turned to an MH-Z19B carbon dioxide
igniting and smouldering somewhere in the sensor. “It was way more accurate and it worked,
province,” says Dmytro Panin. but only temporarily, as the elements in my area
For that reason, he decided to take a break from can be on the extreme side,” Dmytro says.
Dmytro Panin
MAKER
a project he was working on – a device which The solution, therefore, was to write a short
monitors currency prices using Raspberry Pi Zero W program using the open-source programming
Dmytro Panin is a
– to create an air quality reporting system. Having language Go (golang.org). It fetches Air Quality
programmer based
in Kyiv, Ukraine, and found a battery-operated toy traffic light, he came Index data from the website IQAir (iqair.com),
he wrote his first up with a plan that was both practical and fun. which uses information from consumer devices
line of code aged “If the wind blows in the direction of the
eight. He works for
a large provider of
city, you can smell the smoke, which some say
nearshore software resembles whiskey, and it means you don’t want to
engineering services. have the windows open for too long,” Dmytro says.
magpi.cc/ “So, I came up with the idea of having the red light
airquality of a traffic light illuminate if this was to happen.”
Quick FACTS
> The traffic light
can be bought for
about £10
When the Air Quality Index figure > It’s 12 centimetres tall
registers between 50 and 100, the light
is amber. Anything below that lights > The project uses
green, while above 100 shows red a Raspberry Pi
3B+ computer
Dmytro has placed Raspberry Pi in a
LEGO-compatible case. A 3D-printed > Raspberry Pi Zero
LEGO minifigure sits on top, boasting would also work
the AWS Lambda symbol. Dmytro says: perfectly well
“It used to be our team’s mascot”
> All the files are
on GitHub
T he aggregated data
is quite accurate, but it
covers the entire city
located across Kyiv. It also grabs current data from
OpenWeather (openweathermap.org) in parallel.
By storing the data on Raspberry Pi, Dmytro’s
script – written in Python – can determine which
light to illuminate, controlling the LEDs using the
Python library GPIO Zero. Red obviously shows
that the air quality is poor, prompting Dmytro
to close the windows and take precautions when
venturing outside.
Even so, there is room for improvement. “The
aggregated data is quite accurate but it covers the
entire city,” he laments. “Sometimes it would
make more sense for measurements to be more
local. Collecting data myself and combining it with
the information I get from the API should be the
next step.” Data from IQAir is used to help determine which LED should illuminate on the traffic light
Kenbak-2/5
Reproducing a personal computer that was first created way back in 1971
has been, for Michael Gardi, a labour of love. Nicola King turns back the years
Raspberry Pi 4 is connected to the lights and LEDs A close-up of the wiring from the
on the front panel via a 32-channel I/O expansion HAT HAT; most of the channels were used
R
egular readers of The MagPi may recall that in microprocessors that were to follow years
in issue 102 (magpi.cc/102), we covered a later, like the Motorola 6800 (1974) and the MOS
fantastic Turing machine reproduction by Technology 6502 (1975).”
Canadian retro enthusiast Michael Gardi. Well,
Michael is back with another blast from the past – A contemporary take
this time with his take on the Kenbak-1 which, as Michael has a YouTube video (magpi.cc/kenbakyt)
he shares, was “considered by many to be the first that explains in detail how the original computer
commercial personal computer, despite its failure worked, as he enters a program through the model’s
Michael Gardi
MAKER
26 magpi.cc Kenbak-2/5
PROJECT SHOWCASE
3D-printed in two
parts, the case is
held together by two
slotted side pieces
I think that the devices themselves, and their designers, Quick FACTS
deserve to be remembered and honoured > Only 50 of the
original Kenbak-1
Michael 3D-printed the frame of the project. glitches. “Fortunately, there is a pretty active
computers were
“One of the reasons that I chose to make this Kenbak-1 community out there and some people ever sold
reproduction at 2/5 (40%) scale was so that all actually tried out my software and found a few bugs
the 3D-printed parts (of which there were only and misunderstandings.” > As they are so rare,
five) would fit onto my printer. So, this simplified the last one sold
the assembly,” he says. “Aside from the screws Architect’s approval at auction went
used to mount the Raspberry Pi to the frame, The icing on the cake is that Michael’s make has for $40,000
everything just snaps together.” received praise from the original inventor. “I sent
> Michael’s version
A built-in Raspberry Pi 4 is connected to the John Blankenbaker (91 years young) an email with
took one month
front panel via a 32-channel expansion HAT. It pictures of my reproduction and a few questions,
to create
also runs an IDE that can be accessed on a remote and he was gracious enough to answer. The first
machine via SSH or VNC; the source code is on thing he said in his reply was ‘Your email was the > Most of his
GitHub (along with the STL files for 3D printing the most interesting thing I have received today. I was projects are based
case): magpi.cc/kenbakide. very impressed!’. That sure made my day too!” on very retro
Michael created the Kenbak-1 Assembler and Praise indeed, and this underlines one of the reproductions…
Emulator using Python and it’s all based on John reasons why Michael undertook the challenge:
Blankenbaker’s Programming Reference Manual. “I think that the devices themselves, and their > …like this impressive
Any qualms he had about his understanding of designers, deserve to be remembered and replica of a
1968 computer:
the documentation were laid to rest by fellow honoured.” Many enthusiasts would certainly
magpi.cc/vt100
enthusiasts who helped him out with potential agree with that sentiment.
Kenbak-2/5 magpi.cc 27
SUBSCRIPTION
SUBSCRIBE TODAY
FROM ONLY £5
Subscriber Benefits
FREE Delivery
Get it fast and for FREE
Exclusive Offers
Great gifts, offers, and discounts
Great Savings
Save up to 35% compared to stores
FREE Raspberry Pi
Zero W Starter Kit
WITH YOUR FIRST
12-MONTH SUBSCRIPTION
Subscribe in print
today and you’ll
receive all this:
Raspberry Pi Zero W
Raspberry Pi
Zero W case with
three covers
USB and HDMI
converter cables
Camera Module
connector
This is a limited offer. Not
included with renewals.
Offer subject to change or
withdrawal at any time.
SUBSCRIBE
on app stores
magpi.cc 29
FEATURE
W
e like to hope that at least some of
the projects we publish in The MagPi
inspire people to make more. When
it comes to inspiration, though, nothing beats
projects that are changing the world for the
better, and have won awards for doing so.
There are many kinds of awards, and even more
kinds of winners, but here is just a selection of
these prestigious projects that will make you go
‘ooh’ and ‘aah’ in appreciation, and hopefully be
the spark of inspiration for your next build.
This underwater ‘weather station’ from the Save Our friends over at element14 regularly have
Nemo Foundation is being used to protect coral community design challenges that involve
reefs from climate change and divers. Raspberry Pi. A recent one, 1 Meter of Pi,
They work by attaching to a concrete block was to create a 1 m3 area that could grow food
that has been placed on the sea floor – these on a hypothetical trip to Mars. The winner
blocks are attached to a buoy that boats can moor was feiticeir0 with their Space Vegetables, a
up to, rather than randomly dropping anchors hydroponic garden that had a time-lapse camera
that can damage the reefs. The Nemo-Pi can and the ability to post to Twitter.
detect temperature, visibility, pH levels, and Like a lot of the element14 competitions, you
concentration of certain gasses in the water. can read a detailed, regular analysis of how the
As well as monitoring the ocean, it will allow build and growing went. To summarise, the
holidaymakers to know if the conditions for water, nutrient, and air pumps, along with grow
diving are good. lights, were all Raspberry Pi controlled using a
Nemo-Pi won the Google.org Impact Challenge mixture of sensors and code. The results of this
2018 competition. cosmic produce has even been sampled.
Ecosystem monitoring
Sarab Sethi
magpi.cc/ecosystem “ They record and
transmit the
“The health of a forest ecosystem can often be
noise 24/7 for
”
attributed to how much noise it creates,” says
Professor Rob Ewers of Imperial College London,
the university where this project that listens to the
scientific study
rainforest was created.
These solar-powered audio recorders using
Raspberry Pi were the creation of a small team
at ICL, including Dr Sarab Sethi and Dr Lorenzo
Picinali, and are placed around the rainforest in
Borneo. They record and transmit the noise 24/7
for scientific study or for you to just chill out to via
the SAFE Acoustics live stream: magpi.cc/SAFE.
This system won a prestigious NETEXPLO
Innovation Forum Award 2018, an award scheme
from UNESCO that looks at university projects.
Playable LEGO
detect earthquakes
”
Steinway Piano
Lavie from the USA Earthquake Early Warning
magpi.cc/legopiano Vivien He from the USA
magpi.cc/earthquakewarn
This clever hack takes a LEGO piano
that is fully mechanically functional, This consumer grade (under
and uses a mixture of handmade $100/£72) box can accurately detect
paper PCBs with conductive ink earthquakes over a magnitude of 3.0,
and a Raspberry Pi to translate the and filter out footsteps, jumping, and
mechanical functions to the notes it other nearby human activity. It then
should play. Lavie had to debug her sends a warning to the user’s phone.
code to account for the way multiple Vivien hopes this kind of tech can be
keys are pressed in a smart way. used to save lives and reduce damage.
Past
winner
highlights
Vital Signs Monitor
AZ-Tech Teddy Door Pi Plus Adarsh Ambati
Andrei, Ioana, David Daniel and Freddie magpi.cc/vitalsigns
Bianca Laura from Romania magpi.cc/doorpiplus
Adarsh’s project is a system for
This smart teddy bear helps track A door security system for elderly users monitoring vital signs to diagnose
eating habits in younger people, and that makes use of facial recognition illness without touching the patient.
helps them pay closer attention to what software. This project has won more It also provides limitless possibilities,
they’re eating. It connects to various awards as well from other UK and from preventing sudden infant death
apps via Raspberry Pi. global competitions. syndrome to diagnosing viruses.
BEST INTERNATIONAL PRIZE 2018 COOLEST PROJECTS UK 2019 OVERALL WINNER OF COOLEST
HARDWARE WINNER PROJECTS USA 2020
Astro Pi
Y
ou can find Raspberry Pi everywhere, International Space Station orbiting 408 km
even in space! There are yearly above the Earth.
competitions to upload and run science Here we present some of the past winners,
experiments aboard two special Raspberry along with highlights from the entrants for
Pi computers, called Astro Pi, aboard the Mission Space Lab 2021.
Astro Pi in numbers
426 total team
submissions 232 experiments
run on the ISS
1695 participants
From
23 countries
489 (28.8%)
female participants
149 teams
eligible to win
Wan
learn t to
abou more
t
Pi? H Astro
ead t
astro o
pi.or
g
This English team captured lightning in the clouds Italian team Blue-3A captured Turks and Caicos.
during a night-time storm over South America – The blue filter really accentuates the blueness of
the first time this has ever happened during Astro the barrier reef. Images are being taken to analyse
Pi. Their experiment is to test cloud density to see how vegetation and inland waters (rivers, lakes,
if it’s been affected by climate change. etc.) influence local climates.
Tech4Good
Young Pioneers
T
he Tech4Good awards are an annual
event that celebrate many aspects of
technology. One accolade is the BT Young
Pioneers Award, given to young folks that are
using tech to support climate action and other
social good projects. Several winners have all
done so with Raspberry Pi projects, showing
how versatile Raspberry Pi is.
Dyslexia effects a significant portion of the Arnav is one of the youngest award winners
population, and results in people having some in this article at only nine years old. After
difficulties with reading and writing. The studying the intricacies of the respiratory
Dyslexic Aid creates a multi-sensory learning condition asthma, he hooked up a suite of
environment that stimulates different senses, sensors to a Raspberry Pi to monitor the
aimed specifically at helping dyslexic pupils. quality of the air in an asthma sufferer’s home
With a very limited budget, they were able to and send messages with reminders, alerts,
do research and build the device with just a and even warnings to their phone. It can also
Raspberry Pi and a Sense HAT, and make use of help figure out any unknown triggers that can
its full suite of functions. result in an asthma attack.
“ The
Mihika Sharma – 2019
Smart Stick Smart Stick
is surprisingly,
magpi.cc/smartstick
well, smart
”
Mihika is also nine years old, and made the
Smart Stick for blind people after witnessing
her mother helping a blind person across the
road. The Smart Stick is surprisingly, well,
smart. As well as the visible ultrasonic distance
sensors to detect obstacles, it can detect
puddles, it has motors that guide the user left
or right depending on smartphone satnav
directions, LED lights for night-time, and
Braille writing to let users know where to place
a left or right hand. It’s won other awards as
well, and for good reason.
Issue 50 Issue 75
community award community award
To celebrate our 50th issue, In the two years
we decided to count down between issues 50
50 incredible projects, with and 75, we were able
the top 20 voted for by to collate 75 brand
our community. The top new and amazing
five included incredible projects to once again
creations, such as the show off in The MagPi.
SeeMore cluster computer Instead of just voting
art project and the BrewPi for 20 of them, this
beer brewing system that a time we had a top 50,
lot of adult makers love. as voted for by you.
A classic project. The concept, popularised by Michael The design of the Nintendo Switch is an all-timer,
Teeuw, has exploded in popularity, with people and many folks have been inspired by its removable
creating straight smart mirrors, smart vanity mirrors, controllers. PiSwitch went a step further and had
and even recycling a broken iPad to act as a mirror. It’s them connect to a 3D-printed case that also had
deceptively easy to make one, and installing useful a big display for a Raspberry Pi running RetroPie,
code for it is a doddle. It’s very extendible as well, and with the Joy-Cons connected via Bluetooth and
we’ve seen folk add seasonal extras and voice control. completely detachable like its inspiration machine.
PJ Evans
MAKER
PJ is a writer,
software engineer
and tinkerer. His
server has just told
him it’s time for
another coffee.
twitter.com/
mrpjevans
T
he rear of the case
organises all the
ports neatly and the
bridge connects the
M.2 drive to your
Raspberry Pi 4
R
aspberry Pi also makes a great home protecting your data, you’ll need at least 4GB for
server. Why do you need a home server? it to work effectively. Then consider what the
Well, there’s all kinds of uses: file sharing, server will be doing. Serving files doesn’t require
protecting your network from dodgy advertisers, much effort and is well within the capabilities of
controlling your smart devices; the list goes on. In Raspberry Pi Zero, and we strongly recommend a
this new series, we’ll build a home server with all wired network connection.
You’ll Need the bells and whistles to inspire you to create your
own ultimate build, with plenty of ideas and tips
> Raspberry Pi 4
along the way.
magpi.cc/
Choose a case
raspberrypi4
02 Our Raspberry Pi 4 needs a good home
> A
rgon One M.2 case
Choose the right model
magpi.cc/
argononem2
01 It’s probably no surprise that we’re using
if it’s going to be a server. There’s no shortage
of cases available and if you’re lucky enough
a Raspberry Pi 4 with 8GB RAM model for our to have a 3D printer, many more designs are
> 1 TB M.2 SATA
ultimate server. It’s the most powerful Raspberry available for download. Have a think about storage
SSD drive
magpi.cc/ Pi. However, you can go for lower memory sizes requirements such as additional disks or access to
wdbluem2 and get similar performance. If you’re interested USB or GPIO connectors. We’ve chosen the Argon
in using advanced file systems like ZFS for One case. Not only is it beautiful, it also features
passive cooling (as well as a fan) and support for 3B, and Compute Modules 3+ and 4. However, you
M.2 storage devices. As a server is intended to be will need to update the bootloader on these devices.
running 24/7, make sure your choice of case is well See magpi.cc/bootloader for info and instructions.
ventilated and will be placed where it can ‘breathe’.
Argon assemble!
Top Tip
Choose storage 05
03 The standard application for a server is file
Now we have the computer, case and storage,
it’s time to put them together. The Argon One
USB drives
sharing: the ability for anyone in your household to comes with a comprehensive installation guide. Add If you’re going for
access a library of files. If you’re thinking of a media the expansion board to bring all the connections mass storage and
server, consider carefully what type of storage to use to the rear of the case, then mount in the case as fancy adding an
array of drives,
and how much you need. Movies, especially in high- instructed, using the supplied thermal pads to
don’t forget a
definition formats, eat up a lot of space but don’t get a good connection between the board and the powered USB
require fast storage to play back reliably. We’re heatsink. Install your M.2 SSD drive in the lower hub to avoid
making use of the Argon One’s M.2 interface to add part of the case, then screw the two halves together. undervolting –
1TB of fast SSD-based storage, but you may prefer The M.2 SSD device is connected to Raspberry Pi 4 this can damage
one or more USB SSD drives. Using a microSD card using an external USB-to-USB bridge. your data
and hardware.
is still an option, but slower and less reliable.
T
he aluminium case connects to the CPU and memory
using thermal paste to act as a giant heatsink
T
he Argon One’s it’s ready to boot. As this is a server, we don’t need network. If you didn’t do this, set up your hostname
clever expansion
board brings all the a graphical user interface, so we can keep things by running sudo raspi-config from a Terminal.
connectors to the lightweight. Using Raspberry Pi Imager, select You can also set up networking here if you need to.
back and converts the
HDMI ports to full-size Raspberry Pi OS Lite and check out the advanced Update everything with:
menu (CTRL/CMD+SHIFT+X) to set things like
hostname and networking before burning the sudo apt update && sudo apt -y full-upgrade
image to the card. We are naming our hostname
‘ultimate’ so it is easy to find on the network.
e recommend placing
W
your server close to your
home broadband router
based on temperature. It will also allow the power
button to cleanly shut down after being pressed
for three seconds. To change these settings, run
argonone-config from the command line.
...where <name> is the username you would like ...where <name> is the username you created
(avoid spaces and special characters). It will ask previously. Now you can log into your server
you a few optional questions about your full name without a password using SSH:
and location. Finally, you can set a password
(be sensible!). ssh <name>@ultimate.local
To give the user ‘super user’ or ‘sudo’ rights: If your local username matches the server’s, you
don’t even need to include it or the ‘@’.
sudo adduser <name> sudo
L
ast month, we used Recalbox for our As with our DB9 joystick project in issue 101
main arcade cabinet operating system, (magpi.cc/101), we have to tell the GPIO to treat
but it’s not your only choice. In this final the controls as pull-up switches. Recalbox, by
K.G. instalment of the ‘Build an arcade machine’ comparison, implements this by default.
MAKER
Orphanides series, we’ll use the RetroPie distribution, Create the pullup.sh file we’ve supplied
currently at version 4.7, to provide extra (magpi.cc/pullupfix). You can put it anywhere you
K.G. is a writer, maker
features such as Steam Link support, as well like – we stuck ours in /home/pi/. Now open /etc/
of odd games, and
software preservation as taking a longer look at where to buy arcade rc.local on the SD card and, above the exit line, add:
enthusiast. Their games and how to get them onto your system.
household can
This tutorial assumes that you already have a /home/pi/pullup.sh
now hold very retro
Street Fighter II fully assembled and wired arcade cabinet.
tournaments, and This will load your pull-up settings on boot. If you’re
that’s beautiful setting up your disk on a Linux system, you can set
@KGOrphanides pullup.sh as executable now. Otherwise, we’ll do that
Install and prepare RetroPie
M
ore button
01 Fire up Raspberry Pi Imager, connect your
on first boot.
assignments are microSD card writer, and install RetroPie from its
available on RetroPie
than you have arcade Choose OS menu. Re-mount the microSD card
First boot
02
controls. You can skip once you’ve finished flashing it, because we’ve
the ones that don’t
match up got some changes to make. Make sure you have a keyboard plugged
into your cabinet for this bit. We left ours
propped up against the marquee acrylic during
setup for easy access. A Bluetooth keyboard is a
viable alternative, but it’s easier to start with a
wired connection.
Plug in Raspberry Pi’s power. It should boot to the
EmulationStation interface, but we can’t configure
the controls until we’ve set our pull-up script
executable. Press F4 to exit to the command line
and type:
chmod /home/pi/pullup.sh +x
sudo raspi-config
1 system option
s3 password
DOWNLOAD
THE FULL CODE:
magpi.cc/rpipullupfix
reboot
sudo ~/RetroPie-Setup/retropie_setup.sh
P manage packages
driver
819 mkarcadejoystick
B
utton and joystick Optional: Load your hotkey driver
correspondences
for player controls;
04 When Raspberry Pi has rebooted, SSH back
C Configuration / tools
804 bluetooth
we recommend this
configuration for use
in and type:
with RetroPie. L and R Press R to register a device and follow the
map to the right and
left shoulder buttons sudo modprobe mk_arcade_joystick_rpi map=1,2 pairing instructions.
832 samba in the configuration menu sets up
Go over to the arcade machine and press F4 to get Samba shares so you can easily transfer ROMs and
to the command line and test your controllers: BIOS images over your local network
You can add extra emulators here, but we’ll
jstest /dev/input/js0 come to that later. For now, select the R Perform
jstest /dev/input/js1 reboot option from the main menu.
button. In our wiring configuration, our single such as the Sega Mega Drive, used in some
hotkey button – the last we set – is associated arcade systems and for which original games are Top Tip
with player 1. legally available.
Approve your configuration, then set up Some emulators require system BIOS images. Steam Link
player 2’s controls in the same way. Sadly, very few of these have been made smoothly
legally available to emulation enthusiasts. SNK
Use a wired
distributes a UniBIOS compatible BIOS set in its
Ethernet
40th Anniversary Collection. We recommend
connection for
Getting to know RetroPie
07 With your controllers configured, RetroPie’s
adding the following: optimal Steam
Link game
main interface will open. Press A to select menus opt > 327 opentyrian – arcade-like DOS shoot- streaming.
and items and B to go back. Press Start to open the ’em-up Tyrian 2.1 is now freeware.
main menu and Select to open the options menu.
Press the same button again to close each of these. exp > 241 lr-mame – a more up-to-date
As you have yet to put any games on the system, version of MAME that supports a wider range of
only the RetroPie menu will be available. Here, ROMs. Install from source for bleeding edge.
you’ll find easy access links to configuration
tools, including some we used earlier. Install exp > 307 digger – a sanctioned remaster of
new emulators and drivers from the RetroPie Windmill Software’s Dig-Dug.
Setup menu.
You’ll probably need to disable overscan to get exp > 334 steamlink – this allows you to stream
rid of a black border around the screen. In the less emulation-friendly titles directly from a
ReotroPie menu, select Raspi-config > Display Steam installation on a Windows or Linux PC.
options > Underscan > No and then reboot to solve
the problem. Note that button B is mapped to the
ENTER key in this set of menus.
Configure your emulator
When you add any new games, ROMs or
emulators, you’ll have to restart EmulationStation
09 Once you’ve installed a new emulator, such
by pressing Select, going to Quit, and then as lr-mame, you’ll have to configure the libretro
Restart EmulationStation. back end to use it by default for either all games
or selected titles. The easiest way to do this is
to browse to the game you want to play in the
EmulationStation front end.
Install more emulators
08 Although this is an arcade machine,
Go to the Arcade menu, press B to start any
game – it doesn’t matter if it currently works or
you can play what you like on it. The core not – and then press B again when you’re briefly
lr‑mame2003 and lr-fbneo emulators are prompted to ‘press a button to configure’. Select
included, along with those for popular consoles option 1 to set the default emulator for arcade
R
etroPie is
significantly more
configurable than
Recalbox, although its
interface doesn’t look
quite as slick
games and choose lr-mame. Option 2 allows you an Xbox or Steam Controller, which swaps the
Top Tip to select a different emulator for anything that
doesn’t work well with this.
position of the B and A buttons.
To set these, launch Steam Link, press up to
A screw loose highlight the gear icon, press A (per our button
assignment diagram), go right to highlight
If the ball on your Controller and press A. Select the controller you
Connect Steam Link
joystick is loose,
use a screwdriver 10 Linking Steam to your arcade cabinet lets
wish to configure, then press down and right
twice, and select Setup Controller.
in the slot on the
you stream a wealth of modern and classic arcade Hit the button you want to associate with each
underside of the
games to Raspberry Pi from a more powerful PC, Steam Controller-style button as it’s displayed
stick or cloth-
wrapped pliers to like Melty Blood, Guilty Gear, Horizon Chase Turbo, on screen. Use a keyboard or your second set of
hold the shaft still and Street Fighter V. After you’ve installed it and controls to use the skip button at the bottom to
while you tighten restarted EmulationStation, go to the Ports menu bypass extraneous buttons.
the ball. and select Steam Link.
It’ll download updates – you will need a keyboard
plugged in to approve these – and then run.
Why use Steam Link?
Make sure Steam is running on a PC on your local
network and that Enable Remote Play is ticked
12 Steam Link is an invaluable tool for arcade
under Settings > Remote Play. emulation enthusiasts, not only because you can
On the arcade machine, select the computer you play more CPU-intensive games, but also because
want to link to. Steam Link will show a code. Enter it’s the best way of ensuring copyright compliance
this in your PC’s Steam client when prompted. To for a number of re-released arcade games.
avoid a resolution mismatch, run Steam with a We’ve been playing Ghouls ’N Ghosts from the
monitor that matches the resolution of your arcade Capcom Arcade Stadium on our cabinet via Steam
machine set as your primary display. Link. Unlike some SNK and Sega re-releases,
Capcom doesn’t supply emulator-ready ROM files
and the EULA for that compilation doesn’t allow
you to extract its PAK files.
Configure Steam Link
11 You may want to reconfigure your controls,
Neil Brown of decoded.legal opines (magpi.cc/
romextractionlegal) that “when even a legitimate
as Steam Link doesn’t inherit the control layout Steam purchaser extracts the ROMs and runs them
from RetroPie’s EmulationStation, and some on their own Raspberry Pi, they infringe Capcom’s
games do better with alternative button copyright”, making streaming these titles your
assignments – for example, to more closely match best option for fully legal home arcade action.
Code
Configure
Analyze
cdpstudio.com
Tel: +47 990 80 900 • [email protected]
CDP Technologies AS // Hundsværgata 8, 6008 Ålesund, Norway
TUTORIAL
Emoji Match
Create a fun picture-matching game
Y
ou are going to build an emoji picture- import os
matching game (Figure 1). The object of from random import shuffle
the game is to spot the one emoji that
appears in two different sets. You get a point Then, under variables, enter this code which
for each correct match and lose a point for an creates a shuffled list of emojis, each in the form
Laura Sach
MAKER
O’Hanlon Figure 1 Next, the code needs to create two 3×3 grids of
Picture and PushButton widgets which will show
Martin works in the emojis.
the learning team Modify your program to create a guizero app and
at the Raspberry
Pi Foundation, a Box to hold the picture widgets using a "grid"
where he creates layout. In the imports section, add this line to
online courses, import the required widgets:
projects, and
learning resources.
from guizero import App, Box
@martinohanlon
In the app section, add the following code:
Figure 2
emoji2.py
> Language: Python 3
001. # ------------------------------
002. # Imports
003. # ------------------------------
004.
005. import os
006. from random import shuffle, randint
007. from guizero import App, Box, Picture, PushButton
008.
009. # ------------------------------
010. # Variables
011. # ------------------------------
012.
013. # set the path to the emoji folder on your computer Figure 2 No matching emojis
014. emojis_dir = "emojis"
015. emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir)]
016. shuffle(emojis) button = PushButton(buttons_box,
017. grid=[x,y])
018. # ------------------------------ buttons.append(button)
019. # Functions
020. # ------------------------------
021. In the functions section, create a function to set up
022. def setup_round(): each round of the game.
023. for picture in pictures:
024. picture.image = emojis.pop() def setup_round():
025.
for picture in pictures:
026. for button in buttons:
027. button.image = emojis.pop() picture.image = emojis.pop()
028.
029. matched_emoji = emojis.pop() for button in buttons:
030.
button.image = emojis.pop()
031. random_picture = randint(0,8)
032. pictures[random_picture].image = matched_emoji
033. To assign each picture and button widget an emoji,
034. random_button = randint(0,8) the image property is set to an item from the emojis
035. buttons[random_button].image = matched_emoji list. Emojis are selected using pop(), which chooses
036.
the last item in a list and then removes it from the
037. # ------------------------------
038. # App list. We’ve used this function because it will prevent
039. # ------------------------------ any emoji appearing in the game more than once.
040. At the bottom of your program, call the
041. app = App("emoji match")
setup_round function and display the app.
042.
043. pictures_box = Box(app, layout="grid")
044. buttons_box = Box(app, layout="grid") setup_round()
045.
046. pictures = [] app.display()
047. buttons = []
048.
049. for x in range(0,3): Your program should now resemble emoji1.py (see
050. for y in range(0,3): previous page). Test it and you should see two grids
051. picture = Picture(pictures_box, grid=[x,y]) of nine emojis.
052. pictures.append(picture)
053.
054. button = PushButton(buttons_box, grid=[x,y]) Matching emojis
055. buttons.append(button) At the moment, all of the emojis in your app will
056. be different (Figure 2). In the next step, you will
057. setup_round() pick another emoji to match, and update one
058.
picture and one button so they have the same
059. app.display()
matching emoji.
emoji3.py
> Language: Python 3
Add randint to your random import line. This Your code should now look like emoji2.py. Run
is used to obtain a number from 0 to 8 for each your program now; one of the emojis should
picture and button. match. Look carefully – the matching emoji can be
hard to spot.
from random import shuffle, randint
Check the guess
Then add this code (indented) to the bottom of Each time one of the PushButtons is pressed, it will
the setup_round function to pop another emoji need to check if this is the matching emoji and put
from the list and set it to be the image of a random the result ‘correct’ or ‘incorrect’ on the screen.
picture and button. After the player’s guess, a new round will be set up
and different set of emojis displayed.
matched_emoji = emojis.pop() Your app will need a Text widget display the
result. Add it to your imports:
random_picture = randint(0,8)
pictures[random_picture].image = matched_ from guizero import App, Box, Picture,
emoji PushButton, Text
emoji4.py
> Language: Python 3
Figure 3
Using other images
The emoji match game uses picture buttons to allow
the user to pick which emoji matches. You can make
any PushButton widget into a picture button by
setting the image parameter; for example:
You can find out more about image support in score = Text(app, text="0")
guizero at lawsie.github.io/guizero/images. timer = Text(app, text="30")
09-emoji-match.py
> Language: Python 3
def reduce_time(): When the timer is less than 0, the message ‘game
timer.value = int(timer.value) - 1 over’ is displayed and the game's widgets are
# is it game over? hidden so the user can no longer play.
if int(timer.value) < 0: See emoji4.py to get an idea of how your code
result.value = "Game over! Score = should now look. Run it and play the emoji match
" + score.value game. Challenge a friend or family member to
# hide the game a game.
pictures_box.hide() You may want to put the score and timer
buttons_box.hide() widgets into a Box so they can be laid out better
timer.hide() (Figure 3, previous page) – see the complete
score.hide() 09-emoji-match.py listing for how to do this.
G
ames controllers – like keyboards games and take a look at the available input devices
– are very personal things. What and build what you want.
works for one person may not work The first setup we’re creating is an Arcade box.
for another. Why, then, should we This author would really like an arcade machine in
all use almost identical off-the-shelf his house. However, space limitations mean that this
controllers? Let’s take a look at how isn’t going to be possible in the near future. The first
Ben Everard to use Raspberry Pi Pico to create a controller that’s setup, then, is an attempt to recreate the control
just right for you. setup of an arcade machine, but use it to play games
@ben_everard We’ll use CircuitPython for this as it has excellent on a laptop rather than a full-sized cabinet.
support for USB interfaces. The sort of USB devices Arcade controls are quite standard, and you can
Ben's house is slowly that we interact with are called human interface get them from a range of sources. We used one
being taken over by 3D
printers. He plans to devices (HIDs), and there are standard protocols for of Pimoroni’s Arcade Parts sets, which includes a
solve this by printing an common HIDs, including keyboards and mice. This joystick and ten buttons (we only used four of these).
extension, once he gets
enough printers.
is why, for example, you can plug almost any USB The important thing about the joystick you pick is that
keyboard into almost any computer and it will just it’s a button-based joystick and not an analogue one
work, with no need to install drivers. (sometimes called a dual-axis joystick), as the latter
We’ll be using the Keyboard type, as that works won’t work with a keyboard interface. If you want
best with the sorts of games that this author likes to to use an analogue joystick, you’ll need to switch
play, but you can use exactly the same technique to the code around to use a mouse or gamepad as an
simulate a mouse or a gamepad. input device.
Before we get onto this, though, let’s take a look at As well as the electronics, you’ll need some way of
the buttons and how to wire them up. mounting them. We used a wooden craft box. These
We’re going to use eight buttons: four for direction, are available for about £10 from a range of online or
and four as additional ‘action’ buttons. We’ll connect bricks and mortar stores. You can use anything that is
these between an I/O pin and ground. You can use strong enough to hold the components.
any I/O pin you like. We’re going to use slightly The second setup we’re using is a much simpler
different ones in two different setups, just because button-based system on breadboard-compatible
they made sense with the physical layout of the tactile buttons and protoboard. It’s smaller, cheaper,
hardware. Let’s take a look at the hardware we’re and quicker to put together. The protoboard holds
using. Remember, this is just the hardware we want everything together, so there’s nothing extra to
to use. The whole idea of this is to create a setup add unless you want to. You can personalise it by
that’s right for you, so there’s no need to use the selecting different-sized buttons, changing the layout,
same. Think about how you want to interact with your or building a larger chassis around this.
”
Instead, we drilled a 20 mm hole and then used a Gaming like it’s 1989
”
down, left, and right
Above
You can solder the
pin headers straight
turning everything into shards of broken wood. Four
small holes then allow bolts to keep the joystick in
place (we used M5 bolts). The buttons just push
” We placed the buttons in
the protoboard in positions
onto Pico into place. we liked before worrying
”
Right The only remaining thing was a 12 mm hole for a
A little games micro USB cable to pass through to Pico. If you don’t about the wiring
controller that you can
fit in your pocket have a 12 mm drill bit, two overlapping smaller holes
may work if you’re careful.
The buttons just push-fit into place, and that’s the protoboard and use the leg to join. Other times
everything ready to go. you’ll have to surface-mount it. This all sounds a bit
complicated, but while it can be a bit fiddly, it’s all
A SMALLER APPROACH fairly straightforward once you put solder to iron.
Our smaller option used protoboard over the back of
Pico. Since we didn’t want to block the BOOTSEL PROGRAM IT UP
Warning! button, we only soldered it over part of Pico. Now that we’ve got the hardware ready, let’s code
Soldering iron However, before soldering it on at all, we soldered the it up. You’ll first need to load CircuitPython onto
buttons in place. your Pico. You can download the latest release from
Be careful when using
a hot soldering iron Tactile switches typically have four connections. circuitpython.org. Press the BOOTSEL button as
and read Raspberry Well, really they have two connections, but each you plug Pico into your USB port, and then drag and
Pi’s Getting started with
soldering guide. connection has two tabs that fit into the protoboard. drop the downloaded UF2 file onto the RP2 USB drive
This means that you have to orientate them correctly. that should appear.
magpi.cc/soldering
Again, your multimeter’s continuity function will
confirm which pins are connected and which
are switched.
Protoboard is a PCB that contains lots and lots of
holes and nothing else. You solder your components
into the holes and then you have to create
connections between them.
We placed the buttons in the protoboard in
positions we liked before worrying about the
wiring. First, we looked to connect one side of each
switch to ground. To minimise the wiring, we did
this in two groups. We connected one side of each
of the direction buttons together and then linked
them to ground. Then we did the same to all the
action buttons.
There are two ways of connecting things on
protoboard. One is to use jumper wire. This works
kbd = Keyboard(usb_hid.devices)
digitalio.DigitalInOut(board.GP14), GamePad object.
digitalio.DigitalInOut(board.GP9), The while loop may look a little unusual as it’s
digitalio.DigitalInOut(board.GP15), not particularly common to use this sort of binary
digitalio.DigitalInOut(board.GP16), comparison in Python code, but in essence, it’s just
digitalio.DigitalInOut(board.GP17), looking at one bit at a time and seeing either: it’s now
digitalio.DigitalInOut(board.GP18), pressed but wasn’t last time the loop ran (in which
digitalio.DigitalInOut(board.GP20), case, it’s a new button press and we should send it to
) the computer), or it isn’t pressed this loop but was the
last_pressed = 0 previous loop (in which case, it’s newly released so we
while True: can call the release method).
this_pressed = pad.get_pressed() The << operator shifts a value by a number of
if (this_pressed != last_pressed): bits to the left. So, 1<<2 is 100, and 1<<3 is 1000.
for i in range(8): The & operator is bitwise and so it looks at a binary
if (this_pressed & 1<<i) and not number and does a logical AND on each bit in turn.
(last_pressed & 1<<i): Since the right-hand side of the & is all zeros apart
kbd.press(keycodes[i]) from one bit (at a different position depending on the
if (last_pressed & 1<<i) and not value of i), the result will be dependent on whether
(this_pressed & 1<<i): the value of this_pressed or last_pressed is 1 or 0 at
kbd.release(keycodes[i]) the position i. When you have an if condition that’s
last_pressed = this_pressed a number, it’s true if the number is anything other
time.sleep(0.01) than 0. So, (this_pressed & 1<<2) will evaluate to
true if there’s a 1 at position 2 in the binary form of
This uses the HID keyboard object (called kbd) to this_pressed. In our case, that means if the joystick is
send key press and release events for different key pushed left.
codes depending on what buttons are pressed or You can grab this code from the following link –
released. We’ve used the gamepad module that hsmag.cc/USBKeyboard. Obviously, you will need to
is for keeping track of up to eight buttons. When update the GPIO values to the correct ones for your
you initialise it, it will automatically add pull-up setup when you initialise GamePad.
resistors and set the I/O pins to input. Then, it will We’ve taken a look at two ways to build a gamepad,
keep track of what buttons are pressed. When but it’s up to you how you want to design yours.
Raspberry Pi Pico
data logger
Turn Raspberry Pi Pico into a temperature data-logging device
and untether it from the computer to make it fully portable
T
hroughout our Raspberry Pi Pico tutorials, for writing – the "w" part of the instruction. You
you’ve been using your Pico connected to a won’t see anything print to the Shell area when
Raspberry Pi or other computer via its micro you press ENTER at the end of the line, because
USB port. Like all microcontrollers, though, there’s although you’ve opened the file, you haven’t done
no reason your Pico has to be tethered in this way: anything with it yet. Type:
it’s a fully functional self-contained system, with
processing capabilities, memory, and everything it file.write("Hello, File!")
needs to work on its own.
Gareth
MAKER
In this guide you’ll learn how to use the file When you press ENTER at the end of this line,
Halfacree
system to create, write to, and read from files, you’ll see the number 12 appear (Figure 1). That’s
With a passion allowing you to put your Pico anywhere you like MicroPython confirming to you that it has written
for open-source and have it record data for later access – turning it 12 bytes to the file you opened. Count the number of
software and into what is known as a data logger. For this you’ll characters in the message you wrote: including the
hardware, Gareth
was an early adopter only need your Pico and, if you want to use it away letters, comma, space, and exclamation mark, there
of the Raspberry from your Raspberry Pi, a micro USB charger or are twelve – each of which takes up a single byte.
Pi platform and battery pack; once you have finished the tutorial, When you’ve written to a file, you need to
has written several
you can connect additional analogue sensors if close it – this ensures that the data you’ve told
publications on
its capabilities you want to expand your project. MicroPython to write is actually written to the
and flexibility. file system. If you don’t close the file, the data
@ghalfacree The file system might not have been written yet – a bit like writing
The file system is where your Pico stores all the a letter in LibreOffice Writer or another word
programs you’ve been writing. It’s equivalent in processor and forgetting to save it. Type:
function to the microSD card in your Raspberry
Pi, or the hard drive or solid-state drive in your file.close()
Your file is now safely stored on your Pico’s file from your Pico’s on-board temperature sensor. The
system. Click the Open icon on Thonny’s toolbar, readings from the sensor are the data you’re going You’ll Need
click ‘Raspberry Pi Pico’, and scroll through the list to be logging to the file system, so you don’t want to
> Raspberry Pi Pico
of files until you find test.txt. Click on it, then click simply print them out as you did before.
OK to open it: you’ll see your message pop up in a Start by opening a file for writing by adding the > Battery Pack
(optional)
new Thonny tab. following line at the bottom:
You don’t have to use the Open icon to
read files, though: you can do it directly in file = open("temps.txt", "w")
MicroPython itself. Click back into the bottom of
the Shell area and type: If the file doesn’t already exist on the file system,
this creates it; if it does, it overwrites it – emptying
file = open("test.txt") its contents ready for you to write new data.
Now you need to write something to the file – the
You’ll notice that this time around there’s no "w": reading from the temperature sensor:
that’s because instead of writing to the file, you’re
going to be reading it. You could replace the "w" file.write(str(temperature))
with an "r", but MicroPython defaults to opening a
file in read mode – so it’s fine to simply leave that Rather than writing a fixed string in quotes, as you
part of the instruction off. did before, this time you’re converting the variable
Next, type: temperature – which is a floating-point number, Warning!
in other words one with a decimal point in it – to a
Opening a file for
file.read() string, then writing that to the file. writing in MicroPython
As before, to make sure the data is written you will delete anything
you’ve already stored
You’ll see the message you wrote to the file print to need to close the file: in it. Always make sure
the Shell area (Figure 2). Congratulations: you can you’ve opened the file
for reading and saved
read and write files on your Pico’s file system!
Before you finish, remember to close the file –
ow write something to
N the contents somewhere
if you want to keep it!
file.close()
Figure 2
Logging temperatures
Now you know how to open, write to, and read
from files, you have everything you need to build a
data logger on your Pico. Click the New icon to start
a new program in Thonny, and start your program
by typing:
import machine
import utime
sensor_temp = machine.ADC(machine.ADC.
CORE_TEMP)
Figure 3 file.close()
file = open("temps.txt")
file.read()
file.close()
file = open("temps.txt")
file.read()
Figure 3 Your Figure 4 All the file.close()
file records the measurements
temperature at the are there, but the
time the measurement formatting makes it Notice how there’s still only one reading in the
was taken difficult to read file. When your program opened the file for writing
again, it automatically wiped its previous contents
Figure 4 – meaning that each time your program runs, it
will wipe the file and store a single reading.
To fix that, you need to modify your program.
Start by clicking and dragging your mouse cursor
to highlight the lines:
Figure 2 How a
potentiometer works
reading = sensor_temp.read_u16() *
conversion_factor
temperature = 27 - (reading -
0.706)/0.001721
utime.sleep(10)
import machine
import utime
sensor_temp = machine.ADC(machine.ADC.
CORE_TEMP)
file = open("temps.txt")
Figure 6 print(file.read())
file.close()
Isomorphic
Part 01
O
The enclosure
ne alternative layout to a conventional
piano keyboard is an isomorphic
02 We came up with the concept of a two-layer
keyboard. Here, the notes are laid out so box – this is shown in Figure 1. The top surface
that adjacent keys differ by only a semitone. It is where the keys are. They are cut out and press
is said that such a keyboard is easier to learn to down on the tack switches underneath. To stop
Mike Cook
MAKER
play in any key. This month, we show you how them falling out when the box is turned upside
to make a USB interfaced MIDI keyboard with an down, each key has an oversize version of itself
Veteran magazine
author from the old isomorphic layout. glued to it. The tack switches are mounted on
days, writer of the a large piece of stripboard, supported by 3 mm
Body Build series, spacers screwed to the middle level. Underneath
plus co-author of
Raspberry Pi for this is a Raspberry Pi Pico board, supported on five
Isomorphic keyboards
Dummies, Raspberry
Pi Projects, and 01 While the principle of adjacent keys
30 mm pillars between the base and middle level.
Raspberry Pi Projects
differing only by a semitone is simple enough,
for Dummies.
there is considerable variety in exactly how they
magpi.cc/mikecook
Scan the Matrix
are laid out. The arrangement of keys can be on a
square grid, or an offset grid; the keys themselves
03 A scanning switch matrix is a way of reading
can be square, round, or, our favourite, hexagonal. a lot of switches from a few inputs/outputs. Figure 2
There are a number of different layouts that shows the schematic of a small 3×4 matrix. There
detail exactly what keys are where; these have are many variations on this, but we have chosen
names like Gerhard, Park, Maupin, Wicki-Hayden, to use a column drive with a row input. A walking
Harmonic, Janko, C-system, and B-system. We zero signal is applied to the columns, and pressing
You’ll Need are going to use the Harmonic type that was used a key connects a column to an input. As you know
by the now defunct C-Thru Music company. what column was low when an input was low, you
> Stripboard
magpi.cc/
stripboard Figure 1
> 102 tack switches
4‑pin 6×6×5 mm
magpi.cc/
tackswitch
> Hex Keys CAD
diagrams
magpi.cc/
pibakery
> Access to
laser cutter
Painting
know what key was pressed. We will be making a 15
column by 7 row matrix for this project.
06 We have come up with a new way to paint Top Tip
plywood boxes that doesn’t show brush marks, by
using a half-inch foam brush and normal emulsion Box assembly
paint. This allows us to use paint from the wide
The laser files We marked the
04 We have started using the software
range of match-pot colours, and gives a nice flat
finish. To keep things clean from finger marks, we
sides and middle
layer of the inside
LightBurn to produce our laser cutter artwork, add three coats of a water-based clear matt varnish. of the box so
and all the files can be found on our GitHub page. We used yellow for the top and base, and matt black that we always
If you use another system, then you can get a full for the sides and visible edges of the box. assembled it
version of this software on a 30-day free trial to consistently.
use or convert the files. Alternatively, we have also
supplied SVG files for each sheet you have to cut.
Painting the keys
The top panel also includes vector engraving on the
keys – this has to be done first at a lower setting so
07 Figure 5 shows the colours we used to paint
as not to burn all the way through. the keys. They keys can be painted any colours
you like, but keep the groups consistent for the
Figure 2
Enclosure construction
05 Figure 3 shows the construction of the two- Figure 2 A 3×4
layer box. Note how the side with only a 1.5 mm tab switch matrix
Figure 3
Figure 3 The
The stripboard
assembled double box Figure 4 08 We need a piece of stripboard 101 holes long
by 58 strips high. Unfortunately, we couldn’t find
one, so we had to make one out of three pieces of
board. Fortunately, this could be done by buying
just one 119 by 455 mm sheet of stripboard. The
maximum height of this board is 46 strips, so we
Figure 4 Reinforcing cut out a 101 hole by 46 strip high main piece, a 71
the corners of the
two rings formed hole by 12 strip, and a 30 hole by 12 strip piece. We
from the sides
also got a 58 hole by 8 strip piece for the triangular
control button board from the same piece of
stripboard. See our GitHub page for more notes
about joining these together.
The Matrix 2
10 Make sure the tack switches are flat to the
board when you solder them. They have a habit of
pushing themselves out once the board is turned
over for soldering. To make sure they are OK, solder
Figure 7
The Matrix 3
11 The long tracks of tinned copper wire with
a black dot on them denote a joint where one wire
enters the hole and another leaves it. Here, push
all the wires in place before soldering them. We
found this easier if these holes were enlarged
slightly with a 1.2 mm drill. When fitting the keys, one or two securing holes were turned round so Figure 7 Use
masking tape to stop
turn the top over and insert from the back; we that a screw pushed up on the board, correcting the keys falling out
numbered the columns and rows on the board and the warping. We used a 20 cm pan-head M3 when fitting the top
to the switches
wrote the column and row number, along with its screw with a 3 mm spacing and three 0.5 mm
name, on the back of each key. We then placed a solder tags on the underside of the board –
Figure 6 Physical
blank board over the top and inverted it. Finally, see Figure 8. The solder tags allowed for fine wiring of a third of
we attached each key to the top with masking tape adjustment, making the switch tops flush with the switch matrix
so they would not drop out when we fitted the top the board. We had to cut away at the oversize
– see Figure 7. key mount on surrounding keys to ensure the
push-up screw was not fouled.
T
he UK computer games industry has grown
and grown since its origin in the eighties;
grown so much that it’s on a par with the
UK film industry. This trend is true in many other
areas of the world. If you are learning how to write
games, then Raspberry Pi is a great way to get your
teeth into the subject. There are many ways to write
Mark Vanstone
games and get started quickly.
MAKER
Educational games If you are just starting out and not ready for text-
author from the based coding, don’t worry. There are block-based
1990s, author of the
ArcVenture series, systems like Scratch where you can lay out your
disappeared into the game graphics on the screen. You can code games
corporate software using blocks that you drag and drop into place to
wasteland. Rescued
create your program. Once you have mastered that,
by Raspberry Pi!
you may want to move on to text-based coding like
magpi.cc/
Python and Pygame. If you aim to start a career in
technovisual
the games industry, you will find that these days
game designers use both methods: visual block
editing and text-based programming. One of the
most popular game engines, Unreal Engine uses a
block editor called Blueprint that is underpinned by
libraries of C++ code.
Game programming is a great way to learn a
wide range of techniques that are useful for other
areas of programming. You don’t need to start
with advanced scripting but can easily get quick
results with the tools in this article. Let’s make
some games!
S
cratch is a block-based visual editing install of Raspberry Pi OS to your system card
SCRATCH PROJECTS and if you find one you like, you can see how they
did it by selecting the ‘See inside’ button at the
Go to the projects section of Raspberry Pi’s website, top-right corner.
magpi.cc/projects. In the ‘Find a Project’ section,
select Games from the Topic drop-down, and
The costume editor allows
Scratch from the Software drop-down. You will be you to edit and design
shown a selection of game projects for Scratch. graphics for your games
Each of these projects is laid out as a step-by-
step tutorial to help you build the game. There are
lots of different game projects available, so you
shouldn’t run out!
O
More than zero
ne of the best ways to get started with text-
02
Top Tip based programming on your Raspberry Pi
is to jump straight into Pygame or Pygame
Let’s get a graphic moving on the screen.
You will need to find a suitable image to use,
Zero. These are both available with the Python perhaps a spaceship or little green man. Have
Mix and Match programming language and all three are already a look at the ‘Graphics Resources’ section near
installed by default with Raspberry Pi OS. If you are the end of this feature about where to find
Even if you start
not familiar with Python, you can get it running graphics. A PNG is best; you can find our rocket
your program with
Pygame Zero, if you
from the Programming menu by selecting the at magpi.cc/rocketart. Now make a subdirectory
need a function Thonny Python IDE. This will open up an editor to in the same place as you saved your Python file
from Pygame you use Python 3. Python is easy -to learn and read, and and call it images and put your graphic file inside
can include parts this article will show you how to use it with Pygame that directory. Now load that graphic into an
of the Pygame and Pygame Zero. Actor object in your code. Name your graphic file
module too!
rocket.png (you must keep to lower-case letters)
and load it by typing myrocket = Actor('rocket',
center=(400, 500)).
First Pygame Zero
01 Pygame Zero was designed to require as
little code as possible to get a game running. If you
Seeing the rocket
launch the Thonny Editor (IDE) and type import
pgzrun to load the Pygame Zero module and then
03 Now to get our rocket to display on the
after that, write pgzrun.go() to start the game, you screen, we need to add some code to draw it. We do
can then save the file and run it (with the green this with a draw() function, so type def draw(): and
play button). If you have typed the code correctly, press RETURN, then type myrocket.draw(). Then, to
you will see a black window appear titled ‘Pygame make the rocket move up the screen, we need to add
Zero Game’. You have written your first Pygame an update() function by typing def update(): and
Zero game! It’s not a great game yet but that’s all underneath type myrocket.y -=1. If we save and run
you need to get the game engine running. this program, we should see the rocket moving up
Lots of Pygame game
the screen. If you don’t, check the rocket.py code developers share their
to see what you have done differently. It may have creations online like this
game called Dynamite
some drawing left behind, so add screen.clear() at
the beginning of the draw() function. If all is well,
you have the start of your Pygame Zero game.
ROCKET.PY
Language: Python
PGTEST.PY Top Tip
import pgzrun
Language: Python
myrocket = Actor('rocket', center=(400, 500)) Watch your
import pygame
naming
def draw(): pygame.init()
When you save
screen.clear() your code, don’t
myrocket.draw() screen = pygame.display.set_mode([400, 400]) call it ‘pygame’
running = True or Python will
def update(): think that you are
referring to the
myrocket.y -= 1 while running:
pygame module.
# Get events from the user
pgzrun.go() for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the screen
screen.fill((0, 0, 0))
Moving on to Pygame
04 Pygame Zero makes it very quick and easy to
# Draw a red circle at 200,200 with
radius of 50
get games working on your Raspberry Pi, but if you pygame.draw.circle(screen, (255, 0, 0),
want more flexibility you may find that Pygame is (200, 200), 50)
what you require. You will need to write a bit more # Switch from buffered screen to visible
code, but you will be able to access some functions pygame.display.flip()
like using game controllers. To start a Pygame
WHERE TO
GET IDEAS
program, you will need to import the pygame module # Quit the program
using import pygame and then after that, make a call pygame.quit()
to pygame.init(). This starts the game engine off, Did you know that
but we won’t see anything happen if we run it. The MagPi’s sister
magazine, Wireframe,
features a section
Taking it further called Source Code
AppGameKit includes
a full code editor to
develop and run games
A
Get the download
ppGameKit provides a cross-platform
01
Top Tip development system that was originally
for PC desktops, but recently it has become
First, we need to get the AppGameKit files.
You’ll need to go to the website appgamekit.com
available to download free for Raspberry Pi. You and sign up for an account. When that’s done, go
GPIO pins can use the same system on other platforms too, to the ‘AppGameKit For Raspberry Pi’ section in
and develop on one system to run on a different the ‘Classic’ menu item and download the editor
If you are feeling
adventurous, you one. You can even publish your games and earn files (they are free). Double-click the gzip file to
could try out the money without paying any royalties. The engine open it and extract the files to somewhere suitable
AGK features that has many tools to help you build your game, like 2D like your home directory. When it’s unpacked,
allow you to read sprites, 3D, physics, sound, and even virtual reality. you will see a directory called AGKPi. Inside that,
and write to and This guide will get you started with AppGameKit so you will find the AGK launcher. Double-click to
from the GPIO pins.
that you can explore all the features. open the editor. If you want to see an error log
when it’s running, select ‘Execute in Terminal’
Compatibility alert when prompted.
Until recently, AppGameKit was compatible
with all Raspberry Pi computers, but at the
time of writing, it is difficult to get running on
Doing the update
Raspberry Pi 4. Some system updates are needed
for other Raspberry Pi computers, even with the
02 If you try to run any of the samples
latest version of Raspberry Pi OS. Make sure you provided with AGK, you may find that you get
have backed up any data from your Raspberry Pi some errors. This may only be an issue at the time
microSD card before you start. of writing as there are regular updates available.
With the AppGameKit
From a Terminal window, enter sudo apt update, samples, you can quickly
followed by sudo apt upgrade, just to make sure see how to build many
types of games
we have everything up to date. Then, if you are
getting errors about libgles2 (graphics library),
type sudo apt install libgles2-mesa libsdl2-
dev, which will install the necessary libraries.
Then enter sudo rpi-update – this is a firmware
update, so a bit more extreme than the usual
updates, and the reason why you should make a Top Tip
backup of your memory card before issuing this
command. Now reboot your Raspberry Pi. Raspberry Pi 4
a listing of the base code you need to start your
game. Run it and you will see a black window open Feeling brave and
want to run AGK
with the title ‘test’.
on a Raspberry
Load a sample
03 A good sample to start with, to make
Pi 4? Check out
the forum post at:
sure everything is working, is the Space Shooter magpi.cc/agkpi4
The sky’s the limit
game. Select the Open icon on the toolbar of the
editor and then navigate to the SpaceShooter
06 Have a look through the samples to see the
for instructions.
directory, which is found in the Games folder range of what AGK can do. You will find a huge
inside Projects. Open the .agk file and you will range of tutorials at magpi.cc/agkyt and there is
see several files open in the editor. AGK uses a a full user guide at magpi.cc/agkguide. There is
language very much like BASIC, so if you have also an active and helpful community forum at
You’ll Need
used BASIC before you should be right at home. If magpi.cc/agkforum where you will find more hints AppGameKit:
you haven’t learnt BASIC, then it’s quite easy as it and tips to help you on your way. If you are having a appgamekit.com
was designed for beginners. problem with something, you’ll find someone who Raspberry Pi SDK:
has solved it and will tell you how. Don’t be afraid to appgamekit.com/
get stuck in and just start coding: the compiler will agk-pi
give you feedback on anything you get wrong.
Run the game
04 If everything has gone well with the install
and updates, when you press the green Run arrow
you should see a window open up titled AGK and a GRAPHICS RESOURCES
Start Game screen with spaceships floating about. If
you don’t see that, then check the Terminal window There are many graphics resources that are free to download. You can get
images, animations and programs. Here are a few places to visit:
that launched the editor to see if there are any
errors. You may see some warnings there anyway opengameart.org has a wide range of artwork for backgrounds and character
as some of the shader modes are not supported on images to include in your games free of charge.
Raspberry Pi, but the game should work fine. Start
the game by clicking the screen and move the player s● priters-resource.com specialises in sprites, which are the characters to include
ship up and down with cursor keys. in games. They are often available in sprite sheets which have all the frames in
one image file.
f● ree3d.com has many free (and paid-for) 3D models for you to download and
use. There are models for just about any situation, some of them specifically
Make your program
05 Now you have the editor building a game,
designed for games.
why not start your own? Start a new project by gimp.org is a great image manipulation program and should be all you need for
clicking the New icon on the toolbar. You will be creating 2D graphics for your games. It can be installed using sudo apt install
gimp in a Terminal window.
asked for a name for the new project and a base
path. Select the folder icon to the right of the blender.org is best for creating a game with 3D graphics. Install Blender free
base path input box, and navigate to somewhere from your Terminal with sudo apt install blender. Discover a range of
suitable inside your home directory. Select Create Blender projects on Raspberry Pi’s website (magpi.cc/blenderprojects).
and you will see a new file called main.agc open
in the editor. In that file, there will already be
R
en’Py is open-source and free to download and extract it to a suitable place such as your
Top Tip and use. You can even share your creations
without paying a penny in royalties or
home directory. You will also need to download
and extract Raspberry Pi support files from the
licences. Ren’Py includes a simple scripting Additional Downloads section. Once this is all in
Embed Python language to control the flow of your story and add place, you will find a file in the directory you have
Ren’Py scripting
interactivity to the pages. The engine also includes a extracted called renpy.sh. Double-click this file
is quite similar to wide selection of animation and transition effects to and select ‘Execute’. After a few seconds, you will
Python, but if you bring your games and graphic novels to life without see the Ren’Py Launcher open.
need to embed a needing to learn complicated animation software
Python program and supports the most common graphics and sound
inside your Ren’Py
formats like JPG, PNG, MP3, and a whole lot more.
game, you can do
Tutorial time
that too. 02 Ren’Py includes a getting started tutorial,
which is probably the best place to begin. By
Get the files
01 First, download the install files from the
selecting the Tutorial project from the launcher,
you will be introduced to Ren’Py’s features by
Ren’Py website at renpy.org/latest.html. You will Eileen. She will show you how to start a new
need the .bz2 version for Raspberry Pi. When it project and the ways to set colours and screen
has downloaded, double-click to open the archive sizes. There are also sections in the tutorial to
cover adding your images, text, and sound to your the left of the window that opens. If you make
Ren’Py includes a tutorial
where Eileen talks you
pages. It then goes on to creating interactions and changes to your script, you can then press through all the features of
transitions to make your game engaging for your SHIFT+R to reload your script and start the game the system
audience. Have a look at the Choices and Python again. If you need further help, select the
section to see how scripting is used to ask Documentation link at the bottom left of the
questions and branch to different options. Launcher window, or check out the forums
at magpi.cc/renpyforum.
MOTORS: Build a range of robots with aluminium plates and reusable rivets,
2 × 12 V high-
torque geared then control them with Raspberry Pi and pi-top [4] DIY Edition case.
motors with
Hall effect This kit clicks with Lucy Hattersley
sensor
tachometers;
P
2 × modular
servo motors i-top [4] Robotics Kit is a long-awaited IP address and remaining battery level (we got
robot that complements the pi-top [4] around two hours of use). The kit tested comes
SENSORS: DIY Edition case. It promises to be a sturdy with an Expansion Plate that connects to the
HD 720p wide-
and versatile building platform, with competent bottom of the pi-top [4] DIY Edition case and
angle camera
module; 1 × software and good educational chops. breaks it out into several control ports.
ultrasonic And it delivers. Inside the box is a series of .
sensor aluminium plates and plastic rivets that act a Making robots
COMPONENTS: little like LEGO Bricks meet Meccano. Two rivet- Thanks to the rivet system, you can get creative
Chassis compatible servo motors and two encoder DC with your robots. Three designs are included:
interface motors, plus a webcam and ultrasonic distance Alex, a regular wheeled robot with a pan-tilt
plate; 25 mm sensor. Everything you need to build a wheeled mechanism for the camera and ultrasonic sensor;
Durable omni-
robot that can see and sense the world around it. Bobbie uses the servos to control two ping-pong
directional
castor wheel; ball grabbing pincers; Prax is angled in a vertical
2 × 74 mm A plan comes together position and the servos create a moving face for a
wheels with all- We reviewed the pi-top [4] DIY Edition desk-based interactive assistant. Instructions for
terrain tyres; (magpi.cc/pitop4review) back in The MagPi issue all three builds are available as a PDF download
50+ aluminium
plate
99 (magpi.cc/99). At the time, we were impressed from the pi-top Start website (pi-top.com/start)
construction with the build quality, but noted the oddity of the and it’s a good place to get an overview of how the
pieces; 200+ built-in battery and 128×64 OLED display. builds work.
nylon quick- Once clipped into the Expansion Plate on the
build rivets
robot, it all makes sense. The pi-top [4] case Going further
EXPANSION powers both Raspberry Pi and the motors in the Each build took us around an hour. When the build
PLATE: robot; the OLED display provides feedback on the is complete, you attach a pi-top [4] DIY Edition to
Accelerometer,
gyroscope, and The innovative rivet
system enables you to
magnetometer; connect aluminum plates
4 × 6P 12 V DC and build the robot
motor ports;
4 × 3P servo
motor ports; 2 ×
USB 2.0 ports;
camera (CSI)
and display
(DSI) ports;
8 × digital and
4 × analogue
sensor ports
80 magpi.cc
REVIEW
the Expansion Plate and insert the cables to connect default; along with baked-in support for the
the electronic parts to the Expansion Plate. hardware components.
Here is where pi-top [4]’s on-board battery and The Further website has demonstration code to
OLED display spring into useful action, providing follow, and you can SSH directly to your robot from
network information that you can use to quickly the Further website and run the interactive code The pi-top [4] DIY
SSH into the robot. examples directly from the web. Students can log Edition sits on top of the
chassis as the brains and
Pi-top has clearly put a lot of elbow- in separately and collaborate on code and practise battery of the robot
grease into its pi-topOS and its Further 2.0 programming techniques together. We enjoyed
system (magpi.cc/further). The pi-topOS the coding courses and challenges, and integration
ensures elements like SSH are enabled by with OpenCV for object and face recognition.
Moving beyond the Further educational port,
Verdict
you can code pi-top [4] Robotics Kit directly with Very high-quality
the pi-top Python SDK (magpi.cc/pitopsdk) and robotic education
there is support for ROS (magpi.cc/pitopros) and kit, with an
innovative rivet
Microsoft’s .NET (magpi.cc/pitopnet).
construction
There’s a lot here. First of all, the whole kit is
mechanism and
not particularly cheap if you include the price of well-thought-out
the pi-top [4] DIY Edition and a Raspberry Pi 4. It software. It’s been
is, however, superbly designed with a clever rivet worth the wait.
10
construction system and seamless integration with
pi-topOS and Further courses. All in all, pi-top [4]
/ 10
Robotics Kit is plain nice to use, and will sit neatly
into an education environment. Good job.
10 Amazing:
Wearable
Raspberry Pi Smart Watch
Wrist computer
projects
With screens getting smaller and smaller, discreet and wrist-bound Raspberry Pi
builds are easier than ever to do. This Smart Watch build is a very fun example.
magpi.cc/smartwatch
ocial media
S
Ways to wear your Raspberry Pi with pride without the
internet
A
s Raspberry Pi is so small and draws so little power,
it’s a perfect device for powering more complex Offline socialising
wearable projects. We’ve done cosplay stuff with it
This art piece made full use of
in the past, and here are some other incredible projects that
wearable tech by having interactive
let you wear your Raspberry Pi.
objects all over these coveralls.
This allowed for social media-style
interactions in real life.
magpi.cc/socialwear
Pip-Boy built
from scrap
Apocalyptic wrist computer
You can buy official Pip-Boy cases,
or 3D-print carefully crafted models.
However, the recycling nature of
this project makes it a firm favourite
of ours.
magpi.cc/pipboyscrap
magpi.cc/piglass magpi.cc/wearableprojects
magpi.cc/timelapsecam
Smart Cap
Cyber eye
RaspWristRadio This more conspicuous take on a
pair of smart glasses can be used
Portable FM on multiple types of headwear. It’s
also completely open.
We like the very 1980s movie kid inventor look of this DIY radio that fits on your
wrist. Don’t be rude, though: bring headphones to listen!
magpi.cc/smartcap
magpi.cc/raspwristradio
Project Glass
Wearable Cyberpunk Gesture Pad
Real-life subtitles
Hacker wear Real-time translation, while not 100% accurate, is quite
impressive. Using this AR-like Raspberry Pi glasses system, you
Need a wrist-mounted touchpad with multi-touch gestures? Then look no
can use it to try to talk to real people.
further than Zack’s cyberpunk-inspired gesture pad.
magpi.cc/gesturepad magpi.cc/projectglass
Rough
guides
Three websites that
Set up your extensions get you up and
running with Visual
Studio Code
Microsoft Once you’ve installed Visual to add support for languages,
AUTHOR
what you need to know can be into Visual Studio Code with an build a basic HTML document
Price: found in the extensive Visual online course, then there is one walks you through setting
£35/$50
Studio Code documentation and that everybody recommends: up development folders and
vscode.pro introductory video tutorials. Ahmad Awais’s video tutorials adding files.
called ‘VSCode Power’. magpi.cc/vscodecademy
Ahmad is an entertaining
course leader and the video HOW TO USE VISUAL
tutorials are engaging and fun. STUDIO CODE
The course covers everything Flavio Copes has written a
from the basics, and setting great introduction to Visual
up Visual Studio Code, Studio Code that works
through version control with through installation, setting up
GitHub and a professional fonts and workspaces.
extension setup. magpi.cc/flaviovscode
Zack Freedman
Zack loves wearables, and now makes them
full-time on YouTube, among other things
M
any people dream of away – people would spend more making videos about 3D printing
being a YouTuber or time online, substituting and DIY electronics, producing
online content creator streams for meetups and videos videos and streams to show
of some kind. Zack Freedman for talks. So, I started making different parts of the stuff-
basically stumbled into it. YouTube videos to promote making process.”
“I used to be a freelance myself, and people watched –
prototype developer in New York not many at first, but out of What is your history
City,” Zack tells us. “But when... nowhere, lots of people, way with making?
all the meetups and conferences more than I expected. The I tried and failed to build tech
[shutdown last year], the clients videos ended up doing better projects a number of times:
dried up. I knew that social than the prototyping contracts! websites as a kid, RC cars as a
interaction wouldn’t just go Now, I’m a full-time YouTuber, teen, a Nerf ammo counter in
college, and many more dead-
end ideas that my very generous
parents supported. I even got
into engineering school, only to
find that it was all math, and I
hate math. I’ve never been a
great student, even when I want
to learn the topic – I get
obsessed with something like all going pretty well until people of my earliest wearable The Data Blaster is a very
funky cyberdeck using
Nerf blasters and plunge started coughing a lot and computers and Eben signed a a Raspberry Pi 400. We
hundreds of hours into the rabbit pretending it wasn’t dangerous, Raspberry Pi for me. I put it in a like the sporty handles for
when you need to run
hole, but I just can’t force myself and here we are! frame. It’s one of my most
to systematically learn anything prized possessions.
soup to nuts. I was spinning my When did you first learn of
wheels and felt like a moron. Raspberry Pi? What was your first
Everything changed during an I’m by no means an early Raspberry Pi project?
internship in the summer of 2011 adopter, but a MakerBar member My first Raspberry Pi project was
– I was working for an app store was. He pre-ordered a huge pile a wearable computer built out of
startup (’twas a different world) of original Raspberry Pi before a Vuzix AV230, an original
and got assigned to write for the the first release, so I got in on Raspberry Pi, and a USB battery
company blog. At the time, the ground floor. [As] I was pack. It wasn’t the most useful
‘appcessories’ – gizmos designed obsessed with wearable device... still, it was an authentic
to pair with cell phones – were computers, Raspberry Pi was the fully functional wearable
the Silicon Valley hotness, and only pocket-sized device below computer, the kind that took
my research brought me to $500 that output 480p composite MIT geniuses years of work and
Hackaday, where someone had video, so it instantly became a thousands of dollars only a
turned a $25 toy into a wearable critical part in my projects. One couple of decades earlier. It was
computer. I thought that was the of our members learned that the springboard that helped me
coolest thing ever, so I instantly Eben Upton himself was broaden my knowledge and build
got obsessed with turning myself travelling through the East more projects; as I printed better
into a cyborg. Coast, so we invited him to enclosures, designed better
Since then, I’ve built a crazy speak at our hackerspace and electronics, and experimented
number of projects for fun and somehow got a meet-and-greet with different control devices, I
work, at least 200 in total. It was with the team. I showed off one filled out my skills.
This Month in
Raspberry Pi
#MagPiMonday
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 02
things we got sent this month – and remember to
follow along at the hashtag #MagPiMonday!
01.
This robot can be controlled over the
internet! Hopefully it doesn’t grab the
router’s power cable.
02. Astronomy and Raspberry Pi are two 03
great things that go great together.
03. Ravi has been doing some amazing
things with flying Pico projects!
04.
This is proper science fiction stuff
– hopefully we can get portable
versions soon.
05. Pi Wars is still going, even if it is
currently a remote event.
06. This is a very cool project from one of
our regular writers, PJ.
07. CutiePi is a cool tablet project that we
love seeing.
08. The number of Pico applications is
continually rising.
09. This microscope is very cool and
powerful. Apparently, that is the stinger
on a stinging nettle!
04
05
07
06
08
09
Maple Syrup Pi
A Google Coral smart camera
S
mart camera tech is something that has
been around for a little while, although it is
very often under-utilised for many reasons.
Ricardo de Azambuja is making a fresh attempt to
use it in a practical and exciting manner.
“Maple Syrup Pi Camera is part of my research
project,” Ricardo tells us. “I’m one of the 25
TRAIN@Ed Research Fellows at University of
Edinburgh. I am working on a project focused on
helping local tourist attractions to better manage
tourist flow, still GDPR compliant by design. My
solution is to process information in the camera
without ever saving or transmitting personal data.
In addition to that, I wanted something open-
source that could be customised, and as low-power
as possible, allowing it to run a full day on an off-
the-shelf power bank. Raspberry Pi Zero W is my
go-to IoT device and, together with the Google Coral
USB Accelerator, it has become my powerhouse for
machine learning inference.”
The Coral USB Accelerator attached to Raspberry
Pi contains an Edge TPU processor which allows
for offline TensorFlow models to run. It has some
similar tech to the AIY Vision Kit that Google
T
he finished device is
released a little while back.
fairly small
If you’re interested in reading about how it works
in more detail, you can head to Ricardo’s project The case holds a
Raspberry Pi Zero W
page at magpi.cc/maplesyrup. and a Camera Module
90 magpi.cc CoolestSyrup
Maple Projects
Pi online!
THIS MONTH IN RASPBERRY PI
Crowdfund this!
Crowdfund this! Raspberry Pi projects you
Raspberry Pi projects you
can crowdfund this month
can crowdfund this month
CROWD
Lite Berry A PROFJUNDING
If you
ECT?
’ve launc
The design of the Nintendo Switch is very appealing for many folks who play games, Raspb hed a
erry P
projec i-relate
so this kit that helps you turn a Raspberry Pi CM4 into a handheld gaming powerhouse t, let u d
magp s know
using the same form factor looks quite cool. i@ raspb !
errypi.
c om
kck.st/3ivYCVY
PiRelay 8
This board, which is being made in association with SB Components, really expands
the IoT uses of a Raspberry Pi. As its name suggests, it adds eight relays and even has a
built-in touchscreen that controls each one.
kck.st/3qAzLCg
Your
Letters
Backwards compatibility, part two
I am the Chair of a small charity, The Thika Alumni Trust, a need for, to send them to us and we will transport them to
that helps build e-Learning Centres in schools in Kenya. Kenya for use by school children in Kenya. You will be
Typically a 50 desk environment consists of four Raspberry helping enormously in enhancing ICT skills of students in
Pi Internet-In-A-Box (IIAB) Servers and 50 Raspberry Pi the developing world.
Desktops. We also encourage schools, via Kenyan Raspberry
Pi Code Club champions, to hold local code clubs. We Harper via email
provide help and support with experimental kits and any
old IT equipment in our possession. If you missed Rob’s Final Word in the previous issue, he talked
Old Raspberry Pi computers are wonderful for Kenyan about how older Raspberry Pi still work just fine, and can be
school children to learn coding skills and also to build used for a variety of project types. Organisations like The
robots etc. Following on from the article by Rob Zwetsloot Thika Alumni Trust are able to do amazing things with an older
in The MagPi 107, in a similar vein I am appealing to any Raspberry Pi, so if you’re not sure what to do with one, you can
Raspberry Pi enthusiasts out there, who may have an old always check out their website here: thethikaalumnitrust.org.
Raspberry Pi in their possession which they no longer have You can also email them at: [email protected].
I read the article about Avra Saslow and her emulation of the Good news: there are now some new variants of
Mars 2020 helicopter with interest. Raspberry Pi 400 including a Swedish one. It's joined by
I’ve made a short video of my ‘homage’ to Perseverance and keyboard layouts for Portugal, Norway, and Denmark.
Ingenuity. It is far, far less sophisticated, but tries to emulate rover A Japanese version is coming soon for people looking
and drone: magpi.cc/legomars. forward to that as well.
Architecture is a Raspberry Pi 3B, LEGO Mindstorms, BrickPi, Check out more at the following blog post:
CrazyFlie, OpenCV, and Python. magpi.cc/new400layouts.
Raspberry Pi controls the rover and provides the video feed – the
OpenCV component currently runs on a laptop and communicates
with Raspberry Pi over 0MQ. Porting the OpenCV code to Raspberry
Pi is a future step. Contact us!
Nigel via email > Twitter @TheMagPi
> Facebook magpi.cc/facebook
This is an incredible build – Raspberry Pi is perfect for OpenCV as > Email [email protected]
well, so this should be an easy port. Keep us updated with what > Online raspberrypi.org/forums
you’re making as we’d love to cover it more in the magazine.
SAVEUP
TO
35%
on the cover price
ISSUE #45
OUT NOW
hsmag.cc
COMPETITION
WIN
A MARTY
THE ROBOT V2!
IN ASSOCIATION
WITH ROBOTICAL
”Marty the Robot is the best-value
humanoid robot that can offer the
breadth of learning progression from
screen-free coding through to Scratch
and Python” – Robotical
Competition magpi.cc 95
T H AT M A D E
OUT
“The Computers that Made Britain
is one of the best things I’ve read NOW
this year. It’s an incredible story of
eccentrics and oddballs, geniuses and
madmen, and one that will have you
pining for a future that could have been.
It’s utterly astonishing!”
- Stuart Turton, bestselling author
and journalist
Available on
Features Editor
Rob Zwetsloot
[email protected]
Sub Editor
Nicola King
PICO
ADVERTISING
Charlotte Milligan
[email protected]
+44 (0)7725 368887
DESIGN
criticalmedia.co.uk
Head of Design
Lee Allen
PROJECTS
Designers
Lucy Cowan, Sam Ribbits
Illustrator
Sam Alder
CONTRIBUTORS
Mike Cook, David Crookes, PJ
Evans, Ben Everard, Gareth
Halfacree, Martin O’Hanlon,
Rosemary Hattersley, Nicola
MAKE INCREDIBLE King, KG Orphanides, Laura
Sach, Mark Vanstone
Director of Communications
Liz Upton
CEO
Eben Upton
DISTRIBUTION
Seymour Distribution Ltd
2 East Poultry Ave,
London EC1A 9PT
+44 (0)207 429 4000
SUBSCRIPTIONS
Unit 6 The Enterprise Centre
Kelvin Lane, Manor Royal,
Crawley, West Sussex, RH10 9PE
+44 (0)1293 312193
magpi.cc/subscribe
Plus!
system which has been assessed as
conforming to ISO 14001.
magpi.cc/subscribe
Building, St. John’s Innovation Park, Cowley
Raspberry Pi
Road, Cambridge, CB4 0DS. The publisher,
editor, and contributors accept no
responsibility in respect of any omissions
I
was chatting to my in-laws name adorns the office building I technology is indistinguishable from
recently about early computing. often work in. magic”, and into the practical world
My mother-in-law was a They have parts and articles on where computing becomes a tool we
programmer (but has never LEO at The Centre for Computing can control.
really used a computer). This History (magpi.cc/tcch) in
was back when ‘computer’ was a
women’s job description.
Cambridge, which has now reopened
and I can’t recommend it highly
ather oddly,
R
My father-in-law also used to run
simulations back in the 1970s on what
enough. I’ll be heading down there to we need to take
take a look.
turned out (after a long chat and some We tend to think of computing as the magic out of
online digging) to be an IBM
System/360 (magpi.cc/ibm360). He
ultra-modern and, obviously,
forward-thinking. Yet there is the
computing
didn’t personally program the weight of history behind our
machine; he wrote down instructions technological toys. We had just Raspberry Pi
for the simulation on a form, another visited Enderby’s Wharf and, It gave me great pride to show my
person punched the hole cards, and following a drink in Enderby House, in-laws Raspberry Pi and explain
then the programmer ran them there followed a chat about the what each constituent part was.
through the computer. The results history of underwater cabling. The They were amazed by how small it
typically came back a week or so later. first telegraph cable across the was, especially Raspberry Pi Zero.
There followed a surprisingly Atlantic was produced there, and Having this historical perspective
informative chat about the history of much of the world’s subsea helped me explain to them why
computing covering all the usual communication cables were made in Raspberry Pi was so important. It
bases: Charles Babbage, Ada the area. Alcatel Submarine Networks continues the UK’s long tradition of
Lovelace, Alan Turing, John von is still based around the corner. designing, and building, its own
Neumann, and early proto- It often comes as a surprise to computers. Raspberry Pi is vital to
computers like the Difference and folks that most of the internet traffic ensure the existence of a future
Analytic Engines, and orrery devices isn’t whizzing around in space, but generation of programmers, by
like the Antikythera Mechanism. bouncing along vast undersea cables. putting the power of physical
They talked with pride about You can take a look at all the wires computing into the hands of young
Lyons LEO (Lyons Electronic Office, in this interactive map: learners (of all ages).
magpi.cc/leo), a computer I hadn’t submarinecablemap.com.
heard of but intend to learn more Learning how the mystical world
Lucy Hattersley
AUTHOR
Maurice Wilkes, the person whose realm of “any sufficiently advanced magpi.cc