You are on page 1of 100

BUY IN PRINT WORLDWIDE MAGPI.

CC/STORE

+UUWG #RTKN OCIRKEE 6JGQHƓEKCN4CURDGTT[2KOCIC\KPG

LEARN TO TAKE
NIGHT SKY
PHOTOS

WITH
GET STARTED
WITH PICO
CIRCUITS

Discover coding with Raspberry Pi

magpi.cc/store

NEW! RASPBERRY PI GLOBAL SHUTTER CAMERA


 
      


2A9b MJ=DH9,BbBSb5bUMY7AbN5K9Hb- b89SC?K98b\BTAb AC?A UMI9O5KUb7MJNMK9KTSb5K8bKMbJMZBL@b
N5QWSb<MPbBK8XSTOD5Hb5NNIB75TBMKSb %Ub;:5UYO9Sb5b\5T9Q O9SDST5KUb<QMKUbN5K9HbUMX7AS7O9:Kb
7MHMRb(!"b5[5CH56H9bCKb[5QCMXSbSE`9Sb /0b /0 b #UA9QK9U b 40 b !b 1.&
b8F@EU5Hb  b
65TW9Q_657G98b/2!bO95HUEJ9b7HM7Gb5K8bND9aMb6Yaa9Qb

3S9bTA9bO95P N5K9Hb NDKb$,'+bA9589ObUMb9]N5K8bBTSb<95UYO9Sb 5K8b75N56BHDUC9Sb\CUAb588DVDMK5Ib


b6M5O8Sb 2A9b MJ>DH9-BbDSb4)b)CSU98b5K8b9JNIM^Sb/5SN69OO^b-Bb!MJNXU9b*M8XH:b

 
 


   


 $% #!"%
%#%
% %  %%

 

WELCOME

WELCOME
to The MagPi 128

L
earning to code can be a life-changing experience.
Computers are useful things, and learning how to get
under the hood is - in itself - pretty rewarding, and
there’s plenty of demand for coders worldwide.
But beyond that, learning to program teaches you how Lucy

EDITOR
to think. You learn how to break down complex tasks and Hattersley
put things in order. It teaches you how to solve seemingly Lucy is the editor
of The MagPi
impossible problems. Our Learn to Code with Python feature and would like
to petition for a
(page 44) can help you out on this journey. I hope you take it. 7EWTFIVV]5MSǽGI
puppy. Or she’ll
You’ll also discover excellent Computer Science resources in build another robot
this issue (page 80), including CS50 and MITx (both of which magpi.cc

helped me immeasurably when I got serious about coding).


Blending code with hardware is what The MagPi is all about.
And you should also take a look at Stewart Watkiss’ electronics
series, which moves into microcontrollers (page 52).
Being a coder is great fun. I hope this edition of The MagPi
helps you get started.
GET A
RASPBERRY PI
PICO W
Lucy Hattersley Editor
PAGE 42

magpi.cc 03
TCP/IP Offload Ethernet

Design Contest
Supporting up to 80 Mbps Speed
Targeting High Performance
Applications

USE W5300
● 8/16 bit Data Bus Interface (Direct & Indirect Address Mode) Contest
begins Mar 16
● High Network Performance : Max 80Mbps (by DMA)
● 8 Independent hardware sockets

Get a Mar 16
Sample ~ April 30
Buy
W5300($5) or W5300 TOE Shield($10)
at WIZnet e-shop Submissions
W5300 W5300 TOE Shield
close Jun 30

WIN A CHANCE FOR $ 30,000 IN TOTAL Winners


announced by July 18
1st PRIZE 2nd PRIZE 3rd PRIZE
$ 5,000 X2
$ 2,500 X2
$ 1,000 X 10
at maker.wiznet.io
CONTENTS

Contents
> Issue 128 > April 2023

Cover Feature

44 Learn to Code 44
with Python
Regulars
08 World of Raspberry Pi news
40 Case Study: Yoto Player
90 Your Letters
92 Community Events calendar
97 Next Month
98 The Final Word

Project Showcases
14 Heavy Pan Tilt System
18 Word Clock 26
20 Game Boy Interceptor
24 Aquarium dosing pump
26 Tank Driving Simulator
30 Progress Bar
32 BrachioGraph
34 Herbie_Bot
36 CinePI

14

Heavy Pan Tilt System Tank Driving Simulator

The MagPi is published monthly by Raspberry Pi Ltd, Maurice Wilkes Building, St. John’s Innovation Park, Cowley Road, Cambridge, CB4 0DS, United Kingdom. Publishers
Service Associates, 2406 Reach Road, Williamsport, PA, 17701, is the mailing agent for copies distributed in the US and Canada. Application to mail at Periodicals prices is
pending at Williamsport, PA. POSTMASTER: Send address changes to The Magpi, c/o Publishers Service Associates, 2406 Reach Road, Williamsport, PA, 17701.

magpi.cc 05
CONTENTS

56 60
Tutorials
52 Introduction to microcontrollers
56 Build an ML digital transcriber
60 Make a binary clock
Build an ML
digital transcriber Make a binary clock
The Big Feature
66 78

Astrophotography with Raspberry Pi Ten amazing displays

Reviews 86
72 Vizy Camera
74 Meteor 10.1” touchscreen
76 Alpakka controller
78 Ten amazing displays
80 Learn computer science

Community
84 Trevor Warren interview
86 This Month in Raspberry Pi This Month in Raspberry Pi

95
WIN A RETERMINAL
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 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
QER]SJXLIXSTMGWMR8LI2EK5MQEKE^MRIEVIHMǺIVIRXFIX[IIRGSYRXVMIWERHEVIEP[E]WWYFNIGXXSGLERKI=SYEVIVIWTSRWMFPIJSVYRHIVWXERHMRKXLIVIUYMVIQIRXWMR]SYVNYVMWHMGXMSR
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.

06 magpi.cc
THE WORLD OF RASPBERRY PI

Global Shutter Camera


New Raspberry Pi Global Shutter Camera for machine vision and more. By Eben Upton

R
emember those new cameras we launched R]PL_ʭ_QZ]^[Z]_^[SZ_ZR]L[SdLYOXLNSTYP
way back in the dawn of… January? [see vision applications, where even small
magpi.cc/126 – Ed]. We have another one amounts of distortion can seriously degrade
for you – and this time we’re getting specialised. inference performance.
BPɪ]PWL`YNSTYR^ZXP_STYRLWT__WPOTʬP]PY_%_SP
Raspberry Pi Global Shutter Camera, available Rolling shutters, global shutters
now at $50 (magpi.cc/globalshuttercam). Every camera we’ve released to date, from
Built around Sony’s 1.6-megapixel IMX296 2014’s Camera Module 1 to our High Quality
sensor, the Global Shutter Camera is able to Camera and beyond, has used a rolling shutter
capture rapid motion without introducing sensor. These sensors have a two-dimensional
rolling shutter artefacts. This makes it a array of light-sensitive pixels, which generate
an analogue value proportional to the
amount of light falling on the
pixel during the exposure
time; and a row of
analogue-to-digital
converters (ADCs),
which convert

The new Global


Shutter Camera

08 magpi.cc Global Shutter Camera


THE WORLD OF RASPBERRY PI

these analogue values into digital


values which are fed back to your
Raspberry Pi.
The row of ADCs is connected
to each row of the pixel array
in turn, so each row is sampled
L_L^WTRS_WdOTʬP]PY__TXP
Provided there is no motion in the
scene, this isn’t a problem, but
once things start to move – and
particularly if something is moving
fast – we start to see rolling
shutter artefacts. Linear motion
results in compression, stretching,
or shearing of the moving object.
Rotary motion can create some very
odd-looking shapes indeed. Severe

When the shutter fires,


each pixel immediately
copies its analogue value The Global Shutter
Camera combines
into its storage element the C/CS-mount
of the High Quality
Camera with the Sony
IMX296 sensor
rolling shutter artefacts are unsightly, and hard
to detect and correct, but even imperceptible
artefacts can interfere with the operation of
machine vision algorithms. If we want to
Credits
eliminate them altogether, we need to use a
Like all recent camera products, the Global Shutter
global shutter sensor. This pairs each pixel with Camera hardware was designed by Simon Martin.
an analogue storage element; when the shutter Naush Patuck, Nick Hollinghurst, David Plowman,
ʭ]P^PLNS[TcPWTXXPOTL_PWdNZ[TP^T_^LYLWZR`P Serge Schneider, and Dave Stevenson wrote
value into its storage element, from where it can the software. Alasdair Allan, Simon Martin, David
be read and converted at leisure. Plowman, Andrew Scheller, and Liz Upton worked
on documentation. Austin Su led on sourcing. Jack
The storage element adds complexity and area
Willis designed the packaging, and Brian O Halloran
to each pixel. Global shutter sensors tend to have (not included with camera) took the photos and
a lower resolution than rolling shutter sensors of video. We’d like to acknowledge the assistance
_SP^LXP^TeP%NZY_]L^__SP"$ XXXPRL[TcPW of Phil Holden and John Conroy at Sony, and of
48C""^PY^Z]`^POTY_SP3TRS<`LWT_d.LXP]L Shenzhen O-HN Optoelectronic.
with the 6.3 mm, 1.6-megapixel IMX296.

Global Shutter Camera magpi.cc 09


THE WORLD OF RASPBERRY PI

If you think my front is cool…


there’s a surprise logo for the
rear view fans

Enter the Raspberry


Pi Global Shutter
Camera
Despite the challenges
associated with rolling
shutter artefacts, our
existing cameras are
widely used in hobbyist
and industrial machine
vision applications. And
we’ve seen some real
TYRPY`T_d%_ZNZX[PY^L_P
for artefacts when
imaging products on a
high-speed conveyor
belt, one of our industrial
customers ended up
training their models
using pre-sheared
input data.
For these applications,
a global shutter sensor
ZʬP]^NWPL]LOaLY_LRP^
And reduced resolution isn’t
a problem, as high-resolution images are
generally down-sampled before being fed into
machine vision models.
The Raspberry Pi Global Shutter Camera
combines the C/CS-mount metalwork of our
High Quality Camera with Sony’s IMX296 sensor.
It is compatible with the same broad variety of
lenses, including the 6 mm CS-mount and 16 mm
.XZ`Y_.27WPY^P^_SL_bPZʬP]_S]Z`RSZ`]
Approved Reseller partners.
Camera in action Like all our camera products, you can use the
Global Shutter Camera with any Raspberry Pi
computer that has a CSI camera connector, and
The video at magpi.cc/gscamaction illustrates the
ÆåĹåĀƋŸŅü±čĬŅƱĬŸĘƚƋƋåųĜĹƋĘåŞųåŸåĹÏåŅüų±ŞĜÚųŅƋ±ųƼ
we’ve updated our hardware documentation
motion. First, we see the output from the High Quality (magpi.cc/cameradocs) to include everything
Camera, showing distinctive rolling shutter artefacts, and you need to know about the new product. You’ll
then we see the artefact-free output from the Global need to update Raspberry Pi OS to use the new
Shutter Camera. NLXP]L%sudo apt update; sudo apt full-
upgrade; sudo reboot and you’re good to go.

10 magpi.cc Global Shutter Camera


Full-Code

No-Code / Configure Design

now with a

No-Code WEB UI Designer


Pi 4 and
Analyze W it h R

P RO FES S I O N A L CO N T RO L SYS TE M D E V E LO P M E N T TOO L

Home projects made easy.


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

 

Tel: +47 990 80 900 • info@cdptech.com


CDP Technologies AS // Hundsværgata 8, 6008 Ålesund, Norway
THE WORLD OF RASPBERRY PI

Raspberry Pi Pico
Windows Installer
A simpler solution to getting Pico up and running with Windows computers.
By Gordon Hollingworth, Raspberry Pi, Director of Software Engineering

R
aspberry Pi is introducing Raspberry Pi also documented how to get the toolchain up and
Pico Windows Installer, a simple solution bZ]VTYRZYMZ_S,[[WPɪ^XLN:>LYO8TN]Z^ZQ_
to install everything you need to develop Windows for folks that wanted to use those
for Raspberry Pi Pico, and for other RP2040- [WL_QZ]X^@YQZ]_`YL_PWdbSTWPTY^_LWWTYR_SP>/6
based boards, using C or C++ on Windows. ZYXLN:>T^Yɪ__ZZOTʬP]PY_Q]ZXOZTYR^Z`YOP]
The Raspberry Pi Pico C SDK (magpi.cc/picocsdk) 7TY`cLYObZ]V^LWXZ^_Z`_ZQ_SPMZcTY^_LWWTYR
can initially seem quite daunting. There are a lot _STYR^ZYBTYOZb^T^X`NSXZ]POTʯN`W_&T_ɪ^U`^_
of moving parts to install before you can blink LaP]dOTʬP]PY_PYaT]ZYXPY_
dZ`]ʭ]^_70/ZYLYO_SPYZʬLRLTYP^[PNTLWWdTQ 1Z]_`YL_PWdLYPY_P][]T^TYRdZ`YRPYRTYPP]
you want proper debugging using something like called Nikhil Dabas (magpi.cc/ndabas) decided
our new Debug Probe (magpi.cc/debugprobe). _Z^PPbSP_SP]SPNZ`WOOZMP__P]4__`]YPOZ`_
While there has been a ‘one-click’ solution ZQNZ`]^P_SL_SPNZ`WO^Z4L^VPOSTX_ZSPW[
(magpi.cc/picosetup) to install the toolchain us create something even better: a complete
on a Raspberry Pi since launch – see integrated installation package that would give
Chapter 1 of the Getting Started guide [PZ[WPLYTNPPL^dbLdZQM`TWOTYRLYOOPM`RRTYR
(magpi.cc/gettingstartedpico) – installing the the Pico SDK.
_ZZWNSLTYZYZ_SP][WL_QZ]X^WTVPXLN:>Z]
BTYOZb^SL^LWbLd^MPPYLWT__WPXZ]POTʯN`W_ Installing the toolchain
When we launched Raspberry Pi Pico and its Installing the toolchain is now as simple as
>/6Z`]L^^`X[_TZYbL^_SL_[PZ[WPbZ`WOMP OZbYWZLOTYRLYO]`YYTYR_SP;TNZ4Y^_LWWP]
The new Raspberry Pi
Debug Probe SL[[dbT_SL7TY`cML^PO_ZZWNSLTY3ZbPaP]bP (download link: magpi.cc/picosetupwindows). At
_SPPYO_SPTY^_LWWP]bTWWZʬP]_ZNWZYPLYOM`TWO
_SP;TNZPcLX[WP^magpi.cc/picoexamplesRTaTYR
dZ`_SPZ[_TZYZQNSLYRTYRbSP]P_SPPcLX[WP^L]P
TY^_LWWPO7PLaP_SL__TNVPOLYO_SPTY^_LWWP]bTWW
open a command window to do the initial checkout
LYOM`TWOZQLWW_SP;TNZ]P[Z^T_Z]TP^:YNPOZYP
you can safely close this window.

Starting Visual Studio Code


4YdZ`]>_L]_8PY`WZZVQZ]_SPɩ;TNZɧAT^`LW
>_`OTZ.ZOPɪ^SZ]_N`_TY_SPɩ=L^[MP]]d;TɪQZWOP]
The shortcut sets the required environment
aL]TLMWP^LYO_SPYWL`YNSP^AT^`LW>_`OTZ.ZOP
?SPʭ]^__TXPAT^`LW>_`OTZ.ZOPT^WL`YNSPO
`^TYR_SP>_L]_8PY`^SZ]_N`_T_bTWWZ[PY_SP
pico-examplesQZWOP]?ZZ[PY_SPQZWOP]WL_P]`^P
_SPɩ:[PY=PNPY_ɪZ]ɩ:[PY1ZWOP]ɪXPY`Z[_TZY^
and navigate to your Documents/Pico-v1.5.0/
OT]PN_Z]dZ]bSP]PaP]dZ`TY^_LWWPO_SPPcLX[WP^

12 magpi.cc Raspberry Pi Pico Windows Installer


THE WORLD OF RASPBERRY PI

Building the Hello Serial example


4QdZ`[]PaTZ`^WdOTOYɪ_SLaPA>.ZOPTY^_LWWPO
PaP]d_STYR^SZ`WOɩU`^_bZ]VɪLQ_P]TY^_LWWL_TZY
But often we’ve seen problems due to various
]LYOZX^P__TYR^TY^P]_POMdZ_SP]Pc_PY^TZY^Z]
Md_SP`^P]TYLYPcT^_TYRTY^_LWWL_TZY4Q_ST^T^_SP
NL^PQZ]dZ`[WPL^PRZ_Z_SP;TNZ4Y^_LWWP]BTVT
(magpi.cc/picowindowswiki) for a checklist of
known issues and solutions.
AT^`LW>_`OTZ.ZOPXLdL^VTQdZ`bLY__Z
NZYʭR`]P_SP[TNZPcLX[WP^[]ZUPN_bSPYT_T^ʭ]^_
Z[PYPO&NWTNVɩDP^ɪZY_SL_[]ZX[__Z[]ZNPPOTQ
you miss the prompt look for the ‘bell icon’ in the
MZ__ZX]TRS_4QT_OZP^Yɪ_L^VdZ`NLYNWTNVZY_SP
blue status bar where it says ‘No active kit’ and
^PWPN_;TNZ,=82..
?ZM`TWO_SPPcLX[WPNWTNV_SP.8LVPM`__ZY
ZY _SP^TOPML]DZ`^SZ`WOMP[]P^PY_PObT_SL
_]PP aTPbZQ_SPPcLX[WP[]ZUPN_^&Pc[LYO_SP

A simple solution to PicoProbe using a second Raspberry Pi Pico. If you


OZYɪ_SLaPL/PM`R;]ZMP^PP,[[PYOTc,ZQ_SP
Raspberry Pi Debug
Probe connected
to a Dell computer
install everything you Getting Started (magpi.cc/gettingstartedpico) running Windows

guide for instructions on setting up a second Pico


need to develop for as a PicoProbe.
?Z\`TNVWdNSPNVdZ`ɪaP^P__ST^`[[]Z[P]WdTY
Raspberry Pi Pico AT^`LW>_`OTZ.ZOPNWTNVZY_SP>0=4,78:94?:=
tab. When you plug in your Debug Probe (or
ɩSPWWZJbZ]WOɪLYOɩ^P]TLWɪ_]PP^LYONWTNV_SP ;TNZ;]ZMPdZ`^SZ`WO^PPLYLOOT_TZYLW.:8[Z]_
^XLWWɩM`TWOɪTNZY_ZM`TWO_SL_^[PNTʭN[]ZUPN_DZ` TY_SP[Z]_O]Z[OZbYWT^_DZ`^SZ`WOWPLaP_SP
should take a note of the [hello_serial] tag down in ML`O]L_P^P__Z_SPOPQL`W_ZQ TYXZ^_NL^P^
_SP.8LVP_ZZWML]L__SPMZ__ZXZQ_SP^N]PPYdZ` .WTNVɩ>_L]_8ZYT_Z]TYRɪ_ZZ[PY_SP^P]TLW[Z]_
can use this to change the target at any time.
Let’s start debugging
Debugging your example application Assuming you have wired up the Debug Probe to
?ZOPM`RdZ`]SPWWZJ^P]TLWPcLX[WPdZ` dZ`];TNZNZ]]PN_Wd[]P^^F5 to start debugging or
should use the new Raspberry Pi Debug Probe click the Run and Debug button (CTRL+SHIFT+D)
(magpi.cc/debugprobe) or set up your own on the sidebar and then the small ‘play’ icon at the
top of the debug window.
DZ`]^PWPN_PO_L]RP_^SZ`WOYZbMPM`TW_
`[WZLOPOLYO^_L]_PO?SPOPM`RRP]TY_P]QLNPbTWW
WZLOLYObTWW[L`^P_SPPcPN`_TZYZQ_SPNZOPL_
_SPXLTYPY_]d[ZTY_,__ST^[ZTY_dZ`NLY`^P
_SP`^`LWOPM`RRTYR_ZZW^_Z^_P[^P_M]PLV[ZTY_^
TY^[PN_XPXZ]dLYO^ZZY3T_ɩ=`YɪLYOdZ`
^SZ`WOYZbMPLMWP_Z^bT_NSMLNV_Z_SP>0=4,7
8:94?:=_LM_Z^PP_SP^P]TLWZ`_[`_L[[PL]

Next steps
For more information on creating your own
[]ZUPN_Z`_^TOPZQ_SP[TNZPcLX[WP^^PP_SP
tutorial at magpi.cc/piconewprojectZ]]PLO
Chapter 8 of the Getting Started guide (magpi.cc/
The pico-examples repository open in Visual Studio Code gettingstartedpico) for a full walkthrough.

Raspberry Pi Pico Windows Installer magpi.cc 13


PROJECT SHOWCASE

Heavy Pan Tilt System


Keen photographer Vigasan needed a solid stand for his builds,
and found Raspberry Pi ideal, he tells Rosie Hattersley

E
lectronics engineer Vito counts astronomy the work of many months. Its strength derives
and photography among his interests. After from the two aluminium frames, while Vito made
using Raspberry Pi a few years ago as part everything else from parts he 3D-printed. He
of his role in the medical sphere, he realised it was lucky enough to have access to a fairly high-
bZ`WOʭ_]L_SP]YPL_WdbT_SST^SZMMTP^_ZZ?ST^ end PolyJet 3D printer, which meant he got very
led to him setting up the YouTube channel Vigasan accurate results. Vito also designed the electronics
(magpi.cc/vigasanyt) to showcase his projects. and the control software, plus a custom circuit
The Heavy Pan Tilt System addresses a common board, pairing a Raspberry Pi 4 and a small camera
Vigasan
MAKER

issue with astrophotography: the need for a setup capable of automatic object tracking, as his video
robust enough to take a hefty digital SLR camera shows: magpi.cc/pantiltyt.
With 20 years in the
QIHMGEPǻIPHEWER and have it pan smoothly across the night sky Vito began by creating a project using Raspberry
electronic engineer, without juddering or losing either focus or the Pi for object tracking, before moving on to the
Vigasan frequently ZMUPN_TY_SPaTPbʭYOP].ZXXP]NTLWZ[_TZY^_PYO thornier issue of the mechanical design: “The need
uses Raspberry Pi
for both work and to be “quite expensive astronomical mounts,” so to move a camera with lenses of a certain weight
his hobby projects. Vito set about create his own version using his requires considerable torque from the motors. So,
magpi.cc/ own mechanical designs and software to automate to avoid using too big stepper motors, I designed a
motorizedcamgit object tracking. Raspberry Pi provided the critical reduction system based on belts and pulleys with
^_P[[P]XZ_Z]NZY_]ZW^LYO:[PY.AWTM]L]TP^QZ] the advantage of using smaller motors.”
computer vision. Judging by the many plaudits
quickly garnered online when Vigasan revealed Cost-benefit analysis
his build, he’s nailed it, even if some people think Although he can’t quantify the time taken for
it would be ideal for deadly accurate tennis ball designing the software and incorporating the
volleys and other forms of sharp-shooting. necessary libraries (he’s been an engineer for 20
years, so programming is part of his day job), Vito
Labour of love ^Ld^_SP^[PNTʭNL[[_ZNZY_]ZW_STYR^_ZZVSTX
Not surprisingly, the Heavy Pan Tilt System – a about a month, while designing the hardware took
“very robust motorised pan-tilt system capable about twice that. Having initially tried to create
of supporting cameras with heavy lenses” – is the project using an ESP32 microcontroller and

14 magpi.cc Heavy Pan Tilt System


PROJECT SHOWCASE

Quick FACTS
> Designing the
complex pulley
The heavy duty metal system took
frame and precision- several attempts
designed 3D moulded
parts are sturdy enough > The project was
to take expensive originally based
Maker Vigasan enjoys all
camera equipment and on an ESP32
forms of photography
angle it just so microcontroller...
including astrophotography,
for which long exposures and
> ...but really needed
object tracking are needed
Raspberry Pi 4
processing power...

> ...and the precision


of an expensive
PolyJet 3D printer

> Thankfully, there


are no additional
running costs

Similar motorised pan-tilt


systems can cost many
hundreds of pounds more
than this Raspberry Pi 4
and computer vision setup

Heavy Pan Tilt System magpi.cc 15


PROJECT SHOWCASE

The mount can


rotate a camera
in any direction to
track objects

The Heavy Pan


Tilt System works
incredibly smoothly

16 magpi.cc Heavy Pan Tilt System


PROJECT SHOWCASE

Pan, tilt, shoot!

Creating a motorised pan tilt system in


01 order to take videos and photos using heavy
cameras and lenses requires considerable torque,
necessitating the use of stepper motors and a
pulley and weights system to reduce the motor
size required.

ʭYOTYRT_WLNVPO[ZbP]AT_ZbL^RWLOSP^bT_NSPO One of the incredible


Vito designed and laser-cut the aluminium
to using Raspberry Pi 4, which “guarantees good
photos Vigasan was able to
capture using his pan-tilt
02 frames. These precision parts and other
DSLR camera setup Ɛ%ěŞųĜĹƋåÚåĬåĵåĹƋŸƵåųåÚåŸĜčĹåÚƋŅĀƋƋĘå
computing power and the existence of a large
number of libraries for any type of requirement.” two STM L6470 stepper motors and belts, which
Raspberry Pi 4 controls.

I don’t think I created


anything new, I just
enjoyed doing it
His choice of a rock-steady aluminium frame
added €150 to the overall cost, which was in the
region of €800. Even so, this is considerably
cheaper than buying a specialist astrophotography
Vito used Qt framework software and OpenCV
rig. Vigasan modestly claims not to have invented 03 libraries with Raspberry Pi OS for object
anything: “I don’t think I created anything new, detection and computer vision tasks. Everything can
I just enjoyed doing it and I hope that the project now be controlled via Bluetooth and an iPhone – see
will be of help to those who want to use Raspberry magpi.cc/motorizedcamgit for more details.
Pi for their creations.”

Heavy Pan Tilt System magpi.cc 17


PROJECT SHOWCASE

Word Clock
David Crookes reckons it’s time we all paid some attention to Christopher Hall’s amazing clock

I
f you want to know the time, there are many something practical; something with function,” he
methods available to you.;P]SL[^dZ`ɪOWTVP_Z explains. “I was browsing Printables when I came
RWLYNPL_LOTRT_LWZ]LYLWZR`PNWZNVZ]bL_NS across a similar project and thought, ‘I bet I have
8LdMPdZ`ɪOWTVP_ZL^VdZ`]QLaZ`]T_PaT]_`LW XZ^_ZQ_SP^_`ʬ4YPPO_ZXLVP_ST^ɪɮ0aPY^Z
L^^T^_LY__Z]PLOT_Z`_WZ`O4QdZ`ɪ]PQPPWTYRMZWO aspects of the build posed a challenge.
dZ`NZY^`W_L^`YOTLWL_TXPMLWWZ]LXP]VSP_:] >TYNP.S]T^_Z[SP]bL^XLVTYRST^ZbYSZ`^TYR
TQdZ`ɪ]P.S]T^_Z[SP]3LWWdZ`NZ`WO`^PLbZ]O QZ]_SPNWZNVSPYPPOPO_Z`^PL/R]L[STN^_ZZW
NWZNVLYO^PP_SP_TXPL^b]T__PY^PY_PYNP^ ɭ?SL_XPLY_WPL]YTYR-WPYOP]LYO_LVTYR[]PNT^P
Christopher
MAKER

BZ]ONWZNV^L]PYZ_YPbM`__SPd^`]PL]PQ`Y measurements with callipers,” he says. He also


Hall LYO.S]T^_Z[SP]ɪ^PY_]dRZP^Q`]_SP]_SLYXZ^_ Z[_PO_Z`^PL#Ÿ!3@-" 70/XL_]Tc_SL_SPɪO
Christopher Hall is As well as telling the time, it announces holidays ]PNPTaPObT_SLXZY_SWd3LNVP]-Zc^`M^N]T[_TZY
a senior network LYOMT]_SOLd^Md^STYTYR70/WTRS_^MPSTYO LYO_ST^TYʮ`PYNPO_SP^TePZQ_SPbZ]OXL_]Tc
engineer from ^[PNTʭNWP__P]^LYOY`XMP]^ZYLN`^_ZXXLOP that he had to print.
Pikeville, KY, USA.
He’s a maker at
[LYPW0aP]d_STYRT^NZY_]ZWWPOMdL=L^[MP]]d “There was a lot of trial and error,” he says. “A
heart and lover of Pi computer. “When I thought of the project, VPd[]ZMWPX4YZ_TNPOPL]WdZYbL^WTRS_4Z[_PO_Z
all things geeky. =L^[MP]]d;TQPW_WTVPLYL_`]LWʭ_ɮSP^Ld^ `^PLŸR]TOZQ70/^[P]TWW`XTYL_POWP__P]M`_
magpi.cc/ putting the letters too close meant I could see each
wordclock Time to try light,” Christopher says. “In the end, I designed
?SPTOPLNLXPbSPY.S]T^_Z[SP]MZ`RS_L/ a lattice to sit between the RGB matrix and the
Christopher
discovered he could []TY_P]ɭ=L_SP]_SLY[]TY_TYRʭR`]TYP^4bLY_PO printed word matrix. Between it, I placed a grey
not have islands in ^SPP_ZQ[L[P]N`__Z^TePLYO_ST^bZ]VPO[]P__d
the letters – O, P, R,
and so on needed bPWW_ZOTʬ`^P_SPWTRS_ɮ
to be hollow. “I tried
a stencil font but
ultimately couldn’t Clocking on
get the visibility I
wanted,” he says
>TYNP_SPbZ]OXL_]TcbL^!ŸNSL]LN_P]^
Christopher realised he had space for many letters.
ɭ:YNP4ɪOʭYT^SPOL]]LYRTYR_SP_TXP[L]_^4SLO
XZ]P_SLYSLWQL^N]PPYɪ^bZ]_SZQ]PLWP^_L_PWPQ_
which is why I decided to also announce the date
and any holidays and family birthdays,” he says.
?ZVPP[_TXP.S]T^_Z[SP]TYNW`OPOLY=2-
Matrix HAT + RTC from Adafruit so that the
[]ZUPN_NZ`WOMPYPʭ_Q]ZXL[P]^T^_PY_]PLW_TXP
NWZNV>P_`[TYaZWaPONZYYPN_TYR_ST^_Z_SP
=L^[MP]]d;TNZX[`_P]LYOSZZVTYRPaP]d_STYR_Z
the display inside the printed case.
Of course, Christopher also needed to program
the device. “The project I found on Printables
had an example Python script, so that was a good
U`X[TYRZʬ[ZTY_M`_T_^_TWWYPPOPO_ZMPSPLaTWd
XZOTʭPOɮSP^Ld^ɭ4`^POLSZWTOLd^WTM]L]d_Z
determine if the current day was a holiday or not. I
also had the challenge of lighting the letters.”

18 magpi.cc Word Clock


PROJECT SHOWCASE

For the sake of


compactness, Christopher
desoldered several
components and reattached
them directly to the board of
the Adafruit RGB Matrix HAT

The HUB75 RGB Matrix is


daisy-chainable so another
screen could be attached,
perhaps to display weather,
Quick FACTS
IQEMPRSXMǻGEXMSRWERH
> The clock
network health issues
highlights the
letters needed
for the time

> It displays holidays


and birthdays too

> A shiny front was


The case has been designed so ǻ\IH[MXLYPXVEǼEX
XLEXTS[IVGERIEWMP]ǼS[JVSQ black primer
a 5V power brick to the Adafruit
HAT. From there, power goes to > The LEDs can be
Raspberry Pi and the LED Matrix set to any colour

> Arranging the


letters was like a
reverse crossword

3PSLO_ZʭR`]PZ`_QZ]PcLX[WP_SL_70/^
at positions 14,46, 14,47, 15,45 and 15,47 needed
to be turned on for the letter J. “This had to be

I used a holidays library to


determine if the current
day was a holiday or not
done for each letter I wanted to turn on, so I set
them into arrays for better organisation,” he
LOO^:YNPOZYP_SPNWZNVNZ`WO^[]TYRTY_ZWTQP
WZZ[TYRPaP]d^PNZYO_Z`[OL_P_SP70/NW`^_P]^
The completed Word Clock displaying the time, date,
“Raspberry Pi has been a great device for the job,”
and a birthday. “Everything sits neatly in the 3D-printed,
he says. wall-mounted housing,” Christopher says

Word Clock magpi.cc 19


PROJECT SHOWCASE

Game Boy
Interceptor
A challenge by fellow Game Boy Tetris fans led to this
Pico-based recording device, discovers Rosie Hattersley

T
he addictive qualities of the computer game since childhood, Sebastian follows his own advice
Tetris are well-known, so it’s perhaps that the best way to learn new skills is “to become
no surprise to learn that there is a whole obsessed with a project that is just a little bit
community of Game Boy Tetris fans who meet above your current abilities.”
online for tournaments. BSPYSPRZ_ST^ʭ]^_=L^[MP]]d;TLOPNLOPLRZ
The RP2040 microcontroller-based Game he wasn’t quite sure what he would do with it.
Boy Interceptor came about when just such Sebastian has been running a Raspberry Pi-based
a tournament was being planned, “and, of home automation setup ever since, and also keeps
Sebastian
MAKER

course, they wanted to stream the contestants’ a Raspberry Pi handy for the constant stream of
Staacks
gameplay,” relates fellow Tetris fan Sebastian projects that invariably need a simple server for
Sebastian is a Staacks. “Streaming would not be a problem with IoT purposes. When Raspberry Pi Pico launched, he
physicist and LXZOTʭPO2LXP-ZdZ]LXZOP]Y2LXP-ZdNWZYP was curious about Raspberry Pi microcontrollers,
developer of the
such as the Analogue Pocket,” says Sebastian, especially after working with Arduinos for a while.
app ‘phyphox’
at the RWTH “but it would mean contestants would be forced to Happily, “the RP2040 turned out to be a perfect
Aachen University use the same platform in order to compete.” This match for GB Interceptor!” Unlike modern devices,
(Germany). He is a NSLYRPU`^_bZ`WOYɪ_ʮd%ɭ_SPNZY_P^_LY_^LWbLd^ the Game Boy reads data from the cartridge as
father of two and
presents his hobby
played their favourite Game Boy model and, in a fast as from its RAM, so there is no reason for it
projects in his blog... contest, would want to use the model on which _ZWZLOT_^NZOPTY_Z=,8ʭ]^_4Y^_PLO_SPNZOP
there.oughta.be they trained their muscle memory.” is executed directly from the cartridge (with few
Getting everyone to modify their beloved exceptions) and a device in between would know
handheld console was out of the question. Sensing exactly what the Game Boy was doing.
a challenge he could relish, Sebastian agreed to
work out a way of streaming the tournament that Unexpected benefits
would satisfy everyone. His idea was to insert ,_ʭ]^_>PML^_TLY^TX[WdSZ[PO_Z`^P=;
a device between the game cartridge and the to capture information from Tetris, but the
Game Boy that checks what the handheld console microcontroller was powerful enough to render the
is doing and reconstructs the gameplay from graphics, emulate the code from whichever game
the data. was being played, and act as a general-purpose
video capture device. The power and sophistication
Game on! of the RP2040 meant the Game Boy Interceptor
Physicist Sebastian holds a PhD in solid-state bL^LX`NSXZ]P`^PQ`WLYOʮPcTMWPOPaTNP_SLY
physics, “which means that I know the basics of Sebastian had anticipated. “You can simply plug
almost everything technical, but nothing that is it between the cartridge and your Game Boy
required to apply it,” he announces modestly. A and connect it to a host device via USB.” There,
self-taught programmer and electronics enthusiast it shows up like a webcam and, as a USB Video

20 magpi.cc Game Boy Interceptor


PROJECT SHOWCASE

Sebastian realised that the


entire game data would pass
through the Game Boy’s
cartridge slot – and a powerful
microcontroller could emulate it
The GB Interceptor acts
as a video-capture device
for older Game Boys,
streaming moves during
online Tetris tournaments

Raspberry Pi RP2040’s GPIO pins


and programmable IOs capture
video RAM data and emulate
moves without needing the
KEQMRKHIZMGIXSFIQSHMǻIH Quick FACTS
> The Game Boy has
a 1MHz bus...

> ...and uses USB 1.1,


with a frame rate of
just 29 fps

> So, Sebastian had


to be creative in
replicating
MXWIǺIGXW

> Sebastian’s LED


Cube featured in
The MagPi #100

> It has since been


converted into an
EVXMǻGMEPǻVITPEGI

Sebastian’s GB Interceptor board is based on Raspberry Pi’s


minimal hardware spec for the Pico, with added USB-C

Game Boy Interceptor magpi.cc 21


PROJECT SHOWCASE

Capture the gaming action

The Interceptor works “like an emulator on


01 rails” and executes the same instructions
that the Game Boy receives from the cartridge to
reproduce what the Game Boy writes into its
video RAM.

The GB Interceptor Class device, it does not need a driver and just
can even be used as a
webcam, as Sebastian works on Linux, Windows, and Android. It works
demonstrates
with macOS too, though Sebastian says he still
experiences some issues with M1- and M2-based
Macs. It can even make use of the Game Boy’s
camera and function as a webcam.

Snug inside a 3D-printed case, the RP2040 The design and


02 emulates the Game Boy’s graphics unit and
renders images. “It works almost perfectly in 98% of implementation came
the games tested,” says Sebastian.
together quickly
Sebastian had previously worked on a cartridge
using the ESP8266 microcontroller, which had the
MPYPʭ_ZQBT1TM`_bL^QL]_ZZ`YOP][ZbP]PO
to deal with the Game Boy’s 1MHz bus speed
(XLR[TNNbTʭRMNL]_). He had also undertaken a
Raspberry Pi Pico project using its programmable
IOs. Using RP2040 made sense since he didn’t
need wireless connectivity for the Game Boy
Interceptor, whereas the PIOs were adept at
reading bus data leaving the CPU free to pick up
bus events at its own pace. This, plus the fact he
uses Raspberry Pi “a lot”, meant the design and
However, Sebastian had to overclock the
03 RP2040 to 250MHz to get it to work. The
implementation came together quickly. The sole
NSLYRP^Q]ZXST^ʭ]^_aP]^TZYbP]P_ZNZ]]PN__SP
Interceptor is currently limited to classical Game Boy
games since Game Boy Color games use twice the orientation of some of the LEDs and a switch to
clock speed. USB-C which is useful for indicating whether the
2LXP-ZdT^ZYZ]Zʬ

22 magpi.cc Game Boy Interceptor


Escalate your controller
design in style
Fully configurable universal case system- the perfect fit for all your
application needs
Every panel on the UCS enclosure range can be customised enabling you to
create your own individual stylish design easily.
With optional wall, desk & DIN rail mounting adaptors the range is available
in 2 colours, 4 sizes & 2 heights ensuring you’ll find the right enclosure for
your next project.

For more information visit https://phoe.co/ucs-rpi-uk


PROJECT SHOWCASE

Aquarium
dosing pump
There’s something fishy about this fabulous project,
but that’s the whole point, as David Crookes explains

K
eeping corals healthy is a tricky task. As _`MPbSTWP[]PaPY_TYRMLNVʮZb>Z`]NTYR_SP
well as requiring the right temperature [`X[^LYO_SP]PWLd_ZZV5ZPLQPbSZ`]^3PbL^
LYO[]Z[P]L\`L]T`XWTRS_TYRNZ]LW^YPPO _SPYLMWP_ZOP^TRYLNL^P`^TYR/XZOPWWTYR
LMLWLYNPOSPLW_SdOTP_LYOPc_]PXPWd[]PNT^P ^ZQ_bL]PXL[_SPbT]TYRLYOPWPN_]ZYTN^ZY[L[P]
bL_P]NSPXT^_]d5ZP>_TʬbSZVPP[^NZ]LW^LYO ^ZWOP]L[]Z_Z_d[PLYOb]T_P_SP^ZQ_bL]P
XLN]ZLWRLPTY" WT_]PLYOWT_]P^LW_bL_P]
_LYV^T^Q`WWdLbL]PZQ_ST^ɭ/Z^TYRaL]TZ`^ Good dose
TZY^^`NSL^NLWNT`XLYOXLRYP^T`XL^bPWWL^ ɭBSPYdZ`M`dLNZXXP]NTLWOZ^P]dZ`ɪ]P^_`NV
Joe Stiff
MAKER

Z_SP]NSPXTNLW^T^YPNP^^L]dbSPY_LVTYRNL]PZQ bT_S_SPNZX[LYdɪ^[]Z[]TP_L]d^ZQ_bL]PbSTNST^
NZ]LW^ɮSP^Ld^ `^`LWWdLbQ`WLYO[LTYQ`W_Z`^PZ]^TX[WdOZP^Yɪ_
Joe’s life is powered
=L_SP]_SLY[LdLYdbSP]PMP_bPPYn#LYO bZ]VSLWQ_SP_TXPɮ5ZP^Ld^ɭ?ST^[]ZUPN_ʭ_Xd
by Raspberry Pi at
this point and it’s part n ZYLNZXXP]NTLWOZ^TYR[`X[SZbPaP]SP `W_TXL_PLTXbSTNST^_ZM`TWOPaP]d_STYRQZ]_SP
of the ecosystem OPNTOPO_ZXLVPZYPSTX^PWQ-d`^TYRL=L^[MP]]d L\`L]T`XXd^PWQQ]ZX_SP70/ʭc_`]P^_Z_SP
of his home. He ;T;TNZXTN]ZNZY_]ZWWP]LWZYRbT_SRZZO\`LWT_d OZ^P]LYO_PX[P]L_`]P[3XZYT_Z]TYR^d^_PXɮ
promises more
projects are coming ]PWLd^LYO[`X[^SPSL^MPPYLMWP_ZN]PL_PL 5ZPb]Z_P_SP[]ZR]LXTY8TN]Z;d_SZYLYO
soon! O]TaP]QZ]LQ]LN_TZYZQ_SPNZ^_ɧU`^_nTY_Z_LW LQ_P]NLWTM]L_TYRPLNSZQ_SPOZ^P]ɪ^_bZ[`X[^
mustardcorner.com 3PSL^LW^ZOZYP^ZbT_SZ`_NZX[]ZXT^TYRɭ;]TNP _Z]`YL__SP^LXP^[PPOSP^P_T__Z]`YPaP]d 
bL^Yɪ_LWTXT_TYRQLN_Z]L_LWWMPNL`^P_SP^P[L]_^ XTY`_P^?ST^LWWZbPOL^XLWWLXZ`Y_ZQNLWNT`X
L]P]PWL_TaPWdNSPL[ɮSPPc[WLTY^ SdO]ZcTOP_ZʮZb$!_TXP^LOLdQ]ZXZYP[`X[

Nothing fishy
,W_SZ`RSSPbL^LWbLd^VPPY_ZVPP[NZ^_^ When you buy a
`YOP]n_SPXLTY]P\`T]PXPY_bL^_ZN]PL_P
LOPaTNP_SL_NZ`WOOZ^PLNZYʭR`]LMWPLXZ`Y_
commercial doser, you’re
ZQNSPXTNLW^LNN`]L_P_ZbT_STY XTWWTWT_]P^
Z]WP^^3PLW^ZYPPOPOPLNS[`X[_Z^P[L]L_PWd
stuck with the company’s
Z[P]L_PLNZYʭR`]LMWPY`XMP]ZQ_TXP^PLNS proprietary software
OLd^Z_SL_OTʬP]PY_WT\`TO^NZ`WOMP`^POL_
OTʬP]PY_\`LY_T_TP^
ɭ?SPOZ^P]YPPOPO_ZMPWZbaZW_LRPMPNL`^PZQ PY^`]TYR XWZQ_SPNSPXTNLWbZ`WOMPOZ^PO
T_^[]ZcTXT_d_ZbL_P]LYO4bLY_POT__ZMP^XLWW ZYLOLTWdML^T^?SPZ_SP][`X[bL^^P__ZOZ^P
LYOYPL_^Z_SL_T_NZ`WORZYPL]LMPL`_TQ`W]PPQ Z_SP]NSPXTNLW^^`NSL^LXTYZLNTO^LYOQZZO
_LYVLYOYZ_WZZVZ`_ZQ[WLNPɮ5ZPNZY_TY`P^ɭ4 bSPYYPPOPO
LW^ZYPPOPOT__ZMP]P[LT]LMWPLYOPL^d_Z_LVP 4_ɪ^NP]_LTYWdPʬPN_TaP5ZP^Ld^_SL__SP;TNZ
L[L]_TQYPNP^^L]d_Z]P[WLNP_SP[L]_^?ST^T^bSd NZY_]ZW^_SP]PWLd_`]YTYR_SP[`X[^ZYLYOZʬ
4NSZ^P[L]_TN`WL][P]T^_LW_TN[`X[^DZ`NLY_LVP bT_S^TX[WPNZOP^PY_aTLZYPZQ_SP2;4:[TY^
Z`__SP_`MTYRLYO]P[WLNPT_bT_SYPb_`MTYRaP]d ,QPbQ`YN_TZY^NLWN`WL_P_SPOZ^LRP_TXTYRLYO
PL^TWdQ]ZX_SPQ]ZY_ɮ _SPNZOPU`^_WZZ[^^WPP[TYRTYMP_bPPYOZ^TYR
;P]T^_LW_TN[`X[^L]PWZbXLTY_PYLYNPLYOPL^d ɭ8dYPc_^_P[bTWWMP_Z`[R]LOP_Z=L^[MP]]d;T
_Z^_P]TWT^P?SPd`^P]ZWWP]^Z]^SZP^_ZPʬPN_TaPWd ;TNZ BɮSP^Ld^ɭ4bTWW_SPYb]T_P^ZXPbT]PWP^^
XL^^LRPLʭcPOLXZ`Y_ZQNSPXTNLW_S]Z`RS_SP 7,9NZOP_ZNZY_]ZWT_aTLXdXZMTWP[SZYPɮ

24 magpi.cc Aquarium dosing pump


PROJECT SHOWCASE

The pumps are set to turn


SRJSVEWTIGMǻGEQSYRXSJ
time: one second of dosing
administers 1.43 ml of liquid.
For small doses, the pump can
be set for less than a second!

Quick FACTS
> 8LIHIZMGI
TVSZMHIWQMGVS
doses of
a chemical
Tubes can be easily attached to
A Raspberry Pi Pico microcontroller the front of the pumps which, > It’s being used to
sits within this beautiful 3D-printed in turn, are connected directly keep coral healthy
case. The settings are currently being to a 5V power supply. A signal in a tank
changed by connecting the doser to a from the Raspberry Pi Pico is
laptop, but Joe wants to go wireless needed to turn the switch on > It could also be
used to water
plants automatically

> It could be adapted


into a water
GLERKIcW]WXIQ

> Joe is considering


WIPPMRKVIEH]
QEHIcHIZMGIW

Joe printed his case using a Voron 2.4 3D printer


8LIHSWMRKLIEHWGSWXNYWXfIEGL&HH7EWTFIVV]5M5MGSEfVIPE]ERHfSJ[MVMRK YWMRKKPMXXIVǻPEQIRXEPPS[MRKIRSYKLWTEGI
XYFMRKWSPHIVMRKTPEWXMGERHWGVI[WERH]SYLEZIEZIV]GLIETHSWMRKTYQT for wiring and room for a charging port

Aquarium dosing pump magpi.cc 25


PROJECT SHOWCASE

Tank Driving
Simulator
A Swiss tank museum is home to an historic training vehicle that has
been upgraded with a Raspberry Pi. Rosie Hattersley finds out why

A
lthough it has become known by its any components that failed. Their aim was to
German moniker of FASIP (shorthand replace each item “as faithfully as possible.”
for Panzerfahrsimulator), the vehicle Sadly, the original 1970s MITRA-125 computer
was actually developed in France in the 1970s, which controlled almost every aspect, including
explains Gerold Handschin, one of the trio from responding to the displacement sensors and
the tank museum who set about saving the controlling the simulator’s movements, lamp,
unlikely survivor. “A total of eight tracks were and displays, was defective. This central control
used to train prospective tank drivers, initially for unit clearly needed to be replaced. “Fortunately,
the Centurion tank and later for the Panzer 68 and the program in operation on the MITRA-125 was
Leopard 2,” Gerold relates. The trainee driver sat available as a hard copy. So we decided to replace
in a replica driver’s cab, with a screen displaying the old computer with a new system,” says Gerold.
the terrain he needed to negotiate. Hydraulics The only issue: it was all in French. Scanning in
under the cab replicated the tank’s movements, the several-thousand-page document and using
while a camera on a trolley travelled the length text recognition software helped, but in some cases
of the 12 m-long detailed terrain model. The the type had faded so much that the characters
combination of responsiveness to the driver’s could not be recognised. “We sometimes had to
steering movements and on-screen display created approach the correct parameter values by trial and
a realistic driving experience that predated arcade error,” says Gerold, but new C-based simulator
games by several years. In addition to the large software for Raspberry Pi was eventually written.
terrain model and hydraulic system, various
Gerold Restoration challenges
MAKER

computers were required to operate the system.


Handschin, The decision to use Raspberry Pi 3B+ as the new
Michael Ultimate upcyclers central control computer was down to its GPIO, its
Salathé,
In 2004, the Military Museum saved one of the ^TePLYO_SP[]TNP=L^[MP]]d;TbL^ʭ__POZY_ZL
& René
FASIP systems in Thun from being scrapped, and new adapter board via its interface slot, replacing
Demarmels
rebuilt it at the museum site in the village of the interface board for the MITRA-125. The
The museum Full. But, after several years, various defects in original power supply units were in poor condition
team, including the antiquated computers and in other electronic and voltages were no longer stable, so modern
electronics components had led to its apparent end. The Full ^bT_NSTYR[ZbP]^`[[WTP^bP]Pʭ__POɭ?SPYPb
specialist and
museum’s dedicated helpers, Gerold Handschin, adapter board contains multiplexers to connect
technician Gerold,
were determined Michael Salathé and René Demarmels, could not all the signals needed for the Raspberry Pi GPIO,”
to salvage the resign themselves to this. Instead, they began explains Gerold. It was also used to adjust the
50-year-old FASIP.
a thorough analysis of how the FASIP system 3.3 V voltage of the GPIO to the 5 V TTL logic of the
magpi.cc/fasip bZ]VPOTOPY_TʭPOOPQPN_^LYOR]LO`LWWd]P[WLNPO existing systems.

26 magpi.cc Tank Driving Simulator


PROJECT SHOWCASE

The FASIP tank simulator


challenges the trainee
driver to master eight
HMǺIVIRXXIVVEMRW
beamed to the cab from
a camera trained on the
scenic model layout
Originally running
on custom software
written for the
MITRA-125 computer
that powered it in the
W+&.5RS[VYRW
code written in C

Quick FACTS
> The team had four
custom circuit
boards made...

> ...just in case the


This Raspberry Pi-controlled tank simulator
setup emulates the bumps needed
and turns the driver replacements
encounters thanks to cameras in the future
and sensors that follow the
tank simulator’s route > Overall, the project
cost 820 Swiss
francs, including
spare parts

> The original


instruction manual
was in French

> So, they scanned in


the text and used a
translation tool

Tank Driving Simulator magpi.cc 27


PROJECT SHOWCASE

View from inside the


FASIP tank simulator
control cab with live
terrain updates as the
driver navigates

Sensors and camera


hover above the test
track, feeding back
to the FASIP tank sim
control deck

28 magpi.cc Tank Driving Simulator


PROJECT SHOWCASE

Tank training

The 1970s MITRA-125 custom code and


01 hardware were replaced with a bespoke
circuit board to control the cameras and respond to
feedback from them and the track sensors.

The team looking

A realistic driving over the scale


model that the tank 02
The corroded old network and IOs needed
to be replaced with components capable of
‘drives’ around
experience that predated delivering a constant voltage.

arcade games
The IO plug-in unit’s original boards, XERUDI
and XUCI, were replaced by the new board
and Raspberry Pi too, but it was a challenge to
work out the correct timing when driving the
components of the interface plug-in unit. The
overhaul of the simulator was completed at the
end of July 2020. Since then, it has been possible
The original tank sim rig needed a complete
to drive the Panzer 68 simulator through the 03 overhaul, custom circuit board and adapters,
grounds at the Swiss Military Museum in Full plus reprogramming in C.
by appointment.

Tank Driving Simulator magpi.cc 29


PROJECT SHOWCASE

Progress Bar
Do you tend to keep an eye on the clock during the working day?
Nicola King learns how watching for a rainbow is far more enjoyable

W
e have all, let’s be honest, clock- admittedly “tricky”, says Martin, but the gcalcli
watched at some point in our working command-line tool (magpi.cc/gcalcli) handles all
lives. Well, friends of The MagPi, Martin the Google authorisation.
>[PYOTʬLYOALYP^^L-]LOWPdSLaPNZXP`[bT_S The duo used the Wi-Fi-capable Pico W because
a little idea that might improve your working ɭ]`YYTYRLQ`WWdʮPORPONZX[`_P]_Z_`]YZYL
day, bringing a colourful rainbow display at few lights would be overkill,” says Martin. “It
close of business, where once there was the face needs to connect to the internet, so we [opted for]
of a benign and mundane clock. This physical ;TNZB4_bL^_SPʭ]^__TXPbPɪaP`^POZYPLYOT_
Progress Bar (magpi.cc/progressbar) could be was surprisingly easy.”
U`^_ _SP_TNVP__ZM]TRS_PY`[dZ`]ZʯNPLYO He and Vanessa are always open to suggestions
gladden your soul. for tweaks – when someone saw the GitHub
Inspiration, Martin tells us, came from “a page and wanted to use it in a school without the
fondness for clocks and way too much time Google Calendar link, they were keen to help, “The
Martin looking at progress bars. As a random bit of pub
MAKER

Spendiff _]TaTLɳ_SP[]ZR]P^^ML]bL^ʭ]^_`^POWZYRMPQZ]P
& Vanessa computers were invented – back in the 1800s.” It needs to connect to the
Bradley >ZAPPMɪ^Q]P^S_LVPZY_SPNZYNP[_MPRLY
percolating and, armed with a Raspberry Pi
internet, so we opted
Martin is a
mathematical
modeller who
Pico W, a metre-long piece of frame from a
SL]ObL]P^SZ[L[WL^_TNWTRS_OTʬ`^P]LYOL
for Pico W
left the UK for one-metre, 144-LED, 5 V addressable LED strip,
Switzerland, and
the duo set to work. idea of a classroom getting to see a rainbow at
a fan of FOSS and
tech that serves SZXP_TXPbL^^`ʯNTPY_WdL[[PLWTYR_ZXLVP`^
users, rather than A work in… progress ]PʭYP_SPNZOPɮ
the people who Martin and Vanessa quickly put the hardware
made it. Vanessa
is new to coding together, wrote some MicroPython code, and Easy as Pi
and a constant then connected Pico W, which is the brain of the One of the great features of the Progress Bar is
source of weird and Progress Bar. “Pico W connects to the internet its relative simplicity, with very little needed in
KSSHcMHIEW
LYO ʭYO^Z`_bSL__TXPT_T^ɮ]PaPLW^8L]_TY terms of hardware, making it an ideal project for
veeb.ch “After that, it checks the working hours (that any new makers. “It is a nice little example that
you put into the code). It just does a little bit of involves very little soldering and relatively simple
L]T_SXP_TN_ZʭR`]PZ`_TQdZ`ɪ]PL_bZ]VLYO code,” Martin highlights.
SZbQL]_S]Z`RS_SPOLddZ`L]P4_ɪ^_SPYPL^d_Z He and Vanessa have received highly positive
ʭR`]PZ`_SZbXLYdWTRS_^TY_SPF70/H^_]T[T_ feedback from the maker community – although
should turn on.” Martin recalls how one person did declare,
Cleverly, the pair also incorporated a link to ‘imagine hating work so much that you need
Google Calendar, so any appointments are shown _ZVPP[WZZVTYRL_ZYPZQ_SP^Pɪ?SP[LT]L]P
on the bar (and constantly updated through the []LRXL_TN%ɭ4QMPTYR[WPL^POT_ɪ^SZXP_TXPT^L
OLdLYO_SPML]LW^ZʮL^SP^L_L[[ZTY_XPY_ crime, guilty as charged!” They use their Progress
time as a vibrant reminder, although Martin -L]PaP]dOLdSTRSWTRS_TYRɭ?SP]Pɪ^LWZaPWd
envisages that maybe “a Knight Rider-style sweep element of it gently reminding you to work and
would be better!” Linking to Google Calendar was when to down tools for the day.”

30 magpi.cc Progress Bar


PROJECT SHOWCASE

;LIRXLIFEV
reaches the end, you
know it’s home time!
The LED strip is
housed in a wooden
JVEQIǻXXIH[MXLE Quick FACTS
TPEWXMGPMKLXHMǺYWIV
> Martin and Vanessa
spent less than
&7EWTFIVV]5M5MGSc; eight hours on
fetches the time the project
from the internet and
controls the LEDs > Outside of working
hours, no lights
EVIcWLS[R

> You can create your


own version for
around $30

> The code is on


GitHub: magpi.cc/
Adding a plastic hometime
HMǺYWIVWXVMTWSJXIRW
and blends the light
from the LEDs > The code can be
IHMXIHXSVIǼIGX
Fitting the Progress
Bar to the top of your own start/end
a whiteboard time for each day

The colours of the rainbow signify that work time is over

Progress Bar magpi.cc 31


PROJECT SHOWCASE

BrachioGraph
A charmingly inaccurate plotter driven by Raspberry Pi draws the interest of Rosie Hattersley

M
any of us remember being shown, or Motion capture
even making, pantograph pen plotters Playing around with servos and Raspberry Pi was
from the days before graphing tools the entry point for Daniele’s plotting device project.
bP]P[L]_ZQL^_LYOL]OSZXPZ]ZʯNPNZX[`_TYR Moving them around was easy enough, but he was
feature set. Open-source computing guru keen to see a practical result: “What can we actually
Daniele Procida recalled just such a device when do?” With nostalgia for pantographs and XY aerial
considering a low-tech example of what Raspberry plotters in common, Daniele explains he found
Pi could be used for while planning for the PyCon “their ability to reproduce something we do with
Daniele
MAKER

Namibia conference. The result, BrachioGraph, our hands intrinsically fascinating. When you see a
Procida which sketches portraits and reproduces images pen moving around, it looks like it has a purpose”.
Daniele is head
of objects, was an instant hit, inspiring a fan Although servo motors can be used to drive
of engineering at following of keen makers. a device along straight lines, translating the
Canonical, and a Noting the contrast between the resources movements and hand-drawn lines on a page is
regular presenter at
typically available at conference events in the UK more about angles. The question, Daniele says,
Python conferences
around the world. and Europe and those in African host nations, was whether he could turn movements into lines
Daniele says: “It’s one thing doing things with on a page. “Of course you can, because your own
magpi.cc/
brachiograph robotics if you’ve got access to 3D printers, laser arm, if you’re drawing with a pen, also doesn’t
N`__P]^LYOZʬ_SP^SPWQ[L]_^LYONZX[ZYPY_^& have motors that go in straight lines. It just uses
quite another if you’re an undergraduate at the angles.” He began by modelling the design on
University of Namibia, or a high school student that of a pantograph, which faithfully mimics the
and probably have to share a laptop or computer.” movement of the human arm. A BrachioGraph,
Combined with Daniele’s own interest, but lack meanwhile is an ‘arm plotter’.
of experience in robotics, he decided “to do
^ZXP_STYR_SL_bL^L^LʬZ]OLMWPL^[Z^^TMWPM`_ Copycats encouraged
From bitmap to plot also meaningful and also accessible, that didn’t The BrachioGraph can be set up to run on its
via vectorisation, the
require an absolute minimum of materials and own, making it an ideal conference exhibit. “At
Prague Conservatory
concert hall knowledge and facilities.” one conference, I was very embarrassed because I

32 magpi.cc BrachioGraph
PROJECT SHOWCASE

Servo motors help


the BrachioGraph
draw lines at
WTIGMǻGERKPIW

Instructions received
and processed by
Raspberry Pi translate
to actions performed by
the pen, held securely
MRTPEGIF]ETIK

Inner and outer arms plus a Quick FACTS


‘shoulder’ motor enable free
movement suitable for free- > Daniele unveiled
LERHWOIXGLMRK his BrachioGraph
at PyCon Namibia
in 2019
Given an image to
copy, the BrachioGraph
is able to reproduce it
> It was “a big hit”,
attracting a
large crowd

The most important thing is not that he > Everyone was

built this thing, and it works, but that it’s amazed and
wanted their

reproducible by other people own portraits

> Daniele has taken a


BrachioGraph
to every
borrowed a table in the sponsors’ hall and just left
conference since
something running, plotting.” When he returned,
the crowd was three or four deep around the table > There’s a fun
where the BrachioGraph was in action, taking away brachio simulator
all the attention from sponsors who bought tables. you can try at
Daniele says that, after lots of design drafts brachio.me
and experimentation, the most important thing is
not that he “built this thing, and it works,” but
that it’s reproducible by other people and with
household materials such as ice cream sticks, or
cardboard and pencil, or clothes.
“The nicest thing for me is that, every so often,
somebody will email me and say, ‘Oh, it was my
12-year-old niece’s birthday and, when I was
visiting, I took a Raspberry Pi and three servo
The project builds on
motors, and then we spent the weekend ‘making
similar principles to those
a BrachioGraph’.” of a pantograph plotter

BrachioGraph magpi.cc 33
PROJECT SHOWCASE

Herbie_Bot
Keeping weeds at bay is no easy feat – unless you have a robot to help you.
Rob Zwetsloot slaps on some suntan lotion and has a look


H
ave you ever lugged around the yard “These small battery-operated spray wands are
a gallon jug of lawn-safe herbicide aP]^L_TWPLYO4_SZ`RS_T_bZ`WOMPPL^d_Zʭ_
with a battery-powered spray wand?” into the robot. Unfortunately, my welder was
asks Russ Hall. He’s the creator of many lawn- stolen from me, so I used wood for the bracing
keeping robots, and now is battling against and construction, built on the steel rover chassis
pesky weeds. that I had from years ago.”
“After a while, the hands, arms, and eyes tire BPLN_`LWWd\`T_PWTVP_SPWZZVZQ_SPʭYT^SPO
of the repetition; it’s work!” Russ continues. “I product – it’s like a classic Rube Goldberg
Russ Hall
MAKER

remembered my yardbot/mowbot, and thought I machine you’d see in a cartoon, in its own way.
An electronic
could rig up a sprayer with a camera and AI.” Not many Rube Goldberg machines employ
technician for the Russ had previously built a mapping robot modern machine learning though.
US Postal Service, for inside his house using Raspberry Pi, and ɭ?ST^bL^Xdʭ]^_,4[]ZUPN_^Z4SLOLWZ__Z
servicing high-speed
decided to use that instead of the ZED camera learn,” Russ continues. “However, with the OAK
mail processing
machines. and Nvidia-powered computer. “Raspberry Pi camera and its Movidius chip, I felt it would work
was easier to work with, as well as being less well with Raspberry Pi, since the AI is handled in
magpi.cc/
herbiebot expensive,” he says. the camera. To start, I used a standard routine
in the Raspberry Pi to take photos of the lawn
Yard work and weeds by the robot, because it’s important
“Working with hardware is a fun challenge to me to train the AI with photos that are identical
LYO_ST^]ZMZ_bL^YZOTʬP]PY_ɮ=`^^Pc[WLTY^ to the video stream that it will be expected to
[]ZNP^^4`^PO=ZMZʮZb_Z[]P[L]P_SPTXLRP^
and YOLOv5 to do the AI training (on Google
servers), and it wasn’t too hard. Luxonis has a
neat conversion tool online, to make the software
blob that is loaded in the camera.”

Weeds: terminated
The video of Herbie in action can be viewed at
magpi.cc/herbiebot, and it looks great at work
– precisely targeting weeds and giving them a
quick spray.
“If the weeds are too heavy, it can’t hit them
all, of course, since the robot is constantly
moving forward,” Russ says. “Testing with blue
OdPTY_SPSP]MTNTOPNZYʭ]XPO_SPLNN`]LNd
and proper operation. I used 6 VDC for the
sprayer servo so that it is quick. The 5 VDC for
the sprayer pump comes from the USB power.”
Currently, Herbie is not fully automated to cover
the yard, but it’s in the works. Maybe one day the
It’s much easier to get a robot to lug around a big bottle of herbicide all-in-one lawn-keeping robot will be reality.

34 magpi.cc Herbie_Bot
PROJECT SHOWCASE

A camera scans the lawn to spot


weeds using a model trained on
the grass it’s scanning

Quick FACTS
Parts of the rover are
powered by a car battery, > Russ builds robots
This battery-powered with his kids
with several other battery
herbicide spraying
sources employed
wand is controlled > Herbie is powered
via Raspberry Pi by Robot Operating
System (ROS)

> The spray wand has

It’s important to train 15 set positions...

the AI with photos that > ... and is only 12


inches (~30 cms)

are identical to the video behind the camera

stream that it will be > It runs on a


Raspberry Pi 4

expected to process

Warning!
Power tools and
herbicides
This project involves
woodworking which can
be very dangerous, and
The spray wand herbicides that can be
is attached to poisonous to humans.
a servo that Exercise caution if you
Raspberry plan to work with both.
Pi moves to
Blue dye was used to test the accuracy of the model detected weeds magpi.cc/diysafety

Herbie_Bot magpi.cc 35
PROJECT SHOWCASE

CinePI
Using Raspberry Pi as a high-end film camera is not as
weird as it may sound. Rob Zwetsloot gets the shot

W It’s competitive with


henever a new Camera Module, or
updated software for existing camera
hardware comes out, we dream of all
the cool things we could do with it. While custom
cameras that cost orders
cinematography and automated processes are high of magnitude more than
on our list, making a cinematic-quality camera is
where Csaba Nagy went with CinePI. the parts required to build
“CinePI is an open-source project that can
Csaba Nagy a CinePI
MAKER

transform a Raspberry Pi into a high-end cinema


A student at the camera,” Csaba tells us. “Its standout feature is
University of the ability to record 2K RAW Cinema DNG video at colour theory, and other related concepts, which
Alberta, who is also frame rates up to 50 fps with 12-bit colour depth. allowed me to gain a deeper understanding of
a maker exploring
the intersections of
This makes CinePI an ideal camera for capturing camera systems and how they function.”
ǻPQERHXIGLRSPSK] cinematic-quality footage in various projects, Using this knowledge, Csaba went about trying
among his ^`NSL^^SZ]_ʭWX^NZXXP]NTLWbZ]VLYO to build a low-cost, open-source camera that
other passions.
YouTube videos.” everyone could use.
magpi.cc/ 2K is basically 1080 p. However, at a 12-bit
csabanagy
NZWZ`]OP[_S_SL_T^L^_ZYT^STYRɧXZ^_^_`ʬdZ` Software first
see will be at 8- or 10-bit colour. Csaba chose Raspberry Pi for this project due to
“Almost a decade ago, I began using a community and software support that comes with
professional video camera, the Blackmagic T_ɧL[[L]PY_Wd^ZXPZQ_SPNZOPT^ML^POZY^_`ʬ
.TYPXL.LXP]LQZ]XdʭWXXLVTYRSZMMdɮ _SL_^_L]_POWTQPZYZʯNTLW[]ZUPN_^LYO_`_Z]TLW^
Csaba continues. “The steep learning curve that “The development/build process for the most
accompanied the camera forced me to gain an recent version of the CinePI began in September
in-depth understanding of the processes involved of 2022, where initially the core software was
in creating cinematic images, aspects that most being tested/developed,” Csaba says. “The
consumer and amateur camera gear obscure from physical/hardware design quickly came together
users in the name of convenience and simplicity. in January of this year, where the body was
As a result, I spent countless hours learning about 3D-printed and all bits of hardware were
image sensors, codecs, bit-depth, dynamic-range, L^^PXMWPO_ZRP_SP]TY_Z_SPʭYLWPYO]P^`W_

36 magpi.cc CinePI
PROJECT SHOWCASE

CinePI records Quick FACTS


incredibly high-quality
RAW footage that is > Future exposure
great for editing assist tools would
include histograms,
zebras, waveforms,
and more

> For the


cinematography
FYǺW(MRI5.
ǻPPWEKET
between Apertus
&\MSQc'IXEƾ

> ƾERH(ERSR
cameras with
Using a Raspberry Pi HQ Magic Lantern
Camera and a good lens ǻVQ[EVI
allows for great footage
> The 12-bit colour
depth allows for
extensive colour
grading in
post-production

> .XQEOIWYWISJ
E7EWTFIVV]5M
-6c(EQIVE
This 3D-printed case holds
everything in and is designed
to be used like a camera

ɭ?SP]PbP]PXLYdXZOTʭNL_TZY^_SL_bP]P
made to individual components in order to have
all the hardware co-operate with each other.
The greatest hurdle to overcome was the use of
a HyperPixel 4.0 Square display which utilises
nearly every GPIO pin of Raspberry Pi, meaning
all extra hardware would need to interface
with Raspberry Pi using a single I2C bus. This
included an RTC, an I2C I/O expander, and power
management board, which all had to connect via
this single bus.”

Quiet on set
The result not only looks very cool but is
incredibly functional, being able to record
RAW video at 50 fps and 12-bit colour depth –
]PXPXMP]_SL_ʭWX^]`YL_ Q[^^Z_ST^XLVP^
=SYLEZIJYPPEGGIWWXS7EWTFIVV]5MTSVXWEW
QZ]LYPcNPWWPY_bZ]VTYRʭWP well as other specialist recording ports

CinePI magpi.cc 37
PROJECT SHOWCASE

Footage of an
aquarium has been
used in tests

All the advanced


options are surfaced
for you to tweak with

Shadow and colour


data is available in
RAWs, so you can
change the look of
your footage easily

38 magpi.cc CinePI
PROJECT SHOWCASE

#TVJQWUGƓNOKPI

It’s not quite as easy as point-and-shoot, but


01 that’s by design! Using the touchscreen, you
ϱĹÏŅĹĀųĵƼŅƚųŸåƋƋĜĹčŸÆåüŅųåŸƋ±ųƋĜĹčƋŅųåÏŅųÚ
with the physical button up top.

“It delivers better image quality than the Not only is it very
functional, it also looks
Raspberry Pi’s built-in image processing engine, great in our opinion
which uses H.264 compression,” Csaba explains.
“Users can customise the camera with their
own external sensors, buttons, HATs, and I/O.
Real-time image monitoring and adjustments
are possible with an attached HDMI monitor or
compatible LCD touchscreen… CinePI records
video as hundreds of frames in Adobe Cinema DNG
format, which can be edited using software like 8ĜĬĵĜŸųåÏŅųÚåÚeœ±ƋåƻƋųåĵåĬƼĘĜčĘ
DaVinci Resolve.
02 ŧƚ±ĬĜƋƼرĬĬŅƵĜĹčƼŅƚƋŅÏŅĬŅƚųěčų±ÚåĹŅųĵ±ĬĬƼØ
ŅųåƴåĹŸåƋƼŅƚųŅƵĹŸŞåÏĜĀÏÏŅĬŅƚųƋŅĹåüŅų
“The test footage I have captured demonstrates
your project.
_SL__SPMT_=,BNZOPN]P_LTY^L^TRYTʭNLY_
amount of colour information in the shadows and
highlights, resulting in superior quality compared
_ZbSL__SP=L^[MP]]d;TNLYZʬP]MdOPQL`W_ɳ
It’s competitive with cameras that cost orders of
magnitude more than the parts required to build
a CinePI.”
Csaba is not done yet, and wants to add a larger
sensor, a HAT that handles a lot of the extra
Q`YN_TZY^LYOPc[Z^`]PL^^T^__ZZW^ɧ^_`ʬ_SL_T^
beyond our understanding in general, and beyond
Csaba’s skills to currently implement. You’ll need to play back and edit on a PC, but
“[I’m] always looking for more people to get
03 ƋʱƋűŸ屟ƼåĹŅƚčĘƋŅÚŅĜüƼŅƚƚŸå±Ž„ƐţLj
ŸƋĜÏĩƋŅųåÏŅųÚŅĹƋŅĜĹƋĘåĀųŸƋŞĬ±Ïåţ
TYaZWaPObT_S_SP[]ZUPN_ɮSPʭYT^SP^ɧSPLO_Z
cinepi.io if you want to help.

CinePI magpi.cc 39
SUCCESS STORY

SUCCESS STORY magpi.cc/success

Yoto Player
The development possibilities of Raspberry Pi enabled
an appealing, child-focused audio player to take shape

Y oto Player provides a great experience


that children own and control, without
introducing more screen time. Thanks to
Raspberry Pi and the support and expertise of an
approved reseller, it’s a UK success story.
based learning environment came about. But
digital entertainment for children seemed to be
predominantly based around phones and tablets,
with young children increasingly spending time
on platforms such as YouTube and on dedicated
Ben Drury and his Yoto co-founder Filip Denker apps for kids. Drury and Denker’s key idea was
both have backgrounds in digital music services. to develop an audio entertainment product that
Just as they were looking to set up a new venture, children could use without the need for yet more
MZ_SbP]PMPNZXTYR[L]PY_^QZ]_SPʭ]^__TXP?ST^ screen time.
led them to consider how young children interact
with technology, and they decided to focus on a THE SOLUTION
product that allowed kids to access technology “Yoto Player is designed to be a physical way
without using a screen or needing a parent to that kids can be in control of their own listening
operate it for them. experience using physical NFC cards,” explains
Drury. “Kids enjoy collecting and ordering
THE CHALLENGE cards – so it seemed an obvious use of them for
“Audio is better than screen time for inspiring storytelling and podcasts.”
creativity and imagination,” Drury says of the Previously, Drury had used Raspberry Pi for
company’s approach. With children at Montessori monitors and servers, but not for standalone
nurseries, the idea of a physical interaction- connected devices. He began using the Pimoroni

40 magpi.cc Yoto Player


SUCCESS STORY

8×8-pixel Unicorn HAT (later, a 16×16-pixel one)


and, based around this, hashed out a product form
in a makerspace workshop. They also “wrote loads
of code to run on Raspberry Pi and server-side,
and also the Yoto app for iOS and Android.”
R&D and PCB engineering and design for the
ʭ]^_[]ZO`N_L^bPWWL^L^^PXMWdbP]PLWWOZYP
TY_SP@6?SPʭ]^_[]ZO`N_T_P]L_TZYbL^ML^PO
around Raspberry Pi 2, switching over to Pi Zero
and eventually Raspberry Pi Zero W when it
launched – a “huge thing” for Yoto, as it meant
they could build a wireless version of their

Without Raspberry Pi, we


wouldn’t have been able to
build it in the first place
storytelling player. “We were concerned by the
availability of the Pi Zero W boards, as they were of Enid Blyton’s
quite new at the time, but we took the risk and we extensive bibliography,
were able to secure supply,” says Ben. are among the most famous.
There are also phonics cards and 100-word
WHY RASPBERRY PI? aT^`LWN`PNL]O^QZ]WPL]YTYRaZNLM`WL]dQ]ZXʭaP
Drury is a long-time enthusiast of British other languages. With multilingual children, Ben
computing and engineering, with fond memories and Filip are strong advocates for early language
of his BBC Micro, Acorn, and Archimedes learning. They see Yoto Player as the sort of device
computers. He was intrigued from the outset that can help children who don’t have such ready
about Raspberry Pi, and was an early investor in access to a wide vocabulary at home to begin
Pimoroni, a long-standing Raspberry Pi Approved acquiring a broader verbal language base.
Reseller which later became Yoto’s development Raspberry Pi was “absolutely crucial” to the
partner. This was an inspired move, adding development of Yoto Player, says Drury. “Without
hardware know-how to Denker and Drury’s Raspberry Pi, we wouldn’t have been able to build it
expertise in software and user interfaces. TY_SPʭ]^_[WLNPɮ
/PNPXMP]"^LbDZ_Zɪ^ʭ]^_6TNV^_L]_P]
launch, with shipping of their initial run of 750
units in late 2018. A few issues with EMF leakage
meant some design tweaks were needed and the
DZ_Z_PLXbP]PLMWP_ZMPYPʭ_Q]ZX_SPT]^_]ZYR
well-established relationship with Pimoroni,
calling again on their technical expertise.

THE RESULTS
?SPʭ]^_DZ_Z;WLdP]XP_bT_S^`NNP^^WL`YNSTYR
with a starter pack of stories, including ones by
Roald Dahl, as well as blank cards for kids to
record their own stories onto the player’s 8GB SD
card. Capturing the imagination of Roald Dahl’s
grandson early on – he’s now a Yoto board member
– cemented interest in the device’s concept, and a
whole slew of children’s publishers followed. Julia
Donaldson’s beloved ?SP2]`ʬLWZ, as well as some

Yoto Player magpi.cc 41


SUBSCRIPTION

SUBSCRIBE TODAY
FOR JUST £10
Get 3 issues + FREE Pico W
Subscriber Benefits
FREE Delivery
Get it fast and for FREE

Exclusive Offers
Great gifts, offers, and discounts

Great Savings
Save up to 35% compared to stores

Subscribe for £10


Free Pico W
3 issues of The MagPi
Free delivery to your door
£10 (UK only)

+
Subscribe for 6 Months
Free Pico W
6 issues of The MagPi
Free delivery to your door
£30 (UK) £35 (USA)
£35 (EU) £45 (Rest of World)

Subscribe by phone: 01293 312193


Subscribe online: magpi.cc/subscribe
Email: magpi@subscriptionhelpline.co.uk
Subscribe for £10 is a UK-only offer. The subscription will renew at £15 every three months unless
cancelled. A free Pico W is included with a 6-month subscription in USA, Europe and Rest of World.

42 magpi.cc
SUBSCRIPTION

SUBSCRIBE TODAY AND GET A


FREE Raspberry Pi Pico W
Subscribe in print
today and get a FREE
development board WORTH

A brand new
RP2040-based
$6
Raspberry Pi Pico W
development board

Learn to code with


electronics and build
your own projects

Make your own


home automation
projects, handheld
consoles, tiny
robots, and much, This is a limited
offer. Not included
much more with renewals. Offer
subject to change or
withdrawal at any time.

Buy now: magpi.cc/subscribe

SUBSCRIBE
on app stores

magpi.cc 43
FEATURE

LEARN TO
WITH

Discover the joy of coding with our beginner’s


guide to Python 3 on Raspberry Pi

by Phil King

44 magpi.cc Learn to code with Python


FEATURE

I
n this crash course, we’ll take you through
the key principles of Python programming on
Raspberry Pi.
For this guide, we’ll be doing all our coding
in the Thonny IDE (integrated development
environment) in Raspberry Pi OS. An IDE is a
program that is used to create other programs.
You can create programs in any text editor,
but using an IDE makes life easier (especially
for newcomers).
From the desktop applications menu, select
Programming > Thonny. The Thonny IDE starts
up in simple mode by default. Along the top are You can save the program by clicking Save and Hello world: the
simplest of programs
large icons including Load, Save, Run, and Stop. entering hello_world.pyTY_SP9LXPʭPWO is to print a message
to the Shell area

Date types and maths operators


Let’s write some code In our hello_world.py program, we printed a
string of text. Other data types in Python include
integers (whole numbers, such as 1, 2, and 3) and
The main panel is where you will write your lines ʮZL_TYR[ZTY_Y`XMP]^OPNTXLW^bT_SL[ZTY_
of Python code. At the bottom is the Shell panel such as 3.5 or 10.532).
where you’ll see output and any error messages To create these, we omit the double quotes in
resulting from a running program. our print statement. Click New to start a new
Let’s write some code! program and enter:
1Z]Z`]ʭ]^_[]ZR]LXbPɪWW[]TY_LXP^^LRP
to the Shell. This is the window at the bottom
of Thonny that displays the results (or output)
of our program. It’s tradition to welcome a WHY PYTHON?
new programming language by getting it to say
“Hello, World!” ‰Ęåųå±ųåĬŅƋŸŅüÚĜýåųåĹƋŞųŅčų±ĵĵĜĹč
In the main Thonny panel, on line 1, add the languages around, but Python is by far the most
following Python code: ŞŅŞƚĬ±ųüŅųÆåčĜĹĹåųŸţBåųå±ųåĀƴåų屟ŅĹŸƵĘƼ
you should probably choose Python as your
print("Hello, World!")
ĀųŸƋĬ±Ĺčƚ±čå×
1. It’s simple: Python has a relatively simple and
Tip!
easy-to-learn syntax.
The double quotes are used to enclose a text 2. Python is versatile: Python can be used
Name your
message (known as a string). Click the Run for a wide range of applications, from program
icon and Thonny will run and print the message web development to data analysis and
±ųƋĜĀÏĜ±ĬƤĜĹƋåĬĬĜčåĹÏåţ Python programs
to the Shell. Try changing the text between
3. Large and active community: Python are typically
the double quotes and rerunning it to see a named as all
ʱŸ±ƤĬ±ųčå±ĹÚ±ÏƋĜƴåÏŅĵĵƚĹĜƋƼ
OTʬP]PY_XP^^LRP lower-case with
ŅüÚåƴåĬŅŞåųŸƤƵĘŅÏŅĹƋųĜÆƚƋåƋŅĜƋŸ
development. This community ensures underscores
that there are many resources available for splitting multiple
learning and troubleshooting. words, i.e.:
4. Open-source: Python is an open-source • game.py
language, which means that the source code • hello_world.py
is freely available for anyone to use, modify, • number_
and distribute. generator.py
5. Python is portable: Code written in Python It’s a good habit
can be run on multiple platforms including to make sure your
Raspberry Pi OS, other Linux distributions, ĀĬåűĵåųåāåÏƋŸ
Windows, and macOS. what the program
kƋĘåųĬ±Ĺčƚ±č埱ĬĬŅýåų±Úƴ±ĹƋ±čåŸØ±ĹÚƵå does. Try to
think Python is a great place to start. avoid spaces and
Numbers and text strings can be stored in generic names.
variables and then retrieved when needed

Learn to code with Python magpi.cc 45


FEATURE

Variables can be set


to input from the print(128)
user; for neatness,
print("The MagPi" + " is " + "a magazine.")
include a space after
the text Click Run to print the integer 128 to the Shell.
We can also use standard mathematical operators Note the spaces around the word ‘is’. Other
(addition, subtraction, multiplication, and maths operators include ** for ‘to the power’, %
division) on numbers. For example: QZ]XZO`WZOTaT^TZY]PXLTYOP]LYOQZ]ʮZZ]
division (rounded down to the nearest integer).
For example:
We store numbers
print(2**4)
and strings in objects print(20%7)

called variables
print(22//7)

Which give the


results 16, 6, and 3
print(128+57) respectively.

This will produce the result 185. The * and / Variables


symbols are used for multiplication and division. We store numbers or
For example: strings in objects called
variables – so called
print(128/8+5*7) because we can change
(or ‘vary’) their value
...produces the result 51.0. There are two things during our program.
to note here. First, using the divide operator
L`_ZXL_TNLWWdRTaP^LʮZL_TYR[ZTY_]P^`W_SPYNP
the decimal place). Second, the BODMAS/PEMDAS
rule applies, so division and multiplication are
performed before addition and subtraction. SWITCH DATA TYPE
The addition operator can also be used with
strings. For example: It’s possible to switch numbers or strings between
data types if needed. To switch from a number to
a string, we use the str() function. For example:

x = 42
message = "The meaning of life is "
+ str(x)
print(message)

Testing multiple To switch between number types (or convert


conditions with if and a string comprising a number), we use the int()
elif statements; the
following indented
and float() functions.
line only runs if the
condition is true

46 magpi.cc Learn to code with Python


FEATURE

COMPARISON
OPERATORS
Using a for loop
There are six comparison operators available to count down
ĜĹƤ{ƼƋĘŅĹ× from ten to one,
with a sleep delay
between numbers

Operator Meaning
The line after the if statement is indented by
four spaces and the indented code is executed
== is equal to only if the condition is true (i.e. the age variable
is between 13 and 19). An and logical operator
!= is not equal to is also used in this example to check that two
conditions are both true.
> is greater than We can add an elif (short for ‘else if’)
statement afterwards to perform another
< is less than comparison if none of the previous ones is true:

>= is greater or equal to

LOGICAL
<= is less than or equal to
OPERATORS
Note that you need to use == for comparisons,
not = (which is used to set a value). These are used for comparing multiple
conditions at once.

Operator Meaning
?ZOPʭYPLaL]TLMWPbPNSZZ^PLYLXPQZ]T_LYO
use the = symbol to set its value. For example:
and both conditions are true
wings = 4
animal = "bee" or either (or both) condition
print("A", animal, "has", wings, "wings.") is true

nor both conditions are false


@^TYR;d_SZYɪ^M`TW_TYinput() function, we
can obtain user input and store it in a variable:
Note that the or operator in Python is
name = input("What is your name? ") non-exclusive, so it’s still true if both conditions
are true. Other operator types available in
age = input("How old are you? ")
{ƼƋĘŅĹƤĜĹÏĬƚÚåĜÚåĹƋĜƋƼŠis, is not), membership
print("Hello " + name + ", you are " + age +
(in, not in), and bitwise (for comparing
" years old.") ÆĜűųƼƤĹƚĵÆåųŸšţ

Conditions
A key part of many programs involves comparing
variables and values to determine what step
is executed next. For this, we use an if
conditional statement.

age = input("How old are you? ")


age = int(age)
Using nested for
if age > 12 and age < 20: loops to print
print("You are a teenager.") items from two
HMǺIVIRXPMWXW

Learn to code with Python magpi.cc 47


FEATURE

A dictionary
comprises key and
value pairs separated
by a colon

elif age <= 12:


print("You are a child.")

You can add as many elif statements as


you like. At the end, you may also add an else
statement that will only execute the next line if
none of the previous conditions are true.

A list is used to store


an ordered sequence the 10 value we set is when it stops. To make it
count from 1 to 10, we need to use:
of values
for x in range(1, 11):
print(x)
else:
print("You are an adult.") To count down instead, adjust the start and
stop range() parameters and add a third one to
NSLYRP_SP^_P[^TeP_Z
Loops
Instead of writing lines and lines of code to for x in range(10, 0, -1):
perform multiple iterations, you can use a for print(x)
WZZ[_Z]P[PL__SPXbT_SOTʬP]PY_aLW`P^bT_STY
a range. If you want to add a delay between printing
each number, you can use the sleep function from
for x in range(10): Python’s time module, but you need to import
print(x) T_ʭ]^_

Printing out the


values of tuples
This prints the digits 0 to 9, since the default
stored in a list starting value for the range() function is zero and
WHILE LOOP
An alternative to a for loop is to use while to test
a condition and only run the loop while it is true.

x = 1
print("Counting from 1 to 5…")
while x <= 5:
print(x)
x = x +1

We can also use while True: to create a loop


that runs endlessly (until you stop the program),
since the condition is always true.

48 magpi.cc Learn to code with Python


FEATURE

RETURN VALUES
Instead of using print() in our addition function,
we could use return to send the result back to
the caller.
The Shell area shows any errors when running code; here, we
failed to give a function’s variable global scope
def add(a, b):
return a + b
from time import sleep
for x in range(10, 0, -1): result = add(138, 485)
print(x) print(result)
sleep(1)

Another thing you can do with


loops is to nest them, which we’ll This prints nine lines, starting with ‘red Alfa’,
cover in the next section. ‘red BMW’, ‘red Chrysler’, ‘green Alfa’…
Note that here, instead of the range() function
Lists to set an index, we’re using the in membership
In Python, a list is used to store an ordered operator to select each item in turn from a list.
sequence of values (of any type) separated by A list may also contain tuples. A tuple is an
commas. These can then be accessed individually TYOPcPO^P]TP^ZQNZXXL^P[L]L_POaLW`P^_SL_
using an index number. NLYɪ_MPXZOTʭPOPYNWZ^POTY[L]PY_SP^P^

names = ["Alex", "Brooke", "Chloe", rgb = [(255, 0, 0), (0, 255, 0), (0, 0,
"David", "Ed"] 255)]
print(names[1]) colours = ("red", "green", "blue")
for i in range(3):
Since Python starts counting at 0, the index of print("The RGB value for", colours[i],
1 (given in square brackets) selects ‘Brooke’ from "is", rgb[i])
the list.

Dictionaries
A list will be used with a These are similar to lists except they contain

for loop a series of ‘key:value’ pairs separated by a


colon, enclosed in curly braces. Instead of
using an index, we use the key to access the
Typically, a list will be used with a for loop, to relevant value.
print out a range of values.

fruits = ["apple", "banana", "cherry",


"damson", "elderberry"]
for i in range(5):
print(fruits[i])

We can also nest loops to choose items from


two or more lists.

colours = ["red", "green", "blue"]


cars = ["Alfa", "BMW", "Chrysler"]
for x in colours:
for y in cars:
print(x, y)

Learn to code with Python magpi.cc 49


FEATURE

?ZOPʭYPLQ`YN_TZYbP`^Pdef followed by

VARIABLE SCOPE a name, parentheses (which may contain one or


more arguments), and a colon. This is followed
by the indented lines of code for the function.
A variable created within a function is For example, a simple function to add two
only available within that function, or any numbers together:
nested functions inside it. This is known as a
local variable.
def add(a, b):
By contrast, a variable created within the main
body of a Python program can be accessed result = a + b
anywhere, including in functions. This is known as print("The sum is", result)
a global variable.
You can even create global and local variables 9ZbbPɪaPOPʭYPO_SPQ`YN_TZYbPNLYNLWWT_
with the same name, as they will be treated as
with its name followed by parentheses containing
separate objects. To avoid confusion, and possible
the values for the arguments (if any). For example:
errors, you should aim to avoid this.
It is possible, however, to alter the value of a
global variable – or create a new one – inside a add(138, 485)
function by using the global keyword:
You could put this line in a while True: loop
def example(): and have the user input the numbers to add.
global x When looking at Python programs, you’ll
x = 128 ZQ_PY^PPQ`YN_TZY^OPʭYPOLYONLWWPObT_SZ`_
any arguments.
example()
print(x) def message():
print("This is my message!")

message()

This will simply call the function to get it to


execute and, in this case, print a message.

Lots more to learn


phonebook = { Hopefully this guide will help newcomers to get
"Alex" : "0123456789", started coding with Python, but we’ve only really
"Bryony" : "9876543210", scratched the surface here. There are many more
"Charlie" : "0246813579" aspects to the language, such as using string
} formatting, classes and objects, numpy
name = input("Whose phone number do you arrays, regular expressions,
want? ") decorators, and
print(phonebook[name]) handling exceptions.
You can also add
Note that since decimal integers can’t have a graphics to your
leading zero in Python, we are using strings for programs using
the phone numbers. modules such as
Pygame or Pygame
Functions Zero, and a GUI with
A Python function is a block of code that only tools such as Tkinter
runs when ‘called’. While Python has many or guizero.
M`TW_TYQ`YN_TZY^dZ`NLYLW^ZOPʭYPdZ`]ZbY Pick up a copy
custom ones. of Create Graphical
Using functions in your programs is a good way User Interfaces with
to organise everything, make your code easier for Python to continue
others to read, and avoid having to write repetitive your Python journey.
blocks of similar code. Happy coding!

50 magpi.cc Learn to code with Python


Internet Offload co-Processors for IoT

TCP/IP Offload Ethernet

Much Faster, Safer, and Stable than Software TCP/IP Stack


Reduces resources of CPU and Memory
Easy integration to any MCU and does not require OS

Ap
pli
catio
ns

Ap
TC pli
P catio
/IP ns

Ful
ly H
ard
wir
ed TC
TO
E SWIZn
P /IP
tac et
k
So
f
Tra tware
TCP di TC
t
/IP ion P/IP
Sta al
ck
wiznet.io
TUTORIAL

Beginning
Part 02

electronics:
Introduction to
Stewart
microcontrollers
MAKER

Watkiss Learn about microcontrollers using Raspberry Pi Pico. Build a motion sensor
Also known as which turns on LEDs whenever someone enters a room
Penguin Tutor.
Maker and YouTuber

I
that loves all things
Getting started with the Pico
Raspberry Pi and
Pico. Author of
n this project, you will learn how to detect
when someone enters a room using a PIR
02 To be able to insert the Pico onto a
Learn Electronics (passive infrared) motion sensor. You will breadboard you’ll need pins soldered to it. You can
with Raspberry Pi.
learn how to use MicroPython to carry out actions solder headers on yourself, or you can buy versions
penguintutor.com based on the PIR sensor. The code can make of the Pico with the pins pre-soldered. With the
twitter.com/ decisions and set an output. This can be used to headers in place, you can plug the Pico into a
stewartwatkiss turn on LEDs. You’ll also learn about schematic breadboard ready for adding other components.
circuit diagrams, making it easier to understand You’ll also need to install MicroPython onto
how a circuit works. _SP;TNZ/ZbYWZLO_SPL[[]Z[]TL_P@1ʭWP
from magpi.cc/micropython. Hold down the
You’ll Need BOOTSEL button whilst connecting the Pico to
dZ`]NZX[`_P]/]LRLYOO]Z[_SP@1ʭWP_Z_SP
What is a microcontroller?
> Breadboard
magpi.cc/ 01 A microcontroller is an electronic device.
RPI-RP2 drive that appears on your computer.

breadboardhalf It is a type of computer, in that it runs code to


> PIR motion sensor determine what actions to take, but it isn’t as
magpi.cc/pir The PIR sensor and the GPIO pins
> White LEDs
powerful as your Raspberry Pi computer and does
not run an operating system. The microcontroller
03 A PIR sensor is a device that can detect
magpi.cc/whiteled runs your code directly and is great for using as when someone is nearby. It stands for passive
part of an electronic circuit. infrared and is essentially a heat detector, which
> Ƌ VIWMWXSVW
magpi.cc/ You’ll need a Raspberry Pi Pico for this project. detects the heat from someone’s body. To prevent
14wresistor Pico uses the RP2040 microcontroller. It’s a low- unwanted triggering, the sensor is split into zones;
cost microcontroller packed full of features. There it only sends a high output when it detects heat
> Jumper wires
magpi.cc/ are versions of the Pico available with wireless moving across the zones.
jumperbumper connectivity, but the standard Raspberry Pi Pico The PIR sensor will be connected to one of the
T^ʭYPQZ]_ST^[]ZUPN_ GPIO (general-purpose input/output) pins on

52 magpi.cc Beginning electronics: Introduction to microcontrollers


TUTORIAL

the Pico. These are sometimes referred to as GP


(general-purpose) pins. The GPIO port numbers do
not line up with the physical pin number. See the
Pico pinout diagram (Figure 1, overleaf) for details.

Connect the PIR sensor


04 The Pico uses 3.3 V for the GPIO pins. The
PIR sensor is connected to the USB voltage which
is approximately 5 V, but fortunately the PIR’s PIR detects motion
high output signal is only 3 V, which is safe to use based on heat from
people walking
with the Pico. LEDs connect to the 5V
past the sensor
The PIR sensor normally comes with male power supply, with resistors
headers. You will need to use male-to-female to ensure the current doesn’t
jumper leads to connect from the breadboard damage Raspberry Pi Pico
to the PIR sensor. Connect the pin marked GND
(ground) on the PIR to the breadboard row they typically drop 3.3 V across them; with a 5 V
power supply, then, we need a suitable resistor to Figure 2 The
breadboard
limit the current to 12 mA.
The PIR sensor normally Using a maximum of 1.7 V dropped across the
wiring diagram for
XLIcTVSNIGX

comes with male headers ]P^T^_Z]LYOWTXT_TYR_Z X,RTaP^ ŧbSTNS


]Z`YO^`[_Z  ŧ?SP^P^SZ`WOMPbT]POL^
shown in Figure 1 over the page.
connected to pin 3 on the Pico, the VCC (power)
pin to pin 40 on the Pico, and the OUT pin to pin
4 on the Pico. In the diagram (Figure 2), we’ve
Schematic circuit diagram Figure 3 A schematic
used the horizontal power rails of the breadboard,
which makes adding additional components easier.
07 One of the challenges with the breadboard
circuit diagram does
not look the same
as how it does on
diagram is that as more components are added, a breadboard, but
it becomes harder to see where each of the device makes it easier to
see which wires
legs and wires go. connect where
Adding LEDs
05 The aim in this project is to create light
when the PIR sensor detects someone in the
room. Ideally this will turn on a bright light, but
that would need more power than the GPIO ports
can provide. So, for now you can use multiple
white LEDs.
One thing to be aware of is that the GPIO pins
can only provide a small current. According to the
RP2040 data sheet, the total across all the GPIO
pins is 50 mA. The highest current mode for an
individual pin is 12 mA. This is not the absolute
maximum, but the output voltage will decrease
when exceeding that current.

Limiting the current through


06 the LEDs
This circuit uses four LEDs; limiting them to 12 mA
will be just within the maximum for the individual
pins and the total for all pins. Using white LEDs,

Beginning electronics: Introduction to microcontrollers magpi.cc 53


TUTORIAL

port numbers. The PIR sensor is also a rectangle,


which in this case includes an image inside to
represent the sensor.
The resistors are represented by small
rectangles. The LEDs are made up of a diode,
which is an arrow followed by a vertical line, and
then two arrows which indicate that the LED emits
light. The line indicates the cathode (negative end
of the diode).

Power connections
09 The power supply connections are shown
through symbols. The arrows pointing upwards
are used to indicate the positive power connection
which is connected to 5 V from the Pico. These are
Figure 1 The all connected.
location of the port There is an alternative way of showing the The ground, or negative, connection is shown
numbers for the Pico
are shown in this circuit which is the schematic diagram. It involves as a small diagram with the label GND. They are
diagram. Many of
these can be used for
learning some new symbols and conventions, but all connected.
HMǺIVIRX JYRGXMSRW makes it much easier when creating larger circuits. From the diagram, you can see the pins that are
The schematic diagram for this circuit is shown used on the Pico and how all of the components
in Figure 3 on the previous page. are wired together. For complex circuits, this is
much easier than trying to follow the wires on the
breadboard diagram.

Understanding the schematic


Top Tip 08 diagram
Start programming
Pico GPIO
The schematic diagram includes a combination
of boxes and other symbols which represent the
10 To program Raspberry Pi Pico, you’ll
is 3.3 V components (see Figure 4). The components ʭ]^_YPPO_ZNZYYPN_`^TYR?SZYYd4_XLd
The GPIO pins
are then joined by lines representing a wire or connect automatically. If not, then from the Run
for the Pico are electrical connection. menu choose ‘Select interpreter’ and choose
designed to work Raspberry Pi Pico is represented by the large ‘MicroPython (Raspberry Pi Pico)’. Select the
at 3.3 V, however central rectangle, which is a common way of detected port; if running Thonny on a Raspberry
many electronic representing integrated circuits or more complex Pi, it’ll normally say ‘Board in FS mode’; for
components are
modules. The labels around the outside represent Windows, it’ll be the appropriate USB serial port.
designed for
the physical pin numbers, while the labels inside You can write the code in the main window and
5 V which can
damage the Pico. the box indicate the purpose, such as the GPIO ^LaPT__Z_SP;TNZ4QdZ`YLXP_SPʭWPmain.py
then it will run automatically when your Pico is
[ZbP]POZYɧLYdZ_SP]ʭWPYLXPLYOdZ`bTWW
need to run it manually using the Thonny editor.

Control through code


11 The code starts by importing the relevant
modules – the machine module is a standard
Select the Pico MicroPython library for handling GPIO on
and port from the microcontrollers, and the Pin class is used to
(SRǻKYVI .RXIVTVIXIV
menu option. This is represent an individual GPIO pin. The utime module
how the Pico appears
is the MicroPython version of the standard Python
when connected to a
Raspberry Pi time module. It’s used to add delays in the code.

54 magpi.cc Beginning electronics: Introduction to microcontrollers


TUTORIAL

The Thonny editor can be used to write MicroPython code directly


onto the Pico. Switch to standard mode to see all the options

DOWNLOAD
main.py THE FULL CODE:
> Language: MicroPython magpi.cc/picopir

001. from machine import Pin


002. import utime
003.
004. pir = Pin(2, Pin.IN)
Figure 4 Some common circuit symbols used on 005.
WGLIQEXMG HMEKVEQW 8LIVI EVI HMǺIVIRX WXERHEVHW Ƴ XLIWI
are based on symbols used by the KiCad circuit designer 006. led0 = Pin(6, Pin.OUT)
007. led1 = Pin(7, Pin.OUT)
The PIR sensor is used as an input and the four 008. led2 = Pin(16, Pin.OUT)
[TY^QZ]_SP70/^L]POPʭYPOL^Z`_[`_^ 009. led3 = Pin(17, Pin.OUT)
There is a function called leds_on() which can 010.
be passed either True or False as an argument. 011. def leds_on (value):
If True is passed, then it turns all the LEDs on; 012. if value == True:
TQ1LW^PT^[L^^PO_SPYT__`]Y^LWW_SP70/^Zʬ 013. led0.low()
Note that the pin is set to low to turn an LED on, 014. led1.low()
LYOSTRS_Z_`]YT_Zʬ?ST^XLdL[[PL]NZ`Y_P] 015. led2.low()
intuitive, but is because the LEDs are connected to 016. led3.low()
the positive supply and the GPIO needs to be low
Top Tip
017. else:
_ZLWWZb_SPN`]]PY__ZʮZbTY_Z;TNZ 018. led0.high()
019. led1.high()
020. led2.high() Pico numbering
021. led3.high()
Detecting the PIR value With the USB
12 The rest of the code is contained within a
022.
023. while True:
connector
positioned to
while True: loop, which will constantly repeat. 024. if (pir.value() == 1): the left, the pins
If the PIR gives a high signal to the pin, the value 025. print ("Turning LEDs on") are numbered
is set to 1 and the LEDs turn on. If it has a low 026. leds_on(True) starting at 1 in the
signal, then the value is 0. There is a delay in each 027. utime.sleep (10) bottom left. Along
of the conditions – it is intentionally longer when 028. else: the bottom row
up to pin 20, then
the LEDs are turned on to ensure it stays on for a 029. print ("Turning LEDs off")
from right to left
reasonable period of time when triggered. In this 030. leds_on(False)
along the top row
case it stays on for ten seconds, but if the PIR does 031. utime.sleep (1) from 21 to 40.
not detect anyone, then it checks every second.

Beginning electronics: Introduction to microcontrollers magpi.cc 55


TUTORIAL

Machine
learning-powered
private speech
transcriber
Keep your personal data private by carrying out
automated voice transcription on your own Raspberry Pi

S
K.G. peech recognition is massively useful, transcribers, it can get confused by cross-talk and
MAKER

Orphanides from providing accessibility features to indistinct enunciation. However, its performance
people with deafness and reduced hearing rivals that of many commercial services, and your
KG is a writer, to transcribing meetings, lectures, or personal data never leaves your hands.
developer audio notes. It’s also the technology that
and software
preservationist. underpins most personal digital assistants.
They’re sceptical of But between services that leverage cloud
Prepare your system
01
the AI-in-everything processing and those that phone home with
fad, but also don’t
telemetry data and voice samples for later Machine learning applications will
want a human
transcriber to hear LYLWd^T^MdS`XLY^T_ɪ^SL]O_ZʭYO_]LY^N]T[_TZY cheerfully use as much processor power as you
their audio diary. services that keep your personal recordings can throw at them - during cross-platform
magpi.cc/ fully private. So we’re going to build our own testing, we maxed out all 16 threads of a hefty
hauntedowlbear ZʰTYP_]LY^N]TMP] AMD Zen CPU. Although Georgi Gerganov’s
Whisper.cpp isn’t perfect. It can’t distinguish BST^[P][Z]_T^Z[_TXT^POQZ]PʯNTPYNddZ`
MP_bPPYOTʬP]PY_^[PLVP]^LYOWTVPXZ^_ can expect better results from more powerful
systems. We used a Raspberry Pi 400 with
4GB RAM. Unless you just want to transcribe
L`OTZʭWP^dZ`ɪWWLW^ZYPPOLXTN]Z[SZYPbP
used a Blue Yeti USB mic. For somewhat better
performance, you could use an 8GB Raspberry
Pi 4 running Raspberry Pi OS Lite to save on the
overheads of the GUI.

You’ll Need
> Georgi Gerganov’s
Use the source
Whisper.cpp port
magpi.cc/
02 There are no pre-compiled binaries
whispercpp for ARM platforms, so you’ll either have to
> A microphone (for Although less accurate than ‘main’, if want to clone Whisper.cpp from its Git repository, or
make a hands-free note or have the text of a
live transcription) download a release version of the source code
QIIXMRKMQQIHMEXIP]EZEMPEFPI]SYƶPPǻRHXLI
near-real-time ‘steam’ transcription tool useful from magpi.cc/whisperreleases. We’ve gone with

56 magpi.cc Machine learning-powered private speech transcriber


TUTORIAL

the former, but when in doubt, grabbing source


code from the Releases page is always a safe bet.
The current version of the master repository will
always have the latest features, but there’s a
chance that you’ll get the latest bugs, too.

sudo apt install libsdl2-dev By using the smallest Whisper


git clone https://github.com/ggerganov/ model and tweaking its
whisper.cpp listening settings, the ‘main’
cd whisper.cpp ǻPIXVERWGVMTXMSRXSSPGER
XVERWGVMFIHMWTPE]ERHI\TSVX
XI\XFEWIHSRE;&:ǻPI
@YWP^^^[PNTʭNLWWd^_L_POZ_SP]bT^PLWW
commands in this tutorial are run from
this directory (whisper.cpp).

The --print-colors
option will show you how
The model
03 We’re going to use the recommended tiny
QYGLGSRǻHIRGI;LMWTIV
LEWMRXLIXVERWGVMTXMSRSJ
Whisper model for Raspberry Pi, which requires IEGL[SVH
just 75MB of disk space and around 125MB RAM.
While, on paper, the larger and theoretically more
accurate base model might be assumed to work on
Raspberry Pi, in practice the processing overhead
resulted in breaks and delays in transcription, so
we’re going to keep it small.

./models/download-ggml-model.sh tiny.en
make -j tiny.en This command optimises for live transcription
make -j stream performance on Raspberry Pi’s modest hardware
by sampling the audio every four seconds with
the --step 4000 instruction. One second would
be --step 1000.
There are no pre-compiled
binaries for ARM platforms
Transcribe to file
05 Displaying text on-screen after a short
When the build info is shown after making delay is undeniably useful, particularly if you have
^_]PLXdZ`ɪWWYZ_TNP_SL__SPXLVPʭWP OTʯN`W_dSPL]TYRZ]QZWWZbTYR^[ZVPYWPN_`]P^
automatically optimises for armv71, including or conversations. However, you’ll usually want
options such as neon-fp-armv8. to keep the transcribed text for future use. To
do this, append -f filename.txt to the end of
the command.
Top Tip
Press CTRL+C to end transcription.
Use the best
Take dictation
04 The stream tool is your live transcriber.
mic you can
Everything you say into the mic will be passed Microphone
Ride the wave
through Whisper and displayed on screen. At the
terminal, type:
06 You can also use Whisper.cpp to transcribe
quality makes a
ĘƚčåÚĜýåųåĹÏå
[]PaTZ`^Wd]PNZ]OPOʭWP^XLVTYRT_L`^PQ`W to the accuracy of
Whisper.cpp’s
./stream -m models/ggml-tiny.en.bin --step alternative to online AI transcription tools such as
live audio
4000 --length 8000 -c 0 -t 4 -ac 512 ?PXTLYO:__P]LTbT_S_SPMPYPʭ_ZQVYZbTYR_SL_ transcription.
your recording never leaves your hands.

Machine learning-powered private speech transcriber magpi.cc 57


TUTORIAL

./main -m models/ggml-tiny.en.bin samples/


jfk.wav --output-txt

?SPZ`_[`__Pc_ʭWPbTWWMP[WLNPOTY_SP^LXP
OT]PN_Z]dL^_SPB,AʭWPdZ`_]LY^N]TMPODZ`NLY
LW^Z_]LY^N]TMP_Z.>AQZ]XL_bT_S_TXP^_LX[^
using the --output-csv option.
To see words in the on-screen stream (but
YZ__SPPc[Z]_PO_]LY^N]T[_ʭWPNZWZ`]NZOPOMd
NZYʭOPYNPTYNW`OP--print-colors, thus:

./main -m models/ggml-tiny.en.bin --print-


colors samples/jfk.wav --output-txt

You can have the Currently, if you want to transcribe an audio DZ`NLYSLaPT__]LY^N]TMPX`W_T[WPʭWP^`^TYR
transcriber output
EREYHMSǻPIXSXI\X ʭWPT_SL^_ZMPTY!MT_;.8B,AQZ]XL_4Q wild cards:
making it easy to do dZ`]]PNZ]OP]Z`_[`_^8;ʭWP^Z]PaPY;.8ʭWP^
further work on
L_LOTʬP]PY_MT_OP[_SdZ`ɪWWYPPO_ZNZYaP]_ ./main -m models/ggml-tiny.en.bin *.wav
_SPXʭ]^_BPNLY`^PʬX[PRQZ]_SL_L__SP --output-txt
command line.

Top Tip ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a


pcm_s16le output.wav
Multilingualism? It’s rich ground for
Although
OpenAI’s Whisper
4QdZ`ɪaPRZ_X`W_T[WP8;ʭWP^_ZNZYaP]_dZ`
put them all in the same directory and run: experimentation using
was trained on
multilingual for f in *.mp3; do ffmpeg -i "${f}" -ar
different models
speech data, the 16000 -ac 1 -c:a pcm_s16le "${f%.*}.wav" ;
tiny sets we’re done
working with in
:]MdRTaTYRT_X`W_T[WPʭWPYLXP^_ZbZ]VbT_S%
this tutorial only
recognised English
in our tests. ./main -m models/ggml-tiny.en.bin file1.wav
file2.wav --output-txt
File to text
07 ?Z_]LY^N]TMPL[]P]PNZ]OPOʭWPbPɪWW If you want some more audio samples to play
use the main command. First, let’s transcribe the with, type:
supplied sample jfk.wavʭWP?d[P%
make samples

Moving the conversation on


08 For the purposes of this feature, we’re
interested in privacy-focused transcription, but
Whisper.cpp’s examples include support for GPT-2
conversational AI, so we might as well implement
this feature as a novelty.
At the time of writing, the instructions for
obtaining a pre-generated ggml Tensor library
compatible GTP-2 model are incorrect. Functional
versions of Gerganov’s converted small GTP-2
There’s even a two-way voice chatbot function in here, but don’t
expect the best results with the smallest GTP-2 models available model can be found at ggml.ggerganov.com

58 magpi.cc Machine learning-powered private speech transcriber


TUTORIAL

as well as magpi.cc/ggml. Check these if our


TY^_]`N_TZY^RZZ`_ZQOL_PO`P_ZʭWPWZNL_TZY
changes, or see magpi.cc/gpt2 for instructions on
manually converting TensorFlow models.

Summoning Santa
09 We’re going to spin up Whisper.cpp’s
integrated AI chatbot and install the espeak speech
synthesiser, which is the default option for voicing
the bot’s speech. In Whisper’s main directory, at
Further ideas: Command station
11
the terminal, type: The subtitling tool
often does a better
If you’re hoping to use Whisper.cpp to build job than YouTube’s
integration closed
wget --quiet --show-progress -O models/ dZ`]ZbYZʰTYPOTRT_LWaZTNPL^^T^_LY__SP]Pɪ^L
captioner, but
ggml-gpt-2-117M.bin https://huggingface.co/ reference example called ‘command’ to get you it’s not optimised
for Raspberry Pi
datasets/ggerganov/ggml/blob/main/ggml-model- started. First, in the whisper.cpp directory: by default
gpt-2-117M.bin
sudo apt install espeak make command
make talk ./command -m ./models/ggml-tiny.en.bin -ac
./talk -mw models/ggml-tiny.en.bin -p Santa 768 -t 3 -c 0

This demo throws you into a conversation This launch string is optimised for Raspberry
with Santa, once you’ve provided an extra Pi. Once launched, command activates with the
prompt. It’s a bit slow on Raspberry Pi and the spoken instruction ‘OK Whisper, start listening for
conversation wasn’t very satisfying, or believable, NZXXLYO^ɪLYO^[PNTʭNLWWdWT^_PY^QZ]^SZ]__]TRRP]
on any system we tested it on. It’s rich ground phrases. Note that these aren’t actually assigned to
QZ]Pc[P]TXPY_L_TZY`^TYROTʬP]PY_XZOPW^LYO any actions or responses in this sample tool.
prompts, but this mostly requires more processor We found that this short phrase detection
[ZbP]_SLYdZ`]LaP]LRP>-.SL^_ZZʬP]DZ` behaviour was more susceptible to interference
can change the identity of your interlocutor by from background noise than stream’s
following the -p^bT_NSbT_SLOTʬP]PY_YLXP continuous real-time transcription, but if you’re
after a framework to build your own voice
automation system from, this is certainly a good
place to start.
Extra features
10 Also included in Whisper.cpp’s examples

Working with Whisper


directory is generate-karaoke.sh which, once
you’ve done sudo apt install sox to get an audio
processor, will attempt to generate a karaoke video
based on audio input from the microphone. OpenAI’s Whisper neural net was trained on 680,000 hours of speech data
More usefully, there’s a benchmarking tool scraped from the web, covering multiple languages. This gives it remarkable
to help you compare performance between your accuracy, Although it’s not free of worrying ethical implications about both
whether that speech data should have been used like this and how Whisper
devices, a livestream audio transcription tool, and
itself could be used, the nature of speech recognition means that at least we
a YouTube-oriented video download and subtitling
ƵŅĹűƋÆåÚå±ĬĜĹčƵĜƋĘƋĘåŞųŅÆĬåĵŸŅüÏųå±ƋĜƴåŞĬ±čĜ±ųĜŸĵƋʱƋ±ýåÏƋčåĹåų±ƋĜƴå
tool, which has yt-dlp as a dependency. The AIs designed to ‘create’ text and images.
transcription is added to the downloaded video Spend enough time playing with it, particularly if it doesn’t clearly catch
L^L^`M_T_WPʭWPLYOLW_SZ`RST_ɪ^YZ_R]PL_bT_S someone’s words, and you’ll see Whisper inferring content that has nothing to
non-Anglo accents, it’s actually an improvement ÚŅƵĜƋĘƵʱƋƼŅƚ±ÏƋƚ±ĬĬƼŸ±ĜÚØÆƚƋÚŅåŸʱƴå±ĩĜĹÚŅüĜĹƋåųűĬرĬÆåĜƋĀÏƋĜƋĜŅƚŸ
on YouTube’s automated subtitling. Note that logic. It’s this kind of behaviour that leads people prone to anthropomorphising
technology to falsely ascribe sentience to machine learning tools.
all of these use the ggml-base.en.bin model by
Our favourite example generated from entirely unrelated words and a
default, so you’ll need to change the model paths somewhat shoddy microphone was: ‘Thanks, both of the zombies!’ ‘Thank you,
TY_SPT]^SʭWP^_Z`^P_SP_TYdXZOPW_SL_ɪ^MP^_ Master, we love you.’
optimised for Raspberry Pi.

Machine learning-powered private speech transcriber magpi.cc 59


TUTORIAL

Binary clock
Keep track of time, and learn to count in 1s and 0s

B
inary is the key concept in how this particular project requires having an on-board
computers operate. If you drill real-time clock (RTC), so won’t work with all boards.
down far enough on any operation, We’re going to be using a Pico W, but it might work
transmission, or storage, you’ll find 1s on others that have both wireless networking and
and 0s, on or off, positive or negative. RTC hardware. Along the way, we’ll learn how to
This ability to build up to complex connect Pico W to the internet to get the time, and
Ben Everard behaviours from a simple distinction between, and how to use Pico’s Real Time Counter to keep track of
manipulation of two states, is what computing is the time in hours, minutes, and seconds. Let’s take a
@ben_everard
all about. look at this first.
Yet, despite this being absolutely fundamental to There’s a protocol for getting time on a network,
Ben's house is slowly
being taken over by 3D
the way computers work, it can be a bit alien to us and it’s unimaginatively named Network Time
printers. He plans to humans. We’re brought up in a world of ten digits, not Protocol (NTP). This actually does a few things around
solve this by printing an just two, so it can be hard to get an intuitive sense of synchronising time over a network with various
extension, once he gets
enough printers. binary, especially if you don’t use it very much. Our degrees of lag, but we don’t need to worry about
solution is to make a clock that displays time in binary. being a few milliseconds out, so we’re just going to
We're going to use MicroPython for this because grab the current time.
it's quick and easy to get started wirth, and has We’re also not going to worry about daylight
access to Pico's timekeeping features. While savings time. We’re doing all this in MicroPython, so
MicroPython is fairly standard across several boards, we’re going to take the simplest solution – twice a

60 magpi.cc Binary clock


TUTORIAL

if wlan.status() != 3:
raise RuntimeError('network connection
failed')
else:
print('connected')
status = wlan.ifconǙg()
Left
print( 'ip = ' + status[0] ) Soldering resistors
in-line is an easy
way to build circuits
led.on() without a circuit board
simple_ntp.set_time()
year, you’ll connect to your clock and adjust the print(time.localtime())
offset manually. If you want, you could add a toggle led.off()
switch that flips back and forwards to adjust for
daylight savings. Obviously, you’ll need to put in your network’s SSID
We suspected that setting the time on an RTC and password, but other than that, it should just run.
via NTP might be a popular thing to do, so we At the end of it, it’ll print the result of time.localtime().
wrapped up the example code for NTP in a simple Firstly, we should note that this is a misleading name
library that does just this – you can get it from as it won’t print your local time, it’ll print the time in
hsmag.cc/SimpleNTP. GMT. Secondly, it won’t actually print the time in a
You’ll need to copy the simple_ntp.py file over usual format, it’ll print it as a list. The items are: [year,
to your device – you can do this by opening it in month, monthday, hour, minute, second, weekday,
Thonny, then selecting ’Save as’ and MicroPython yearday]. All of these should be set correctly.
device. Remember, it must have the same name on
the device.
We’ll shortly look at what’s in that file, but for now,
DIMMING
we’ll use it to grab the time and set the RTC. You can Our program turns the LEDs all the way on or all the
do this with the following code: way off. This is fine for us, and we can control the
brightness by picking the right resistor. However, you
import network can control the brightness of LEDs by flicking them
import socket on and off really fast. This is known as pulse width
modulation (PWM). Pico W does support PWM but is
import time
limited to just 16 pins, so we can’t use it in this project.
import struct We could create a PIO program that took in details of
from machine import Pin all the pins that should be on, and do a global PWM Below
The ground wires
import simple_ntp across all of them, but this is more than we need. connect across
all the LEDs
led = Pin("LED", Pin.OUT)

ssid = 'your_ssid'
password = 'your_password'

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)

Binary clock magpi.cc 61


TUTORIAL

bones look on perfboard. You could design a PCB for


it. You could get some wood and drill holes to mount
the LEDs in. Or, you could 3D-print a front panel for
it. We opted to laser-cut ours because we wanted a
wooden front panel, but any of these options should
be reasonably straightforward.
Our laser-cut panel has holes for 5 mm LEDs in a
line, so you can push the LEDs in place and secure
them with a drop of hot glue.
The circuit is quite simple because the output is
in binary, and our GPIOs work in binary. Each GPIO
connects to a current-limiting resistor, then to the
positive leg of an LED (usually the longer leg), and the
negative leg of the resistor connects to ground. There
are more LEDs than ground connections available, so
you’ll need to connect them all together.
This uses simple_ntp.set_time() to set Pico W’s The resistors need to be at least 220 1, but
Above
Pico W is a great
RTC to the correct time. We won’t go through the you might want to make them higher to limit the
choice for this whole of this, but let’s look at a few key bits. The brightness of the LEDs. This will depend a lot on the
because it’s cheap,
has a lot of GPIOs, function is defined with: particular LEDs you have, and how bright you want
has WiFi for time, and them. We found that around 1 k1 usually works well,
has an RTC
def set_time(offset=0, delta=2208988800, but it’s obviously worth experimenting to see what
host="pool.ntp.org"): you like.


There are three optional parameters here. The first is
offset, which is a number in seconds that you want We’ve used the classic 5 mm
red LEDs that give a retro
to set your RTC’s time to – this is useful if you want
to set it to a particular time zone. The second is delta,
feel, but 3 mm LEDs will give


which you can probably ignore most of the time, but
it’s the difference between the way time is encoded
you a more compact design
in NTP. The final parameter is the NTP server. Again,
pool.ntp.org is probably a good choice for the vast
majority of cases. This isn’t a specific server but a You can use any LEDs that work with 3.3 V. They
domain that will resolve to an NTP server close to can be any colour and any form factor. We’ve used
your location. By being close to you, it should (in the classic 5 mm red LEDs that give a retro feel, but
theory at least) have a low latency and, therefore, 3 mm LEDs will give you a more compact design. You
you’ll get a more accurate time. However, for our could use surface-mount LEDs if you’re making it on
purposes, the difference between high- and low- a PCB. You could even get creative and use 3 V flex
latency servers should be irrelevant. LED ‘noodles’ to build a more abstract-looking clock.
Now we’ve got our time, we will need to create the We need five pins to display the hours (in 24-hour
hardware to display it. Here, it’s up to you what you format) and six each for minutes and seconds. That
want to do. We obviously need a lot of LEDs, but how means 17 LEDs in total on the GPIO pins 0 to 16.
you mount them depends on what you have and what We found it easiest to first solder the LEDs and
look you want to create. You could create a bare- resistors together, then put the LEDs in their holes,
and then solder the connectors to Pico W’s GPIO
pins and ground. One thing you need to be aware of
NEW TO MICROPYTHON? is making sure that there’s no risk of short circuits if
If you’ve not used MicroPython before, you have an exciting time ahead of you! It’s anything gets bent. We did this by covering the LED
a great way of programming Pico and Pico W with very little setup. It’s powerful, and positive leg and resistor in heat shrink. That way, all
user-friendly. There’s a quick guide to getting started at hsmag.cc/DocMicroPyth. For a the ground wires are exposed, but it doesn’t matter if
more in-depth guide, take a look at our book Get Started with MicroPython on Raspberry anything shorts between them. It would perhaps be a
Pi Pico, which you can download for free or buy in print at hsmag.cc/mpbook. bit more secure if the grounds were also protected –
it’s up to you how you set it up. If you don’t have heat

62 magpi.cc Binary clock


RETRO GAMING WITH

RASPBERRY PI 2 ND E D I T I O N
Retro Gaming with Raspberry Pi shows you how to set up a
Raspberry Pi to play classic games. Build your own games console
or full-size arcade cabinet, install emulation software and download
classic arcade games with our step-by-step guides. Want to make
games? Learn how to code your own with Python and Pygame Zero.

Set up Raspberry Pi for


retro gaming
Emulate classic
computers and consoles
Learn to code your
own retro-style games
Build a console,
handheld, and full-size
arcade machine

BUY ONLINE:
magpi.cc/store
English not your
mother tongue?
The MagPi is also available in German!

Subscribe to the German edition of


The MagPi and get a Raspberry Pi Pico
with headers and a cool welcome box
FOR FREE!
Use the coupon code 115PicoDE
on www.magpi.de/115
TUTORIAL

shrink, you could also cover it with electrical tape, but max_wait -= 1
given how much there is to do, it might be easier to print('waiting for connection...')
just get some heat shrink. time.sleep(1)
Now we’ve done the hardware, it’s time to turn our
attention back to the software. The main thing we if wlan.status() != 3:
need to do is convert the time as numbers into the raise RuntimeError('network connection
LEDs that we want to turn on and off. We’ve done failed')
this in a method called display_num. This method else:
takes two arguments: the number you want to print('connected') This tutorial is from
display, and a list of pins on which to display it. status = wlan.ifconǙg() HackSpace magazine.
Each issue includes a
Converting a number to binary isn’t too hard. We’ve print( 'ip = ' + status[0] )
huge variety of maker
used enumerate(pins). This is a useful Python method projects inside and
when you want to loop through an iterable but still led.on() outside of the sphere
want a counter – as you can see, it returns both. simple_ntp.set_time() of Raspberry Pi, and
Each loop, we want to know if the number print(time.localtime()) also has amazing
remaining is greater than or equal to the current digit. led.off() tutorials. Find out
more at hsmag.cc.
If it is, we light that digit up and take the value of that
digit away from the number, if it’s not, we turn that def display_num(number, pins):
LED off and move to the next number. for counter, pin in enumerate(pins):
Since Pico W’s RTC can keep track of time, we can if number >= pow(2, len(pins)-
just grab the time when the computer boots up and (counter+1)):
let Pico W take care of the rest. number = number - pow(2, len(pins)-
Here’s our final code for the clock: (counter+1))
pin.value(1)
import network else:
import socket pin.value(0)
import time
import struct while True:
from machine import Pin display_num(time.localtime()[3], hour_pins)
import simple_ntp display_num(time.localtime()[4], minute_pins)
display_num(time.localtime()[5], second_pins)
led = Pin("LED", Pin.OUT) time.sleep(0.1)

ssid = 'your_ssid' This is a very bare-bones clock, but you can extend
Below
password = 'your_password' this basic timepiece in any way you like. You could We attached Pico W
add an alarm, a date function, a time control, or with hot glue, but you
could also use screws
hour_pins = [Pin(4,Pin.OUT), Pin(3,Pin.OUT), anything else you’d like to keep track of. in the mounting holes
Pin(2,Pin.OUT), Pin(1,Pin.OUT), Pin(0,Pin.OUT)]
minute_pins = [Pin(17,Pin.OUT),Pin(16,Pin.
OUT),Pin(15,Pin.OUT),Pin(14,Pin.OUT),Pin(13,Pin.
OUT),Pin(12,Pin.OUT)]
second_pins = [Pin(26,Pin.OUT), Pin(22,Pin.
OUT),Pin(21,Pin.OUT), Pin(20,Pin.OUT),Pin(19,Pin.
OUT),Pin(18,Pin.OUT)]

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break

Binary clock magpi.cc 65


FEATURE

TOGRAPHY
ASTROPHO
aspberry Pi
with R
o ts o f th e c o s mos with your
h
Get stunning s ra M o d ule, and some
C a m e
Raspberry Pi, a g u id e Rob Zwetsloot
s te ll a r
smart code. By

L
ooking up at the night sky is something
we’ve been doing since ancient times,
with stars, planets, and moons shining
down from the cosmos to remind us that
there’s a whole universe beyond Earth.
Taking photos of the night sky to capture these
sights can be a little tricky, though.
This is where Raspberry Pi comes in. With
a range of excellent Camera Modules and
customisable automation, you can pretty easily
create a setup that will catch the wonders of
_SPYTRS_LYO_SPMPL`_dZQQL]ZʬNPWP^_TLW
bodies. It’s time to heed the call of the night.

66 magpi.cc Astrophotography with Raspberry Pi


FEATURE

y photography
Basic sk
h
smic shots wit
Get the best co
is-world tips
these out-of-th The HQ Camera
has a maximum
exposure time
of about

Y
Command-line code
ou can still get great shots without a
telescope, using just a Raspberry Pi HQ
03 With the right lens and knowledge
ten minutes

Camera, if you choose the right lenses and of exposure settings, we can start building a
[]ZR]LX_SP^SZ_TYL^[PNTʭNbLd command that works in libcamera. For
long exposures, we need to disable
some automatic control algorithms
for the best results. Overall, the
Choosing a lens
01 Without a telescope, you’ll probably be
command looks like this:

aiming for night sky photos that include a lot libcamera-still -o


of the sky and don’t focus on celestial bodies. nightsky.jpg --shutter
In this case, 16-24 mm 15000000 --gain 1
wide-angle lenses are --awbgains 1,1 –
a good option, which immediate
means the 16 mm
lens often sold This will take a 15-second
with High Quality exposure as a high-quality JPG. You
Cameras is a perfect can read the docs further if you’d like to
place to start. XLVPQ`]_SP]XZOTʭNL_TZY^PR_Z_SPRLTY
level of the capture: magpi.cc/libcamera.

02 Exposure settings
A longer exposure
setting allows for more light to
Tip
be captured by the sensor. For
astrophotography, you normally The HQ Camera
want 15 to 30 seconds of exposure uses a C/CS-mount
so enough light data can be and M12 mounts for
captured. The libcamera library is lenses, so you can use
programmed in microseconds, so whatever lens you like,
this would be a value of 15,000,000 MJcMXƶWGSQTEXMFPI
and 30,000,000 respectively.

star ting with

ASTRO
68 Creating tos 70 Shoolescope
trail p h o a te

NAVIGATION

Astrophotography with Raspberry Pi magpi.cc 67


FEATURE

r trail photos
Create sta
d ti m e -l a p s e techniques
ure an
Use long expos ti fu l night shots
to cre a te b e a u

W
ith the basic setup, you’re able to
create a couple of kinds of classic
space shots – wonderful photos of
the night sky, or stylish star trails. With a
Python script, you can create the streaking star
PʬPN_N]PL_POMd_SP0L]_Sɪ^]Z_L_TZY

USB drive

Hardware Taking a lot of


big pictures can
take up space
really fast
onal)
Screen (opti
i (any)
Raspberry P

It’s always a good


idea to check
what you’re
taking a photo of,
although you can
always use VNC if
you don’t have a
spare screen

i High
Raspberry P
era and lens
Quality Cam
You can use any
Raspberry Pi with

Power bank
a CSI port, which
means most
Raspberry Pi Zeros
and any standard
model. The newer
the better, though

See the previous


page for tips on
what lens to get
– although the You’ll want to do
16 mm one will this outside, so
be more than a decent mobile
ǻRIJSVXLMW battery is essential

68 magpi.cc Astrophotography with Raspberry Pi


FEATURE

Software
s im p le P y th o n code that
Some
u s e to ta k e a night full of
you can
shots . P u t it o n y o ur USB drive Tip
Depending on how big
a USB drive you have
Setting up the software attached, you can always
01 For doing what is called a photo stack, star_trails.py increase the number of
photos and exposure time
we are going to be using the GNU Image
(up to 60 seconds), and
Manipulation Program (IMP) from gimp.org.
> Language: Python decrease the number of
Once you’ve installed that, you’ll also need seconds between shots!
a plug-in to create the stack. Grab this from
magpi.cc/starstack and follow the instructions. 001. #!/usr/bin/python3
002. import time
003.
004. from picamera2 import Picamera2
Get your photos
02 Grab the USB drive with your photos and
005.
006. picam2 = Picamera2()
put it into your PC. We suggest copying them to a 007. picam2.configure("still")
new folder on your PC to work with – make sure 008. picam2.start()
009.
You might be able to 010. # Give time for Aec and Awb to settle, before disabling
them. Exposure time of 30 seconds
tailor the perfect shot 011. time.sleep(1)
012. picam2.set_controls({{"ExposureTime": 30000000,
you know where it lives! Once that’s done, open "AeEnable": False, "AwbEnable": False, "FrameRate": 1.0})
IMP, go to File > Create > Startrail. Set ‘Light 013. # And wait for those settings to take effect
Frames’ to the folder you put all the photos you 014. time.sleep(1)
want to use in, and click OK. 015.
016. start_time = time.time()
017. for i in range(1, 100): # 100 shots
018. r = picam2.capture_request()
More options
03 There are more options to play with, which
019.
020.
r.save("main", f"image{i}.jpg")
r.release()
dZ`NLYʭYOZY_SP[W`RTYbPM^T_P_SL_NLY 021. time.sleep(300) # Five minute delay for timelapse
SPW[dZ`]PʭYPdZ`][SZ_Z?LVPLWZZVL__SPX 022.
TQdZ`ɪ]PYZ_^L_T^ʭPObT_SdZ`]]P^`W_LYOdZ` 023. picam2.stop()
might be able to tailor the perfect shot.

LOCATION, You’ll obviously want to shoot at night, but where should you
shoot from? The best place is somewhere away from a city
LOCATION, SVYVFEREVIE[LIVIPMKLXTSPPYXMSRHSIWRƶXEǺIGXXLIZMI[

LOCATION
of the stars. The website gostargazing.co.uk has excellent
recommendations for places to visit.

Astrophotography with Raspberry Pi magpi.cc 69


FEATURE

h a telescope
Shooting wit
p h o to s o f d is tant objects
Get clear
le s c o p e a n d smart software
using a te

T
o take amazing photos of celestial
bodies, you need to be able to keep
them in view, which means moving
the camera. Luckily, with the right software,
hardware, and a Raspberry Pi, you can take
some amazing photos.

PiFinder
Hubble Pi A lot of modern telescopes can connect to
computers to help with tracking distant objects.
Student Santiago Rodriguez took a fairly Richard (aka ‘brickbots’) had been doing a
simple approach of setting up a telescope for lot of manual checking with paper and then a
astrophotography with Raspberry Pi – he merely commercial computer – he decided to build one
used an adapter for the eyepiece on a telescope based on Raspberry Pi.
so the HQ Camera could be plugged in. It uses a mixture of GPS positional data and
With that done, he created a special UI LaT^`LWQPPOQ]ZXL3<.LXP]L_ZʭR`]PZ`_
called AstroCam that allows him to point the exactly where the telescope is pointed, including
telescope at the right spot and then also control a custom interface so it can be controlled out in
some of the camera settings, like the ones _SP WT_P]LWʭPWO
we’ve previously discussed. It’s a lot cheaper ɭ8dSZ[PT^_SL_Z_SP][PZ[WPbTWWʭYO_ST^
as a result. combination of functionality useful, will build
“Most good USB cameras for astrophotography their own PiFinder, and help the whole project
start at about €200 and require a connected improve by making suggestions and potentially
computer at all times. Hubble Pi can also work contributing to the software. It’s a pretty easy
wirelessly, or as a standalone if needs be,” he M`TWObT_SZʬ_SP^SPWQ[L]_^LYOMPRTYYP]
told us, when we interviewed him about it. friendly soldering,” Richard says on his website.

magpi.cc/hubblepi XLR[TNN[TʭYOP]

70 magpi.cc Astrophotography with Raspberry Pi


FEATURE

er
ophotography Autoguid
Astr
After spending many nights trying to get great
shots from stacked photos – and too many not
coming out very well – Joe Kutner decided to
program his own autoguider that could keep his
telescope pointing at the same celestial object.

Every step in the process


had its challenges
Making use of a touchscreen and Raspberry Pi,
Joe created a ton of automated scripts that could
be activated at the press of a button, and make
sure his telescope was always pointing at the exact
same object in the night sky.
ɭ0aP]d^_P[TY_SP[]ZNP^^SLOT_^NSLWWPYRP^ɮ
Joe told us a few years ago. “I would install one
[TPNPZQ^ZQ_bL]PLYO_SPYʭYOZ`_T_bL^Yɪ_
compatible with some version of another piece of
^ZQ_bL]P4YPPOPOBSPY4ʭYLWWdRZ_PaP]d_STYR
running, it wouldn’t talk to my telescope until I
installed yet another version of the software. There
were dozens of these little paper-cuts but, in the
end, it was worth working through them.”

magpi.cc/autoguider

COSMIC Want to know when the best times for seeing


WTIGMǻGSFNIGXWMW$8LIGEPIRHEVJVSQIEERH

EVENTS O]LEWHEXIWJSVEPPXLIQENSVIZIRXWMRXLI
night sky. Take a look here: magpi.cc/astrocal.

Astrophotography with Raspberry Pi magpi.cc 71


REVIEW

Vizy
Pixy vizycam.com £280 / $259
SPECS

COMPONENTS:
Raspberry Pi 4 (2, This purpose-built AI camera combines Raspberry Pi
4, or 8GB RAM),
universal tripod with machine learning software. By Lucy Hattersley
mount, 32GB

V
microSD, 25 W
AC power supply, izy is an interesting camera product that A microSD card is pre-installed and all you need to
Vizy case (900 g; combines Raspberry Pi 4 with a Sony do is plug it in and press the button to turn it on.
10×15×10 cm)
camera and lens. This is housed inside a While there’s no fun in the build process, it
CAMERA: custom plastic case with heatsinks, a fan, and a T^\`TNV_ZRP_`[LYO]`YYTYR:Yʭ]^_]`YT_
12-megapixel high-current I/O connection. uses Raspberry Pi’s Wi-Fi module to broadcast
Sony image Once it’s on your network, you can log in via a network, which you can join from another
sensor (IMX477),
a web browser pointing to vizy.local, and all the computer. You can also connect via an Ethernet
wide-angle,
3.25 mm M12 lens interaction takes place through this web-based cable, which was the approach we favoured.
(optional high- interface. Vizy has a laudable aim of making Once connected, you set up Vizy to automatically
quality 8-50 mm it easy for students and makers to explore AI- connect to a local wireless network so it connects
C/CS zoom lens), powered machine learning projects. whenever you boot up. Then, you can investigate
electronically
switchable IR-
the built-in software, divided into a range of apps
cut filter Vizy setup and examples.
Vizy comes self-assembled (you can choose -`TW_TYL[[^TYNW`OPL-T]O1PPOP]TOPY_TʭP^
I/O: between 2GB, 4GB, and 8GB Raspberry Pi inside). birds), MotionScope (captures the motion of
Digital I/O,
analogue I/O, objects), and Object Detector (detects
PWM, UART and logs classes with text alerts
serial; high- sent via Signal).
current output The examples are more simple,
(up to 1000 mA
including OpenCV Edge Detection,
per channel),
optional lighting Pet Companion, Pic Taker,
accessory TensorFlow Lite, and simple video
capture. You can investigate the
Python code for each example, to
help you start to build your own
apps. Detailed documentation
at docs.vizycam.com includes
a ‘Getting started’ guide, and
information about accessories and
applications, plus some simple API
information. You can access the
Python editor directly from the web
interface, or log into the Shell and
control Raspberry Pi directly.
These built-in programs
ensure Vizy is a great platform
for exploring machine learning
possibilities. We particularly liked
MotionScope, which captures the
.RWMHI:M^]MWEWITEVEXIHEYKLXIVFSEVHSǺIVMRK.4GSRRIGXMSRWERHEJER
XSOIITXLIYRMXGSSP movement of an object (such as a

72 magpiGG Vizy
REVIEW

Vizy houses a
bouncing ball) and provides detailed x, y, and z
Raspberry Pi 4 and
co-ordinates as graphs and a data dump. We can GEQIVEMRWMHIEWLIPP
with everything you
imagine this working incredibly well alongside need to get started
calculus learning. [MXLQEGLMRIPIEVRMRK
MQEKITVSNIGXW
Meanwhile, the Object Detector and Bird Feeder
can be used to analyse and respond to scenes,

Vizy provides you with


a great introduction to
image recognition

N]PL_TYRLWP]_^QZ]^[PNTʭNT_PX^BPSLOLWZ_ZQ
fun tracking a pet cat and sending alarms when
she was detected on a table.
The camera is the equivalent of a Raspberry Pi
High Quality Camera, although we’d be happier if
T_`^POLYZʯNTLWNLXP]LZʬP]TYRBPLW^ZQZ`YO

Verdict
the 1.5 m power lead to be a little short for some
setups, mainly when we tried to move out into
the garden for testing – although we note a Power
over Ethernet Splitter (£15/$18, magpi.cc/vizypoe) An interesting
camera that
that would work well in this setting. There is also
allows you to
an optional outdoor enclosure with IP66 rating quickly investigate
and a 4G LTE cellular network adapter. image recognition
Vizy provides you with a great introduction projects.

9
to image recognition that does a lot of the
heavy lifting, allowing you to focus on practical
-IVI[IEVIEGGIWWMRK:M^]XSWIXYTETIXHIXIGXSV

/10
projects. We think this would be ideal in a XLEXWIRHWEPIVXW[LIREGEXWMXWSRXLIXEFPI [IEVI
classroom setting. YWMRKEWXYǺIHXIHH]FIEVEWEXIWXYRMX

Vizy magpiGG 73
REVIEW

/GVGQT¡
IPS Capacitive
Touch Screen
Elecrow magpi.cc/meteor10 £91 / $110
SPECS

DISPLAY: A versatile Raspberry Pi touchscreen with


ģ.5
¡
TM\IPWTSMRX
RGB animated lighting. By Phil King
QYPXMXSYGL

W
GSRXVSP
ith a trail of glowing RGB LEDs around Whether you appreciate the
PORTS & _SPPORPLYO]PL]_SP8P_PZ]ť RGB marquee lighting or not,
the screen quality is very good
CABLES: ?Z`NS>N]PPYZʬP]^LYTXL_POLXMTPY_
-)2.TSVXc¡
WTRS_TYRbT_S$^PWPN_LMWPPʬPN_^ It can prove
QMGVS9'
TSVXW-)2.
GEFPIQMGVS
a little distracting, though, so luckily there’s a
M`__ZY_Z_`]YT_Zʬ
There’s a mounting point
-)2.EHETXIV
¡QMGVS9'
Another button enables adjustment of the on the rear to secure
backlight for the screen, which is plenty bright
XS9'GEFPIW
PYZ`RSL__SPSTRSP]^P__TYR^BSTWPŸ# Raspberry Pi to create an
OTHER: [TcPW^QZ]LTYNSOT^[WLdXTRS_^PPXZY_SP
7EWTFIVV]5M WZb^TOPbT_SL;;4[TcPWOPY^T_dTY[]LN_TNP all-in-one unit
QSYRXMRKTSMRX
T_WZZV^OP_LTWPOPYZ`RSPaPYbSPY[WLdTYRaTOPZ
[MXLWGVI[W
c¡cTPEWXMG ?SP]Pɪ^YZM`TW_TY^[PLVP]_SZ`RS^ZdZ`ɪWWYPPO ]PL]_Z^PN`]P=L^[MP]]d;T_ZN]PL_PLYLWWTYZYP
WXERHPIKW L^P[L]L_PZYPNZYYPN_PO_ZdZ`]=L^[MP]]d;T `YT_NZX[WP_PbT_SL_bZ[L]_[WL^_TN^_LYO
:YP[W`^[ZTY_T^_SPQ`WW^TeP3/84^ZNVP_^Z
dZ`NLYPL^TWd[W`RTYL=L^[MP]]d;T`^TYR_SP Touch control
^`[[WTPONLMWPɧbT_SLXTN]Z3/84LOL[_P]QZ] ?bZXTN]Z@>-^ZNVP_^YPPO_ZMPNZYYPN_POaTL
Verdict =L^[MP]]d;T?SP]Pɪ^LXZ`Y_TYR[ZTY_ZY_SP ^`[[WTPONLMWP^_Z=L^[MP]]d;Tɪ^@>-[Z]_^_Z
^`[[Wd[ZbP]LYOPYLMWP_Z`NSNZY_]ZW,YZʯNTLW
The RGB marquee ;>@T^LOaT^LMWPZ_SP]bT^P_SP^N]PPYXLdMP
lighting is a bit `YOP][ZbP]POLYOVPP[^bT_NSTYRZʬ4YLYdNL^P
gimmicky, but the T_^SZb^ɩ9Z^TRYLWɪL__TXP^bSTWP=L^[MP]]d;T:>
picture quality is
T^MZZ_TYR`[`Y_TW_SPOP^V_Z[L[[PL]^
good and touch
BPQZ`YOT_ʭOOWd_Z_L[TNZY^LYObTYOZb
control works well.
As a bonus, the controls, but this improved after changing the
screen can also be system default to ‘Larger screens’ to make
used with many _SPXMTRRP];TYNSeZZXRP^_`]PNZY_]ZWbZ]V^
other devices. bPWWPYZ`RSLW_SZ`RSLMT_ZQUTRRP]d[ZVP]dT^

8
YPPOPOTY=L^[MP]]d;T:>_ZPYLMWP]TRS_NWTNVTYR
bT_SLWZYR[]P^^@YWP^^dZ`bLY__ZL__LNSL

/10
physical keyboard, you’ll also need to install an
You can mount a Raspberry Pi on the rear
of the display using the supplied screws ZY^N]PPYaT]_`LWZYP^`NSL^:YMZL]O

74 magpi.cc 2IXISVģ.5(ETEGMXMZI8SYGLGVIIR
Your FREE guide to
making a smart TV

BUILD A RASPBERRY PI
MEDIA PLAYER
Power up your TV and music system

FROM THE MAKERS OF THE OFFICIAL RASPBERRY PI MAGAZINE

magpi.cc/mediaplayer
REVIEW

Alpakka
Input Labs magpi.cc/alpakka Free + cost of components
SPECS

LICENSES:
Open-source
A DIY controller that can be used like a mouse or a gamepad
firmware,
Creative
with extra buttons. Rob Zwetsloot get to grips with it
Commons

D
hardware
IY controllers are becoming more and MPTYR_SPʭYLW^LYObTNSTYRZQ_SP[L]_^_ZʭYT^S
INPUTS: more popular in the gaming space, the controller.
2 × gyro
especially when it comes to making Build quality is quite dependant on how you
sensors, 13 ×
face buttons, accessible controllers for folks with disabilities, print the controller, and also if you decide to
2 × sticks, 1 × and 3D printing has really made it easy to roll customise it before sending the STL over to your
scroll wheel, your own input system. printer. With all the electronic parts inside, it
c¡WLSYPHIV
Alpakka has taken all this and gone a little does have a satisfying weight and, thanks to the
grip buttons
step further, creating a customisable controller compact design, it doesn’t feel loose and creaky
OTHER base for (mostly) free and showing you how to like other 3D-printed handhelds and controllers
FEATURES: put it together. We say mostly free because you we’ve used in the past.
Customisable, do have to buy some extra components and get
Raspberry Pi
Pico-powered
the PCB printed. However, even with a handful Game on
of components, you’re not spending more than a As for how it plays – if you’ve ever used
tenner, especially if you have a Raspberry Pi Pico 3D-printed controls before, you’ll know that they
lying around to power it. OZYɪ_LʬZ]OL^X`NSNZXQZ]_L^Z_SP]NZY_]ZWWP]^
Ours came pre-assembled but the instructions with softer and smoother plastic. The right stick
L]PaP]dNWPL]]P\`T]TYRdZ`_ZʮPcZYWdLQPb isn’t really supposed to act like a traditional right
soldering skills to put it together. stick, so it sits there as an awkward cube that
OZP^Yɪ_RTaP_SPMP^_WZZVTYʭ]^_Z]_ST]O[P]^ZY

It’s powered by a Pico


Custom controls games for aiming.
inside which allows Once everything is soldered, construction is fairly The left stick also feels a little clunky, and the
the whole controller straightforward. Parts slot in and are tightened triggers are hard to use as, thanks to the extra
to work like a standard
XInput controller in place with a few screws, with the hardest part WPaP]LRPdZ`SLaPZY_SPXT_ɪ^OTʯN`W__ZQPPW_SP

76 magpi.cc Alpakka
REVIEW

click on the button. They’re also not analogue like


on modern game consoles.
One of the reasons the controller is like this,
though, is that you can also use it like a mouse
thanks to advanced gyro functions – in fact, the
scroll wheel on the controller is supposed to mimic
one on a mouse. We found it a little awkward to
`^PL^bPɪ]PYZ_aP]d`^PO_ZT_M`_T_OPʭYT_PWd

With all the electronic


parts inside, it does have
a satisfying weight
works better than older systems we’ve tried. It
NLYLW^ZPL^TWdMP_`]YPOZʬLYOZYLRLTYbSTNS retro games, too, that don’t require analogue Rear grip buttons
are also included,
is a bonus. controls and, due to its DIY nature, you could just in case you
For the price of putting this together at its most PL^TWdʭYOXZ]PNZXQZ]_LMWP]P[WLNPXPY_M`__ZY^ need more inputs

basic, it is very good though. It’s great for more if you wanted to head down that route.

It’s a very cool-


looking controller
with even
cooler features
packed inside

Verdict
We really like the
idea of Alpakka,
but if you want
to use it as a
main controller,
you will need to
start customising

7
it yourself.

/10
Alpakka magpi.cc 77
RESOURCES

10 Amazing:
Monitors
and displays
See what you’re doing with these
incredibly diverse add-ons

U
sing a Raspberry Pi without any sort of screen
is fairly common. However, if you want to show
something visually from Raspberry Pi, or even a
Raspberry Pi Pico, you’re spoilt for choice – not only in size Cosmic Unicorn
but also in type. Here are ten of our favourites.

1024 colourful LEDs


‰ĘåŽĹĜÏŅųĹĬĜĹåŅüX)%ĵ±ƋųĜÏ埱ųå±čųå±Ƌ±ĬƋåųűƋĜƴåƋŅ±Ƌų±ÚĜƋĜŅűĬ
ÚĜŸŞĬ±Ƽô±ĹÚƵĜƋĘŸŅĵ±ĹƼX)%ŸØƋĘåŅŸĵĜÏŽĹĜÏŅųĹĵĜčĘƋ±ŸƵåĬĬÆå
±ųå±ĬÚĜŸŞĬ±Ƽţ

magpi.cc/cosmicunicorn | £80 / $97

IPS wide
touchscreen
Wide boy
FüƼŅƚĹååÚ±ÚĜŸŞĬ±ƼƋʱƋĜŸƴåųƼƵĜÚå
ŅųƴåųƼĬŅĹčØƋĘĜŸƀţĿtƋŅƚÏĘŸÏųååĹƵĜƋĘ
±Ŏƅ×ñŸŞåÏƋų±ƋĜŅĜŸ±čųå±ƋŞĬ±ÏåƋŅ
ŸƋ±ųƋţ

magpi.cc/ipswide | £85 / $103


EPD Pico
Development Kit
HyperPixel 2.1 Round e-ink board
‰ĘĜŸ±ÚÚěŅűĬĬŅƵŸƼŅƚƋŅ±ƋƋ±ÏĘ
HD circle
±ĹåěĜĹĩÚĜŸŞĬ±ƼƋŅ{ĜÏŅţFƋűŸŅű
eƋĜĹƼŸÏųååĹƋʱƋĀƋŸĹå±ƋĬƼŅĹƋŅŞŅü±±ŸŞÆåųųƼ{Ĝ¬åųŅţFƋűŸ ϱÆĬåØŸŅ{ĜÏŅÚŅåŸĹűƋʱƴåƋŅÆå
ŞųŅƱÆĬƼƋŅŅÆĜčƋŅÆåƚŸåÚ±Ÿ±Ƶ±ƋÏĘØÆƚƋĹŅŅĹåƵĜĬĬŸƋŅŞ ĵŅƚĹƋåÚƋŅĜƋåĜƋĘåųţ
ƼŅƚƋųƼĜĹčţ

magpi.cc/hyperpixel2r | £54 / $65 magpi.cc/epdk | £25 / $30

78 magpi.cc Monitors and displays


RESOURCES

HyperPixel 4.0
4-inch touchscreen
œĘ±ƋƵåÏŅĹŸĜÚåųƋŅÆåƋĘåŸƋ±ĹÚ±ųÚŸĵ±ĬĬÚĜŸŞĬ±ƼüŅų±±ŸŞÆåųųƼ{ĜØƋĘå
BƼŞåų{ĜƻåĬĉţLjʱŸÆååűųŅƚĹÚüŅų±ƵĘĜĬå±ĹÚĜŸŸƋĜĬĬƋŅŞĜĹĜƋŸÏĬ±ŸŸţ

magpi.cc/hyperpixel | £54 / $65

Inky Impression
ģ41*)
E-paper add-on
Tiny display ‰ĘĜŸŸåƴåĹěÏŅĬŅƚųÚĜŸŞĬ±ƼĬŅŅĩŸÆå±ƚƋĜüƚĬ±ĹÚƚŸåŸƴåųƼĬĜƋƋĬåŞŅƵåų
ƋŅĩååŞĜƋŸåĬüčŅĜĹčţ:ųå±ƋüŅųĵŅųå±ųƋƼŞųŅģåÏƋŸţ
‰ĘĜŸƋĜĹƼŸÏųååĹĀƋŸŸĹƚčĬƼ±ƋŅޱ
{ĜÏŅØƵĜƋĘƅĉĸŎƖíŞĜƻåĬŸƋŅŞĬ±ƼƵĜƋĘţ
FƋåƴåĹʱŸ±ÏŅƚŞĬåŅüÆƚƋƋŅĹŸú
magpi.cc/inkyimpression | From £50 / $60

magpi.cc/oled13 | £11 / $11

Round LCD
Breakout
SPI colour screen
‰ĘĜŸƋĜĹƼųŅƚĹÚŸÏųååűƋƋ±ÏĘåŸ
ƋŅ±{ĜĵŅųŅĹĜųå±ĩŅƚƋ:±ųÚåĹØ
ŸĬŅƋƋĜĹčĜĹƋŅŅĹåŅüƋĘåĵ±ĹƼ
ŞŅųƋŸƤĜĹĜƋţ

magpi.cc/roundlcd
| £25 / $30

GFX HAT
4PHWGLSSPGLEVQ
œåʱƴ屟ŅüƋŸŞŅƋüŅųƋĘå Raspberry Pi Touch Display
:8£Be‰ØčĜƴĜĹčƼŅƚ±ƴåųƼ
üƚĹÏƋĜŅűĬųåƋųŅX%ÚĜŸŞĬ±Ƽ
Desktop ready
ƵĜƋĘŸĜƻϱޱÏĜƋĜƴåÆƚƋƋŅĹŸ
ƋŅÆŅŅƋţ ‰ĘåŅþÏĜ±ĬƋŅƚÏĘŸÏųååĹŸĬŅƋŸĜĹƋŅƋĘå%„FŞŅųƋŅĹüƚĬĬěŸĜDŽå±ŸŞÆåųųƼ
{Ĝ±ĹÚϱĹÆåĵ±ÚåŧƚĜƋåÏŅĵޱÏƋĜüĹååÚåÚţ
magpi.cc/gfxhat
| £17 / $21 magpi.cc/touch | £69 / $83

Monitors and displays magpi.cc 79


RESOURCES

Learn Computer Science


Getting to grips with the lingua franca of how computers work is well worthwhile,
recommends Rosie Hattersley

FutureLearn
FutureLearn: FutureLearn is an online
AUTHOR

IT & Computer learning portal with courses


Science Courses b]T__PYMdPc[P]_^TY_SPT]ʭPWO
O]LbYQ]ZXLbTOP]LYRPZQ
Price: LNLOPXTN[]ZQP^^TZYLWMZOTP^
£30 per month
Unsurprisingly, you’ll spot
magpi.cc/futurelearn
the Raspberry Pi Foundation
LYO^ZXPaP]dSTRS[]ZʭWP
universities have contributed computer programs. Clicking package. To make the most of
courses, with topics ranging on the Overview tab takes you this, clear your diary and tackle a
Q]ZXP_STNLWSLNVTYRL]_TʭNTLW to a synopsis, expected prior NZ`[WPZQNWL^^P^LN]Z^^OTʬP]PY_
intelligence and robotics, to game knowledge, and what you’ll disciplines. Depending on your
development and data analysis, learn. Most FutureLearn courses interests and chosen courses, you
as well as courses focusing on are included in the Unlimited could accrue credits towards a
particular software packages and recurring monthly subscription degree or MBA.

Books CODE: THE HIDDEN LANGUAGE


OF COMPUTER HARDWARE
EVXMǻGMEPMRXIPPMKIRGIMQTEGXXLI[E][I[SVO
MRǼYIRGIWSGMIX]ERHVI[EVHWSQIEXXLI
AND SOFTWARE expense of others.
These bookshelf Author Charles Petzold looks at how magpi.cc/2mabook
computers and code impact our everyday
essentials contextualise lives and our interactions, from the THE SOUL OF A NEW MACHINE
computer science way we describe things to our modes Tracy Kidder’s seminal guide
of communication. to the history of computer
magpi.cc/codebook science is essential
reading, introducing us to
THE SECOND MACHINE AGE: WORK, the industry’s blow-hard
PROGRESS, AND PROSPERITY IN A business overachievers,
TIME OF BRILLIANT TECHNOLOGIES grafters, and wingers with
Unavoidable and sometimes awkward humorous insight.
consequences as machines, robots, and magpi.cc/soanm

80 magpi.cc Learn Computer Science


RESOURCES

CS50 .> cT^3L]aL]Oɪ^Q]PP


learn-at-your-own-pace
well as encountering various
programming languages such as
tasks, and you will earn a
prestigious Harvard University
TY_]ZO`N_TZY_ZNZX[`_P] C, Python, and JavaScript, and NP]_TʭNL_P.> LW^Z[]ZaTOP^
^NTPYNPLYO_SPL]_ZQ learning about SQL databases, a good grounding for related
Harvard
AUTHOR

University []ZR]LXXTYRLYOT^_SPZYWTYP you are expected to apply what courses in web and games
P\`TaLWPY__Z_SPXZ^_[Z[`WL] you’ve learnt by tackling a development, Python, and AI.
Price: XZO`WPLaLTWLMWP_ZNLX[`^ range of data sets in order to
Free L__PYOPP^The course is billed demonstrate your understanding
magpi.cc/cs50 as ideal for learning about of cybersecurity, cryptography,
“thinking algorithmically” and
^ZWaTYR[]ZMWPX^PʯNTPY_Wd,^
gaming, and forensics. Score
^`ʯNTPY_WdSTRSWdZY_SP^P
Websites
Places for advice and
additional prompts

STACK OVERFLOW
If your code is broken, or you
just can’t think of a way to

edX Computer Programming


tackle something, appeal to
fellow coders and get some
expert advice.
XYFHPT[JW‫ܫ‬T\HTR
edX 4Q?0/cT^_SP[WLNP_ZRZ_Z course selected, you can follow
AUTHOR

SPL]TY^TRS_Q`WLYOTY^[T]TYR an academic CS track for free


Price: _LWV^LMZ`__PNSYZWZRdPOC but forego personalised feedback JAVA T POINT
Varies from free T^T_^ZYWTYPWPN_`]P]NZ`^TY LYOZʯNTLWNP]_TʭNL_TZY_SZ`RS ,VIEXJSVLIPT[MXLEWTIGMǻG
to $10,000 for full
A helpful FAQs page makes it paid-for upgrades are optional computing topic, or a detailed
master’s degree
easier to choose between areas of extras. Some courses are pitched video overview of how to use a
edx.org
study and select an appropriate at upskilling for vocational particular program, no matter
academic (such as the University advancement, and others tailored how obscure it seems.
of Texas degree in Data Science) _Z^[PNTʭNTYO`^_]TP^bSTNSXLd javatpoint.com
or general interest level, listed in be useful if you want to take
the Executive section. Depending advantage of funding for
on the institution (e.g. MITx) and lifelong learning. ISAAC COMPUTER
SCIENCE
The perfect site to head to if
you’re studying (or teaching)
Computer Science at GCSE or
above, as Isaac was developed
together with UK exam boards
in tandem with renowned
computing companies such
as Microsoft, Oracle, and
Raspberry Pi.
isaaccomputerscience.org

Learn Computer Science magpi.cc 81


T H AT M A D E

“The Computers That Made Britain is one


of the best things I’ve read 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.
.YѣXZYYJWQ^࣢FXYTSNXMNSLѧ
- Stuart Turton, bestselling author
and journalist

Buy online: wfmag.cc/ctmb


Available on
OUT
NOW
INTERVIEW

Trevor
Warren
An open-source advocate and community creator in Melbourne

> Name Trevor Warren > Occupation Software engineer


> Community role Community leader > URL hack2.live

W
e love High Altitude source growing up,” Trevor tells electronics into the hands
Ballooning (HAB) – us. “Linux was my gateway to of makers. Raspberry Pi
we’ve been covering learning more about computing did to the SBC market what
it in The MagPi basically as and how computers worked... the Arduino did to the
long as the magazine has been hardware was expensive and microcontroller market.
around. When Trevor emailed YZ_]PLWWdLʬZ]OLMWPTY_SZ^P “I have been lucky to
us about some launches he’d days, the only way to dabble have had some really great
been doing in Australia, we were with electronics was to build experiences growing up. These
VPPY_Z_LWV_ZSTXʭYOTYR everything yourself from scratch experiences have given me
out he’s set up several coding or use expensive commercial _SP^VTWW^NZYʭOPYNPLMTWT_d
and making-related volunteer platforms which cost an arm to build and grow community
groups over the years. and a leg. In many ways, organizations. I consider myself
“I have always been playing Arduino democratized [the] privileged to be able to set up
Preparng for launch with a
-&'ǻPPIHNYWXVMKLX around with Linux and open- learning of electronics, put and run these volunteering
groups (Melbourne Raspberry
Pi Makers Group, CoderDojo
Altona North, EMDRC High
Altitude Balloon Group) here in
Melbourne, Australia.”

BSPYOTOdZ`ʭ]^_WPL]YLMZ`_
Raspberry Pi?
I read about Raspberry Pi in
a magazine, and ended up
[`]NSL^TYRXdʭ]^_=L^[MP]]d
Pi from a local electronics store.
I was quite comfortable with
Linux, so getting started with
Raspberry Pi wasn’t such a big
deal for me. However, I never
really found much application
for my Raspberry Pi 1 Model A.
It would be a few more years
before I realized the importance
of Raspberry Pi, and its power
as a learning platform for
makers and tinkerers.

84 magpi.cc Trevor Warren


INTERVIEW

creating a platform that brings 8VIZSVEPWSLIPTWVYR(SHIV)SNSW


makers with diverse interests
together in person and online.
We have been meeting in person
at the Docklands Makerspace
here in Melbourne (thanks to
the Melbourne City Council for
their support), and stay in touch
online through Discord.
YGGIWWJYPTE]PSEHVIXVMIZEP
What standout memories do
What drew you to organising issues we were having, while you have of previous events?
community events? helping the newbies set up their Every event is a memorable
It all started when I mentioned own Raspberry Pis – connecting event for me. Things are very
the Raspberry Pi to a few of my it to the network. OTʬP]PY_YZbL^NZX[L]PO_Z
colleagues at work – some of I didn’t know, at that time, bSPY4^_L]_POZʬbT_SLR]Z`[
them expressed interest and that the Melbourne Raspberry of four makers at the rented
wanted to learn more about it, Pi Makers Group was going to room in the council library. We
but didn’t know where to start. be such an important part of my now have a group of over 1000+
makers within the Melbourne
Raspberry Pi Makers Groups on
We shared our experiences with Meetup, and over 300+ makers
on Discord. 2020 was hard on
Raspberry Pi, helped each other out everyone, hard on the makers
and their families. But we
used it to bring us together, to
So, we rented out a room at the life. I am honoured to be able to support each other, and stay in
local library on a Saturday seven serve the community of makers touch with each other through
years ago, and got together as here in Melbourne, Australia. Discord. Discord has been such
the Melbourne Raspberry Pi It’s a privilege to work with a lifesaver for all of us. We now
Users Group. We shared our makers here, give them an use Discord extensively and stay
experiences with Raspberry Pi, opportunity to showcase the in touch between the monthly
helped each other out with the work they are doing, and meetups using Discord.

Trevor Warren magpi.cc 85


THIS MONTH IN RASPBERRY PI

MagPi
01

Monday
Amazing projects direct from our Twitter!

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

01. The perfect gear for going clubbing with.


=SYVJVMIRHW[MPPEP[E]WǻRH]SY
02. We love these kind of upcycling projects –
and it’s a fun use of an old display!
03
03. .RǻRMX]QMVVSVW[MPPEP[E]WFIJEWGMREXMRK
to us.
04. As well as looking cool, this is also a very
neat visualisation of how analogue
sticks work.
05. &P[E]WRMGIXSKMZITPERXWEJERG]LSQI
06. This arcade stick looks great and, despite
its warnings, will not electrocute you.
07. &WMQTPI]IXZIV]YWIJYPTVSNIGXƳ[IRIIH
QSVIPMXXPIMRJSWGVIIRWMRSYVPMJI
08. 8LMWWSMPQSMWXYVIWIRWSVTVSNIGXOIITW
getting better.
09. &RSXLIVLETT]VSFSXFYMPHMRKGYWXSQIV

86 magpi.cc MagPi Monday


THIS MONTH IN RASPBERRY PI

05

04
06

08

07

09

MagPi Monday magpi.cc 87


THIS MONTH IN RASPBERRY PI

Events in pictures
Raspberry Jams are back, and we have the photos to prove it

CODERDOJO BAARLE RASPBERRY PI BIRTHDAY PARTY

What better way to celebrate the birthday of Raspberry Pi than coding? The Astro Pi Kit gets a good workout here

MELBOURNE RASPBERRY PI MAKERS GROUP MEETUP

What does the robot see? The meetups occur at the Docklands Makerspace & Library
THIS MONTH IN RASPBERRY PI

Crowdfund this!
Raspberry Pi projects you can
crowdfund this month

UHF Reader
Raspled Digital Signage
“A Rain RFID module built into both models can scan up to 50 tags
per second within a 1.5-metres range. The Ultra-High Frequency Raspberry Pi is used in digital signage a lot – which is why you’ll
(UHF) band, which ranges from 840MHz to 960MHz, is where this sometimes see people post bemused pictures of a sign in an
device operates. One reader may interact with numerous tags at ±ĜųŞŅųƋŸĘŅƵĜĹčŅýĜƋŸ±ŸŞÆåųųƼ{ĜĜĹűųÚŸţeŞŞ±ųåĹƋĬƼرĬŅƋĵ±ĩå
once, fast, and within more than a metre of one another because of use of monthly fees for a very simple operation, which maker Angel
its wider read range than HF NFC scanners.” Rijo says won’t happen here.

kck.st/3SIgNYx kck.st/3ZFYvJr

Best of the rest!


Other amazing things we saw this month

N64 Digital
HDMI converter
Solar rover Train logger
Using older consoles with an analogue output
on modern TVs is fraught with various quality If there’s one way to explore the Australian User iHoller913 was interested to know if
issues. However, this amazing project uses a outback without being attacked by natural there was any pattern to the trains going by
Pico to convert the signal better than horrors, it’s through the safety of a video feed their home, resulting in this professional-
some solutions. attached to a remote-controlled robot. looking device.

magpi.cc/n64hdmi magpi.cc/solarrover magpi.cc/trainlogger

Best of the rest! magpi.cc 89


YOUR LETTERS

Your
Letters
Raspberry Jams
I read about CamJam coming back and was wondering if the calendar
with all the Jams would be too? It helped introduce me to a few events Learn about
making interfaces
TYXdL]PLLQPbdPL]^MLNVLYObL^SZ[TYR4XTRS_ʭYO^ZXPXZ]P with Python with
if it came back. our excellent book

Mel via Twitter Future article request


This issue sees the triumphant return of our community events pages I wonder if, in the future, you could print articles
– you can check them out over the page – and they’re backed up by the on the following:
YPbPaPY_^^T_P_SL_dZ`NLYʭYOL_magpi.cc/events. Hopefully, the gpio readall - the installation of and usage
TYQZbTWWSPW[dZ`ʭYOXZ]PWZNLWPaPY_^LYOQ]TPYO^ of as a means of checking the status of inputs
and outputs.
Python scripts on a Raspberry Pi - in particular,
the means of running a script that gets data from
an API and displays the data on PyQt5 GUI, then,
after a time delay, getting fresh data from the API
and displaying this new data.

Marian via email

It’s not quite PyQt5, but our book Create Graphical


User Interfaces with Python (magpi.cc/pythongui)
does cover this kind of program inside. A lot of
the parts that reference and access API data are
the same, you’d just need to rework the outputs to
bZ]VbT_S;d<_ BPɪWWOPʭYT_PWdVPP[T_TYXTYO
for future articles on Python programming, though.
,^QZ]ʭYOTYRZ`__SP^_L_`^ZQ2;4:ɧT_ɪ^
The new
community not something we’ve covered, but it is part of
events website BT]TYR;T/PʭYT_PWd^ZXP_STYRbPbTWW_LWVLMZ`_
has been in the
works for a while in the future.

90 magpi.cc Your Letters


USA SPECIAL!
6 ISSUES
Space is now
In The MagPi #125, the Next Month page (97) featured
astrophotography. However, in The MagPi #126, the
main focus was on the new Camera Module, with little
to nothing pertaining to astrophotography. Will this be a
FOR $42
feature of a future magazine?

Andy via email

As you’ve probably noticed by now, this issue has the


astrophotography feature we were originally planning for
#126. Sometimes plans change behind the scenes over the
month between issues, although we do prefer to keep our
plans consistent. We think the feature this issue will have
been worth the wait.

FREE
RASPBERRY PI
PICO W
Check out our astrophotography feature and
make amazing time-lapse photos like this

Contact us!
>
>
Twitter
Facebook
@TheMagPi
magpi.cc/facebook
Subscribe online:
>
>
Email
Online
magpi@raspberrypi.com
forums.raspberrypi.com
magpi.cc/subscribe

Price is charged at £35 sterling. The dollar price will depend on the exchange rate. Six issues and free
Pico W for £35 is also available in Canada and Europe. Subscription is for the next six issues and does
not renew automatically. This is a limited offer. Offer subject to change or withdrawal at any time.
EVENTS

Community
Events Calendar
Find out what community-organised Raspberry
Pi-themed events are happening near you…
01. Melbourne Raspberry Pi 03. Pi and More 13
Makers Group Meetup Saturday 22 April
Sunday 2 April Trier University of
Library at the Dock, Melbourne, Australia Applied Science,
magpi.cc/mrpmgm128 Trier, Germany
This meetup is open to everyone with an interest in magpi.cc/pam13
electronics, robotics, home automation, 3D printing, laser At Pi and More, beginners
cutting, amateur radio, high altitude balloons, space tech, and experts meet in a relaxed atmosphere for talks,
etc. Makers are invited to bring along their projects and workshops, and projects focusing on Raspberry Pi,
project ideas, and come embedded systems, and microcontrollers.
connect with other makers.
Get your questions answered, 04. Cambridge Raspberry Jam
WLS[SǺXLI[SVO]SYEVI Saturday 22 April FULL CALENDAR
doing, and get support to Makespace Cambridge, Cambridge, UK Get a full list of upcoming
ÏŅĵĵƚĹĜƋƼåƴåĹƋŸƤĘåųå×
resolve nagging issues. magpi.cc/camjam128
CamJam is back! Cambridge Raspberry Jam (known as magpi.cc/events
02. Cornwall Tech Jam CamJam) is an event and meetup for those interested in
Saturday 15 April the Raspberry Pi family
Fraddon Village Hall, Saint Columb, UK of computing devices
magpi.cc/ctj128 and other technologies
Cornwall Tech Jams are run by volunteers working in IT which encourage
and education throughout Cornwall. They are supported making and education.
by Software Cornwall, its members and other local There will be a series
businesses. Our volunteers of talks, organised
give their own time and workshops for both the
expertise to plan each Raspberry Pi and Pico,
Cornwall Tech Jam and to the plus a ‘show and tell’
regular maintenance of all area for people to show
our equipment. SǺXLIMVTVSNIGXW

92 magpi.cc Community Events Calendar


EVENTS

04

03
02

RASPBERRY PI 01
STORE POP-UP

9JGTGECP[QWƓPF
Raspberry Pi next?
> Next location Raspberry Pi Store pop-up Southampton
> Where West Quay Shopping Centre, Southampton, UK
> When Friday 7 April and Saturday 8 April

A
t this Raspberry Pi Store pop-up in
Southampton, you can experience
and buy Raspberry Pi products.
Explore some of the things you can do with
a Raspberry Pi, discover our accessories
04
and books, and get your hands on limited
edition exclusives.
If you’re lucky, you might spot Features
Ed. Rob!
02
magpi.cc/popup2023soton

Community Events Calendar magpi.cc 93


SUBSCRIBE AND

SAVE UP
TO

35% on the cover price

ISSUE #65

OUT NOW
hsmag.cc
COMPETITION

WIN A
RETERMINAL
A product on our ever-
growing list of excellent
Raspberry Pi Compute
Module 4 products, reTerminal
is a hardened production
terminal for factories, or other
industrial-level monitoring. It’s
also modular, allowing you to
expand its functions.

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

Terms & Conditions


Competition opens on 29 March and closes on 27 April5VM^IMWSǺIVIHXSTEVXMGMTERXW[SVPH[MHIEKIHSVSZIVI\GITXIQTPS]IIWSJ7EWTFIVV]5M1XHXLITVM^IWYTTPMIVXLIMV
JEQMPMIWSVJVMIRHW;MRRIVW[MPPFIRSXMǻIHF]IQEMPRSQSVIXLERHE]WEJXIVXLIGSQTIXMXMSRGPSWIW']IRXIVMRKXLIGSQTIXMXMSRXLI[MRRIVGSRWIRXWXSER]TYFPMGMX]KIRIVEXIH
JVSQXLIGSQTIXMXMSRMRTVMRXERHSRPMRI5EVXMGMTERXWEKVIIXSVIGIMZISGGEWMSREPRI[WPIXXIVWJVSQ8LI2EK5MQEKE^MRI;IHSRƶXPMOIWTEQTEVXMGMTERXWƶHIXEMPW[MPPVIQEMRWXVMGXP]
GSRǻHIRXMEPERH[SRƶXFIWLEVIH[MXLXLMVHTEVXMIW5VM^IWEVIRSRRIKSXMEFPIERHRSGEWLEPXIVREXMZI[MPPFISǺIVIH;MRRIVW[MPPFIGSRXEGXIHF]IQEMPXSEVVERKIHIPMZIV]&R]
[MRRIVW[LSLEZIRSXVIWTSRHIHHE]WEJXIVXLIMRMXMEPIQEMPMWWIRX[MPPLEZIXLIMVTVM^IVIZSOIH8LMWTVSQSXMSRMWMRRS[E]WTSRWSVIHIRHSVWIHSVEHQMRMWXIVIHF]SVEWWSGMEXIH
[MXL.RWXEKVEQ+EGIFSSO8[MXXIVSVER]SXLIVGSQTERMIWYWIHXSTVSQSXIXLIWIVZMGI

Competition magpi.cc 95
AN INTRODUCTION TO

&
PROGRAMMING
All you need to know
to write simple
programs in C and
start creating GUIs
Inside:
Q Create simple command-line C programs
Q .ZY_]ZWʮZbbT_SNZYOT_TZY^LYOWZZ[^
Q 3LYOWPaL]TLMWP^^_]TYR^LYOʭWP^
Q /P^TRYR]L[STNLW`^P]TY_P]QLNP
applications in C
Q 3LYOWP`^P]TY[`_bT_SM`__ZY^LYOXPY`^
Q @^PLOaLYNPO@4QPL_`]P^^`NSL^OL_L
stores and dialogs

£10 with FREE


worldwide delivery

Buy online: magpi.cc/cgui


NEXT MONTH

EDITORIAL
Editor
Lucy Hattersley
lucy@raspberrypi.com
Features Editor
Rob Zwetsloot
rob@raspberrypi.com
Sub Editor
Nicola King

ADVERTISING

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

DESIGN
criticalmedia.co.uk

AUTOMATION
Head of Design
Lee Allen
Designers
Olivia Mitchell, Sam Ribbits
Illustrator
Sam Alder

WITH
CONTRIBUTORS
David Crookes, Ben Everard,
Rosemary Hattersley, Gordon
Hollingworth, Nicola King,
Phil King, KG Orphanides,

RASPBERRY PI
Eben Upton, Stewart Watkiss

PUBLISHING
Publishing Director
Brian Jepson
brian.jepson@raspberrypi.com
Director of Communications
Liz Upton
CEO

Let’s wire up your house 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

THE MAGPI #129 magpi@subscriptionhelpline.co.uk

ON SALE 27 APRIL This magazine is printed on paper sourced


from sustainable forests and the printer
operates an environmental management
system which has been assessed as

DON’T MISS OUT!


conforming to ISO 14001.

Plus! The MagPi magazine is published by

magpi.cc/subscribe
Raspberry Pi Ltd, Maurice Wilkes Building,
St. John’s Innovation Park, Cowley Road,

A LEGO brick that Cambridge, CB4 0DS. The publisher,


editor, and contributors accept no

plays Doom
responsibility in respect of any omissions
or errors relating to goods, products, or
services referred to or advertised in the

ChatGPT with @TheMagPi magazine. Except where otherwise noted,


content in this magazine is licensed under

Raspberry Pi
a Creative Commons Attribution-
fb.com/MagPiMagazine NonCommercial-ShareAlike
3.0 Unported

Learn Sense HAT magpi@raspberrypi.com (CC BY-NC-SA 3.0).


ISSN: 2051-9982.
THE FINAL WORD

Let’s get together


Raspberry Pi events will bring our community
together again. By Lucy Hattersley

R
aspberry Pi is as much a PaPY_^%?PNS5LX^XPP_`[^LYO computer is used for a wide range of
community as a computer, and maker space days. applications, from building robots to
I am utterly overjoyed to see running servers; playing retro games
the return of the brilliant Events Team huddle and automating your home. And, of
pages to this magazine (page 92). ?SP=L^[MP]]d;TNZXX`YT_dT^L course, coding and computing for its
Rob Zwetsloot runs our vibrant place, where industrial own sake. I’m happy to mess around
community section and will be a makers, enthusiastic programmers, with some abstract concepts in
familiar face to most of you. Rob educators, and hobbyists all gather Visual Studio Code.
loves Raspberry Pi and our to discuss projects and share ideas. Perhaps the most important part
community and is – I’m sure – as ?ST^OTaP]^PR]Z`[ZQ[PZ[WPT^ of the Raspberry Pi community is the
happy as I am to see real-world brought together by a love of spirit of collaboration that brings
events taking place again. everyone together. Whether you’re a
Raspberry Pi itself is deeply This diverse group total beginner or an experienced
connected with industry professional, everyone is welcome,
professionals and enthusiasts, and a of people is brought and everyone is encouraged to share
new Events section can also be _SPT]VYZbWPORP?ST^^`[[Z]_TaP
found on Raspberry Pi’s website together by a love L_XZ^[SP]PT^]PʮPN_POTY_SPXLYd
(magpi.cc/events). online forums, blogs, and social
3P]PdZ`ɪWWʭYO=L^[MP]]d;TL_ of computing and media groups that are dedicated to
industry trade shows and hobbyist
PaPY_^6TNVTYRZʬbT_S0XMPOOPO
the idea that making the Raspberry Pi and the projects
that can be built with it.
World 2023, where you can meet
Raspberry Pi makers. Eben Upton
makes the world a We’re currently in the midst of
our #MonthOfMaking event, but you
will be talking about “Raspberry better place can share whatever you’ve made
Pi: past, present, and future” with The MagPi team using
at the University of Cambridge computing and the idea that ‘making #MagPiMonday. Your build could
(magpi.cc/camfest), and we will makes the world a better place.’ make it into these hallowed pages.
be at the Write the Docs festival ?ST^WZaPXLYTQP^_^T_^PWQaTL
in Portland, OR. You can also Raspberry Pi, because it’s the best
Lucy Hattersley
AUTHOR

visit Raspberry Pi at its store in low-cost, single-board computer,


Cambridge, or a pop-up store around; but it’d probably exist
Lucy is editor of The MagPi and makes
coming soon to Liverpool. LYdbLd4ɪaP_]TPOWZ_^ZQOTʬP]PY_ the magazine with Rob, Nicola, Olivia,
And this is just the beginning of computers, and Raspberry Pi is the and some extremely talented people.
ZʯNTLW=L^[MP]]d;TPaPY_^?SP]P best – mostly because it’s so .XƶWZIV]QYGLEXIEQIǺSVX

are also Raspberry Pi community aP]^L_TWP?ST^^XLWWWZbNZ^_ magpi.cc/lucyhattersley

98 magpi.cc Let’s get together


The new case from the HiPi.io team

Rapid tool-free assembly and disassembly Secure microSD card cover


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

Available at these great Pi stores:

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


.BOBHFZPVSTFSWFSTPS
XPSLTUBUJPOTSFNPUFMZ

"DPTUFŗFDUJWFTPMVUJPOGPSEBUBDFOUFST 
*5EFQBSUNFOUTPSSFNPUFNBDIJOFT

1J,7.)"5
GPS%*:BOEDVTUPNQSPKFDUT 1SF"TTFNCMFEWFSTJPO

3FBMUJNFDMPDLXJUISFDIBSHFBCMFTVQFSDBQBDJUPS 0-&%%JTQMBZ #PPUBCMFWJSUVBM$%30.


ŚBTIESJWF 4FSJBMDPOTPMF 0QFOTPVSDF"1*JOUFHSBUJPO 0QFOTPVSDFTPGUXBSF

$YDLODEOHDWWKHPDLQ5DVSEHUU\3LUHVHOOHUV

3FTFMMFSTVHHFTUJPOTBOEJORVJSJFT
XIPMFTBMF!IJQJJP

You might also like