Download as pdf or txt
Download as pdf or txt
You are on page 1of 100

BUY IN PRINT WORLDWIDE MAGPI.

CC/STORE

+UUWG ,WPG OCIRKEE 6JGQHƓEKCN4CURDGTT[2KOCIC\KPG

RASPBERRY PI
PHOTOGRAPHY
SETUP • EDITING • PROJECTS

- L A P S E & B A T C H
TIME I A L S
CONV E R T T U T OR

BU IL D Y O U R O W N magpi.cc/store

VECTREX MINI
A F T W E A R A BL E K IT
CR
10 FACE TRACKING
PROJECTS

WIN! CUTIEPI COMPUTE MODULE 4 TABLET


Sɟ͝ʡʄ˱

H́Ɏɟ

H́˱ɿʡʄͽ̿ɟ

P i 4 a nd
˱ǵˍΰφɟ W it h R ye s u p p o rt
B u l l s e

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

Home projects made easy.


CDP Studio, a great software development tool for your home projects. Build
͝ΰͮ͝ɟ˪͝‫ڂ‬ɿ́̿‫ڂ‬żǵ̵͝Ȼɟ̿̿ΰ‫ڂ‬Ŵʡհ‫͝ͽڂ‬ɟ‫ڂ‬H֕֕‫ڂ̿́ڂ‬ĩ́H́Ɏɟ‫̵́̿ڂ‬ʄ̿ǵ˪˪ʡ˱ʄհ‫̵́ڂ‬ɟ˱‫̿ͽ́͝ڂ‬ɂɟ‫ˍڂ‬ʡȻ̿ǵ̿ʡɟ͝հ‫ڂ‬
out of the box support for GPIO, I2C, MQTT, OPC UA and more. Create beautiful user
interfaces. Built for industrial control system development, FREE for home projects.

cdpstudio.com
Ɨɟˍմ‫ڂ‬ֈԊԎ‫ڂ‬ԐԐԅ‫ڂ‬ԏԅ‫ڂ‬Ԑԅԅ‫ڂ‬՘‫ڂ‬ʡ˱ɿ́ԺɂɎ̵ͮɟɂʎձɂ́˪
HSŴ‫ڂ‬Ɨɟɂʎ˱́ˍ́ʄʡɟ͝‫ڂ‬Ɖ‫ڂ‬ՄՄ‫ڂ‬ ͽ˱Ɏ͝ΞȘ̿ʄǵͮǵ‫ڂ‬ԏհ‫ڂ‬ԍԅԅԏ‫ˍڂ‬ɟ͝ͽ˱Ɏհ‫ڂ‬ĩ́̿΢ǵΰ
WELCOME

WELCOME
to The MagPi 118
P
hotography is a great way to make use of your
Raspberry Pi single-board computer.
Raspberry Pi’s camera modules provide our small
computer with an eye to the world, enabling sight-based
projects and digital camera creations. Using the newer High
Quality Camera enables you to snap images every bit as
Lucy

EDITOR
impressive as with an expensive camera. Hattersley
But, of course, you can do so much more with a Raspberry Pi Lucy is editor of The
because it’s a fully programmable computer. Raspberry Pi can MagPi magazine
and keeps a beady
perform smart vision sensing tricks – capturing whatever you eye on things. She
is a big fan of art
ask it to. And you can automate shots, taking one every few and photography
computer projects.
minutes to create stunning time-lapse shots. You can even use @LucyHattersley
the images to create your own amazing works of art.
This month we have a superb photography feature (page 32)
that collects everything you need to know about Raspberry Pi
cameras. Plus, Nik Rawlinson has written an excellent time-
lapse tutorial (page 40), and Sean McManus provides us with GET A
wkh#Ľuvw#sduw#ri#DuwHyroyhu#+sdjh#77,#Ğ#d#idqwdvwlf#sulphu#rq# RASPBERRY
batch-converting images with Raspberry Pi. PI ZERO 2 W
Some of my favourite
Raspberry Pi projects involve
PAGE 30
cameras. And this issue
is packed with some of
the greatest image-based
Raspberry Pi projects around.

Lucy Hattersley Editor

magpi.cc 03
Raspberry Pi
goes industrial
PWR

USR

232

485

CAN

IONO PI MAX

Long term availability, high reliability and support

Tailor-made embedded solutions


Our range of Raspberry Pi-based devices is wide.
Really wide.
StratoPi R. 3.0

But what if your project needs something more?

Visit our website www.sferalabs.cc


CONTENTS

Contents
> Issue 118 > June 2022

Cover Feature

32 Raspberry Pi 32
Photography
Regulars
28 Case Study: Crux Labs
92 Your Letters
97 Next Month
98 The Final Word

Project Showcases
08 Portsdown 4 TV Transmitter
12 Air raid siren monitor
14 Synch.Live
16 5\GTCƓP//& 22
Mushroom Farm
20 Vectrex Mini
22 NMS Ceefax
24 AI Weather Station
26 (KDTG1RVKE/CVTKZ&KURNC[

16

5\GTCƓP//&/WUJTQQO(CTO NMS Ceefax

The MagPi magazine is published monthly by Raspberry Pi Ltd. 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 magazine c/o Publishers Service Associates, 2406 Reach Road, Williamsport, PA, 17701.

magpi.cc 05
CONTENTS

44 66
Tutorials
40 Time-lapse photography
44 ArtEvolver - part 1
48 5RGE&GEM
52 Learn ARM Assembly - part 3 ArtEvolver - part 1 Wearables and costumes

The Big Feature 78


66

#KT3WCNKV[&CVCNQIIKPI$QCTF

Wearables and costumes 86


Reviews
76 5VCEM[2K
78 #KT3WCNKV[&CVCNQIIKPI$QCTF
82 Top 10 facial recognition projects
84 Learn Terminal

Community
86 Kevin McAleer interview
88 This Month in Raspberry Pi Kevin McAleer interview

95
WIN A CUTIEPI
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
PROJECT SHOWCASE

Portsdown 4 Digital
TV Transmitter
Fancy running your own digital TV station? Dave Crump did and he
used a Raspberry Pi to do it. PJ Evans takes to the airwaves

D
ave Crump is no couch potato; in fact, he wkh#ehjlqqlqj1#Wkh#Ľuvw#zdv#kdugzduh#K597#
much prefers it on the other side of the encoding. Radio amateurs are limited in the
TV set. Since his early years, he has had a amount of bandwidth and power that they can use
passion for amateur TV. Starting with analogue for communication. The second was easy image
home-built equipment, his projects have raised capture using the camera, which works seamlessly
him up to be a key player in the British Amateur zlwk#wkh#K597#hqfrghu1Ĥ
Television Club. His latest project, Portsdown 4,
brings the new world of digital television Proof of concept
Dave Crump
MAKER

transmission to a wider audience than ever before. Wkh#vxujh#lq#srsxodulw|#ri#vriwzduh0ghĽqhg#


“I was inspired by the desire to reproduce a radios (SDRs) meant that a relatively cheap
Dave is a retired
RAF pilot who
capability that a few years ago would have occupied piece of hardware could handle the reception
UYEPMǻIHJSVER half a room and cost hundreds of thousands of and transmission of DTV signals using the DTB
amateur radio pounds, and replace it with something cheap
PMGIRGIEX
and portable that could be used by myself and
ERHLEWFIIR
XVERWQMXXMRK my fellow amateur TV enthusiasts,’’ Dave tells A capability that a few
XIPIZMWMSRWMRGILI
[EW
us. Fellow enthusiasts had been discouraged
by the seeming complexity of DTV (digital TV)
years ago would have
magpi.cc/
portsdowndatv
broadcasting. It was assumed to be out of the
reach of the home enthusiast, but the advent
occupied half a room
of Raspberry Pi changed all that. “Raspberry and cost hundreds of
Pi brought two key elements to the project at
thousands of pounds
standard used by services such as Freesat. Dave
started to piece together a proof of concept
connecting a Raspberry Pi 3B, SDR, camera, and
audio via a £5 USB dongle to create a rudimentary
DTV transceiver. It was named Portsdown, in
tribute to a late president of BATC in whose
Amateur TV
IRXLYWMEWXWGER Portsdown home the idea took shape.
use satellite dishes
Now Dave has completed Portsdown 4, using the
XSXVERWQMXHMKMXEP
TV worldwide more powerful Raspberry Pi 4 Model B. In addition,

08 magpiGG Portsdown 4 Digital TV Transmitter


PROJECT SHOWCASE

Quick FACTS
> Dave Crump is
GLEMVSJXLI'VMXMWL
&QEXIYV8IPIZMWMSR
(PYF '&8(

> 8LIGSRGITXGEQI
JVSQE+VIRGLVEHMS
amateur –
Evariste Coujard

> The project uses


XLI1MQI)79'
XSXVERWGIMZI

> The project is


Enclosed here is a STIRWSYVGI
Raspberry Pi Camera, ERHER]SRIGER
which provides the FYMPHSRI
video feed
> The Es’hail 2
WEXIPPMXIGERFI
YWIHF]EQEXIYVW

eĹŅþÏĜ±Ĭ±ŸŞÆåųųƼ
Pi 7” touchscreen
provides control
ŅƴåųƤŅŞåų±ƋĜŅĹŸ

A robust case containing


the Raspberry Pi ensures
the unit is suitable for
outdoor transmission

Portsdown 4 Digital TV Transmitter magpiGG 09


PROJECT SHOWCASE

+SVQSVIEHZIRXYVSYW
XVERWQMWWMSRWXLI
5SVXWHS[RGERFI
XEOIRER][LIVI

&HHEHMWLERH
]SYGERVIGIMZI
XVERWQMWWMSRWJVSQ
amateur satellites

Warning!
Frequency
restrictions
9WISJXLMWTVSNIGX
requires a valid UK
PMGIRGIERHQYWXRSXFI
STIVEXIHMRVIWXVMGXIH
JVIUYIRGMIW)MǺIVIRX
VIWXVMGXMSRWETTP]MR
HMǺIVIRXTEVXWSJXLI
[SVPH)S]SYVVIWIEVGL
MJEXXIQTXMRKXSVIGVIEXI
XLMWTVSNIGX

rsgb.org

10 magpiGG Portsdown 4 Digital TV Transmitter


PROJECT SHOWCASE

Evolution of Portsdown 4

)EZIƶWXSYGLWGVIIR
YWIVMRXIVJEGIMW
TIVJIGXJSVXLINSF.X
MWLMKLGSRXVEWX[MXL
PEVKIFYXXSRWXLEXEVI
GPIEVP]PEFIPPIH

Dave started with a block diagram that


a Raspberry Pi 7-inch touchscreen and strong 01 showed how the key parts would link
case have made a complete, travel-ready unit together. The key section is communication with
suitable for outdoor transmission. The power and ±ŸŅüƋƵ±ųåěÚåĀĹåÚų±ÚĜŅŠ„%šƋʱƋƵŅƚĬÚʱĹÚĬå
frequencies that can be used are heavily regulated transmission. A tuner unit allows incoming signals.
by Ofcom and you’ll need a licence to operate a

You’ll need a licence to


operate a Portsdown 4
Portsdown 4, but such licences have been granted
to those as young as ten years old. Amazingly, you
can add a powerful enough antenna to relay your
DTV signal to a satellite that has transponders
The next step was a proof of concept. Here
available to amateur radio enthusiasts. 02 ƵåϱĹŸååƋĘåƋĘųååĩåƼޱųƋŸ×±ŸŞÆåųųƼ
{ĜØ„%ÏŅĹĹåÏƋåÚÆƼŽ„رĹÚƋŅƚÏĘŸÏųååĹţ%±ƴå
Compatibility created the custom touchscreen software to control
Dave’s biggest challenge was compatibility. the system.
Wkh#exlog#uhtxluhg#vshflĽf#frpsrqhqwv#dqg#
peripherals. When he published the build and
the software, he soon found that even very
similar models of webcams and SDRs could cause
problems. This led to the birth of the project wiki
that provides a detailed bill of materials to anyone
who wants to try their hand at building their own.
It’s estimated that over 500 hobbyists have built
their own Portsdown transmitter.
We asked Dave, what was next for Portsdown?
“Development of the Portsdown system as a
piece of radio test equipment is proving to be
very popular. Current capabilities include a
Dave wanted to be able to transmit from
radio frequency signal generator, a simple radio 03 anywhere and, in particular, to relay signals
vshfwuxp#dqdo|vhu/#dqg#d#uhfhlyhu#qrlvh0Ľjxuh# from a satellite. This required a rugged enclosure
meter. Developments are underway to provide with suitable connectors. This also shows the ability
additional test-bench capabilities using the to receive digital video.
h{lvwlqj#kdugzduh1Ĥ#

Portsdown 4 Digital TV Transmitter magpiGG 11


PROJECT SHOWCASE

Air raid siren monitor


Dmytro Panin’s project has the potential to save lives as war in Ukraine
continues to devastate the country, as David Crookes explains

L
ast year, The MagPi featured two projects by ģZkhq#dq#dlu#udlg#ru#vkhoolqj#vwduwv/#zh#xvxdoo|#
Gp|wur#Sdqlq=#klv#Dlu#Txdolw|#WudĿf#Oljkw# khdu#vluhqv#jrlqj#rļ/#vljqdoolqj#wkdw#flwl}hqv#vkrxog#
in issue 108 and his Solar System Display jr#wr#d#erpe#vkhowhu#ru#wdnh#fryhu/Ĥ#kh#h{sodlqv/#ri#
in issue 110. Wkh#Ľuvw#surmhfw#vrxjkw#wr#dgguhvv# klv#prwlydwlrq#wr#fuhdwh#wkh#ghylfh1#ģL#qrwlfhg#wkdw#
frqfhuqv#wkdw#klv#krph#flw|#zdv#rqh#ri#Hxurshġv# p|#idplo|#zrxog#wu|#dqg#jhw#dgglwlrqdo#lqirupdwlrq#
prvw#srooxwhg/#zkloh#wkh#vhfrqg#doorzhg#klp#wr# rq#wkh#suredelolw|#ri#dlu#udlgv#ehiruh#jrlqj#rxw#e|#
jd}h#dw#wkh#vnlhv1#Zkhq#zh#fdxjkw#xs#zlwk#klp# eurzvlqj#wkurxjk#phgld#dqg#rwkhu#fkdqqhov1#L#
uhfhqwo|/#krzhyhu/#kh#zdv#zruulhg#derxw#klv#flw|# wkrxjkw#lw#zrxog#khos#wr#kdyh#d#ghylfh#wkdwġv#dozd|v#
Dmytro Panin
MAKER

dqg#vwdulqj#xszdugv#iru#d#yhu|#glļhuhqw#uhdvrq1 rq#wkdw#frxog#vkrz#wklv#lqirupdwlrq#derxw#dfwlyh#dlu#
Gp|wur#lv#d#Xnudlqldq#iurp#N|ly/#dqg#kh#dqg# udlg#vluhqv#dfurvv#Xnudlqh1Ĥ
Dmytro Panin is a
klv#idplo|#duh#dprqj#ploolrqv#ri#shrsoh#glvsodfhg# Wr#gr#wklv/#kh#wxuqhg#wr#wkh#srsxodu#lqvwdqw#
programmer based
in Ukraine, and dqg#vxļhulqj#vlqfh#Uxvvld#lqydghg#wkhlu#frxqwu|1# phvvdjlqj#sodwirup#Whohjudp1#ģLw#kdv#ihdwxuhv#
LI[VSXILMWǻVWX ģL#zdv#lq#N|ly#zkhq#wkh#Ľuvw#zdyh#ri#h{sorvlrqv# uhvhpeolqj#d#vrfldo#phgld#sodwirup/Ĥ#Gp|wur#vd|v1#
line of code aged vxujhg#dfurvv#Xnudlqh#dqg#zh#ohiw#wkh#flw|#zlwk# ģRqh#ri#wkhvh#lv#ĠFkdqqhovġ#Ğ#suhww|#pxfk#d#rqh0
eight. He works for
a large provider of qrwklqj#exw#rxu#edfnsdfnv/Ĥ#kh#vd|v1#\hw#dprqj# wr0pdq|#lqirupdwlrq#glvwulexwlrq#sodwirup1#\rx#
nearshore software wkh#lwhpv#kh#pdqdjhg#wr#jude#ehiruh#hydfxdwlqj# vxevfuleh#wr#d#fkdqqho#|rxġuh#lqwhuhvwhg#lq#dqg#jhw#
engineering zhuh#d#Udvsehuu|#Sl#]hur#frpsxwhu#dqg#dq#h0lqn# phvvdjhv#zlwk#olqnv/#skrwrv#dqg#ylghrv#iurp#shrsoh#
services.
vfuhhq#Ğ#dq#rgg#ghflvlrq/#kh#dgplwv/#exw#rqh#wkdw#
magpi.cc/ kdv#suryhq#wr#eh#yhu|#xvhixo1
airraidmonitorgit
We left the city with nothing
Getting alerts
E|#xvlqj#wkrvh#wzr#frpsrqhqwv/#Gp|wur#kdv# but our backpacks
fuhdwhg#dq#dlu#udlg#vluhq#prqlwru#wkdw#vkrzv#zklfk#
sduwv#ri#wkh#frxqwu|#duh#ehlqj#vkhoohg1#Kh#vd|v#kh#
qhyhu#lpdjlqhg#wkdw#kh#zrxog#hyhu#pdnh#vxfk#d# zkr#uxq#lw1#Whohjudp#ehfdph#d#zd|#iru#rĿfldov#wr#
ghylfh/#exw#wkh#zdu#kdv#vkliwhg#wkh#sdudgljp#ri# qrwli|#zkhuh#dlu#udlg#vluhqv#vwduw#dqg#vwrs1Ĥ
zkdw#lv#d#pxvw/#d#qhfhvvlw|/#ru#xvhixo1#ģL#nqrz#
zkhuh#doo#wkh#ordg0ehdulqj#zdoov#lq#p|#dsduwphqw# Making predictions
duh/Ĥ#kh#odphqwv/#vd|lqj#kh#qrz#orrnv#dw#rog# Zkhq#Gp|wur#ehjdq#klv#surmhfw/#wkh#h0lqn#vfuhhq#
frqfhswv#lq#frpsohwho|#qhz#zd|v1 zdv#douhdg|#frqqhfwhg#wr#Udvsehuu|#Sl#]hur1#Wkh#
lghd#zdv#wr#frgh#d#surjudp#wkdw#zrxog#prqlwru#dqg#
sduvh#phvvdjhv#lq#Whohjudp#dqg#fuhdwh#d#ylvxdo#
vqdsvkrw#ri#wkh#fxuuhqw#vlwxdwlrq#dfurvv#Xnudlqh1#
ģQrw#rqo|#grhv#lw#vkrz#uhjlrqv#zkhuh#wkh#dlu#udlg#
vluhqv#duh#dfwlyh/#lw#khosv#wr#suhglfw#d#srwhqwldo#dlu#
udlg#e|#orrnlqj#dw#wkh#vsuhdg#dqg#surjuhvvlrq#ri#wkh#
dwwdfn#Ğ#fkdqfhv#duh#wkdw#li#pxowlsoh#uhjlrqv#duh#
klw/#lw#zloo#vsuhdg/Ĥ#Gp|wur#vd|v1
Lw#zdvqġw#doo#sodlq#vdlolqj/#wkrxjk1#ģWkh#sureohp#
zdv#wkdw/#hyhq#wkrxjk#L#kdg#d#suhfrqĽjxuhg#
plfurVG#fdug#lqvwdoohg#lq#Udvsehuu|#Sl#]hur/#L#
Although there are qhhghg#wr#fkdqjh#wkh#frqĽjxudwlrq#lq#wkh#Ġerrwġ#
lots of air raid sirens
across Ukraine, there gulyh#dqg#d#fdug#uhdghu#zdvqġw#vrphwklqj#L#
are still many places
frqvlghuhg#hvvhqwldo#zkhq#sdfnlqj#p|#edj$#
in a city where they
cannot be heard L#hqghg#xs#sxwwlqj#wkh#plfurVG#fdug#lqwr#d#idplo|#

12 magpi.cc Air raid siren monitor


PROJECT SHOWCASE

The device works


remarkably fast, says
Dmytro, and it is powered
using a micro-USB cable

eƋĀųŸƋرŸŞÆåųųƼ{Ĝ¬åųŅƤœ
processed Telegram
messages to gather air raid
siren data, but Dmytro has
ŸĜĹÏåÏŅĹĀčƚųåÚ±ÏĬŅƚÚ
Ÿåųƴåų±ĹÚÏųå±ƋåÚ±Ĺe{F Quick FACTS
> It can help predict
the likelihood
of airstrikes

> The device updates


every few seconds
The project displays
a key-coded map of
> All code is
Ukraine on a Waveshare
open-source
e-ink 2.13-inch display

> It monitors
Telegram for
information

Dmytro had already put the screen and > Dmytro’s family
Raspberry Pi Zero W together in a case
before being forced to evacuate Kyiv evacuated with
paperwork, clothes,
food, and laptops

phpehuġv#skrqh#dqg#xvlqj#d#wh{w#hglwru#wr#
frqĽjxuh#wkh#fpgolqh1w{w#dqg#frqĽj1w{w#wr#VVK#lqwr#
Udvsehuu|#Sl#]hur#wkurxjk#wkh#XVE#frqqhfwlrq1Ĥ
Wkh#surmhfw#kdv#dovr#ohg#wr#wkh#fuhdwlrq#ri#d#
preloh0Ľuvw#rqolqh#pds#dw#sirens.in.ua1#ģLwġv#kdug#
wr#jhw#Udvsehuu|#Sl#lq#Xnudlqh#li#|rx#grqġw#douhdg|#
kdyh#rqh/Ĥ#Gp|wur#uhyhdov1#
Vr#idu/#wkh#ghylfh#kdv#suryhq#xvhixo1#ģOdvw#
zhhnhqg/#zh#zhuh#jhwwlqj#uhdg|#wr#jr#wr#wkh#
vkrs#exw/#edvhg#rq#wkh#gdwd#iurp#wkh#ghylfh/#zh#
srvwsrqhg#wklv#dqg#wkh#dlu#udlg#vluhq#zhqw#rļ#whq#
plqxwhv#odwhu/Ĥ#kh#vd|v1#Vlqfh#srvwlqj#derxw#wkh#
prqlwru#rqolqh/#orwv#ri#rwkhu#Xnudlqldqv#kdyh#dovr#
fuhdwhg#wkhlu#rzq#yhuvlrq1#ģL#kdyh#rshq0vrxufhg#
wkh#frgh#dqg#wkh#lqvwuxfwlrqv1#L#krsh#lw#nhhsv#shrsoh#
There’s a macOS widget too, with Linux
vdih#gxulqj#wkhvh#xqwklqndeoh#wlphv1Ĥ# and Windows versions in the works

Air raid siren monitor magpi.cc 13


PROJECT SHOWCASE

Synch.Live
Combining art and brain science with
Raspberry Pi? It’s not as strange as you
think. Rob Zwetsloot ponders it

C
reating art with Raspberry Pi is one of our
favourite things to see, which is why we
have been excited about this project during
an email exchange with its creator, Hillary Leone.
“Synch.Live is a joyful, participatory community
art experience and cutting-edge brain science
Construction of the hat system
experiment, designed to spark emergent behaviour
and fortify human connection,” Hillary tells us.
Hillary Leone Idea emerging
MAKER

“Here’s how it works. A group of players wear


erzohu#kdwv#htxlsshg#zlwk#udqgrpo|#ľdvklqj# How does one go about creating such a system?
A New York-based
artist working at the LEDs. Their challenge is to synchronise the LEDs “Functionally, the system needed to extract
intersection of art, on all of the hats without talking or touching. A position and movement information, feed it into
science, technology, tracking system mounted above tracks collective the emergence algorithm, and then create a visual
and social impact.
movement and calculates the level of group feedback loop to signal how close the participants
synch.live fr0ruglqdwlrq#lq#uhdo#wlph1#Li#wkh#jurxs#fdq#Ľjxuh# were to the goal of the game,” Hillary explains.
out how to move together in a coherent, emergent “The system needed to run the emergence
fashion, the LEDs will synchronise.” criterion in real-time and provide feedback to the
Hillary explains that emergence can mean player hats. The hats needed to be able to ‘blink’
many things: “capturing the creation of galaxies, lq#shuihfw#v|qf/#olnh#Ľuhľlhv#gr#lq#qdwxuh1#Wkh|#
The tracking intelligent behaviour in ant colonies, economics, qhhghg#wr#eh#vdih#dqg#frpiruwdeoh>#ľh{leoh#wr#doorz#
system uses an HQ
ecosystems, and conscious brains.” The use of it in
Camera and hangs
from the ceiling this context is brand new.
The system needed to
run the emergence
criterion in real-time
for complex patterns and artistic expression; and
precise and reliable in order for the results of the
vflhqwlĽf#sduw#ri#V|qfk1Olyh#wr#eh#ydolg1Ĥ
Building the system wasn’t so easy, and the
team also wanted to make the code easy to use
as well. “We wanted to build a system that was
easy for other artists, scientists, and enthusiasts
to replicate and play with,” Hillary says.
“Scalability was also an important requirement:
while we are currently running small pilots
with only a few players (ten), we envision a
future for Synch.Live where dozens of players
meet up to create large mesmerising displays of
emergent co-ordination.

14 magpi.cc Synch.Live
PROJECT SHOWCASE

The lights are used by the


people in the experiment to
know if they’re co-operating

The whole thing is


powered by a single
mobile battery

All the components


are stored in and
Quick FACTS
around the hat
> Synch.Live began
as a thought
experiment about
future language

“With those requirements in mind, we designed


> 'MVHWǼSGOMRK
the software to be highly modular and extensible.
together, without
Precise clock synchronisation and scalable a leader or plan,
deployment were tough nuts to crack; we solved is emergence
them with RTC modules and Ansible. We have been
lucky to have a network of very supportive friends > The tracking
and collaborators, including professional software system uses a
engineers and computer vision researchers, who Raspberry Pi 4
have helped us make this project a reality. The and camera...
project has been developed fully open-source, Here’s how the experiment looks in action
> …while the hats
and our in-house software engineer Madalina has
use Raspberry Pi
thoroughly documented the build process in her The project is currently undergoing further
Zero W and an
blog (mis.pm/projects).” uhĽqhphqwv#dv#slorwv#duh#uxq#wr#whvw#wkh#v|vwhp/# RTC add-on
and Synch.Live will show up on 18-19 June at
Scientific fun Imperial College London. > Conversations
If you’re like us, this all sounds very fascinating, “Once we have the data to demonstrate about the project
and also a fun experience to participate in. collective emergence, we want to scale-up the started in 2020
“People are incredibly excited about the group size, design the wearable, develop new
work and its potential applications,” Hillary scenarios and rules sets, and explore applications
mentions. “As one attendee wrote after one of vxfk#dv#frqľlfw#uhvroxwlrq#dqg#whdp#exloglqj1Ĥ#
our presentations: ‘The vision is powerful, the Kloodu|#Ľqlvkhv/#ģXowlpdwho|/#zh#zdqw#wr#pdnh#wkh#
implications and potential are clearly articulated experience of Synch.Live available to communities
and beautifully expressed, and the need for this durxqg#wkh#zruog/#dqg#pdnh#d#Ľop#wkdw#fhoheudwhv#
zrun#lv#ghhs#dqg#vljqlĽfdqw1ġĤ our collective humanity.”

Synch.Live magpi.cc 15
PROJECT SHOWCASE

5\GTCƓP//&
Mushroom Farm
Hobbyist farmers Judit and Zsolt used engineering and tech know-how
to expand their mushroom farming business. Rosie Hattersley hears how

W
ith two decades of engineering “The aim is to ensure the automatic operation
experience gained during military of mushroom growing sites, so the characteristics
service, Hungarian Zsolt Pozsár of the growing environment can be monitored
uhvxphg#klv#yrfdwlrqdo#txdolĽfdwlrqv#dqg# dqg#prglĽhg#uhprwho|/Ĥ#vd|v#]vrow1#ģGhylfhv#
began a career maintaining the bottling lines must operate continuously and reliably in a humid
for a multinational company. Meanwhile, his hqylurqphqw#zlwkrxw#xvhu#lqwhuyhqwlrq1Ĥ#Uhprwh#
wife Judit’s small farming concern seemed as management without smart controller devices
wkrxjk#lw#frxog#ehqhĽw#iurp#]vrowġv#nqrzohgjh# such as relays and timers is impossible. “These
of how technology could improve their crops. operations should be user-friendly, with no
The couple have been growing mushrooms for surjudpplqj#nqrzohgjh#uhtxluhg1Ĥ
wkh#sdvw#Ľyh#|hduv1#]vrowġv#PP8G#Udvsehuu|# ]vrow#zdqwhg#d#vpdoo/#orz0srzhu/#Olqx{0edvhg#
Pi-based monitoring system – a four-channel vlqjoh0erdug#frpsxwhu1#Kh#fkrvh#Udvsehuu|#Sl#iru#
programmable control and remote monitoring his mushroom farm on the recommendation of
Zsolt
/#-'4

v|vwhp#Ğ#kdv#nhsw#dq#h|h#rq#wkh#pxvkurrpvġ# a technical vocational high school teacher who’d


Pozsár
ghyhorsphqw#iru#wkh#sdvw#wkuhh#|hduv/#Ľuvw#lq#d# used them and said he wouldn’t be disappointed.
Judit and Zsolt cellar underneath the house, and more recently in ]vrow#qrz#xvhv#Udvsehuu|#Sl#6E.#lq#doo#klv#surmhfwv/#
Pozsár’s remotely dedicated mushroom fruiting chambers. doo#ri#zklfk#kh#vhoi0ghvljqv/#pdnlqj#xvh#ri#
managed mushroom
standard items such as display, relay boards, and
farm is an excellent
ǻVWX7EWTFIVV] third-party libraries. The hardware cost no more
5MTVSNIGXJSVXLI wkdq#73/333#Kxqjduldq#irulqwv#+dssur{lpdwho|#
engineer and his wife. $110, or £90). “The hardest part of building a
QEKTMGGW^IVEƤR ghylfh#lv#pdnlqj#wkh#er{#dqg#pdnlqj#wkh#iurqw#
sdqho1#Lw#uhtxluhg#d#forvhg#er{1#L#erxjkw#wklv/#exw#
lw#zdv#kdug#wr#Ľqg#d#frpsdq|#wkdw#ghdov#zlwk#
Soh{ljodv#fxwwlqj#dqg#sulqwlqj/Ĥ#]vrow#h{sodlqv1#

The mushroom tents


Mushroom for growth
LEZIVIGIRXP]FIIR The mushroom monitoring system consists of
NSMRIHF]WMQMPEVP]
controlled outdoor
d#WWO0ohyho#lqsxw#lq#zklfk#whpshudwxuh#dqg#
ZIKIXEFPIGVSTW humidity are measured. The remotely accessible

16 magpi.cc ^IVEǻR22)2YWLVSSQ+EVQ
PROJECT SHOWCASE

Zsolt’s MM5D controller is


based around Raspberry
Pi 3B+, and runs a
Logging in via SSH allows the bespoke Python script
couple to check for any issues
with overwatering or humidity,
as well as optimising light levels

Quick (#%65
> >WSPXIRNS]W5
languages: Pascal,
Perl, and Python

> And has a


weakness
for rescuing
EFERHSRIHGEXW

The MM5D remotely > His army years


controlled mushroom [IVIWTIRXPSSOMRK
growing environment after air
is successful enough defence radars
to operate as a
commercial farm > He still can’t resist
VITEMVMRKSPH
electron
XYFIIUYMTQIRX

> But he’s currently


tinkering with
irrigation controls

Warning!
Mains Electricity
Do not connect 230 V
contacts to the relays
SRXLITVMRXIHGMVGYMX
FSEVHEWXLIMVLMKLGSMP
voltage and current will
also cause the contact to
WTEVOERHMRXIVJIVI[MXL
XLIHMWTPE]ƶWWIVMEPHEXE
XVEǽG9WIPS[ZSPXEKI
and current fast relays
and move them away
from the control unit.

 2YWLVSSQWFIRIǻXJVSQXLIMV magpi.cc/
STXMQEPKVS[MRKGSRHMXMSRW electricalsafety

^IVEǻR22)2YWLVSSQ+EVQ magpi.cc 17
PROJECT SHOWCASE

Zsolt’s controller system shows the status of the lights, fans, kh#pdnhv#wkh#lqvwdoohu#vriwzduh#iru#klv#PP8G#
allows the user to
see at a glance the kxplglĽhu/#dqg#zdwhulqj#v|vwhp#Ğ#lqfoxglqj#wkh# plant-monitoring devices available online
WXEXYWSJXLIGVST pressure, and whether or not the tent door is open. (magpi.cc/mm5dgit). He also maintains his own
and the current
environment settings ģPhdvxuhphqw/#wlplqj/#dqg#hohfwulfdo#htxlsphqw# Gheldq#uhsrvlwru|#iru#Udvsehuu|#Sl#RV/#Gheldq/#dqg#
control is done by a Python-language program that Xexqwx#Olqx{#+magpi.cc/pozsi).

Grow more greens


Growing mushrooms this way has proved Jurzlqj#pxvkurrpv#wklv#zd|#kdv#suryhg#

successful enough for Judit and Zsolt to vxffhvvixo#hqrxjk#iru#Mxglw#dqg#]vrow#wr#rshudwh#d#


local delivery service for customers in the vicinity

operate a local delivery service


uxqv#dv#d#vhuylfh#lq#wkh#edfnjurxqg/Ĥ#]vrow#whoov#xv1#
Wkh#surjudp#uhtxluhv#dq#lqwhuqhw#frqqhfwlrq#dqg#
access to data from OpenWeatherMap.org.
Wkh#PP8G#vhwxs#+rqh#ri#vhyhudo#khġv#ghyhorshg#
and implemented at the family farm), uses
Udvsehuu|#Sl#6E.#dqg#kdv#ehhq#lq#frqwlqxrxv#xvh#
since 2019. “The devices were built one after the
rwkhu/#vr#L#zdv#deoh#wr#xvh#wkh#h{shulhqfh#jdlqhg#lq#
exloglqj#iru#wkh#qh{w#ghylfh1Ĥ#Wklv#lwhudwlyh#surfhvv#
lv#uhľhfwhg#lq#]vrowġv#phwlfxorxv#JlwKxe#zkhuh#

18 magpi.cc ^IVEǻR22)2YWLVSSQ+EVQ
PROJECT SHOWCASE

ri#wkhlu#idup#lq#Wlv}diØogyÃu/#forvh#wr#Exgdshvw1#
Their mushrooms, as well as oyster mushroom )TQY[QWTQYP
compost useful for growing other crops, are sold in
hqylurqphqwdoo|#iulhqgo|#sdfndjlqj1
Wkh|ġyh#dovr#h{sdqghg#zlwk#dgglwlrqdo#
mushroom fruiting chambers, as well as
diversifying into other crops. The addition of these
yhjhwdeoh#sorwv#kdv#dovr#jlyhq#]vrow#wkh#h{fxvh#wr#
frph#xs#zlwk#dqrwkhu#prqlwrulqj#surmhfw#dgglqj#
automated irrigation to the whole site, as well as
the mushroom tents. “The water and electrical
system, electrical cabinet, and pump shaft will be Judit and Zsolt’s son
WLS[WSǺXLIPEXIWX
ready by the summer. Tomatoes, eggplants, and QYWLVSSQGVSTKVS[RMR
XLIMVGIPPEVTVSHYGIH[MXL
sxpsnlqv#zloo#jurz#dqg#wkh#hqylurqphqw#zloo#
XLILIPTSJXLISVMKMREP
eh#ehdxwlixo$Ĥ# TVSXSX]TIGSRXVSPPIV
The MM5D controller unit houses Raspberry
01 Pi and sensors and controllers to adjust the
lights, temperature, and humidity sensors. It’s linked
to OpenWeatherMap.org.

Powered by Raspberry Pi 3B+, the MM5D has


02 four inputs, four controllers, and four status
relay contact outputs. Parameters are customisable.
Details of the Python-based hardware controller are
at: magpi.cc/mm5d.

Environmental settings can be manually


03 overridden, but the system is largely designed
to operate automatically.

^IVEǻR22)2YWLVSSQ+EVQ magpi.cc 19
PROJECT SHOWCASE

Vectrex Mini
A bespoke version of a rare video games console is within your reach... if you’re willing
to make one. Nicola King learns how to ‘mini-fy’ an inimitable console of yesteryear

R
emember the Vectrex video games system?
Maybe not. Launched in 1982, it soon
disappeared. Still, it was one of the most
curious consoles ever made, with an integrated
vector CRT monochrome monitor – colour could be
added with the addition of an acrylic screen overlay
that came with each cartridge-based game. Only
5;#wlwohv#zhuh#rĿfldoo|#uhohdvhg/#lqfoxglqj#wkh#
Brendan
MAKER

Meharry built-in Mine Storm, although some homebrew


games were later created by fans.
Brendan runs a Anyone now wanting to get their hands on a
YouTube channel Yhfwuh{#zloo#Ľqg#wkhpvhoyhv#kxjho|#fkdoohqjhg/# Brendan designed the Vectrex Mini
about retro gaming case in Blender and 3D-printed it
because this unique games system is extremely
called Retro Game
On. As a keen rare. With that in mind, Aussie retro gamer Brendan
maker too, he Meharry decided to fashion his own version of this the spare Raspberry Pi that he already had in his
tries to mix the
classic console, investing some six months of his stash. For the audio element of the build, he used
two hobbies.
spare time into the project in the process. d#vxshu0vpdoo#SDP;635#dpsolĽhu#e|#Dgdiuxlw1#
retrogameon.com Brendan employed a Waveshare 2.5-inch LCD
Honey, I shrunk the console screen for the project, but would he entertain the
Having experienced the console’s delights, playing idea of replacing that with a mini upcycled CRT
on an original Vectrex in a local gaming museum, display? “Maybe! To be honest, the high voltage
Brendan was motivated to make one. “They were ri#FUWv#whuulĽhv#ph#+hyhq#wkh#vpdoo#rqhv,/#exw#
released in Australia, but they’re quite rare,” he Lġg#oryh#wr#vhh#li#vrphrqh#hovh#frxog#sxoo#lw#rļ/Ĥ#
whoov#xv1#ģL#zdv#lqvsluhg#e|#rĿfldo#plql#frqvrohv# he enthuses.
like the SNES Mini or PlayStation Classic. I thought The Waveshare screen plugs into the GPIO pins
it would be fun to ‘mini-fy’ something more of a Raspberry Pi 2 Model B which runs a Vectrex
obscure, especially since the original included a emulator using the latest build of RetroPie. “It
built-in monitor.” So, with his 3D printer ready to wrrn#ph#d#orqj#wlph#wr#Ľjxuh#rxw#krz#wr#uxq#wkh#
roll, he set to work. emulation in portrait mode with no weird scaling
Alert! The Vectrex Mini didn’t prove too expensive to or stretching of the image,” says Brendan of one of
Copyright create, totalling around $70 all-told, not including several challenges he faced along the way.

:MHISKEQIǻPIWEVI An achievable goal


protected by copyright Brendan says that building the separate controller,
law. Be sure to use
742ǻPIWXLEXLEZI which is based on an Arduino Pro Micro with a
been released with KY-023 joystick module, proved to be the easiest
the owner’s blessing,
or modern homebrew part of the build. “If you’ve watched the [YouTube]
games designed to be
shared. There are lots
ylghr/#lwġv#sodlq#wr#vhh#wkdw#lw#zdv#p|#Ľuvw#wlph#
of legal options. designing something like that. But on the upside,
magpi.cc/legalroms the later designing/building of the controller went
much smoother. It’s obvious I learned from my
plvwdnhv/Ĥ#kh#dĿupv1#
Ghvslwh#wkh#ohduqlqj#fxuyh/#Euhqgdq#lv#frqĽghqw#
Testing out the
that such a project would be within the grasp
electronics for the
controller unit of many hobbyists. “The 3D modelling is likely

20 magpi.cc Vectrex Mini


PROJECT SHOWCASE

An LCD is used for the


Vectrex Mini’s screen,
in portrait mode like
the original console

Brendan made a
separate controller
Quick FACTS
unit for the project
> It’s powered by a
WXERHEVHSǽGMEP
5.1 V 2.5 A micro-
USB supply

> 3D printing time


totalled around
30 hours

> The 3D models


EVISR8LMRKMZIVWI
magpi.cc/
vectrexmini3d

> Brendan has also


built a wooden
arcade stick
This banana gives
running RetroPie….
you an idea of just
how small this
> :MI[XLIZMHISJSV
ĵĜĹĜĀåÚÏŅĹŸŅĬåĜŸ
MXLIVImagpi.cc/
woodarcadestick

I thought it would be fun


to ‘mini-fy’ something
more obscure
the most complex portion of the project, but
the wiring, software etc. is quite basic. Overall,
I’d say it’s a reasonably easy project for an
experienced maker.”
Brendan has a detailed and informative YouTube
ylghr#+magpi.cc/vectrexmini,#wdnlqj#|rx#wkurxjk#
his build, which is well worth a watch if you’re
interested in fabricating your own version, and
he’s been bowled over by the response to his
project. “As a newbie, I’ve been blown away by
the encouraging comments and constructive
criticism,” he recounts. But, more than that, he’s
also gained a huge amount from the experience,
and surely that’s what we all want to acquire from
Final assembly of the 3D-printed case
every project we make. and the innards of the project

Vectrex Mini magpi.cc 21


PROJECT SHOWCASE

NMS Ceefax
The BBC closed its Ceefax service in 2012 but Nathan Dane is keeping
memories of the iconic blocky service alive, as David Crookes explains

B
efore the internet, there was teletext
– a brightly coloured, blocky-looking
information service built into a huge
number of television sets from the mid-1970s
onwards. It allowed millions of people to read
qhzv#dqg#vsruw#khdgolqhv/#fkhfn#wkh#zhdwkhu/#Ľqg#
travel information, view TV and radio listings, and
even play a quiz or two.
Nathan Dane
MAKER

But while it still exists across the world, many


popular services have long been axed – including
Hailing from
Northern Ireland, BBC Ceefax which ended in 2012. Rather than allow
Nathan spends its memory to wither, however, enthusiasts are
most of his time determined to keep this charming service alive,
working on
electronic projects among them Nathan Dane who had recreated his Nathan has designed his own VBIT-Pi 3 board which
and coding. own version of Ceefax on a Raspberry Pi connected adds a teletext stream to a PAL video signal

magpi.cc/ to a VBIT-Pi board.


nmsceefax to Raspberry Pi’s composite video output, and
Top stories anyone can use it to generate teletext without
Nathan’s original aim was to produce a teletext additional hardware.”
service as a personal project. “I only really wanted Dw#Ľuvw/#kh#zrxog#pdqxdoo|#w|sh#vwrulhv#iurp#
a service that would be useful to me and my BBC News – which he found too time-consuming,
family, so I coded things like the national and despite the 40-column text screen limitations. It
local news headlines for my dad to read, and wrote was then that he started scraping the BBC website
‘school news’ and other information for my sister for news and sport content, going as far as adding
and I,” he explains. the ever-popular football league tables.
To do this, he made use of Peter Kwan’s VBIT-Pi ģWkh#EEF#rļhuv#UVV#ihhgv#Ğ#[PO#grfxphqwv#
project and Alistair Buxton’s Raspi-teletext dxwrpdwlfdoo|#Ľoohg#zlwk#olqnv#wr#wkh#odwhvw#
software. “The VBIT-Pi adds the teletext signal khdgolqhv/Ĥ#Qdwkdq#vd|v1#ģP|#frgh#sduvhv#wkhvh#
to any PAL composite video signal so you can links and extracts the text from each page. One
play a TV channel through it and add teletext,” lvvxh/#ri#frxuvh/#lv#wkdw#vrph#vwrulhv#grqġw#Ľw#zhoo#
he says. “Raspi-teletext adds the teletext signal into the teletext format, such as reports made up
mostly of photos or videos, so I had to build in
checks to remove those.”

Rain or shine
Nathan also tweaked the Ceefax page design so that
it would allow headlines longer than 35 characters
dqg#kh#pdgh#klv#QPV#Fhhid{/#dv#kh#fdoov#lw/#gudz#
data from other sources, too. TV listings, for
lqvwdqfh/#frph#gluhfwo|#rļ0dlu#iurp#wkh#Iuhhylhz#
Electronic Programme Guide. Weather, meanwhile,
You can view the lv#wdnhq#iurp#wkh#Phw#RĿfhġv#DSL#Ğ#d#ghflvlrq#wkdw#
pages on Nathan’s
website using overcame a major challenge.
an interactive
ģIru#wkrvh#zkr#grqġw#uhphpehu/#wkh#Fhhid{#
viewer created by
Alistair Cree weather map was essentially a blocky outline of

22 magpi.cc NMS Ceefax


PROJECT SHOWCASE

The project has made


use of a Raspberry Pi
3B+ running customised
Raspi-teletext software

This is an In-Vision Decoder which


takes a teletext signal in a raw
VBI form and outputs to a TV or
monitor. It’s added mainly for fun,
and isn’t needed for NMS Ceefax

Quick FACTS
> BBC Ceefax was
XLIǻVWXXIPIXI\X
service in 1974
Raspberry Pi can generate a valid
> Nathan’s version
teletext signal without VBIT-Pi, but
scrapes the BBC
the board allows teletext to be
website for news
added to an existing video signal

> His NMS Ceefax


runs entirely on
Raspberry Pi
wkh#XN#zlwk#duhdv#vkdghg#lq#glļhuhqw#frorxuv/Ĥ# it was an old broadcast technology that I could
Nathan explains. “Coloured text around the recreate, but I very quickly came to love the > He’s built it up
edges told of the weather to be expected in the simplicity of the format,” he says. “People have over six years
corresponding area, but this was challenging to said hard limits induce creativity and this couldn’t
> It can be accessed
recreate because it relies on a lot of ‘fuzzy logic’.” be more true with teletext.”
via Nathan’s
website too

Raspi-teletext adds
the teletext signal to
Raspberry Pi’s composite
video output
Dw#Ľuvw/#kh#kdug0frghg#wkh#irxu#XN#frxqwulhv#lq#
glļhuhqw#frorxuv#dqg#lqfoxghg#wkh#gdwd#ehvlgh#hdfk#
ri#wkhp1#E|#wdnlqj#zhdwkhu#iurp#wkh#Phw#RĿfh/#
however, Nathan could download weather data for
the UK’s eleven regions. “Comparison code then
grouped all the areas with similar conditions under
one colour – it’s not perfect, but it’s close enough
to do the job,” Nathan reveals.
Having kept the project for personal use for
a long time, he’s now made his Ceefax publicly
This fuzzy image shows how the teletext signal looks in the Vertical
available online, where it’s gone down well with
Blanking Interval (VBI). “This was made visible by adjusting the
visitors. “I was initially drawn to teletext because V-Hold on a CRT to ‘roll’ the VBI down into view,” Nathan says

NMS Ceefax magpi.cc 23


PROJECT SHOWCASE

AI Weather Station
Forecasting air quality with this Raspberry Pi weather station
and machine learning, Rob Zwetsloot takes a whiff

A
ir quality is a big issue in many parts of
the world – especially in cities and other
built-up areas. While we’ve seen a couple
projects like this before which just show current air
quality readings, this project does something a bit
more special.
“I focused on creating an AI-driven, budget-
Kutluhan Akar friendly device to collect local weather data with
MAKER

ozone concentration to train a TinyML (TensorFlow


A self-taught full- Lite) neural network model,” Kutluhan Akar, the
stack developer, project’s maker tells us. “[It runs] the trained model
maker, and
to forecast air quality levels so as to get prescient
electronics
enthusiast, he warnings regarding pulmonary risk factors to avert
concentrates on potential hazardous respiratory diseases.”
proof-of-concept It’s built like a regular home weather station, The completed kit is very sturdy and
environmental and has some weather resistance
ecological projects. with sensors that can track local conditions.
Combining those with the ozone concentration and
online data in the training model adds that extra being trained,” Kutluhan explains. “To collect the
sauce to the project. required data to train my model, I connected an
I2C ozone sensor, an anemometer, and a BMP180
Arduino and Raspberry Pi precision sensor to the Nano 33 BLE. Then, I added
Data is fed to Raspberry Pi from an Arduino Nano
33 BLE for analysis.“I decided to utilise an Arduino The predictions are at
Nano 33 BLE in this project since it can easily
Multiple screens
collect local weather data with ozone concentration roughly 92% accuracy for
WLS[HMǺIVIRXHEXE and run my neural network model outdoors after
the three quality classes
an SSD1306 OLED display to monitor the collected
gdwd#lq#wkh#Ľhog1
“Since I collected local weather data with
ozone concentration on my balcony, I was able
to transmit the collected data from the Nano 33
BLE to a Raspberry Pi 4 in my house over BLE
instead of sending data packets to a web server as
usual. In that regard, I was able to transfer data
packets via the Nano 33 BLE without requiring any
additional procedures.”
After running the data through TensorFlow, he
assigned the results to three categories: Good,
Moderate, and Unhealthy. With the training done,
he transferred the model back to the Nano 33 BLE
as a C array so it could use the model on the system
for predictions.

24 magpi.cc AI Weather Station


PROJECT SHOWCASE

The case is inspired by


the humble windmill

Quick FACTS
> If you wish to
replicate this,
Kutluhan says a
Raspberry Pi 3B+
will work too

> Displays around


the weather station
display predictions

> The C array is a .h


The weather station ǻPIXLEXXLI
is designed to Nano 33 uses
predict air quality
> Raspberry Pi was
able to read the
wireless data from
the Nano 33...
The sensors
gather data > … which were
which are then WXSVIHMR(:ǻPIW
combined with for analysis
online forecasts

“Lastly, to make the weather station as sturdy


and robust as possible while enduring harsh
weather conditions, I designed a windmill-themed
fdvh#+6G0sulqwdeoh,/Ĥ#Nxwoxkdq#Ľqlvkhv1

Good quality
According to Kutluhan, the predictions are at
roughly 92% accuracy for the three quality classes.
“After publishing my project, I received
encouraging comments to keep improving
this weather station as an SDG (Sustainable
Development Goals) project,” he reveals. “[I also
got] questions regarding how to make the station
frpsdwleoh#zlwk#ZlIl#ru#JSUV#e|#xwlolvlqj#glļhuhqw#
development boards.”
Kutluhan is planning to add LoRaWAN and GPS
capabilities to the weather station in the future, for
collecting data in forests and industrial areas. We
look forward to seeing how it goes! Testing the weather station to make sure it all works

AI Weather Station magpi.cc 25


PROJECT SHOWCASE

Fibre Optic
Matrix Display
This unique Raspberry Pi Pico-powered display produces
some amazing arty effects. Phil King is mesmerised

W
e’ve seen a wide variety of displays
used in projects, but none quite like
this. With a standard 16×16 NeoPixel LED
pdwul{#erdug#frqqhfwhg#e|#rswlf#Ľeuhv#wr#d#julg#ri#
wlq|#krohv#lq#d#vpdoohu#68¹:#iurqw#sodwh/#lw#uhvxowv#
lq#vrph#frro#frorxu#hļhfwv#iurp#wkh#oljkw#ohdnlqj#
iurp#wkh#vlghv#ri#wkh#Ľeuhv1#Wr#jhw#wkh#ixoo#lpsdfw/#
fkhfn#rxw#wkh#ylghr#+pdjsl1ff2Ľeuhrswlf|w) on
ElliotMade
MAKER

HoolrwPdghġv#\rxWxeh#fkdqqho1
Hoolrw#whoov#xv#wkh#frqfhsw#lv#d#qdwxudo#h{whqvlrq#
A technical product
manager for ri#wkh#zrug#forfnv#khġv#pdgh#suhylrxvo|1#Kdylqj#
an online retail ehhq#lqwurgxfhg#wr#Udvsehuu|#Sl#Slfr#rq#d#frxuvh#
company, Elliot at teachmepcb.com/#kh#rswhg#wr#xvh#lw#iru#wklv#
spends his spare
surmhfw=#ģLw#Ľw#wkh#uhtxluhphqwv#iru#wklv#glvsod|/#  1
 MKLXPIEOMRKJVSQXLIWMHIWSJXLISTXMGǻFVIW
time on electronics, VIWYPXWMRWTIGXEGYPEVTEXXIVRWERHIǺIGXW
machining, soxv#doo#ri#wkh#rwkhu#jrrg#uhdvrqv=#lwġv#fkhds/#hdv|#
gardening, and wr#jhw/#uxqv#FlufxlwS|wkrq/#uhdoo|#hdv|#wr#
just making things
in general.
xvh/#dqg#kdv#suhww|#juhdw#fryhudjh#lq#wkh# Sandwiched plates
frppxqlw|#rqolqh1Ĥ Wkh#exlog#frpsulvhv#d#qxpehu#ri#sodwhv/#ghvljqhg#
elliotmade.com Diwhu#vshqglqj#d#|hdu#ru#wzr#wklqnlqj#derxw# lq#VrolgZrunv/#vdqgzlfkhg#wrjhwkhu1#Dw#wkh#yhu|#
wkh#lghd#Ğ#lq#zklfk#wlph#kh#ohduqhg#wr#xvh#wkh# iurqw/#khog#e|#wzr#phwdo#urgv/#wkh#pdlq#glvsod|#
VrolgZrunv#FDG#vriwzduh/#zklfk#fdph#lq#xvhixo# julg#kdv#68¹:#wlq|#krohv#frqqhfwhg#zlwk#rswlf#
Ğ#Hoolrw#vhw#derxw#exloglqj#wkh#lqqrydwlyh#glvsod|1# Ľeuhv#yld#d#iurqw#sodwh#wr#wkh#OHG#pdwul{#erdug#
ģL#vshqw#d#zhhn#ri#hyhqlqjv#dqg#rqh#zhhnhqg#wr# ehklqg/#zkrvh#uhdu#lv#vxssruwhg#e|#d#plggoh#
nqrfn#rxw#wkh#phfkdqlfdo#frqvwuxfwlrq#dqg#wr#jhw# sodwh1#Dq#rswlrqdo#edfn#sodwh#lv#xvhg#wr#prxqw#wkh#
vrph#edvlf#frgh#uxqqlqj1Ĥ hohfwurqlfv/#lqfoxglqj#Slfr1
Warning! Rqh#ri#wkh#pdlq#fkdoohqjhv#zdv#soxjjlqj#
CNC Cutter doo#ri#wkh#rswlf#Ľeuhv#lq#sodfh=#ģWkh|#zhuh#qrw#
frpsohwho|#xqlirup#lq#wklfnqhvv/Ĥ#vd|v#Hoolrw/#ģvr#
Be careful when using vrph#Ľw#hdvlo|/#vrph#zhuh#orrvh/#dqg#vrph#glgqġw#
CNC cutters in your
projects. Wear ear
Ľw#dw#doo#Ğ#e|#wkh#hqg#ri#lw/#p|#Ľqjhuwlsv#zhuh#
protection and safety suhww|#vruh#iurp#wkuhdglqj#wkhp#doo#lq1Ĥ
glasses and stand clear
of the machinery as it Dozd|v#xs#iru#d#ixq#fkdoohqjh/#kh#rswhg#wr#pdnh#
works. Understand the wkh#sodwhv#rq#d#FQF#pdfklqh/#ploolqj#wkhlu#vkdsh#
FEWMGWEJIX]JYRGXMSRW
of your machine. dqg#guloolqj#hyhu|#vpdoo#kroh/#zklfk#zdvqġw#zlwkrxw#
lwv#glĿfxowlhv1#ģL#xvhg#wkh#vdph#nlqg#ri#vrolg#
magpi.cc/cncsafety
fduelgh#guloo#elw#wkdw#lv#xvhg#lq#SFE#pdqxidfwxulqj/#
zklfk#lq#klqgvljkw#zdv#suredeo|#qrw#d#juhdw#fkrlfh#
Elliot used a CNC iru#doxplqlxp#Ğ#wkh|#duh#yhu|#hdv|#wr#euhdn/#
machine to mill two
of the panels and sduwlfxoduo|#li#wkh#ľxwhv#Ľoo#xs#zlwk#fklsv#lq#d#kroh1#
drill all the tiny holes,
P|#FQF#ploo#wrsv#rxw#dw#6;33#usp#dv#zhoo/#zklfk#
FYXXLI]GSYPHFI
3D-printed instead lvqġw#wkh#ehvw#iru#vpdoo0gldphwhu#wrrov#olnh#wklv1Ĥ

26 magpi.cc Fibre Optic Matrix Display


PROJECT SHOWCASE

A 16×16 NeoPixel LED


matrix is used as a
light source, controlled
by a Raspberry Pi Pico
on the rear

Supported by two metal


rods, the 35×7 main
display panel is used to
show text or patterns

kŞƋĜÏĀÆųåŸÏŅĹĹåÏƋå±ÏĘ
matrix LED to a tiny hole
in the main display panel
Quick FACTS
> &TVSNIGXFYMPH
guide is on
.RWXVYGXEFPIW
Krzhyhu/#kh#vd|v#wkdw#dq|rqh#zdqwlqj#wr# wkh#rswlf#Ľeuhv1#Wklv#pdnhv#lw#hdv|#wr#dgdsw#wr#
magpi.cc/
uhsolfdwh#wkh#surmhfw#frxog#6G0sulqw#wkh#sodwhv# vkrz#dq|#wh{w#ru#sdwwhuq1#Vr#idu/#Hoolrw#kdv#xvhg# ĀÆųåŅŞƋĜÏÚĜŸŞĬ±Ƽ
lqvwhdg1#ģLq#idfw/#dqrwkhu#xvhu#rq#Lqvwuxfwdeohv# wkh#glvsod|#dv#d#gljlwdo#forfn#+zlwk#dq#UWF,#dqg#
wrrn#p|#Ľohv#dqg#sulqwhg#klv#rzq#yhuvlrq#dqg#lw# iru#vfuroolqj#wh{w2judsklfv#dqg#dqlpdwhg#hļhfwv/# > The code and
orrnv#olnh#lw#wxuqhg#rxw#juhdw$#Wklv#ghvljq#lv#dovr# exw#ģlw#fdq#gr#mxvw#derxw#dq|wklqj#|rx#zdqw/#rqo|# )QSHIPǻPIW
txlwh#hdv|#wr#pdnh#zlwk#d#odvhu#fxwwhu1Ĥ olplwhg#e|#|rxu#lpdjlqdwlrq1Ĥ# GERFIJSYRHSR
,MX-YFmagpi.cc/

One of the main challenges ĀÆųåŅŞƋĜÏčĘ

was plugging all of the > An EVA foam


gasket is used

optic fibres in place to prevent


light leaking to
RIMKLFSYVMRK
matrix LEDs
Coding the matrix
Zlwk#wkh#kdugzduh#dvvhpeohg/#Hoolrw#vhw# > An external 5 V
derxw#fuhdwlqj#wkh#Slfr#Ľupzduh#wr#uxq#lw#lq# power supply is
FlufxlwS|wkrq/#zklfk#kh#irxqg#fkdoohqjlqj1#ģL# required to achieve
frgh#dw#d#kree|lvw#ohyho/#vr#lw#wdnhv#d#orw#ri#hļruw#wr# full NeoPixel
FVMKLXRIWWƳERHMXƶW
jhw#zkdw#L#zdqw#wr#dfwxdoo|#kdsshq1#FlufxlwS|wkrq#
ZIV]FVMKLX
zdv#d#elj#khos=#lw#pdnhv#lw#vxshu0idvw#wr#whvw#
fkdqjhv#e|#vlpso|#vdylqj#d#Ľoh#rq#wkh#ghylfh#dqg# > *PPMSXƶWTVIZMSYW
ohwwlqj#lw#uherrw1Ĥ projects include a
Dq#duud|#lq#wkh#frgh#lv#xvhg#wr#pds#578#ri#wkh# calendar using a
OHGv#rq#wkh#pdwul{#wr#wkh#fruuhvsrqglqj#srvlwlrqv# 7EWTFIVV]5M
 &
 7EWTFIVV]5M5MGSGSRXVSPWMXEPPWLS[RLIVIQSYRXIHSR
lq#wkh#68¹:#iurqw#glvsod|#sdqho/#dv#frqqhfwhg#e|# ERSTXMSREP5('[MXLFYXXSRWERHa real-time clock module ERH)&0FSEVH

Fibre Optic Matrix Display magpi.cc 27


CASE STUDY

CASE STUDY

Crux Labs
digital telephony
Raspberry Pi was this company’s clear choice to enable
seamless home working. By Rosie Hattersley

C
rux Labs’ CEO and founder Rohit Pdq|#Ľupv#zlwk#xqghu#433#hpsor|hhv#odfn#
Gupta noticed that, while home d#vshfldolvw#LW#h{shuw#wr#pdlqwdlq#d#fodvvlf#SE[#
communications technology had become whohskrqh#v|vwhp#dqg#lqwhjudwhg#frppxqlfdwlrqv#
well-integrated, many small businesses were kxe#dqg/#lq#dq|#fdvh/#wkh#frvw#ri#lqvwdoodwlrq#lv#
still using analogue telephony solutions, surklelwlyh#iru#pdq|#exvlqhvvhv#dw#wklv#vfdoh1#
with no means of recording missed calls Jxswd#irxqghg#Vlqjdsruh0edvhg#Fux{#Odev#wr#rļhu#
and following up on the potential business dq#dffhvvleoh#gljlwdo#whohskrq|#vroxwlrq#wr#VPHv/#
opportunities they represent. iurp#vroh#wudghuv#xs#wr#durxqg#583#vwdļ1

28 magpi.cc Crux Labs digital telephony


CASE STUDY

THE CHALLENGE
Fux{#Odev#kdg#wr#hqvxuh#wkdw#qhlwkhu#frvw#qru#
frpsoh{lw|#zrxog#eh#d#eduulhu#iru#vpdoo#frpsdqlhv#
vhwwlqj#xs#wkhlu#Ľuvw#gljlwdo#whohskrq|#vroxwlrq1#Lwv#
fxvwrphuv#qhhghg#dq#hdv|0wr0lqvwdoo#surgxfw#wkdw#
zrxog#uhtxluh#plqlpdo#vxssruw/#zkloh#uholdeo|#
gholyhulqj#exvlqhvv0fulwlfdo#ixqfwlrqdolw|1

THE SOLUTION
Fux{#O[/#Fux{#Odevġ#Ľuvw#VPH#surgxfw/#lv#d#gljlwdo#
whohskrq|#vroxwlrq#dlphg#dw#exvlqhvvhv#iurp#vroh#
wudghuv#xs#wr#durxqg#583#vwdļ/#zlwk#d#Udvsehuu|#
Sl#6#dw#lwv#khduw1#Lw#xvhv#VLS#whohskrq|#dqg#d#zlgh# Iru#Fux{ġv#pxowlqdwlrqdo#folhqwv#zlwk#rĿfhv#lq#
duhd#qhwzrun#wr#fuhdwh#d#orz0frvw/#vfdodeoh/# erwk#Pdod|vld#dqg#Vlqjdsruh/#wklv#vrsklvwlfdwhg#
ghylfh0djqrvwlf#dqg#orfdwlrq0djqrvwlf#gljlwdo# Udvsehuu|#Sl0edvhg#v|vwhp#rļhuv#vxevwdqwldo#
whohskrqh#qhwzrun1#Ihdwxuhv#vxfk#dv#fdoo#uh0 vdylqjv#rq#lqwhuqdwlrqdo#fdoov/#dw#d#frvw#wr#
urxwlqj#doorz#wkh#lqwhjudwlrq#ri#whohskrq|#dfurvv#
pxowlsoh#rĿfh#orfdwlrqv/#dv#zhoo#dv#hqdeolqj#
hpsor|hhv#wr#slfn#xs#fdoov#iurp#wkhlu#krph#rĿfhv# The powerful and low-cost
dv#wkrxjk#wkh|#zhuh#lq#wkh#exvlqhvv#edvh1#
Fxvwrphu#ghpdqg#ohg#Fux{#wr#ghyhors#lwv#vhfrqg# Raspberry Pi 3 was ideal
gljlwdo#whohskrq|#surgxfw1#Fux{#Y[/#d#ģfdoo#fhqwuh#
lq#d#er{Ĥ/#wdnhv#doo#wkh#ixqfwlrqdolw|#ri#wkh#Fux{#O[#
for large-scale rollout
dqg#dggv#FUP#dqg#fdoo#pdqdjhphqw#ihdwxuhv1
wkh#folhqw#ri#ohvv#wkdq#d#vl{wk#ri#wkh#sulfh#ri#d#
WHY RASPBERRY PI? frpsdudeoh#hqwhusulvh#v|vwhp1
Fux{#Odev#glg#wkhlu#uhvhdufk=#kdylqj#wuldoohg#qr#
ihzhu#wkdq#hljkw#rwkhu#rswlrqv/#FHR#Urklw#Jxswd# THE RESULTS
vd|v#Udvsehuu|#Sl#zdv#wkh#fohdu#fkrlfh1#Kdg#Fux{# Zkhq#Frylg04<#orfngrzqv#ehjdq#wr#lpsdfw#
fkrvhq#d#vwdqgdug#exvlqhvv#whohskrq|#rswlrq/#kh# vhyhuho|#rq#exvlqhvvhv#dfurvv#wkh#zruog#lq#5353/#
eholhyhv#lw#zrxog#kdyh#frvw#dv#pxfk#dv#†633/333# Fux{#Odev#fxvwrphuv#zkr#zhuh#douhdg|#xvlqj#
mxvw#wr#dftxluh#d#surwrw|sh1#Wkh#srzhuixo#dqg#orz0 Fux{#O[#uhsruwhg#wkdw#wkh|#zhuh#deoh#wr#vzlwfk#
frvw#Udvsehuu|#Sl#6#zdv#lghdo#iru#odujh0vfdoh#uroorxw1 wr#uhprwh#zrunlqj#frpiruwdeo|/#zlwk#vwdļ#
Zlwk#Udvsehuu|#Sl/#wkh#vwdeoh#kdugzduh#lv# frqwlqxlqj#wr#zrun#iurp#krph#zlwk#qr#glvfhuqleoh#
vxlwdeoh#iru#wkh#dssur{lpdwho|#;33#vriwzduh# qhjdwlyh#hļhfw#rq#wkh#exvlqhvv1#Fux{#O[#uhsruwv#
sdfndjhv#wkdw#Fux{#O[#frqwdlqv/#iurp#plqru# ryhu#43/333#xvhuv#dfurvv#44#frxqwulhv1#Wkh#PG#ri#
kdqgolqj#ihdwxuhv#wr#XL#ryhuod|v#wkdw#hqvxuh#d# Fux{#Y[#folhqw#Idu#Hdvw#Iorud/#Vlqjdsruhġv#ohdglqj#
frqvxphu0iulhqgo|#lqwhuidfh1#Wkh#uhvxow#lv#d#kljk0 rqolqh#ľrulvw/#qrwhg#wkdw#fkrrvlqj#wkh#Udvsehuu|#
txdolw|#surgxfw#wkdw#fdq#eh#vhw#xs#lq#durxqg#63# Sl0srzhuhg#v|vwhp#zdv#ģrqh#ri#wkh#zlvhvw#
plqxwhv#e|#d#qrq0vshfldolvw1 whfkqrorj|#ghflvlrqv#^zh`#pdgh1Ĥ#

Crux Labs digital telephony magpi.cc 29


SUBSCRIPTION

SUBSCRIBE TODAY
FROM ONLY £5

Subscriber Benefits
FREE Delivery
Get it fast and for FREE

Exclusive Offers
Great gifts, offers, and discounts

Great Savings
Save up to 35% compared to stores

Rolling Monthly Subscription


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

Subscribe for 12 Months


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

Subscribe by phone: 01293 312193


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

JOIN FOR 12 MONTHS AND GET A

FREE Raspberry Pi Zero 2 W


WITH YOUR FIRST
12-MONTH SUBSCRIPTION

Subscribe in print
WORTH

$15
today and get a
FREE computer!

A full Raspberry
Pi desktop
computer

Learn to code and


build your own
projects

Make your own


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

Buy now: magpi.cc/subscribe

SUBSCRIBE
on app stores

magpi.cc 31
FEATURE

RASPBERRY PI
PHOTOGRAPHY
The Raspberry Pi Camera Module offers a world of creative
and fun digital photo opportunities. By Rosie Hattersley

L
ess than two years after Raspberry Pi
revolutionised the world of personal
computing, the tiny but powerful
Fdphud#Prgxoh#lqwurgxfhg#d#wrwdoo|#glļhuhqw#
approach to digital photography.
The three Raspberry Pi Camera options
open up dozens of fantastic projects to try
that involve little more than adding a tiny-
but-mighty lens and a smattering of code. Try
point-and-shoot photography via a designed-
it-yourself camera, capture superb sports day
action shots and all-day time-lapses; explore
duwlĽfldo#lqwhooljhqfh#xvlqj#lpdjh#uhfrjqlwlrq>#
set up smart surveillance in case of unwelcome
guests; use wildlife cams to enjoy the birds
and the bees; a delivery cam just in case the
postman doesn’t ring twice; encase a camera
in a waterproof housing to explore the world
aquatic; or bolt to a telescope to peer at celestial
realms unknown.

32 magpi.cc Raspberry Pi Photography


FEATURE

RASPBERRY PI
CAMERA OPTIONS
There are three main camera options
available for Raspberry Pi owners

MODULE 2 HIGH QUALITY


CAMERA CAMERA
8LISVMKMREPQSHIPPEYRGLIHMRSǺIVIH 8LIVIƶWEPWSEQIKETM\IP-MKL6YEPMX](EQIVE
5MP (megapixel) image capture whereas its [LMGLMWHIWMKRIHcXSc[SVO[MXLMRXIVGLERKIEFPIPIRWIW
WYGGIWWSVcXLIcGPIZIVP]REQIH(EQIVE2SHYPI RSXEFP]2MGVSc+SYV8LMVHWcPIRWIWYWMRKIMXLIVE(SV
(magpi.cc/cameramodule), features an 8MP Sony (QSYRX8LI5M-YXcLEWEKSSHWIPIGXMSRSJEZEMPEFPI
WIRWSV.XGERGETXYVIFSXLWXMPPWERHZMHISW PIRWIWc magpi.cc/cameralenses).

ASPBERRY PI NOIR
R
8LI7EWTFIVV]5M3S.7(EQIVE2SHYPISǺIVWPS[
PMKLXERHRMKLXXMQITLSXSKVETL]XLEROWXSMXWPEGOSJ
MRJVEVIHǻPXIV magpi.cc/noir), hence its name, but can
also be used for daytime shots if you’re after some
YRYWYEPIǺIGXW

Raspberry Pi Photography magpi.cc 33


FEATURE

CONNECTING
AND USING
THE CAMERA
Find out how to connect your High Quality Camera or
Camera Module, enable it, and take your first shots

W
e are going to show you how to connect
the High Quality Camera or Camera
Module to your Raspberry Pi using the
supplied ribbon cable.
Attaching a Camera Module to Raspberry Pi is
easy, using the CSI (camera serial interface) found
on most Raspberry Pi boards.
You’ll need a compatible ribbon cable. The larger
Model A and Model B Raspberry Pi boards use a
standard cable (magpi.cc/cameracable), while
the smaller Zero boards use a Zero Camera Cable
(magpi.cc/zerocameracable).
With a camera attached to Raspberry Pi, you
can then start to capture images and video using
terminal commands
and Python code.
You’ll Need We will then enable

RASPBERRY IPDIE
it in Raspberry Pi
> Raspberry Pi Zero,
OS, before entering

CAMERA GU
Model A, or Model B
magpi.cc/products some commands in a
Terminal window to
> (EQIVE2SHYPI
magpi.cc/camera start shooting photos
and video. Let’s Inspired to try more Raspberry Pi photography?
> (EQIVEGEFPI
magpi.cc/ get started... Download for free ‰ĚåƐkþÏбĮƐ±žŤÆåŹŹDžƐ{ĞƐ±ķåŹ±Ɛ
cameracable :ƣĞÚåERHXV]WXSTQSXMSRZMHISKVETL]PIEVRLS[
XSGETXYVILMKLWTIIHEGXMSRWLSXWHS7EWTFIVV]5M
ǼEWLTLSXSKVETL]ERHQSVI;IƶPPEPWSXIEGL]SYXS
build a photo booth (Minecraft optional), how to shoot
YRHIV[EXIVJSSXEKIERHLS[XSXEOITLSXSWVIQSXIP]
magpi.cc/cameraguide

34 magpi.cc Raspberry Pi Photography


FEATURE

GET THE CABLES


THE RIGHT WAY AROUND
FIGURE 2

FIGURE 1 The ribbon cable on


XLI(EQIVE2SHYPIǻXW
[MXLXLIWMPZIVIHKIW
downwards and the blue
plastic facing upwards

 -SPH7EWTFIVV]5M[MXLXLI
-)2.TSVXWJEGMRKHS[RERH
slide the ribbon cable in so
XLIWMPZIVIHKIWEVIXS]SYV
left and the blue plastic to
your right

Top Tip
Camera
documentation
Take a look
at the High
Quality Camera
documentation
to set up
ƼŅƚųƤϱĵåų±ţ
magpi.cc/hqcam
gettingstarted

 8
 LI-MKL6YEPMX]
(EQIVE[MXLEWXSGO
6 mm lens enables you
to capture seriously
MQTVIWWMZIWLSXW

Raspberry Pi Photography magpi.cc 35


FEATURE

I
f you have a Camera Module V2,
or Camera NoIR, you are ready to
connect it directly to Raspberry Pi.
The High Quality Camera will need a
lens mounting on top of the sensor on
the camera board before you can take
photographs. A low-cost 6 mm lens is
available for the High Quality Camera
(magpi.cc/6mmlens). This lens is
suitable for basic photography. It can
also be used for macro photography
because it can focus objects at very
short distances. It does not require the
adaptor ring and connects directly to the
HQ Camera.
Start by screwing your lens onto the
High Quality Camera and adjusting the focus rings.
Follow the High Quality Camera documentation to
set up the lens (magpi.cc/hqcamgettingstarted).

Connect ribbon cable to camera


01 On the HQ Camera or Camera Module board,
Connect cable to Raspberry Pi
|rxġoo#Ľqg#d#ľdw#sodvwlf#frqqhfwru1#Fduhixoo|#sxoo#
the sticking-out edges until the connector pulls
02 Find the CSI port on Raspberry Pi and pull
part-way out. Slide the ribbon cable, with the wkh#sodvwlf#ľds#jhqwo|#xszdugv1#Zlwk#Udvsehuu|#
silver edges downwards and the blue plastic facing Pi positioned so the HDMI port is facing you, slide
Gently pull the
xszdugv/#xqghu#wkh#ľds#|rx#mxvw#sxoohg#rxw/#wkhq# the ribbon cable in so the silver edges are to your
plastic tabs sxvk#wkh#ľds#jhqwo|#edfn#lqwr#sodfh#zlwk#d#folfn# left and the blue plastic to your right (Figure 2
SYXSRXLI(.
connector to (Figure 1, previous page); it doesn’t matter which - suhylrxv#sdjh,/#wkhq#jhqwo|#sxvk#wkh#ľds#edfn#
open it. Slide the end of the cable you use. If the cable is installed into place. If the cable is installed properly, it’ll be
camera cable in
and gently push properly, it will be straight and won’t come out if straight and won’t come out if you give it a gentle
the plastic tabs |rx#jlyh#lw#d#jhqwoh#wxj>#li#qrw/#sxoo#wkh#ľds#rxw#dqg# wxj>#li#qrw/#sxoo#wkh#ľds#rxw#dqg#wu|#djdlq1#
FEGOXSPSGOMX
into place try again. If using a Raspberry Pi Zero, its camera port is
found on the edge of the board.

Enable the camera


03 Connect the power supply back to Raspberry
Pi and load Raspberry Pi OS. Before you can use
the raspistill tool in the next step, you will need to
enable Legacy Mode. Open a Terminal window and
rshq#udvsl0frqĽj=

sudo raspi-config

Use the arrow and ENTER keys to choose three


Interface Options and I1 Legacy Camera. Select
Yes to the ‘Would you like to enable legacy camera
vxssruwBġ#Udvsl0frqĽj#zloo#ohw#|rx#nqrz#lw#kdv#
been enabled. Choose Finish and Yes to the ‘Would
you like to reboot now?’ message.

36 magpi.cc Raspberry Pi Photography


FEATURE

Rotate the image


06 If the live preview was upside- Top Tip
down, you’ll need to tell raspistill that the
camera is rotated. The Camera Module is Raspberry Pi
designed to have the ribbon cable coming 400?
out of the bottom edge; if it’s coming out
Sadly, you cannot
of the sides, or the top, as with some third-
connect Raspberry
party camera mount accessories, you can Pi Cameras to
rotate the image by 90, 180, or 270 degrees Raspberry Pi
using the -rot switch. For a camera mounted 400 computers,
with the cable coming out of the top, use the although you can
use a stock USB
iroorzlqj#frppdqg=#
camera instead
(magpi.cc/
raspistill -rot 180 -o test.jpg usbcamerašţ
Test the camera
04 Wr#frqĽup#wkdw#|rxu#fdphud#lv#fruuhfwo|# You can discover more commands that work
installed, you can use the raspistill tool. This, with raspistill in the Raspberry Pi Documentation
along with raspivid for videos, is designed to (magpi.cc/raspistilldoc). This includes an example
capture images from the camera using Raspberry of a short script that takes a photograph and adds
Pi’s command-line interface (CLI). To take a test the date and time.
vkrw/#w|sh#wkh#iroorzlqj#lqwr#wkh#Whuplqdo=

L VS LIBCAMERA
RASPISTIL
raspistill -o test.jpg

As soon as you hit ENTER, you’ll see a large


picture of what the camera sees appear on-screen. It is a somewhat confusing time for Raspberry Pi camera coding as the
This is called the live preview and, unless you tell raspistill functionality we are using here is being slowly replaced by the
udvslvwloo#rwkhuzlvh/#lw#zloo#odvw#iru#Ľyh#vhfrqgv1# newer libcamera option.
Diwhu#wkrvh#Ľyh#vhfrqgv#duh#xs/#wkh#fdphud#zloo# Sadly, you can only use one or the other, and most Raspberry Pi projects
capture a single still picture and save it in your EVIYWMRKVEWTMWXMPP[LMPIQEOIVWKIXYTERHVYRRMRK[MXLPMFGEQIVE
home folder under the name test.jpg. If you want To use raspistill, you must enable Raspberry Pi Legacy mode (as shown
to capture another, type the same command again MRXITSVMRWXEPPEWTIGMEPGYWXSQZIVWMSRSJ7EWTFIVV]5M4 1IKEG]
Ğ#exw#pdnh#vxuh#wr#fkdqjh#wkh#rxwsxw#Ľoh#qdph/# 9RJSVXYREXIP]XLMWTVIZIRXW]SYJVSQYWMRKXLIRI[PMFGEQIVE
after the -o, or you’ll save over the top of your ETTPMGEXMSRW;SVV]RSXXLSYKLMXƶWIEW]XSXYVRSǺ1IKEG]YTTSVXF]
Ľuvw#slfwxuh1 VYRRMRKVEWTMGSRǻKEKEMRERHGLSSWMRK3SXSXLIƵ;SYPH]SYPMOIXS
enable legacy camera support?’ (Don’t forget to reboot.)

Now try out these commands in Terminal:


More advanced commands • ĬĜÆϱĵåų±ěĘåĬĬŅ&WMQTPIƵLIPPS[SVPHƶETTPMGEXMSR[LMGLWXEVXWE
05 The raspistill command has a list of options GEQIVETVIZMI[WXVIEQERHHMWTPE]WMXSRXLIWGVIIR
so long that it borders on the intimidating. Have • ĬĜÆϱĵåų±ěģŞåč&WMQTPIETTPMGEXMSRXSVYRETVIZMI[[MRHS[ERH
qr#ihdu/#wkrxjk=#|rx#zrqġw#qhhg#wr#ohduq#wkhp#doo/# XLIRGETXYVILMKLVIWSPYXMSRWXMPPMQEKIW
but there are a few that might be useful to you, • ĬĜÆϱĵåų±ěŸƋĜĬĬ A more complex still image capture application
vxfk#dv=# which emulates more of the features of raspistill.
• ĬĜÆϱĵåų±ěƴĜÚ&ZMHISGETXYVIETTPMGEXMSR
raspistill -t 15000 -o newpic.jpg • ĬĜÆϱĵåų±ěų±Ƶ A basic application for capturing raw (unprocessed
Bayer) frames directly from the sensor.
The -t option changes the delay before the • ĬĜÆϱĵåų±ěÚåƋåÏƋ This application is not built by default, but users
slfwxuh#lv#wdnhq/#iurp#wkh#ghidxow#Ľyh#vhfrqgv#wr# GERFYMPHMXMJXLI]LEZI8IRWSV+PS[1MXIMRWXEPPIHSRXLIMV7EWTFIVV]
whatever time you give it in milliseconds – in this Pi. It captures JPEG images when certain objects are detected.
case, you have a full 15 seconds to get your shot
arranged perfectly after you press ENTER. 8EOIEPSSOEXLIPMFGEQIVEHSGYQIRXEXMSRJSVQSVIMRHITXL
MRJSVQEXMSREFSYXXLIRI[JYRGXMSREPMX] magpi.cc/libcamera

Raspberry Pi Photography magpi.cc 37


FEATURE

INCREDIBLE
CAMERA
PROJECTS
All the incredible things you can make with
Raspberry Pi and a Camera Module

SET UP A PAREN
T TOY CAMERA
DETECTOR 8LI7EWTFIVV]5M-MKL6YEPMX](EQIVEGERFIYWIH
[MXLXLI(QSYRXERHPIRWIWFYXMXƶWRSXXLISRP]
8LMWSRIMWKVIEXJSVOMHWERHMWEWYTIVFMRXVSHYGXMSR STXMSR&WQEOIV:SP^SI\TPEMRWQSYRXPIRWIW MHIEP
XSYWMRKXLI(EQIVE2SHYPIYWTMGMSYWXLEX JSVQEGLMRIZMWMSRERHMRJVEVIHTLSXSKVETL]GEREPWS
WSQISRIƶWFIIRMR]SYVVSSQERHLEZMRKEKSSHSPH be used, which is what he chose for this Raspberry
RSWI$SYRJEMVVMKLX$8IIRWERHLSYWIWLEVIVWOIIR 5M>IVSFYMPHHIWMKRIHXSEHH^ER]JIEXYVIWERH
to put a hunch to the test can set up a spy cam to alert MRXVSHYGIYRTVIHMGXEFPIIǺIGXWXSHMKMXEPTLSXSKVETL]
XLIQ[LIRIZIVWSQISRIHEVIWIRXIVXLIMVHSQEMR ƳWSQIXLMRKQSVIKIRIVEPP]ORS[REW1SQSKVETL]
8LIIEW]XSJSPPS[XYXSVMEPI\TPEMRWLS[XSWIXYTXLI )ITIRHMRKSR]SYVPIZIPSJQEOIEFMPMX]]SYGERIMXLIV
7EWTFIVV]5M(EQIVE2SHYPIERH5.7QSXMSRWIRWSV YWIERI\MWXMRKSPHGEQIVEFSH]SVERSXLIVZIWWIPXS
XSXVMKKIVZMHISVIGSVHMRKWLSYPHERYRI\TIGXIHZMWMXSV house your camera, or fashion one yourself, for which
FIHIXIGXIHTPYWLS[XSEHNYWXXLIWIRWMXMZMX]WS]SY :SP^STVSZMHIWHIQSWERHPMROWXSEQTPIEPXIVREXMZI
HSRƶXKIXNYQT]IZIV]XMQIXLIHSSVVEXXPIW8LIVIƶW HIWMKRMHIEW-MW)TVMRXIHERH(3(GYXZIVWMSRMW
IZIREWXIEPXLQSHIWSXLIXIPPXEPIVIHVIGSVHMRKPMKLX held together with magnets as well as screws, while
MWWLMIPHIHWLSYPH]SYVLSYWIQEXIWLEZIXLIMVS[R XLIZMI[ǻRHIVMWJVSQETEMVSJRMKLXZMWMSRKSKKPIW
WYWTMGMSRW-IPTJYPP]]SYKIXEREPIVX[LIRERMRXVYHIV *\LSVXMRKSXLIVWXSVIHMWGSZIVXLIUYMVOMRIWWSJ
MWHIXIGXIHERHGERXLIRZMI[XLIJSSXEKIXSGLIGOMX analogue photography, this project shows how much
[EWRƶXNYWXEGLIIO]TYWWTE]MRK]SYEZMWMXFIJSVI]SY fun it can be to experiment when the basic Raspberry Pi
launch in and raise merry hell with the oldies about an camera and other parts are cheap enough to allow you
MRZEWMSRSJTVMZEG] the freedom to do so.
magpi.cc/parentdetector magpi.cc/digitaltoycamera

38 magpi.cc Raspberry Pi Photography


FEATURE

MART BIRD BOX


O S
INSTANT PHOT
PRINTER
'PYIWOMIWǼS[IVWFPSSQMRKERHFMVHWX[IIXMRK
EVIKSSHJSVXLIWSYP,IXXMRKEGPSWIYTZMI[SJ
the magic of nature without disrupting said critters
&HEJVYMXƶW5LMPMT'YVKIWWSǺIVWWSQIKVIEXTVSNIGXMHIEW from going about their daily business is thoroughly
including this super means of printing out the results [SVXL[LMPI8LMWZIVWMSR[MPPWXVIEQFMVHFS\JSSXEKI
SJ]SYV7EWTFIVV]5MTLSXSKVETL]SRHIQERHQEOMRK JSVVIQSXIZMI[MRK
use of the sort of $45 thermal printer more commonly 2EOIWYVIXLIRIWXFS\]SYƶVIKSMRKXSYWIMWRSX
JSYRHEXEKVSGIV]XMPP8LIXLIVQEPTLSXSTVMRXIV[SVOW GYVVIRXP]MRLEFMXIH SVGVIEXIEGUYMVIERI[SRI
[MXLER]WXERHEVHWM^I7EWTFIVV]5MERHXLIVIXVSTLSXS FIJSVI]SYTPEGI]SYV-MKL6YEPMX](EQIVEƳSV
VIWYPXWEVINYWXEWKSSH[LIXLIVXEOIRSREWXERHEVH 7EWTFIVV]5M3S.7(EQIVE2SHYPIMJ]SYƶVIOIIRXS
(EQIVE2SHYPISVXLI-MKL6YEPMX](EQIVE2SHYPI SFWIVZIRIWXMRKFMVHWEXRMKLXXSSƳMRWMHI
You’ll need an SD card for the Python code and You won’t be able
7EWTFIVV]5M4EPEVKITYWLFYXXSRERHEQIERWSJ to adjust things once
connecting this and the printer to Raspberry Pi, plus the bird box is in use Observers of the night sky
JSYV&&3M2-FEXXIVMIW&GEWIJSVXLIWIXYTGSYPHFI (as disturbing birds is
as simple as a cardboard box or something fancier you PMOIP]XSGEYWIXLIQ with even a basic telescope
HIWMKR]SYVWIPJSV)TVMRXJVSQ8LMRKMZIVWI
magpi.cc/instantcamera
to desert the nest), so
QEOIWYVI]SYXIWX
can use it in tandem with
IZIV]XLMRKXSGSRǻVQMX
[SVOWFIJSVIMRWXEPPMRK
Raspberry Pi and the High
it in place.
magpi.cc/
Quality Camera
infraredbirdbox

ION
FACE RECOGNIT
SMART LOCK
HUBBLE PI
A great way to control access to a building is using the
7EWTFIVV]5M-MKL6YEPMX](EQIVEERHEWQEVXTLSRIXS
EWGIVXEMR[LSƶWGEPPMRK;LIREJEQMPMEVJEGITSTWYT
SRWGVIIR]SYGERXLIRKVERXXLEXTIVWSREGGIWW8LMW 4FWIVZIVWSJXLIRMKLXWO][MXLIZIREFEWMGXIPIWGSTI
[SVOWVIEPP][IPPƳEWPSRKEW]SYƶVIEVSYRHXSGLIGO GERYWIMXMRXERHIQ[MXL7EWTFIVV]5MERHXLI-MKL
]SYVTLSRI[LIREZMWMXSVRSXMǻGEXMSRTSTWYT+SV 6YEPMX](EQIVETPYWE(QSYRXXSXIPIWGSTIEHETXIV
scenarios in which you aren’t around, you could train XSGETXYVIMRGVIHMFPIEWXVSRSQMGEPWMKLXW-YFFPI5M
Raspberry Pi 3 or 4 to recognise friends’ faces and allow pairs Raspberry Pi 4 with free astronomy software
XLIQIRXV].RIIIHXYHMSƶW[EPOXLVSYKL]SYXEOI 0XEVW[LMGLHMWTPE]WEPMZIQETSJXLIRMKLXWO]SR
photos of people you want to let in, as per this amusing XLIXIPIWGSTIƶWHMWTPE]2EOIVERXMEKSI\TPSMXIHXLI
JEGIVIGSKRMXMSRWIXYTEPSRK[MXL,VSZIƶW7IPE]8S PEVKIPIRWSJXLI-6(EQIVEERH[VSXI5]XLSRGSHI
18*-&8E[MVIPIWWERXIRREERHSJGSYVWI7EWTFIVV] LIGEPPW&WXVS(EQXSGSRXVSPMXWWLYXXIVWTIIHXLI.4
5M[MXLXLI(EQIVE2SHYPIEXXEGLIH&XI\XQIWWEKI and exposure time. Bonuses include being able to
MWWIRXXSXLIS[RIVWXEXMRK[LS[EWPIXMR[LIRIZIV EYXSQEXMGEPP]XEOIQYPXMTPI7&;TLSXSWERHYWMRKIMXLIV
WSQISRIMWVIGSKRMWIHERHXLIMVHSSVYRPSGOIH VIQSXIHIWOXSTSVEXSYGLWGVIIRXSXVMKKIVEWLSX
magpi.cc/facerecogsmartlock magpi.cc/hubblepi

Raspberry Pi Photography magpi.cc 39


FEATURE

TURN YOUR
PHOTOS INTO
TIME-LAPSE VIDEOS
Can we get to the good bit? Shooting time-lapse
videos makes drawn-out processes more engaging

Python code controls


the PIR sensor and snaps Our Camera Module will
images with the camera take a new picture every
time we detect movement

G
Enable legacy camera support
ood things are usually worth the wait –
unless they come at the end of a long and
01 The functions we need to use in our
Nik
MAKER

largely repetitive video. In this workshop, Python code will run natively on older versions
Rawlinson we’ll show you how pairing Raspberry Pi with a of Raspberry Pi OS, but require legacy support if
Camera Module 2 and a PIR motion detector lets you’re running Raspberry Pi OS Bullseye or later.
(SǺIIHVMROMRK
X]TI[VMXIVPSZIV you shoot stills only when there’s something To enable support in these versions, open a new
with a penchant for worth watching. Discover how to convert images Terminal window by pressing CTRL+ALT+T (or
pencils and paint.
into a time-lapse video packed with action. We’ve connect to your Raspberry Pi remotely using SSH)
+VIUYIRXP]JSYRH
staring at the sea been using this technique to show how time- dqg#w|sh=
JVSQXLIFEGOSJ frqvxplqj#duwlvwlf#surfhvvhv#uhvxow#lq#d#Ľqlvkhg#
EGEQTIVZER image, but you could also use it to see what your sudo raspi-config
nikrawlinson.com pet does when you’ve left it home alone.

40 magpi.cc Raspberry Pi Photography


FEATURE

Select option 3 – Interface Options and 1 – Legacy


camera/#wkhq#frqĽup#wkdw#|rx#zdqw#wr#hqdeoh#
ohjdf|#fdphud#vxssruw1#Txlw#udvsl0frqĽj#dqg#
allow your Raspberry Pi to reboot and implement
the changes.

Correct your screen


02 We’re setting up our time-lapse camera
using a Raspberry Pi 3 B+ connected to a Raspberry
Pi Touch Display (magpi.cc/touch). Enabling legacy
camera support caused our display to rotate through
180 degrees (only locally; the orientation was still
correct when connecting via VNC), and removed the
Connect your PIR sensor
Displays option from Raspberry Pi OS’s graphical
interface. If you experience the same, open a
04 The passive infra-red (PIR) sensor lets
The screw on the
right controls the
WIRWMXMZMX]SJXLI5.7
Whuplqdo#zlqgrz#dqg#w|sh= you take pictures only when there’s some kind motion detector

ri#pryhphqw1#Sodfh#|rxu#Udvsehuu|#Sl#rq#d#ľdw#
sudo nano /boot/config.txt surface so the USB ports are to the right and the
GPIO pins are running along the top edge, and hold
Nh|#grzq#wr#wkh#erwwrp#ri#wkh#Ľoh/#dgg#d#qhz# your PIR sensor so that its pins are also running
olqh/#dqg#w|sh= along the top edge and pointing towards you. Use
jumper wires to connect the PIR’s left pin and right
lcd_rotate=2 pins to GPIO pins 6 and 2 respectively, and the
PIR’s middle pin to GPIO pin 7 (magpi.cc/pinout).
Press CTRL+X to quit and press Y when asked if
|rx#zdqw#wr#vdyh/#wkhq#uherrw#e|#w|slqj=

Position and test your camera


Top Tip
sudo reboot
05 At this point, you want to get your Zeroes ain’t
Raspberry Pi and camera in position. We’ve heroes
Enabling legacy camera mounted ours on a goose-neck stand, which plugs
into an unused USB port, so we can point it directly If any of your

support caused our at the scene we want to capture. Take a test photo
e|#uhwxuqlqj#wr#wkh#Whuplqdo#surpsw#dqg#w|slqj=
saved images are
0kB in size, delete

display to rotate them: FFmpeg


may quit early if it
raspistill -o test.jpg
through 180 degrees åĹÏŅƚĹƋåųŸƋĘåĵţ

Open the resulting test.jpg, which will be saved


in your home folder (/home/pi/test.jpg) to check
Connect your camera
03 We’re using the regular Camera Module 2
the orientation, so you can apply correction later,
if necessary. You’ll Need
here because we only want to shoot time-lapses
in regular lighting. However, this tutorial works > (EQIVE2SHYPI
magpi.cc/
equally well with the Camera Module 2 NoIR, which
cameramodule2
Set up your FTP server
can shoot low-light and night-time stills and
video (you will need to provide an infra-red light
06 Wr#dyrlg#Ľoolqj#xs#|rxu#Udvsehuu|#Slġv# > PIR motion sensor
source for night-time use). Connect the camera to microSD card, our code uploads each captured image magpi.cc/pir
Raspberry Pi’s CSI (Camera Serial Interface) using to a server and then deletes the local copy. It doesn’t
> 8LVIIJIQEPIJIQEPI
the bundled ribbon cable. Don’t confuse it with matter whether you’re running your own server on-
jumper wires
wkh#glvsod|#frqqhfwru=#rq#Udvsehuu|#Sl#Prgho#E# vlwh#ru#xvlqj#d#uhprwh#frpphufldo#rļhulqj=#zkdw# magpi.cc/
computers, the camera connector is the one does matter is that you have FTP access. Log on to jumperjerky
between the HDMI and headphone ports. your host’s control panel and create a folder for your

Raspberry Pi Photography magpi.cc 41


FEATURE

Top Tip
Running
too slow?
FFmpeg defaults
to a framerate of
ƖĂüŞŸţ‰ŅŸƵ±Ş
it for 60 fps, add
‘-framerate 60’
before ‘-pattern_
ƋƼŞåűĜĹ„ƋåŞŎƖţ

uploaded images, as well as a user account that logs removing the # at the start, and adjust the number
straight into that folder. The process for doing this at the end of the line to correct the framing. Our
will vary between providers. Make a note of your camera is positioned with Raspberry Pi’s logo
username, password, and server address. printed on the baseboard in the top left corner,
so we need to rotate the image by 270 degrees to
correct its orientation. However, you may instead
need to make an adjustment of 90 or 180 degrees,
Supply your login details
07 Download the code from GitHub
depending on your setup.

(magpi.cc/timelapsepy) and save it in your home


folder (/home/pi/) as timelapse.py. Open it in
Automate your capture
Thonny Python IDE (in the Programming menu of
a standard install of Raspberry Pi OS) or an editor
09 Save your edited code, then return to the
of your choice. Edit lines 21 and 22, inserting your Whuplqdo#dqg#w|sh=
server address where indicated on line 21, and your
You’ll need three
jumper leads to username and password where indicated on line 22. crontab -e
connect the PIR
motion detector to
XLI,5.4TMRWSR If you’ve never edited crontab before, you’ll be
your Raspberry Pi
asked which tool you want to use. Select 1 for Nano.
Correct the camera…
08
If you’re running When Nano opens, key down to the bottom of the
7EWTFIVV]5M4
Bullseye or later, if necessary Ľoh/#fuhdwh#d#qhz#olqh#dqg#w|sh=
YWIVEWTMGSRǻK If the test shot you took in Step 5 showed that
to enable legacy
camera support the camera was rotated, uncomment line 17 by @reboot python3 /home/pi/timelapse.py &

This tells Raspberry Pi OS to run your code as soon


as it starts, with the & at the end telling it to run the
process in the background. Press CTRL+X to quit
Qdqr/#frqĽup#wkdw#|rx#zdqw#wr#vdyh#|rxu#hglw/#dqg#
reboot your Raspberry Pi.

Testing, testing, 123


10 Your Raspberry Pi should begin capturing
images and uploading them to your server when
the sensor detects motion. If it doesn’t, either
reposition the sensor (not the camera) or adjust its
sensitivity. To set the sensitivity to maximum, hold

42 magpi.cc Raspberry Pi Photography


FEATURE

the sensor so the dome is pointing up and the pins


are away from you, then rotate the orange screw on
the right (which controls sensitivity) as far as you
can to the right, to maximise the range across which
it detects motion. If you get false positives, dial back
a little. Finding the optimal position can require
some trial and error.

Download your stills


11 Download the stills from the server to a
folder called timelapse inside your home folder.
Rshq#Whuplqdo#dqg#w|sh=


cd timelapse

Press RETURN/#wkhq#w|sh= timelapse.py DOWNLOAD


THE FULL CODE:
(VIHMXQEKTMGGVITEHH^IVSWERHQEKTMGGVIREQMRKǻPIWWIU

lv -v | cat -n | while read n f; do mv -n


> Language: Python magpi.cc/timelapsepy
"$f" "$n.jpg"; done

Press RETURN1#Wklv#uhqdphv#|rxu#Ľohv# 001. import time


sequentially. You now need to add padding so the 002. import os
Ľoh#qdphv#duh#doo#wkh#vdph#ohqjwk1# 003. import ftplib
004. from datetime import datetime
W|sh#wkh#iroorzlqj= 005. from gpiozero import MotionSensor
006. from picamera import PiCamera
sudo apt install -y rename 007. from ftplib import FTP
008.
Press RETURN, then type the following and 009. pir = MotionSensor(4)
press RETURN= 010.
011. def thegrab():
rename 's/\d+/sprintf("%05d",$&)/e' *.jpg 012. thetime = datetime.now()
013. detectiontime = thetime.strftime("%y-%m-%d-%H-%M-%S")
014. extension = ".jpg"
015. filename = detectiontime + extension
Create your time-lapse
12 Lqvwdoo#IIpshj#e|#w|slqj=
016.
017.
camera = PiCamera()
#camera.rotation = 270
018. time.sleep(2)
sudo apt install -y ffmpeg 019. camera.capture(filename)
020. camera.close()
Press RETURN. When installation completes, 021. ftp = FTP('[server address]')
frpsloh#|rxu#lpdjhv#lqwr#d#ylghr#e|#w|slqj= 022. ftp.login('[username]','[password]')
023. ftp.cwd('')
ffmpeg -pattern_type glob -i "*.jpg" 024. ftp.storbinary("STOR " + filename, open(filename, 'rb'))
-s:v 640:480 -c:v libx264 -pix_fmt yuv420p 025. ftp.quit()
timelapse.mp4 026. os.remove(filename)
027.
If you want to change the output resolution, 028. while True:
adjust 640:480 to your preferred dimensions. The 029. pir.wait_for_motion()
time taken to complete the process depends on 030. thegrab()
both the resolution and the number of images 031. time.sleep(30)
you’ve saved.

Raspberry Pi Photography magpi.cc 43


TUTORIAL

ArtEvolver:
Part 01

batch-convert
images with
ImageMagick
Prepare to build an ever-evolving artwork using Python
code that merges images endlessly. Start by discovering
ArtEvolver blends
how to bulk process images with ImageMagick the robot with other
pictures, constantly
changing the

B
Sean composite image
WRITER

rian Eno’s 77 Million Paintings is a video


McManus installation that merges slides together to
Author of Mission create endless variations of abstract art. I
Python, Scratch created my own version, called ArtEvolver, which
Programming in runs on a Raspberry Pi and uses a Pimoroni 8-inch
Easy Steps, and
Raspberry Pi For
LCD screen. To work well, it needs a large library
Dummies (with of images. This issue, you’ll see how to curate
Mike Cook). Get them and prepare them using ImageMagick’s
free chapters at
(imagemagick.org) powerful batch processing.
Sean’s website.
You’ll learn how a single command can resize,
sean.co.uk crop, or transform hundreds of pictures. There’s a
short Bash script to automate image rotation, and ImageMagick’s edge
we’ll take a tour through some of ImageMagick’s åýåÏƋƋų±ĹŸüŅųĵŸƋĘĜŸ
vshfldo#hļhfwv1 robot photograph
ÆåüŅųåŞƚƋƋĜĹčĜƋ
into ArtEvolver

Collect your images


01 In Add/Remove Software (Raspberry Pi your personal photo archive and pick images that
menu > Preferences), search for ‘ImageMagick’ resonate. You can bulk these up with free images
and select the ‘image manipulation programs from sites such as unsplash.com, pixabay.com,
You’ll Need – binaries’ option. Click Apply to install the and pexels.com. Your images will be layered in
software. Alternatively, open a terminal window unpredictable ways, so search for colours, textures,
> Raspberry Pi and enter: and shapes that could be part of an abstract
artwork. Textures like paper, stone, and paint
> Raspberry Pi OS
sudo apt update make the art feel more organic; illustrations often
> Some images sudo apt install imagemagick -y work well. We’ve collected about 1000 images for
> ImageMagick this version, but you only really need a hundred
imagemagick.org In this tutorial, you will make ArtEvolver unique or so. Put all your images (and nothing else) in a
by curating the images that you feed into it. Scour folder, and keep a separate, safe copy as a backup.

44 magpi.cc ArtEvolver: batch-convert images with ImageMagick


TUTORIAL

Make all your images


04 landscape format Top Tip
We are assuming you want to display your artwork
on a landscape format screen (wider than it is View progress
tall). It’s OK to have some portrait shape images in in the desktop
DuwHyroyhu/#exw#lw#zrunv#ehvw#li#prvw#lpdjhv#Ľoo#wkh#
Use ImageMagick’s
screen. With abstract images, it doesn’t matter if display image_
you rotate them. The landscapify.sh listing shows file.jpg
a Bash script that rotates all the portrait images command to see
You can use ImageMagick from the desktop, but the command
line enables powerful batch processing capabilities in a folder by 90 degrees. You can download it at an image. It’s
magpi.cc/artevolver or create it using Text editor. easier to use the
Image Viewer in
Save it in the same folder as your images, with
the desktop to
Experiment with the desktop app
02 ImageMagick installs into a desktop menu’s
the name landscapify.sh. Open the folder in the
terminal and enter:
quickly review
image batches.
Graphics folder. Start ImageMagick and click the
splash screen. The splash screen is actually an chmod +x landscapify.sh
image you can edit, but you’ll get better results
by loading a photo using the File menu. Try the This will make the script executable. Then
ydulrxv#rswlrqv#lq#wkh#Hļhfwv#dqg#I2[#phqxv1# run it with ./landscapify.sh. The script uses
These include emboss, sharpen, blur, sepia tone, ImageMagick’s identify command to get the
and oil paint. The Enhance menu has options for dimensions of each image, and its convert
changing the colour and tone of your image. You’ll command to rotate any pictures where the height
Ľqg#wkh#rswlrq#wr#uhvl}h#|rxu#lpdjh#lq#wkh#Ylhz# is greater than (-gt) the width. Unchanged
menu. The Image Edit menu enables you to draw. versions of the rotated images are saved in the new
\rx#fkrrvh#dq#hohphqw#vxfk#dv#d#Ľoohg#flufoh/#d#Ľoo# original_images subfolder.
colour, and ‘stipple.’ The stipple is a pattern for the
Ľoo/#vxfk#dv#eulfnzrun/#zdyhv/#ru#Ľvk#vfdohv1#Gudj#
on the canvas to draw your shape, but be warned
Combining images
that it can be slow on high-resolution images.
05 For some images, you could instead make
d#odqgvfdsh#Ľoh#e|#mrlqlqj#wzr#ru#pruh#sruwudlw#
images, side by side. The montage command
First steps with the terminal
03 Go into your images folder on the desktop
enables you to join images together. You list the
images you want to combine and specify the layout
and press F4 to open a terminal window in that with the -tile parameter. We are using 2×1 to place
directory. There are two main ImageMagick the images side by side. You could create a 4×2 grid
commands: convert and mogrify. Convert is good of images as well, and give the command eight
for changing individual images or experimenting Ľohv#wr#frpelqh1#Wr#uhpryh#dq|#jdsv#ehwzhhq#wkh#
zlwk#hļhfwv1#Iru#h{dpsoh/#|rx#fdq#pluuru#dq#lpdjh# images, you use the -geometry parameter with two
vertically with the -flip operation like this: }hur#ydoxhv1#Wu|#wklv#+uhsodflqj#wkh#ĠlpdjhbĽoh1msjġ#
qdphv#zlwk#|rxu#lpdjh#Ľohv,=
convert image_file.jpg -flip new_image_file.
jpg

Use -flop to mirror it horizontally. With


mogrify, you can process many images at the same
time, which is a huge plus over the desktop app.
\rx#xvh#zlog#fdugv/#zkhuh#-#uhsuhvhqwv#hyhu|#Ľoh/#
dqg#-1msj#zrxog#eh#hyhu|#Ľoh#hqglqj#zlwk#1msj1#
Here’s an example:

 8
 LITSWXIVM^IIǺIGX
mogrify -flip * (here used with a
value of 4) gives your
image the style of a
Ehzduh=#prjuli|#ryhuzulwhv#|rxu#lpdjh#Ľohv1 vintage PC palette

ArtEvolver: batch-convert images with ImageMagick magpi.cc 45


TUTORIAL

Crop your images


07 For typical landscape camera images, any
overmatter will be on the width of the image. Let’s
xvh#prjuli|#wr#furs#lw#rļ1#Wkh#-gravity parameter
vshflĽhv#zklfk#sduw#ri#wkh#lpdjh#|rx#zdqw#wr#nhhs/#
using compass points. To keep the left and trim
the right, use west, for example. Set the gravity to
center to trim both sides equally. The best-looking
crop depends on the image. I manually sorted
my images into three folders for cropping left,
right, and centre, and then ran a version of this
command in each folder.

 8
 LIMQTPSHIIǺIGX montage image_file1.jpg image_file2.jpg mogrify -gravity center -crop 1024x768+0+0 *
here used with a
value of 0.5, distorts -tile 2x1 -geometry +0+0 new_file.jpg
the image
If you have images with unusual dimensions,
This will create a qhzbĽoh1msj#Ľoh#iurp#wkh#wzr# you may need to crop north or south instead. (You
images you supply. can also use a north crop to extract the top of a
portrait-shaped image before you resize it.)

Resize your images


06 Convert to greyscale
The Pimoroni display we are using has a
resolution of 1024×768 pixels, but camera images
08 Some photos will blend better with other
are typically much larger. To resize all the images images if you convert them to greyscale. I use

Top Tip in one go, use ImageMagick’s mogrify command,


like this:
convert for changes like this so I can keep and
frpsduh#wkh#uhvxowv#ri#glļhuhqw#hļhfwv1#\rx#fdq#
convert an image using:
Experiment mogrify -resize 1024x768^ *
with small
convert -colorspace Gray image_file.jpg
batches
The ^ symbol after the resolution sets the images new_image_file.jpg
Image wr#Ľoo#wkh#vfuhhq/#zlwk#vrph#vsloolqj#ryhu1#Li#|rx#
transformations leave the ^#rļ/#wkh#uhvl}hg#lpdjhv#zloo#Ľw#wkh# You can convert to sepia (a browned-out photo
can be slow, so screen. In that case, you see the entire image, style) using -sepia-tone, where a higher number
experiment with but the empty spaces at the top and bottom makes the image darker:
test batches
zrqġw#zrun#zhoo#lq#rxu#Ľqdo#surmhfw1#Ehzduh=#wklv#
before running a
command on a command might take a while, and it will overwrite convert -sepia-tone 75% image_file.jpg new_
big batch. your original images. image_file.jpg

Adjust the colours


09 Swapping colours often makes striking
images. Use -negate to switch black and white,
and swap complementary colours (e.g. blue and
yellow). Try this:

convert -negate image_file.jpg new_image_


Charcoal images like file.jpg
this can work well
when blended with
coloured textures by You can also try negating only the red, green, or
ArtEvolver. The line
thickness here is 5 blue channel:

46 magpi.cc ArtEvolver: batch-convert images with ImageMagick


TUTORIAL

convert –channel blue -negate image_file.jpg


new_image_file.jpg

Posterize reduces the number of colours in the


image. Use a value of 2 for an 8-colour palette, 3
for 27 colours, and 4 for 64:

convert -posterize 2 image_file.jpg new_


image_file.jpg

Add visual effects


10 Wkhuh#duh#d#qxpehu#ri#vshfldo#hļhfwv#|rx# image_file.jpg new_image_file.jpg
 8
 LIIHKIIǺIGX
creates striking
can apply to images, including -emboss, -charcoal, results like this

-edge, -paint, and -spread. Experiment with them Using ImageMagick enables you to batch-convert
to transform photographs creatively. Spread gives lpdjhv#lqwr#d#udqjh#ri#glļhuhqw#vw|ohv1#Lq#wkh#qh{w#
|rx#d#iurvwhg#jodvv#hļhfw1#Wkh#ydoxh#iru#fkdufrdo#lv# ArtEvolver tutorial, we will collate these into a
a line thickness. Start here: physical project that uses these transformations.

convert -emboss 2 image_file.jpg new_image_


DOWNLOAD
file.jpg landscapify.sh THE FULL CODE:
> Language: Bash magpi.cc/artevolver
Distort images
11 The -wave#hļhfw#dggv#ulssohv#wr#|rxu#lpdjh1# 001. #!/bin/bash
You give it the height of the wave (amplitude) and 002. # Rotates portrait images (only) in the current folder
the distance between two waves (wavelength), 003. # From ArtEvolver Tutorial in The MagPi - by Sean McManus
like this: 004.
005. mkdir original_images
convert -wave 5x20 image_file.jpg new_image_ 006.
file.jpg 007. # Remove any extensions in the list below that you're not
using to avoid error messages
You can also use the implode#hļhfw#wr#froodsvh#dq# 008. for image_file in *.jpg *.JPG *.png *.PNG;
image, like this: 009. do
010. # Make sure there is no space around the = below
convert -implode 1 image_file.jpg new_image_ 011. width=$(identify -format "%w" $image_file)
file.jpg 012. height=$(identify -format "%h" $image_file)
013. if test $height -gt $width
Use a negative number for the implode value to 014. then
explode the image instead. 015. echo "$image_file is portrait shape [$width x
$height]. Rotating..."
016. new_name="rotated-${image_file}"
017. convert -rotate 90 "$image_file" "$new_name"
Combine effects
12 You can combine multiple transformations
018.
019. else
mv $image_file original_images

in one command. They’re carried out in the order 020. echo "$image_file is landscape already [$width x
you list them. Here’s an example that resizes, $height]."
mirrors, and negates an image in a single command: 021. fi
022. done
convert -resize 1024x768^ -flop -negate

ArtEvolver: batch-convert images with ImageMagick magpi.cc 47


TUTORIAL

Make a SpecDeck:
Digital tape
loader for the
ZX Spectrum
Fed up with ‘R Tape Loading Error’ errors on your classic Speccy?
Load ZX Spectrum software with ease using Raspberry Pi and Pirate Audio
PJ Evans
WRITER

F
Prepare your SD card
PJ has owned a ZX
Spectrum since
orty years ago, Sir Clive Sinclair brought
home computing to the masses with his
02 It’s software time now. We don’t need a
1982. He’s pictured dļrugdeoh#][#Vshfwuxp1#It was soon the full-blown OS, so Raspberry Pi OS Lite is perfect for
here with Richard
Altwasser and Dr
centrepiece of living rooms across the UK as our needs. If you’re building this project headless
Steven Vickers, young gamers and coders battled with parents (with no keyboard or monitor attached), then we
the hardware and for control of the television. As wonderful a recommend the new advanced features in Raspberry
software designers
machine as it still is, the tape loading system Pi Imager (magpi.cc/imager). Run Imager and select
of the ZX Spectrum.
for games and other software was fraught with Raspberry Pi OS (Other) then Raspberry Pi OS Lite as
twitter.com/ errors. Wonky cassettes and unreliable playback the image and your SD card as the storage. Now click
mrpjevans
hardware caused no end of frustration. Now we the cog to set the hostname, enable SSH, create an
can use a Raspberry Pi Zero to emulate a tape onto account, and set wireless LAN credentials. Now you
an original ZX Spectrum with a reliability you can write your image and, on boot, your Raspberry
could only have dreamt of in 1982. Pi will connect to the network and be ready to go.

You’ll Need

Raspberry Pi, Assemble! Enable and test Pirate Audio


> Pirate Audio
Headphone 01 Rxu#Ľuvw#fkdoohqjh#zlwk#wklv#surmhfw#lv#
03 By now you should be able to boot your
&QTc-&8
volume. ZX Spectrums like it loud and the audio Raspberry Pi and gain access via SSH. Don’t worry
magpi.cc/
pirateaudiohead output from Model A and B Raspberry Pi computers if you’ve connected a monitor and keyboard:
just isn’t enough for these old computers to hear. the instructions are exactly the same. Now we
> Headphone
So we start by adding a Pimoroni Pirate Audio need to enable Pirate Audio. Log in and enter the
EQTPMǻIV
magpi.cc/ KDW/#vshflĽfdoo|#wkh#Khdgskrqh#Dps#yhuvlrq/# following command:
compactstereoamp which will get us some of the way to an acceptable
output level. It also means we can use the more sudo nano /boot/config.txt
> ¡ģEYHMSGEFPIW
portable Raspberry Pi Zero W for this project.
> 3D-printed case Start by carefully adding the HAT to Raspberry Pi Wkhq/#dw#wkh#erwwrp#ri#wkh#Ľoh/#dgg#wkhvh#olqhv=
(optional)
magpi.cc/ Zero (it’ll need GPIO headers, so a WH variant is
pirateaudiocase perfect). If you’re not planning on using a case, we dtoverlay=hifiberry-dac
recommend adding some pillars for stability. gpio=25=op,dh

48 magpi.cc Make a SpecDeck: Digital tape loader for the ZX Spectrum


TUTORIAL

The SpecDeck converts


digital versions of ZX
„ŞåÏƋųƚĵĀĬåŸƋŅ±ƚÚĜŅ
and plays them back just
like a cassette player

This vintage ZX
Spectrum loads games
by listening to tones
from a cassette player
and converting them
into digital information

dtparam=audio=off sudo apt -y update && sudo apt -y upgrade

Save (CTRL+[) then reboot (sudo reboot). After Once complete, you can install all the libraries
reboot, connect the audio out to headphones you need:
(careful of the volume!) and run this command:
sudo apt install git libsdl2-mixer-2.0-0
speaker-test -c 2 python3-rpi.gpio python3-spidev python3-pip
python3-pil python3-numpy libatlas-base-dev
Do you hear static-like white noise? If so, you’re libportaudio2 Top Tip
good to go. Press CTRL+C to stop the racket.
Finally, run sudo raspi-config and under Keep it down
Interfacing Options, enable SPI and I2C.
Please be careful
Will it work? when testing
04 It depends on dependencies playback, ZX
Spectrums
Turn it up to 11
The lines we added to frqĽj1w{w in the previous
step did two things: enable audio output to the
05 What you do next depends on what kind
need it loud,
so please don’t
DAC (digital-to-analogue converter) on the HAT of hardware you are intending to use with this listen directly
and disable any other audio output. However, to project. If it is an emulated ZX Spectrum such as to playback on
get control over the screen, we have to install FUSE or Spectaculator, or a modern recreation such headphones! If
you need to test
libraries that will help us write and display data. as Harlequin, you can skip this. However, if you
hold them away
These are known as dependencies. Start by want to load to an original ZX Spectrum, including from you, you’ll be
making sure you have updated everything already later variants such as the 128+, you’ll need further able to hear!
installed to the latest version: dpsolĽfdwlrq1#Zkdw#zloo#gr#wkh#wulfn#lv#d#vwdqgdug#

Make a SpecDeck: Digital tape loader for the ZX Spectrum magpi.cc 49


TUTORIAL

Playing with Python


07 For our project, we want to be able to
select from a number of games, and also handle
conversion from the compact TZX format directly
to WAV. We’re going to create a Python app
that will do this for us, as well as allow playback
control and display cover art on the Pirate Audio’s
tiny display. To demonstrate how you can control
playback of audio in Python, take a look at the
vshfghfnb41s| code listing. We need the amazing
Pygame module and a few other libraries to help
xv#Ľuvw=
 8
 LI5MVEXI&YHMS battery-powered headphone amp. You need to
-&8MWE)&(
(digital-to-analogue connect its input to the Pirate Audio HAT and the sudo pip3 install pygame keyboard st7789
GSRZIVXIVGSQFMRIH rxwsxw#wr#wkh#][#Vshfwuxp1#Lw#zloo#surylgh#wkh#Ľqdo# tzxtools
with a small
headphone amp boost needed for reliable loading.
Qrz/#li#|rx#hqwhu#wkh#frgh#lqwr#d#Ľoh#fdoohg#
sod|edfn1s|#lq#wkh#vdph#gluhfwru|#dv#wkh#ZDY#Ľoh/#
you can start playback with:
Soundcheck
06 We’ve now got enough of the project sudo python3 playback.py
working to test loading on a real ZX Spectrum (or
whatever you are using) but we need something to
load. We provided a test program. To download it,
Get the full code
enter this at the command line:
08 Wkh#Ľqdo#surmhfw#frgh#lv#d#elw#orqj#iru#wkhvh#
wget https://github.com/mrpjevans/specdeck/ pages, so we’ve provided an easy way to download
raw/main/raspberrypi.wav everything and get running. From your home
directory, run the following:
Once downloaded, hook up the output from
|rxu#dpsolĽhu#wr#wkh#HDU#vrfnhw#rq#wkh#][# git clone https://github.com/mrpjevans/
Spectrum, turn it up to max, run LOAD "" on the specdeck.git
ZX Spectrum and enter:
This will download everything you need.
aplay raspberrypi.wav Wkh#pdlq#Ľoh#lv#fdoohg#vshfghfn1s|, but we’ve
also included several iterations of the project
If all is well, the program will start to load! (vshfghfnb41s| to vshfghfnb91s|) to show how
the program evolved from the original code listing
wr#wkh#Ľqlvkhg#yhuvlrq1#Wklv#phwkrg#ri#frglqj#

specdeck.service DOWNLOAD is much more satisfying than trying to build


THE FULL CODE: hyhu|wklqj#doo#dw#rqfh1#\rxġoo#Ľqg#hyhu|wklqj#lq#
the vshfghfn directory.
> Language: Service magpi.cc/
specdeckservicepy
001. [Unit]
Add some files
002.
003.
Description=specdeck
09 In the vshfghfn#gluhfwru|/#|rx#zloo#Ľqg#
004. [Service] three further directories; w}{ takes the standard ZX
005. ExecStart=/usr/bin/python3 /home/pi/specdeck/specdeck.py Spectrum TZX tape image format. When played for
006. Restart=on-failure wkh#Ľuvw#wlph#lw#zloo#eh#frqyhuwhg#lqwr#d#ZDY#Ľoh#
007. and placed in the wav directory, so we don’t have
008. [Install] wr#frqyhuw#lw#djdlq1#Li#d#MSJ#Ľoh#lv#irxqg#zlwk#wkh#
009. WantedBy=multi-user.target same name in the image directory, it is loaded and
displayed on the screen (it will be automatically

50 magpi.cc Make a SpecDeck: Digital tape loader for the ZX Spectrum


TUTORIAL

specdeck_1.py DOWNLOAD
THE FULL CODE:
> Language: Python 3 magpi.cc/specdeck1py

001. from time import sleep


002. import pygame.mixer
003. pygame.mixer.init()
 8LMWMRI\TIRWMZILIEHTLSRIEQTPMǻIVGERFIGSQFMRIH 004. pygame.mixer.music.set_volume(1)
[MXLXLI5MVEXI&YHMS-&8XSTVSHYGIEWSYRHPSYH
IRSYKLJSVE><TIGXVYQXSPSEHVIPMEFP] 005. pygame.mixer.music.load("./raspberrypi.wav")
006. pygame.mixer.music.play()
uhvl}hg#li#qhhghg,1#\rx#fdq#dgg#dv#pdq|#Ľohv#dv# 007. while True:
you like here from legitimate sites such as World 008. sleep(0.1)
of Spectrum (zruogrivshfwuxp1ruj). We’ve
provided our test program so you can try things
out immediately.

Add some files


10 From the command line, run this:

cd ~/specdeck
sudo python3 specdeck.py
Here we can see a
healthy loading tone:
After a few seconds, ‘SpecDeck!’ will be XLIIUYEPFEVWMRXLI
displayed on the screen and then Raspberry Pi’s FSVHIVWLS[XLEX
we have the levels
logo. This means all is working. Pressing button just right
A on the HAT will start conversion of the TZX to
WAV. This takes a little time on the Raspberry Pi Finally, test it with a reboot:
Zero, but the resulting WAV will be kept so it will
be instant next time. You can pause playback by sudo reboot
pressing button A again and rewind by pressing
B. On the right-hand side, X and Y will scroll On startup, you should see the ‘SpecDeck!’
through all the TZXs available. Press CTRL+C to dqqrxqfhphqw#dqg#wkhq#rxu#whvw#Ľoh1#\rx#fdq#
stop the program. shut down your Raspberry Pi safely by pressing
dqg#kroglqj#exwwrq#E#iru#Ľyh#vhfrqgv1

Spectrum service
11 We don’t want to have to log in via SSH
Add some files
every time we want to use our SpecDeck, so let’s
start everything up on boot by installing the
12 Our SpecDeck is a little exposed and Top Tip
program as a system-level service. wkhuhġv#orwv#ri#gholfdwh#vwxļ#wkdw#qhhgv#
Iluvw/#fuhdwh#d#qhz#Ľoh= protecting. Fortunately, there are a lot of cases Legal ROMs
that people have designed for the Pirate Audio
sudo nano /usr/lib/systemd/specdeck.service HAT that can be 3D printed. Our favourite, by Looking for
Yasuhiro Wabiko, can be downloaded here: content for your
Now add the text in the vshfghfn1vhuylfh listing pdjsl1ff2sludwhdxglrfdvh. This can add that SpecDeck? The
ZX Spectrum
and use CTRL+[ to save and exit. Now we have our all-important protection and make the SpecDeck
homebrew scene
vhuylfh#Ľoh/#zh#fdq#hqdeoh#lw#wr#uxq#rq#errw= truly portable. Other improvements could be to is as busy as ever.
add a battery to make it truly portable, or add See magpi.cc/
sudo systemctl enable /usr/lib/systemd/ support for other computers such as the ZX81 or legalroms.
specdeck.service Commodore 64. As ever, it’s over to you.

Make a SpecDeck: Digital tape loader for the ZX Spectrum magpi.cc 51


TUTORIAL

Learn ARM
Part 03

assembly:
Raspberry Pi Pico
Learn how to code a small assembly language OpenOCD providing a
link between gdb and
program for Raspberry Pi Pico the Raspberry Pi Pico
Stephen
MAKER

Smith

R
aspberry Pi Pico is a low-cost
Stephen is a retired microcontroller board built around
software developer
who has written
Raspberry Pi’s custom RP2040 system-
three books on on-a-chip (SoC) containing dual-core 32-bit
ARM Assembly ARM processor cores. The RP2040 uses ARM’s
Language
microcontroller M-series instruction set,
Programming.
He is a member sometimes referred to as the ‘thumb’ instruction
of Sunshine set, which is based on the 32-bit instruction set,
Coast Search except most instructions use 16 bits of memory.
and Rescue and Single-stepping
enjoys mountain This makes programs compact and allows you to do through the
biking, hiking, and quite a lot in the RP2040’s 264kB of memory. program in gdb
running. He is also There is no operating system on Pico, and just
a member of the
one program running, which is your program.
Sunshine Coast
Writers and Editors However, there is an SDK that you link into your
The output from our
Society (scwes.ca). program to provide useful function libraries, program in minicom
magpi.cc/ including those to initialise the processor. The
stephensmith SDK is open-source, and you can browse the
processor initialisation assembly language code in
src/rp2_common/pico_standard_link/crt0.S. your home folder by Raspberry Pi Pico SDK’s
setup script. The source code for this tutorial is in
You’ll Need HelloMagPi.S and CMakeLists.txt1#Frs|#wkh#Ľoh#
pico_sdk_import.cmake from the SDK’s external
> Raspberry Pi
Create the program
> Raspberry Pi OS 01 Start by setting up Raspberry Pi Pico and
folder to the tutorial3 folder. In this folder, create a
new folder called build. The tutorial3 folder should
32-bit
install Pico’s SDK on your Raspberry Pi. Connect now look like:
> Raspberry Pi Pico your Pico to Raspberry Pi via the Serial Wire Debug
> Raspberry Pi Pico
(SWD) pins using jumper leads. Follow Chapter 5 in pi@raspberrypi:~/pico/tutorial3 $ ls -l
SDK the Getting Started with Pico documentation if you total 16
need a refresher (magpi.cc/getstartedpico). drwxr-xr-x 6 pi pi 4096 Apr 9 10:39 build
> Serial and debug
connectors In Raspberry Pi OS, create a folder named -rw-r--r-- 1 pi pi 412 Apr 9 10:37
tutorial3 in the pico folder that was created in CMakeLists.txt

52 magpi.cc Learn ARM assembly: Raspberry Pi Pico


TUTORIAL

-rw-r--r-- 1 pi pi 665 Apr 9 10:37 drwxr-xr-x 6 pi pi 4096 Apr 11 09:22


HelloMagPi.S elf2uf2
-rw-r--r-- 1 pi pi 2763 Apr 9 10:37 pico_ drwxr-xr-x 3 pi pi 4096 Apr 11 09:21
sdk_import.cmake generated
-rwxr-xr-x 1 pi pi 20224 Apr 11 09:22
HelloMagPi.bin
-rw-r--r-- 1 pi pi 324975 Apr 11 09:22
Build the program
02 If you have built a C program using
HelloMagPi.dis
-rwxr-xr-x 1 pi pi 307468 Apr 11 09:22
Pico’s SDK, then these steps are identical. The HelloMagPi.elf
glļhuhqfh#lv#wkdw#wkh#CMakeLists.txt#Ľoh#olvwv# -rw-r--r-- 1 pi pi 226499 Apr 11 09:22
dq#dvvhpeo|#odqjxdjh#vrxufh#Ľoh#udwkhu#wkdq#d#F# HelloMagPi.elf.map
vrxufh#Ľoh1#Rshq#d#Whuplqdo#zlqgrz#dqg#cd to the -rw-r--r-- 1 pi pi 56944 Apr 11 09:22
tutorial3 folder. HelloMagPi.hex
-rw-r--r-- 1 pi pi 40448 Apr 11 09:22
cd pico/tutorial3/build HelloMagPi.uf2
-rw-r--r-- 1 pi pi 74243 Apr 11 09:21
Run cmake with the option to perform a debug Makefile
build, so we can step through the program in the drwxr-xr-x 6 pi pi 4096 Apr 11 09:21 pico-
gdb debugger in a later step. Placing this command sdk
lq#d#vfulsw#Ľoh#lq#wkh#$HOME/bin folder with a
vkruw#Ľohqdph#fdq#eh#d#uhdo#wlph0vdyhu1
Everything needs to be in
the one executable
cmake -DCMAKE_BUILD_TYPE=Debug ..

The cmake command doesn’t build the program,


Run the program
lqvwhdg#lw#fuhdwhv#d#pdnhĽoh#xvhg#wr#frpsloh#e|#
running make:
03 Power on Raspberry Pi Pico by plugging
the USB cable into Raspberry Pi, while holding
make grzq#wkh#ERRWVHO#exwwrq1#Zkhq#wkh#Ľoh#h{soruhu#
zlqgrz#dsshduv/#rshq#lw/#dqg#frs|#wkh#Ľoh#
The make command takes time to execute and HelloMagPi.uf2 to Pico; it then reboots and the
produces a lot of output. Even though our program
lv#rqh#vpdoo#dvvhpeo|#odqjxdjh#Ľoh/#make compiles
the entire Pico SDK and links it into our program.
Without an operating system running on Pico,
Stephen’s stuff
just our program, everything needs to be in the
He’s written three books on Assembly Language
one executable. Programming. The most recent one is RP2040
The build folder should now look like the Assembly Language
example below: Programming for the
Raspberry Pi Pico, which
pi@raspberrypi:~/pico/tutorial3/build $ ls is the place to go for a
deeper understanding of
-l
the topics touched on in
total 1080 ƋĘĜŸƋƚƋŅųĜ±Ĭţ‰ĘåĀųŸƋŅĹå
-rw-r--r-- 1 pi pi 18809 Apr 11 09:21 is Raspberry Pi Assembly
CMakeCache.txt Language Programming
drwxr-xr-x 5 pi pi 4096 Apr 11 09:22 for 32-bit ARM code,
CMakeFiles and the second is
Programming with 64-bit
-rw-r--r-- 1 pi pi 1670 Apr 11 09:21
ARM Assembly Language.
cmake_install.cmake

Learn ARM assembly: Raspberry Pi Pico magpi.cc 53


TUTORIAL

openocd -f interface/raspberrypi-swd.cfg -f
target/rp2040.cfg

Now, let’s debug our program, with the


following command:

gdb-multiarch HelloMagPi.elf

To load the program, enter the load command:

(gdb) load

Step through the program


05 The program starts by executing Raspberry
Pi Pico SDK’s startup code. To skip this part and
step through the program in our code, we will set a
breakpoint at our main routine.
Figure 1 Running program runs. The program prints out ‘Hello MagPi
our program and
observing the output
Readers’ and a counter. Open a serial port program (gdb) b main
in minicom to see this output. Breakpoint 1 at 0x1000035c: file /home/pi/
pico/tutorial3/HelloMagPi.S, line 14.
minicom -b 115200 -o -D /dev/serial0 Note: automatically using hardware
breakpoints for read-only addresses.
The minicom command displays data being sent
from Pico to Raspberry Pi (see Figure 1). Now, when we execute the program using the
continue command, execution will initialise the
RP2040 and Pico’s SDK before halting at the start
The minicom command displays data of the main routine.

being sent from Pico to Raspberry Pi (gdb) c


Continuing.
Debug the program
04 Let’s look at how the program works using
target halted due to debug-request, current
mode: Thread
the gdb debugger. Gdb will run on Raspberry Pi xPSR: 0x01000000 pc: 0x00000178 msp:
and remotely control Raspberry Pi Pico via the 0x20041f00
debug pins. To communicate with Raspberry Pi
Pico’s debug hardware, use the Open On-Chip Thread 1 hit Breakpoint 1, main () at /home/
Ghexjjhu#+RshqRFG,1#Iluvw/#frqĽjxuh#jge#wr# pi/pico/tutorial3/HelloMagPi.S:14
wdon#wr#RshqRFG/#e|#fuhdwlqj#d#Ľoh#.gdbinit in 14 MOV R7, #0 @ initialize counter to 0
the home folder. Create .gdbinit and place the
following line in it: We can now execute a step command, the MOV
R7, #0 instruction will execute, and we can use
target remote localhost:3333 info registers to see that R7 has been set to 0. R7
holds an index that we increment in our loop.
Next, open a Terminal window to run
OpenOCD. Enter the following command in the (gdb) s
Terminal window: 15 BL stdio_init_all @ initialize uart or usb

54 magpi.cc Learn ARM assembly: Raspberry Pi Pico


TUTORIAL

(gdb) i r r7
r7 0x0 0
CMakeLists.txt DOWNLOAD
THE FULL CODE:
The next statement calls the SDK routine
stdio_init_all, which initialises Pico’s SDK to > Language: CMake magpi.cc/learnassembly3
either send text output to the serial port or the USB
sruw1#Wklv#lv#frqĽjxuhg#lq#wkh#CMakeLists.txt#Ľoh# 001. cmake_minimum_required(VERSION 3.13)
by the following two lines: 002.
003. include(pico_sdk_import.cmake)
pico_enable_stdio_uart(HelloMagPi 1) 004. project(HelloMagPi C CXX ASM)
pico_enable_stdio_usb(HelloMagPi 0) 005.
006. set(CMAKE_C_STANDARD 11)
Khuh/#zh#frqĽjxuh#rxwsxw#wr#wkh#vhuldo#sruw1#Li# 007. set(CMAKE_CXX_STANDARD 17)
zh#zdqw#wr#vhh#rxu#rxwsxw#Ľoh#ghexjjlqj/#zh#pxvw# 008.
use this option. When gdb stops Pico’s processor, 009. pico_sdk_init()
it stops everything since our program is the only 010.
thing running. This stops and disconnects the USB 011. include_directories(${CMAKE_SOURCE_DIR})
connection, preventing it from working. The serial 012.
port doesn’t require continuous attention, so it 013. add_executable(HelloMagPi
doesn’t mind. 014. HelloMagPi.S
This routine contains a lot of code, and it will 015. )
take quite a long time to step through it all. So, we 016.
will set a breakpoint at the next statement which 017. pico_enable_stdio_uart(HelloMagPi 1)
happens to have a label, namely loop. Then we 018. pico_enable_stdio_usb(HelloMagPi 0)
will continue, so we stop at the loop label after 019.
stdio_init_all. 020. pico_add_extra_outputs(HelloMagPi)
021.
(gdb) b loop 022. target_link_libraries(HelloMagPi pico_stdlib)
Breakpoint 2 at 0x10000362: file /home/pi/
pico/tutorial3/HelloMagPi.S, line 17.
(gdb) c 18 ADD R7, #1 @ Increment counter
Continuing.
target halted due to debug-request, current The ADD R7, #1 instruction increments our
mode: Thread counter that is printed out. Again, we step through
xPSR: 0x01000000 pc: 0x0000012a msp: this instruction.
0x20041f00
(gdb) s
Thread 1 hit Breakpoint 2, loop () at /home/ 19 MOV R1, R7 @ Move the counter to second
pi/pico/tutorial3/HelloMagPi.S:17 parameter
17 LDR R0, =hellomagpi @ load address of
hellomagpi string Perform MOV R1, R7, which moves the counter
from register 7 to register 1. This is since R1
The next instruction is LDR R0, =hellomagpi holds the second parameter to printf. We can’t
which loads the address of the hellomagpi string use R1 as our counter, since printf will not
into the register R01#Wklv#zloo#eh#wkh#Ľuvw#dujxphqw# preserve the value of this register. Step through
to printf which we call in a few steps. We step this instruction.
through this instruction.
(gdb) s
(gdb) s 20 BL printf @ Call pico_printf

Learn ARM assembly: Raspberry Pi Pico magpi.cc 55


TUTORIAL

The BL printf instruction will call Pico command to execute this instruction without
SDK’s printf function. This isn’t the printf debugging into it.
function from the C runtime, but part of the SDK.
It is a good implementation of printf and helpful (gdb) n
to use from any programming system using the target halted due to debug-request, current
SDK. If we step, it will take a lot of step calls to mode: Thread
get through this function, so we use the next xPSR: 0x01000000 pc: 0x0000012a msp:
0x20041f00
21 B loop @ loop forever

HelloMagPi.S Raspberry Pi Pico’s SDK has


> Language: Assembly Language full support for assembly
language programming
001. @
002. @ Assembler program print out "Hello MagPi Readers" If you have minicom running, you should see the
003. @ using the Pico SDK. string print. The B loop instruction branches back
004. @ to the loop label. In most environments, executing
005. @ R0 - first parameter to printf dq#lqĽqlwh#orrs#lv#d#exj1#Lq#wkh#plfurfrqwuroohu#
006. @ R1 - second parameter to printf world this is typical because you want your
007. @ R7 - index counter program to run forever – there is nothing else for
008. @ the processor to do. Execute a step command to
009. jump back to the LDR statement. We need to re-
010. .thumb_func @ Necessary because sdk uses initialise R0, since printf will have overwritten the
BLX value we placed previously.
011. .global main @ Provide program starting address
to linker (gdb) s
012. Thread 1 hit Breakpoint 2, loop () at /home/
013. main: pi/pico/tutorial3/HelloMagPi.S:17
014. MOV R7, #0 @ initialize counter to 17 LDR R0, =hellomagpi @ load address of
0 hellomagpi string
015. BL stdio_init_all @ initialize uart or
usb
016. loop:
Modify the program
017. LDR
hellomagpi string
R0, =hellomagpi @ load address of
06 Congratulations! Welcome to the world of
018. ADD R7, #1 @ Increment counter writing assembly language for microcontrollers.
019. MOV R1, R7 @ Move the counter to Raspberry Pi Pico’s SDK has full support for
second parameter assembly language programming. If you browse
020. BL printf @ Call pico_printf wkh#VGN#vrxufh#frgh/#|rx#zloo#Ľqg#txlwh#d#ihz#
021. B loop @ loop forever functions written in assembly language. Try
022. pdnlqj#vrph#vlpsoh#prglĽfdwlrqv#wr#wklv#surjudp#
023. .data to ensure you understand it. Try using the MUL
024. .align 4 @ necessary alignment instruction instead of the ADD instruction, counting
025. hellomagpi: .asciz "Hello MagPi Readers %d\n" down with the SUB instruction, and adding
additional elements to the print string.

56 magpi.cc Learn ARM assembly: Raspberry Pi Pico


HIGHPI PRO
The new case from the HiPi.io team

Rapid tool-free assembly and disassembly Secure microSD card cover


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

Available at these great Pi stores:

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


TUTORIAL

Part 1

Write your own


Game Boy game in C
Learn the basics of making a game on original handheld
hardware with the Game Boy Development Kit

AUTHOR Download
EDWIN JONES the code
from GitHub:
Edwin Jones is a senior software engineer at Mediatonic wfmag.cc/
who’s been working in the games industry for around 17
wfmag62
years. edwinjones.me.uk

H
ow can you make your own game &&ZL]\RXȇOOSUREDEO\ȴQGWKLVHDVLHUWKDQ
for a handheld console that came previous projects, but the Game Boy still has some
out in the 1980s? It’s actually quite quirks you may be unfamiliar with. If you want to
easy, thanks to a few factors. jump ahead, I can recommend this primer from
Because the Game Boy is so old, IUHH&RGH&DPSwfmag.cc/c-begin.
it’s simple to program. And, thanks to the open- 2XUȴUVWVWHSLVWRFRQȴJXUHRXUWRROVWRDOORZXV
source community, its tools are better now to write some code, compile it, and deploy it. First,
than they’ve ever been. If you have a desktop you’ll need a Game Boy or another compatible
computer, you can write code and run it on a console such as the Game Boy Advance or DS.
Game Boy. <RXȇOODOVRQHHGDȵDVKFDUWWRFRS\520VRQWR
One of the simplest ways to get started is such as an EZ Flash: ZIPDJFFH]ȵDVK. If you
with the Game Boy Development Kit, or GBDK. don’t have access to a Game Boy, you can just
:HbFDQXVHWKLVWRZULWH&FRGHDQGFRPSLOHLW run your code on an emulator. I’m using BGB
into a Game Boy program, also known as a ROM. (wfmag.cc/BGB), which has excellent tools for
There are a few versions of software around, visualising what our code’s doing as it runs.
INCLUDES but we’re using the modern version on GitHub: Once you have these tools, you’ll need to
You’ve probably twigged that wfmag.cc/gbdk2020. install GBDK. Follow the instructions on GitHub
our ’main’ function is the code There’s quite a bit of code required for this for your preferred operating system to get it
that our program executes at project – too much to print here in full, but you running. Follow the README to get started
run time. Those lines above FDQGRZQORDGWKHȴOHV\RXȇOOQHHGIURPRXU*LW+XE (wfmag.cc/GBDK). Download the latest release
that which start with a ‘#’ are at wfmag.cc/wfmag62. We’ll be going over all DQGXQ]LSLWWRWKHGLUHFWRU\RI\RXUFKRLFH2QFH
includes. These tell the compiler the code you need step by step, so don’t worry you’ve got that set up, we need to write some
to add some code in place of
LI\RXGRQȇWXQGHUVWDQGLWDOODWȴUVWΖI\RXȇUHD code. Open your editor of choice (my favourite
these lines when compiled.
is VS code: ZIPDJFFYVFRGH DQGFUHDWHDȴOH
We’re using this to import the
called main.c$GGWKHIROORZLQJWH[WWRWKLVȴOH
GBDK code we’ll need to make
our code talk to the Game Boy
hardware directly. #include <gb/gb.h>
#include <stdio.h>

void main()
j Figure 1: This is what your
Hello World should look {
like. Notice how a Game printf(“hello world!”);
Boy-compatible font has
automatically loaded. }

58 magpi.cc Write your own Game Boy game in C


TUTORIAL

individually – it uses tiles to save on memory.


These are split into two kinds – background tiles,
and sprite tiles which are used for foreground
ON THE TILES
objects like the player character and enemies. Why so much memory per tile?
Each 8×8 pixel tile is encoded
Sprites can be 8×8 or 8×16 pixels wide.
into 16 bytes that contain which
The Game Boy can draw a maximum of 40
colour each pixel of the tile
sprites on screen at any one time with a limit of can be. That’s 64 pixels that
ten per line. We’ll avoid this limitation by making could be one of four different
sure to draw fewer than this number. The console colours the Game Boy screen
Figure 2: The player’s health, money, and equipped
j

items are drawn to the window layer. can also draw onto two layers: the background could draw – that’s 128 bits.
layer and what’s called a window layer. This is Divide that by 8 bits per byte
XVHGIRU8ΖHOHPHQWVVXFKDVWKHSOD\HU+8'RU and you get 16 bytes.
Now run the following commands in a terminal health bars. If you go back and play some of your
IURPWKHGLUHFWRU\\RXVDYHGWKLVȴOHLQ favourite Game Boy titles, like The Legend of Zelda:
Link’s Awakening (Figure 2), you can see where the
“{path where you installed the GBDK}/bin/lcc” layer’s been placed.
-c -o ./main.o ./main.c The Game Boy lets us scroll the background
“{path where you installed the GBDK}/bin/lcc” and move sprites freely, so we don’t need to
-o ./main.gb ./main.o worry about clearing any previously used pixels.
It even handles wrapping for us – if a background
ΖI\RXRSHQWKDWIROGHU\RXVKRXOGVHHDQHZȴOH or sprite moves too far in one direction, it will
in there called main.gb. Open this in your Game appear on the other side of the screen.
Boy emulator and you Now you understand a
should see the output in “You’ve written and bit more about how the Wireframe
Figure 1. Game Boy works, let’s get 1YZruvufqZEb’qruEnnREqRP
ǁljɥȢɁʰljǁʰɁʍɨˎɨɰɽ in Wireframe, our sister
&RQJUDWXODWLRQV<RXȇYH started with our own game:
magazine that lifts the
written and deployed your Game Boy program” DVLPSOHLQȴQLWHUXQQHU lid on the world of video
ȴUVW*DPH%R\SURJUDP called Drop Bear. A bear’s games. Every issue
)HHOIUHHWRPRYHWKLVRQWRDȵDVKFDUWDQGUXQLW falling from the sky, dropping coins; how many includes tutorials and
in-depth interviews, along
on your own hardware. can he collect before the time runs out?
with news and reviews
First, we’ll need to create some sprites using of the latest indie and
HELLO WORLD a browser-based tool called the Game Boy Tile triple-A games.
Now our tools work, let’s look at the Game Boy’s Data Generator (wfmag.cc/gbtdg). Open the 1f’dPfvucfqRŧ{ZrZuuYRZq
specs in more detail so we can understand how it folder the project has downloaded to, then open website at wfmag.cc.
works before we make a real game: the LQGH[KWPOȴOHLQ\RXUEURZVHUDQG\RX Check out their
should see something like Figure 3. subscription offers at
wfmag.cc/subscribe.
• $™SL[HOIRXUFRORXU/&'VFUHHQ
™DGGUHVVDEOHFDQGUDZR΍VFUHHQ
• four-way direction pad and four buttons
A
(start, select, A, B) for a total of eight inputs
• $QELW6KDUS/5&38
• 8kB of working RAM
• 8kB of graphics memory
• At least 32kB of ROM memory from the game
carts themselves

These are the basics we need for this project.


You may notice that the Game Boy can ’draw’ to
™SL[HOVZLWKIRXUGL΍HUHQWFRORXUVZKLFK
would mean we’d need at least 16kB of memory
to control the colours. The Game Boy only has half j
Figure 3: This is how the
of that for graphics memory. How is this possible? Tile Data Generator looks
in a browser without any
Because the console doesn’t control every pixel data uploaded.

Write your own Game Boy game in C magpi.cc 59


TUTORIAL

LET’S MAKE A SPLASH!


7KHUHȇVRXUVSODVKVFUHHQ7KDWZDVDORWRIFRGH
though, so what did we just do? Well, everything
outside the main function is just asset data
for the logo, generated the same way as we’ve
GHVFULEHGEHIRUHEXWZLWKRQHFUXFLDOGL΍HUHQFH
ȂZHȇYHR΍VHWHYHU\WKLQJLQWKHWLOHPDSE\WKH
value 0×80. This is a bit of a hack, as the Game
Boy has limited memory. We’re already using a
third of it for the font we need to print text with,
VRZHSXVKWKHORJRGDWDLQWRDGL΍HUHQWSDUWRI
the video memory so we don’t override the font
WKDWȇVDXWRPDWLFDOO\ORDGHGZLWKWKHȴUVWprint
statement. You can view graphics RAM in BGB to
see it for yourself by right-clicking then using the
Other > Vram viewer menu option (Figure 6).
Figure 4: This is how the 7KHȴUVWSDJHLVWDNHQXSE\WKH1LQWHQGRORJR
j

Tile Data Generator looks


with a sprite loaded. – this is a form of primitive DRM as the Game Boy
Note how text has If you look at the bottom left, you’ll see two ZRQȇWERRWLIWKLVORJRLVQȇWWKHȴUVWWKLQJORDGHG
generated to the right of
the loaded image. options under ‘formatting’ – it’s important we use into memory. We’ll override it soon, though, as
Ȇ&IRUPDW*%'.ȇIRUDOORXUDVVHWVDVWKDWPHDQV once you’re past the logo screen, it’s no longer
the output will work with GBDK. I’ve already needed. The Drop Bear logo is in one segment
created all the assets our game needs, but let’s of memory and the font’s in another, while tiles
walk through how to do this yourself so that you currently rendering are highlighted in green.
can make your own or edit them later. All you We’re only using a few characters of our font, but
need to do is click under ‘Input Image’ on the top DOORIRXUORJRȴOHV1RWHWKDWWKHFRPSRVHGORJR
left and select an image from your local hard drive reuses some of these tiles to save memory as we
to load it into the editor. When we do this with a covered earlier.
pixel art image of a bear’s face I’ve prepared for Interestingly, the Game Boy’s video memory
the project, we get the output in Figure 4. layout starts at address 0×8000 and ends at
See the text on the right under ‘Data Output’? 0×97FF. Addresses 0×8000 to 0×8FFF were
That’s the raw binary data the Game Boy needs to designated for sprite data, as you can see with
draw this image alongside WKHȴUVWWZREORFNVLQ
a few constants, like how “The Drop BearȢɁǼɁȈɰȈȶ the bgb vram viewer
many tiles wide and high screenshot (Figure 6).
ɁȶljɰljǼȴljȶɽɁǹȴljȴɁɨʰ
the sprite needs to be – Background memory
DVWKH31*ΖȇYHXVHGLV ƃȶǁɽȃljǹɁȶɽԇɰȈȶƃȶɁɽȃljɨԅ runs from 0×8800 to
32×32 pixels, we’ll need 0×97FF. “Hold on, those
four 8×8 tiles to represent the image on a Game DGGUHVVHVRYHUODSȋΖKHDU\RXFU\DQG\RXȇUH
HOLY MACRO Boy. You can see the height and width constants FRUUHFW7KHbPLGGOHSDJHRIJUDSKLFVPHPRU\
A macro is a fancy word are the number 4. I’ll include the relevant data in- from 0×8800 to 0×8FFF can be used by either
for something the compiler line when we need it, as we go along. Feel free to sprite or background tile data, but not both. This
replaces at compile time. import your own assets, though, as that’s half the is why we needed to move the logo tilemap into
You can create your own fun of making your own game. DGL΍HUHQWSDUWRIPHPRU\VRZHFRXOGORDGRXU
macros to replace any text
First, let’s create the title screen. For this, we’ll logo into tile memory without overriding the font
with any other bit of code. For
need a logo asset and some on-screen text. Let’s that lives in the highest part.
instance, you could replace
start with the easiest bit, printing the text. We can We add 0×80 to each tilemap value because
‘printf(“hello”)’ with a macro
M~EPPZdXEbZdRbZaRƅūPR’dR do this by modifying our ‘Hello World’ program WKH*DPH%R\WUHDWVWKHȴUVWQXPEHUHG
HELLO printf(“hello”)’ to the top ȂȴQGWKHFRGH\RXQHHGLQWKHȴOHWLOHVFUHHQ background tile (0×00) as living at address
fW~fvqNfPR’bRŧuYRdM~vrZdX FRGHF on our GitHub: wfmag.cc/wfmag62. 0×9000, not 0×8000. Adding 0×80 pushes the tile
‘HELLO’ in place of the formal If you compile and run this program the indices into the correct portion or VRAM where
function call. same way as before, you should see the output we’ve loaded our logo. This is because 0×80 is
in Figure 5. 128 in decimal, which is exactly how many tiles

60 magpi.cc Write your own Game Boy game in C


TUTORIAL

each third of the video memory can hold – 128 WKHFRGHIURPWKHȴOHEDFNJURXQGWLOHFRGHF


tiles * 3 blocks * 16 bits per tile = 384 available on our GitHub and paste it above your main
tiles to use. function. Then add the following lines to the end
ABOUT VBLANK
Inside the main function, we invoke a few of your main function: VBLANK is the time taken from
the end of drawing the last line
macros to clear the screen. We then call printf
on the screen to the start of
with a blank string to tell GBDK to load the default // Load tileset into background memory
drawing the next. By waiting until
font into memory without drawing anything on set_bkg_data(128, BACKGROUND_TILE_SET_COUNT, the VBLANK period, we know
screen. We move the background layer a little, background_tile_set); we’re not looping faster than
then load the tile logo into memory by setting the screen’s drawing. We can
the tile data and tile layout map. We call another // Load tile map into memory. use this to make sure each loop
macro to force the background layer to render set_bkg_tiles(0, 0, BACKGROUND_TILE_MAP_WIDTH, executes no faster than a single
and show our logo. We then call another function BACKGROUND_TILE_MAP_HEIGHT, background_tile_ frame, which takes roughly 16
to move the print cursor and print the words map); milliseconds (1 second / 60 fps =
Ȇ3UHVV6WDUWȇRQWRWKHERWWRPRIWKHVFUHHQ 0.01666).

Let’s move on to input. Most games have We’re loading this new tilemap to the background
multiple ‘states’. Here, we’ll keep it simple by only layer as we did with the logo – you’ll see each
using three – the game splash screen, the game tilemap entry is adjusted by 0×80, so we
play screen, and a game over screen. We can get don’t interact with the loaded font as before.
the Game Boy to wait for our input with another &RPSLOHb\RXUSURJUDPDJDLQDQGORDGLWLQWR%*%
command. Add the following lines to the end of You should now see Figure 7 (overleaf).
your main function: Now, at the end of your main program, add the
following code to the end of your main function:
waitpadup();
waitpad(J_START); // scroll the background forever
cls(); while(1)
{
These functions wait for all buttons to be scroll_bkg(0, 3);
released, just in case the user has any depressed. // Wait until VBLANK to keep time Figure 6: You can see
j
When the Start button is pressed, the screen wait_vbl_done(); the sprites that make
up each letter in this
is cleared. Try it yourself in the BGB emulator: } view. This is the same
font we used for our
press the RETURN key, and the screen should Hello World program.
FOHDU:HFDQȵHVKRXWWKHJDPHSOD\E\DGGLQJ
a background that loads when we move to the
second stage. As our game involves a dropping
bear, a simple trick is to load a background we
can then scroll vertically to generate the feeling
of movement. You can make a striped tile via
the tools mentioned above, but for now, copy

Figure 5: Our title screen.


j

Write your own Game Boy game in C magpi.cc 61


TUTORIAL

If you compile and run your game again, then // set game timer
press Start, you’ll see the background scrolls. game_time = 600;
SHORTHAND We’ve used an ļŝǙŝļƢĕ loop that scrolls the while(game_time)
You might have noticed we background up three pixels and then waits for {
used a new type here called
a vertical blank. This ensures the code only // scroll the background
‘UINT16’. This is a ‘typedef’:
runs once a frame. The Game Boy has a frame scroll_bkg(0, 3);
a way C programs can use
rate of ~60 fps, which means we’re moving the
their own shorthand to refer
to existing types. The GBDK background at roughly ~180 pixels a second. //decrement the game timer
PR’dRruYRrRWfqvrrf|R game_time--;
YE{RE|E~ufPR’dRvdrZXdRP FALLING DOWN
integers by size instead of Next, let’s add a little code to allow the main // Wait until VBLANK to avoid
using byte for UINT8 etc. game to run for a while, then stop. We can then corrupting memory and keep time
add some code that resets us back to the main wait_vbl_done();
splash screen, creating a basic game loop. We }
know that each refresh of our loop happens
roughly 60 times a second, so if we want to create //jump back to the start of the
a quick ten-second cycle, we can start a counter program
at 600, decrement it each loop, and exit when goto start;
LWȴQLVKHV$GGWKHIROORZLQJFRGHWRWKHDERYH
main function: Recompile and run the game again. The screen
should fall for ten seconds then you should come
UINT16 game_time = 0; back to the start screen.
Next up, let’s add a player character with
This lets us store a value of 16 bits, more than sprites. I’ve prepared the bear sprite data
enough for number 600. Next, add this at the PHQWLRQHGHDUOLHUZKLFK\RXFDQȴQGLQWKHȴOH
very top of your main function: SOD\HUFKDUDFWHUFRGHF. Just copy this code and
paste it outside of the main function (as you have
start: previously) for now.
)LUVWZHQHHGWRGHȴQHVRPHYDULDEOHVWR
This is a label for a goto statement which we’ll control the position of our player character. Add
use in a minute. Next, update the loop statement this code before your main function like so:
like so:
UINT8 player_x = 72;
UINT8 player_y = 32;

Now we can load the player character into


memory with a similar set of commands as
before. Add these lines to the bottom of your
main function just before the while loop:

// Load the ‘sprites’ tiles into sprite


memory
set_sprite_data(0, BEAR_TILE_SET_COUNT, bear_
tile_set);

// Set the first movable sprite (0) to be the


first tile in the sprite memory (0)
for (UINT8 i = 0; i < BEAR_TILE_MAP_SIZE; i++)
{
set_sprite_tile(i, bear_tile_map[i]);
j Figure 7: Notice how the
tiles repeat over and over }
– this is how we can make
a little bit of data useful
over a large screen area. SHOW_SPRITES;

62 magpi.cc Write your own Game Boy game in C


TUTORIAL

Figure 8: Here’s our bear sprite drawing


j

over the background.

<RXPD\KDYHQRWLFHGDGL΍HUHQFHLQWKHQDPHRI
the command from before – this is because we’re
setting sprite data, not background data. As we
need more than one 8×8 tile to draw an image, Figure 9: Here you can see

j
we also need to set multiple sprite tiles at a time, the bear sprite in VRAM.
Note how some tiles are
hence the loop. We then invoke a macro to make Here, we write some loops to go over every tile of repeated to save memory.
VSULWHVYLVLEOH3RVLWLRQLQJWKHVSULWHVLVDOLWWOH our sprite and move them around based on the
trickier – add a new block inside your for loop FXUUHQWSOD\HU[DQGSOD\HU\YDOXHVZHFRQȴJXUH
before the wait_vbl_done() call like this: We then wait for player input to see if the sprite’s
x position should move. If you’re wondering
// move player DERXWZKDWȆȇDQGȆȇPHDQWKHȆȇLVWKHVL]HRID
for (UINT8 y = 0; y < BEAR_TILE_MAP_WIDTH; tile in pixels and the ‘2’ how many pixels we want
y++) to move per update.
{
UINT8 yOffset = y * 8; BEAR NECESSITIES
If you recompile your game and load it in an
for (UINT8 x = 0; x < BEAR_TILE_MAP_ emulator, you should see Figure 8 if you press
HEIGHT; x++) Start on the splash screen, and if you press the
{ OHIWDQGULJKWNH\VEXWWRQVWKHEHDUZLOOPRYH
UINT8 xOffset = x * 8; around the screen.
move_sprite(tileCounter++, player_x If you load up the VRAM debugger view again,
+ xOffset, player_y + yOffset); you’ll see that our bear sprite has overwritten
} some of the Nintendo logo in that memory area
} (Figure 9).
// update input If you’re wondering why some tiles are
GOTO JAIL
// LEFT highlighted in this view, it’s just BGB’s way of GOTO is a simple C command
that lets you move execution
if (joypad() & J_LEFT) telling you what’s currently being drawn on
to any other part of the code
{ screen. The other tiles represent that state of
PR’dRPM~EbEMRbŬuƆrWEbbRdfvu
player_x -= 2; VRAM for things not currently being drawn. This of favour in modern times as
} FDQEHKDQG\IRUȴJXULQJRXWZK\WKLQJV\RXORDG it’s considered risky, but it still
// RIGHT in aren’t being drawn – usually because their has uses now and then as you
if (joypad() & J_RIGHT) positions haven’t been correctly set. can see in our code – as long
{ And that’s it for now. In the second part of the as you keep an eye on exactly
player_x += 2; guide, we’ll add objectives, a timer, and end game where your labels are!
} states. See you next issue.

Write your own Game Boy game in C magpi.cc 63


PLAY
& CODE
GAMES!
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


FEATURE

WEARABLES
&
COSTUMES
Make your clothes Raspberry
Pi-powered masterpieces
with Rob Zwetsloot

C
ostumes and cosplay aren’t just about
sewing. Crafting armour from foam or
thermoplastics, or turning some PVC
piping into a spear is all part of it these days.
So are electronic add-ons like screens, LEDs, or
moving parts.
Raspberry Pi Zero and Raspberry Pi Pico are
perfect devices to use with more interactive
costumes. With their small size, low power
requirements, and ease in which to program,
they’re a great choice for your Iron Man costume.
Time to make some plans and try to get your
frvwxph#Ľqlvkhg#ehiruh#wkh#frq1

66 magpi.cc Wearables & Costumes


FEATURE

r e s o u r c e s
Co s p l a y
t o f yo u r b u i ld
e p a r
he c o s t um
He lp w i t h t

ft a ny
o s c r a sells m
C k s a n d fabric,
at s to c
th igs to
ro m w s.
A s to r e rials, f plastic
p l a y m a t e
a n d t hermo
cos foam
n c ra f t
t o ev e
k
ft.co.u
Cosplay photography co s c ra
If you want to take decent
selfies or other shots of your
own cosplay, this guide is a Wearable
great start to getting into that. Tech Projects
d
From Sophy Wong, an
at
magpi.cc/costog our colleagues over
e ma ga zin e,
HackSpac
ea t bo ok
comes this gr
ble
full of excellent weara
projects and ideas
beyond Raspberry Pi.

book
magpi.cc/wearable

KamuiCosplayd
s, an
Tutorials, book
te your
patterns to crea
costumes
own incredible
from Kamui.

m
kamuicosplay.co

Alysson Ta
Alyson has
bb itha
incredible
up tutorials make-
, something
is an expert she
on, being a
transform h b le to
erself into
different ch m a ny
aracters.

magpi.cc/
tabbitha

Wearables & Costumes magpi.cc 67


FEATURE

LIGHTING UP
LEDs and displays
W
ant to really make your costume eye-
catching? Install lights and displays on it
so that you instantly light up the room.

y l i g h t s
C o spl a
Maker
01 Build the circuit
Freya and For this project, a round NeoPixel board
Rob Zwetsloot was used. NeoPixel lights require power, a data
input, and ground. While there are not many lights
Web in this setup, they usually require more power than
magpi.cc/cosplayeyes a Raspberry Pi can deliver, so you’ll need a battery
pack as well. A button is also added, which acts as
Project wkh#wuljjhu#iru#wkh#glļhuhqw#oljkw#hļhfwv1
Using NeoPixel LEDS,
these lights were
programmed to recreate
colour patterns for the 02 Coding
NeoPixels require special libraries to
character Sans from
work with Python and MicroPython, including
Undertale. Using
a button press Adafruit_Blinka (magpi.cc/blinka) and the
cycled through CircuitPyhon libraries, like so:
FKHHGTGPVǭUGVVKPIU
sudo pip3 install rpi_ws281x adafruit-
circuitpython-neopixel

Colours are done with RGB values from 0 to 255.


Li#|rxġuh#orrnlqj#iru#d#vshflĽf#frorxu/#Jrrjoh#wkh#
name of it with ‘RGB’ appended, and you’ll usually
Ľqg#d#jxlgh#rq#krz#wr#pdnh#wkh#frorxu1#Wkh#frgh#
for this build uses GPIO Zero, but Pygame can also
work with the button input. oljkwv#wr#glļxvh#dqg#orrn#pruh#qdwxudo1#Wkh#zluhv#
were quite long and she was able to have them all
Ľw#lqwr#wkh#srfnhw#ri#wkh#krrglh#wkurxjk#d#kroh#rq#

03 Installing into the costume the inside. With everything in place, she just had
In this build, Freya glued the NeoPixel ring to press the button in her pocket to change the
to some frosted acrylic in the eye, allowing the code sequence.

68 magpi.cc Raspberry Pi
Wearables & high-end
Costumesaudio
FEATURE

St om ach sh o t 01 Set up the hardware Maker


The basic hardware for this is a Raspberry Luis Martín
Pi Camera Module, any kind of Raspberry Pi- Nuez
mountable display, and some cable extenders for
the camera cable. All you need to have it do is use
the camera preview to have a constant display Web
of what the camera sees, which is set up to start magpi.cc/
during boot. stomachshot

Project
02 Build the prosthetic Inspired by The
Walking Dead, Luis
Luis went the extra mile and created a
decided to make a
latex stomach wound attached to the front of Halloween costume
the display, and connected to a harness he could where you could see
wear under his T-shirt. It’s coloured with make- through him. In TV
up to look skin-coloured, and paint for the blood and movies, there’s
and ‘insides’. green screen magic
involved during
editing. In real life, it’s
as simple as using a

03 T-shirt time camera and display.


The last part is the T-shirt. Two holes are
cut into it: one at the front that is slightly smaller
than the screen, and one at the back so that the
camera can see behind you. With the harness on
and the T-shirt over it, it’s time to turn it all on
and try and scare some kids. Although, apparently,
wkh|#whqg#wr#mxvw#zdqw#wr#wdnh#vhoĽhv#wkurxjk#
the stomach.

e h a r n e s s
Wi t h t h
h e T - s h i r t
on and t
  Q \ ¼[ \ Q U M \ W
W ^M ZQ \
n i t a l l o n
t ur

Wearables & Costumes magpi.cc 69


FEATURE

MOVING
MOTORS
and servos
R
obots and robotic armour are cool costumes
to make. And sometimes, you need some
fake eyes to blink. Using servos and motors,
you can really make a costume come alive.

Te nt ac le hat
Maker
01 Electrical components
Derek The hat uses eight servos, two for each
Woodroffe tentacle, which are hooked up to a Raspberry Pi
Zero. A sine wave is sent to each servo – an X and
Y movement – to try and emulate a more natural
Web
pryhphqw#lq#wkh#Ľqlvkhg#surgxfw1#Wklv#exlog#
magpi.cc/tentaclehat
uses an eight-port I2C PWM controller so that
everything can be connected properly.
Project
This writhing and
wiggling hat is
more of a passive
02 Make the tentacles
accessory. Just turn it The build of the tentacles is very smart;
on and the tentacles the core is made from the spring of a net curtain are slotted over it to give the whole thing some
will move of their
vr#lwġv#ľh{leoh#dqg#pryhv#lq#fxuyhv1#Dfu|olf#glvfv# structure, before stockings are applied on top.
own accord.
Vrph#odwh{#lv#dssolhg#rq#wrs/#dqg#vrph#odvhu0fxw#
2 mm MDF suckers are glued on. Wonderful.

03 Put your hat on


Cut a hole in a top hat (preferably a spare
one from a costume shop) and glue the whole
dssdudwxv#lqwr#wkh#kdw1#Juhhq#odwh{#zdv#dssolhg#
here to make it look like they were bursting out of
a pool of ooze. The only thing left is power which,
lq#wklv#fdvh/#lv#khog#lq#d#vshfldo#er{#iru#wkh#zkroh#
system. You can add it to your belt or secrete all the
components in a jacket.

70 magpi.cc Wearables & Costumes


FEATURE

Warning!
Projectiles
Wear goggles when
working with face
tracking weapons,
however soft the
darts are

magpi.cc/nerfsafety

Maker
Engineering
After Hours

Fac e - t rac k ing NE R F g u n Web


magpi.cc/
predatortrack

Project
01 Creating a model 03 Wearing a gun Taking inspiration
Using a Raspberry Pi connected to an Edge The mount in this project is quite simple from the predators
TPU, you can start training the model for your – a few pieces of wood are cut to length and of… Predator, this
AI face tracker. Feeding it with pictures of faces attached to a series of straps that keep the gun shoulder-mounted
NERF gun uses AI to
allows it to learn what they look like, although you counterbalanced while wearing it on his back. The
track faces and aim
fdq#dozd|v#Ľqg#h{lvwlqj#prghov#wkdw#zloo#kdyh#idfhv# whole thing is powered by a series of batteries
a NERF gun in that
already built in. The more it’s used, the better it dqg/#xvlqj#d#vlpsoh#zluhohvv#uhprwh/#fdq#eh#Ľuhg# direction. Good thing
becomes as well. at the person it’s tracking. Be careful, even with there are no laser
foam darts. pointers attached.

02 Tracking
A Pan-Tilt HAT from Pimoroni was used,
with the code manipulating the motors to turn the
pan and tilt portions of the setup. This is usually
used in robots for object tracking, but is perfect
for anything that requires a camera to move and
track at the same time. The NERF gun needs to
be mounted to the Pan-Tilt HAT and the camera
mounted to the gun.

<P MUW ZMQ \ ¼[][ M L 


t h e b e t te r it
b e c ome s a s we ll

Wearables & Costumes magpi.cc 71


FEATURE

I N S TA L L I N G
inputs and sound
Y
our costume moves? It lights up? Great.
Grhv#lw#kdyh#vrxqg#hļhfwv#dqg#lqwhudfwlyh#
elements on the outside? Time to add them.

o u t t h e i n t e r n e t
S o c ia l me dia w i t h
Maker
01 Components galore
Tuang Wkhuh#duh#vhyhudo#sduwv#wr#wklv#rxwĽw/#
Thongborisute controlled by a Raspberry Pi and several Arduino
frqwuroohuv1#Frqgxfwlyh#ulqjv#rq#wkh#Ľqjhuv#wrxfk#
Web during a handshake, a button is used to unfriend
tuangstudio.com dqg#lv#wlhg#wr#dq#OHG#glvsod|/#d#olnh#lv#d#kljk#Ľyh#
which activates a force-sensitive resistor (FSR),
Project dislike is via a touchscreen, and microswitches and
This social interaction pressure-conductive resistors (PCR) are used for
project has a lot of follow/following. It’s a lot to connect, but very cool.
buttons and lights and
displays everywhere,
which the general
public can interact 02 Jacket attachment
with, just like Rqfh#doo#ri#wkh#frpsolfdwhg#flufxlw#vwxļ#lv#
Twitter, Facebook, completed, it’s time to attach it to a jacket. This
QTǭ+PUVCITCO can be done with conductive thread to reduce
wire usage, along with tape to attach things and
glue and whatever else you have. The locations
are important for the experiment – the unfollow
button is over the heart you could break, and the
PCR is on the shoulder.

03 Socially interact
The experiment can now begin – go out into
wkh#zruog#dqg#Ľqg#rxw#zkdw#shrsoh#wklqn#derxw#
you. Tuang’s experience showed that people react
glļhuhqwo|=#ģVrph#pd|#khvlwdwh#wr#dvn#ru#lqwhudfw/#
but some partake in face-to-face conversation.”

72 magpi.cc Wearables & Costumes


FEATURE

R ob ot co st ume
01 Hardware setup
The display on the chest uses Instagram
likes to create an electrocardiogram heartbeat, and
the buttons control the LED colours, play random
sounds, and start playing videos on the display.
The voice changer uses Arduino parts as well, and
employs a microphone inside the head. The speech
dfwlydwhv#wkh#vhuyr#wkdw#ľdsv#wkh#urerw#mdz1

02 Cardboard construction
One of the best things about this costume
is how much cheap and recycled material it uses.
Cardboard boxes, googly eyes, aluminium foil, and
air conditioner hoses, among many other things.
Be careful when cutting and gluing to make sure
|rx#kdyh#hqrxjk#vsdfh#wr#dfwxdoo|#Ľw#lqvlgh1

03 Spook time Maker


With the robot suit completed, it’s time Estefannie
to go out and trick-or-treat. Make sure you have
a handler, as you may not be able to see very well. Web
Pxfk#olnh#wkh#rŀlqh#vrfldo#phgld#mdfnhw/#shrsoh# magpi.cc/
might not always come up to interact with you, robotcostume
especially if you try and beckon them over with a
robotic voice. Project
This excellent
Halloween costume

k e s u re y o u h av e uses just about

M a everything we’ve
covered so far –
lights, displays,

a h a n d le r, a s yo u
buttons, and a
moving mouth using
servos. There’s also

y n o t b e a b le t o a voice changer

ma for some sound


integration as well.

s e e ve r y we l l

Wearables & Costumes magpi.cc 73


This stunning 224-page hardback book not only tells
the stories of some of the seminal video games of
the 1970s and 1980s, but shows you how to create
your own games inspired by them using Python and
Pygame Zero, following examples programmed
by Raspberry Pi founder Eben Upton.

Get game design tips and


tricks from the masters

Explore the code listing


±ĻÚƐĀĻÚƐŇƣƒƐĚŇƾƐƒĚåDžƐƾŇŹī

Download and play game


examples by Eben Upton

Xå±ŹĻƐĚŇƾƐƒŇƐÏŇÚåƐDžŇƣŹƐŇƾĻƐ
ď±ķåžƐƾЃĚƐ{Džď±ķåƐ¬åŹŇ

Available now
magpi.cc/codetheclassics
REVIEW

StackyPi
SB Components magpi.cc/stackypi £14 / $18
SPECS

CONNECTORS:
40-pin GPIO An RP2040 microcontroller compatible with standard HATs. By Phil King
header, 6-pin

W
debug header,
micro-USB ell is it a Raspberry Pi Zero? Is it a
Pico?… No, it’s StackyPi. While there
STORAGE: are a few dedicated add-ons for Pico, if
8MB on-
board flash, you’re a Raspberry Pi fan then you probably have
plus microSD some HATs kicking around that you might like to
card slot xvh#zlwk#lw1#Gxh#wr#Slfrġv#glļhuhqw#duudqjhphqw#ri#
GPIO pins (in two separate rows), however, it’s not
FEATURES:
Boot and reset possible to simply plug in a HAT.
buttons, status Step forward StackyPi. Based on the same
The size of a Raspberry Pi Zero, the StackyPi is an RP2040-
LED, 4 × 12-bit Raspberry Pi RP2040 microcontroller chip as based microcontroller with a 40-pin GPIO header
ADC channels,
Slfr/#lw#rļhuv#wkh#vdph#ixqfwlrqdolw|/#exw#zlwk#d#
PIO, I2C,
SPI, UART pre-soldered 40-pin (2×20) GPIO header. It has Plug and play?
a very similar form factor to a Raspberry Pi Zero, That standard 40-pin GPIO header means you can
DIMENSIONS: including four mounting holes. There’s even a connect any standard Raspberry Pi HAT, pHAT, or
65 × 30 × 10 mm
microSD card slot for extra storage, although other compatible add-on board. The downside is
Vwdfn|Sl#douhdg|#kdv#;PE#ri#rq0erdug#ľdvk# that it’s not a case of plug and play. You will need
(compared to Pico’s 2MB).
Other features include a standard micro-USB
port (for 5 V power or connecting to a computer),
You will need to adapt any
two tiny push-buttons (including a handy reset), existing software for your
an on-board status LED, and six debug pins.
HAT to make it work
to adapt any existing software for your HAT to
make it work.
SB Components has adapted software for several
Verdict of its own HATs for StackyPi, available in a GitHub
repo (magpi.cc/stackpigh), which also features a
Not a plug-and- handy GPIO pinout comparison chart – it’s very
play solution for similar to that on a Raspberry Pi, although some
HATs, as you’ll JSLR#slq#qxpehuv#duh#glļhuhqw1
need to do some
As with Pico, you need to connect the board
software tinkering,
yld#plfur0XVE#wr#d#frpsxwhu#wr#ľdvk#wkh#XI5#
but still a neat
little Pico-style Ľupzduh#dqg#surjudp#lw#Ğ#xvlqj#PlfurS|wkrq/#
board with some CircuitPython, or C++.
bonus features. Why use this over a Raspberry Pi Zero? Well,

7
lw#grhv#rļhu#idu#orzhu#srzhu#frqvxpswlrq#dqg#
four ADC channels. Alternatively, you could use

/10
a Raspberry Pi Pico with a Red Robotics Pico 2 Pi
adapter for standard HATs.

76 magpi.cc StackyPi
SUBSCRIBE AND

SAVE UP
TO

35%
on the cover price

ISSUE #55

OUT NOW
hsmag.cc
REVIEW

Kitronik Air Quality


Datalogging Board
for Pico
The Pi Hut magpi.cc/picoairquality £39 / $42
SPECS

SENSOR: Much more than an air quality monitor for your Pico. By Phil King
BME688 –

A
temperature,
humidity, ir pollution is an ongoing issue in many Ľuvw#xvhg/#exw#wklv#d#rqh0rļ#surfhvv#dqg#hqvxuhv#
pressure, gases parts of the world, so the Air Quality greater accuracy for future readings.
Datalogging Board for Pico may well come All in all, this is a well-thought-out board backed
CONNECTORS:
Dual female in very useful for monitoring purposes. A fair up by some top-notch documentation and software.
header for Pico, bit larger than a Raspberry Pi Pico (not supplied) Multiple online tutorials cover its various functions
3 × ADC inputs, which plugs into its dual female headers, this
ZIP LED socket,
square board surprised us with just how many
servo output,
2 × high-power features have been crammed in. A well-thought-out board
For starters, there’s a mini OLED screen (128×64
outputs, 5 V
power input, monochrome) to show sensor readings, plus two backed up by some top-
plus extra
solder pads
small push-buttons, a piezo buzzer, and three ZIP
(WS2812B) RGB LEDs along one edge.
notch documentation
FEATURES:
128×64
Then there’s a host of input and output options,
including three analogue inputs (connected to
and software
monochrome Pico’s ADC channels) for connecting external
OLED, 2 × push-
sensors, a ZIP socket to add more LEDs, a three- in detail, including data logging and analogue
buttons, piezo
buzzer, 3 × ZIP pin servo connector, and two high-power outputs input/output control. The GitHub repo includes a
(WS2812B) RGB (screw terminals) with a max draw of 1 A. In comprehensive MicroPython library for the board
LEDs, 3 × AA addition, there are solder pads for 3V3 power, GND, and numerous code examples to try out.
battery holder
digital pins, SPI, and UART.
DIMENSIONS: Power-wise, there’s a handy switch in one
74×72×27.1 mm corner and a 3 × AA battery holder on the rear. Verdict
There’s even a 5 V input if you want to charge up
the batteries with a solar panel. A fully-featured
Pico add-on with
What a gas plentiful input/
output options,
The key feature of the board is its BME688 sensor, ŅýåųĜĹč±ĘŅŸƋŅü
located in one corner. As well as measuring possibilities for
temperature, humidity, and atmospheric pressure projects. Excellent
(as on a BME680), it features an AI-enhanced documentation too.

9
gas sensor that detects volatile compounds and
The BME688 sensor So many inputs and
is at the top left of the gases to determine IAQ (Index of Air Quality) outputs! Hook it up to a
board; its readings can

/10
and estimated CO2#ohyhov1#Lw#wdnhv#Ľyh#plqxwhv# servo, water pump, heating
be shown on a small pad, or even a solar panel
OLED in the middle to calculate the baseline for the gas sensor when to recharge the batteries

78 magpi.cc Kitronik Air Quality Datalogging Board for Pico


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
200 PAGES OF RASPBERRY PI
QuickStart guide to setting up The very best projects built by
your Raspberry Pi computer your Raspberry Pi community

Updated with Raspberry Pi Pico Discover incredible kit and


and all the latest kit tutorials for your projects

Buy online: magpi.cc/store


RESOURCES

10 Amazing:
Facial Pan / tilt face tracking

recognition
Simple movement
eŸĜĵŞĬåƵ±ƼƋŅƚŸåü±ÏåƋų±ÏĩĜĹčôĬĜƋåų±ĬĬƼģƚŸƋƋų±ÏĩƋĘåü±ÏåƵĜƋĘ
±ϱĵåų±ţ‰ĘĜŸϱĹÆåƚŸåüƚĬüŅųųŅÆŅƋŞųŅģåÏƋŸŅųĵŅƋĜŅĹƋų±ÏĩŸØŅų

projects
åƴåʼnšţ

magpi.cc/pantilt

EmpathyBot
Make faces at your Raspberry Pi
Emotional robot
with these incredible builds This Dexter Industries project
ƵĜĬĬųåŸŞŅĹÚÚĜýåųåĹƋĬƼƋŅ

W
ÚĜýåųåĹƋåĵŅƋĜŅĹŸô±üƚĹĬĜƋƋĬå
ith software like OpenCV, it’s easy to create ųŅÆŅƋƋʱƋĘŅŞåüƚĬĬƼƵĜĬĬĹŅƋ
Raspberry Pi projects that can both recognise and ÆåƚŸåÚÚƚųĜĹčƋĘåĜĹåƴĜƋ±ÆĬå
track faces from a camera. Here are some of our ±ƚƋŅĵ±ƋŅĹƚŞųĜŸĜĹčţ
favourite uses of this kind of smart vision.
magpi.cc/empathybot

Object-tracking robot
Archimedes
Follow the ball
Handsome owl
:åƋƋĜĹčųŅÆŅƋŸƋŅüŅĬĬŅƵŸŞåÏĜĀÏƋĘĜĹčŸĜŸ±čųå±ƋƵ±ƼƋŅĜĵŞĬåĵåĹƋ
ŽŸĜĹčƋĘåeF¥šĜŸĜŅĹĩĜƋØƋĘĜŸųŅÆŅěŅƵĬĬŅŅĩŸ±ųŅƚĹÚüŅųĘ±ŞŞƼŞåŅŞĬå±ĹÚ ±ƚƋŅĵ±ƋĜŅĹƋ±ŸĩŸôĜƋűŸ±ĬŸŅĘŅƵųŅÆŅƋų±ÏĜĹčĬå±čƚå8ŅųĵƚĬ±{Ĝ
±ĬĬŅƵƼŅƚƋŅƋ±ĩ屟ƋĜÏĩåųţšåųƼÏƚƋåţ ƚŸåÚƋŅƵŅųĩţ

magpi.cc/archimedes magpi.cc/objecttrack

82 magpi.cc Facial recognition projects


RESOURCES

Face recognition door


lock system
Creepy face-tracking portrait
Stare to enter
Halloween trick ŽŸĜĹčŸĜĵĜĬ±ųü±ÏĜ±ĬųåÏŅčĹĜƋĜŅĹƋåÏʱŸÆåüŅųåØƋĘĜŸŅĹåĜŸ
ÏŅĹĹåÏƋåÚƋŅ±Ĺ±ÏƋƚ±ƋŅųƋʱƋƵĜĬĬƚĹĬŅÏĩ±ÚŅŅųţFƋƵĜĬĬ±ĬŸŅčåƋ
‰ĘĜŸÏĬ±ŸŸĜÏĜĬĬƚŸĜŅĹʱŸÆååĹƚŞÚ±ƋåÚüŅųƋĘåÚĜčĜƋ±Ĭ±čåÆƼʱƴĜĹčƋĘåü±Ïå
ÆåƋƋåųƋĘåĵŅųåĜƋűŸƚŸåÚţ
±ÏƋƚ±ĬĬƼĵŅƴ屟ƼŅƚÚŅرĬÆåĜƋƴåųƼŸƚÆƋĬƼţcåƻƋŸƋåŞØš‰ƚÆåųŸţ

magpi.cc/creepyportrait magpi.cc/facelock

Face-tracking
robot mannequin
head
Nightmare fuel
eޱĹě±ĹÚěƋĜĬƋŸƋƼĬåŞųŅģåÏƋرĬƋĘŅƚčĘƋĘĜŸ
ƋĜĵå±ƋƋ±ÏĘåÚƋŅ±ųŅÆŅƋƋʱƋ±ÏƋŸ
±Ÿ±Ĺ±Ĭ±ųĵŸƼŸƋåĵôĹŅƋ±ƴåųƼčŅŅÚ
ŅĹåƋĘŅƚčĘţ

magpi.cc/robothead
Face mask detector
Don’t spread it
‰ĘĜŸÏĬåƴåųü±ÏĜ±ĬųåÏŅčĹĜƋĜŅĹĵŅÚåĬĩĹŅƵŸĜüƼŅƚűųåƵå±ųĜĹč±ü±Ïå
ĵ±ŸĩŅųĹŅƋţFƋűŸĜĹŸŞĜųåÚÆƼ±ŸĘŅŞŞĜĹčÏåĹƋųåĜʼnʱĜĬ±ĹÚƋʱƋ
ƵŅƚĬÚŅĹĬƼĬåƋƼŅƚĜĹƵĘĜĬåƵå±ųĜĹč±ĵ±Ÿĩţ

magpi.cc/facemask

Face recognition
Face landmark tracking Who’s there?
Expression tracking œĜƋĘƋĘåųĜčĘƋƋų±ĜĹĜĹčĵŅÚåĬØĜƋűŸ
ü±ĜųĬƼ屟ƼƋŅƋå±Ïʱ±ŸŞÆåųųƼ{ĜƋŅ
ŽŸĜĹčƋĘ埱ĵåƋåÏʱŸƋĘŅŸåÏųååŞƼ±ĹĜĵ±ƋåÚĵåĵŅģĜƋĘĜĹčŸØ±ĹÚĬ域ÏųååŞƼ ųåÏŅčĹĜŸåŞåŅŞĬå±ĹÚŅÆģåÏƋŸţœĜƋĘ
ϱųƋŅŅĹš‰ƚÆåųŸØƋĘĜŸĜŸ±ÏŅŅĬ±ĹÚŞŅƵåųüƚĬƚŸåŅü±ŸŞÆåųųƼ{Ĝü±ÏåƋų±ÏĩĜĹčţ ƋĘĜŸØƼŅƚϱĹčåƋŸƋ±ųƋåÚƵĜƋĘƋʱƋţ

magpi.cc/landmarktrack magpi.cc/recognition

Facial recognition projects magpi.cc 83


RESOURCES

Learn Terminal
with Raspberry Pi
Unleash the power of the Linux command
line with these resources. By Phil King

The Linux Command Line


William Shotts Like most Linux systems, |rx#iurp#hqwhulqj#|rxu#Ľuvw#
AUTHOR

Raspberry Pi OS has a user- command right through to Part three covers common tasks
Price: friendly graphical user interface, writing programs in Bash and essential tools, including
£34 / $40 (Free PDF
but opening up a terminal shell script. Part one covers package management and
version)
window enables you get under topics such as navigating the regular expressions. Finally,
magpi.cc/linuxclbook
the hood. Its command-line Ľoh#v|vwhp/#pdqlsxodwlqj# part four is all about writing
interface can often prove quicker Ľohv#dqg#gluhfwrulhv/#dgydqfhg# shell scripts.
dqg#pruh#hĿflhqw#wkdq#d#JXL#Ğ# keyboard tricks, permissions, The book is also available
once you get to know it and learn and processes. The second as a free PDF download from
a few useful commands. part introduces text editors, linuxcommand.org, where
Over 500+ pages, The with a detailed section on vi, there’s also a stripped-back
Linux Command Line takes and prompt customisation. online guide to get you started.

Websites
Useful web resources COMMAND LINE FU
This searchable repository of basics of how to use it on Raspberry
for the command line terminal commands is a goldmine Pi, including a selection of
of information. Users share their useful commands.
most useful commands, as can magpi.cc/terminaldocs
you. It can also be used to store
your personal favourites. BASH REFERENCE MANUAL
commandlinefu.com Bash is the standard shell, or
command language interpreter,
RASPBERRY PI used in Linux. This comprehensive
DOCUMENTATION resource covers a wide range of
This section of the Raspberry Pi features and functions beyond the
online documentation gives an entry-level commands.
overview of the terminal and the magpi.cc/bashref

84 magpi.cc Learn Terminal with Raspberry Pi


RESOURCES

Learn the Online


Command Line courses
Codecademy If you just want to quickly Study the terminal
AUTHOR

learn the basics, this course online with


Price: lv#juhdw#Ğ#wr#jhw#vwduwhg/# these courses
£32 / $40 per month you’ll just need to sign up
(Free trial)
to Codecademy and start
magpi.cc/
a free seven-day Pro trial
codecadamycl
(just remember to cancel
it later). It features an
interactive virtual terminal to remove), then redirecting
enter commands and navigate the input and output from
d#v|vwhp#Ğ#qrw#txlwh#wkh#vdph# commands and programs
nor as satisfying as using a Linux +slsh/#fdw/#juhs,1#Wkh#Ľqdo#sduw/#
system terminal directly, but ĠfrqĽjxulqj#wkh#hqylurqphqwġ/# LEARN THE LINUX
Ľqh#iru#ohduqlqj#sxusrvhv1 covers aliases, environment COMMAND LINE: BASIC
Wkh#Ľuvw#vhfwlrq#wdnhv# yduldeohv/#wkh#Edvk#surĽoh/# COMMANDS
you through navigating the history, and exporting. Cheat Comprising 17 video lectures,
Ľoh#v|vwhp1#Qh{w#frphv# sheets and quizzes reinforce this free Udemy course
pdqlsxodwlqj#Ľohv#+frs|/#pryh/# the learning. will help you to become
familiar with many essential
commands. It even shows

Conquer the
you how to create your own
custom commands.
magpi.cc/udemyclbasics

Command Line BASH FOR


Richard It’s Raspberry Pi’s own guide to PROGRAMMERS
AUTHOR

Smedley the command line! While the Accessible on a free seven-


print edition is now sold out, day trial, this comprehensive
Price:
you can still download the PDF course from Educative
Free
version for free. features 49 lessons,
magpi.cc/clibook
Qdwxudoo|/#lwġv#dlphg#dw# eight quizzes, and 66
Raspberry Pi users and helps playgrounds for interactive
you to unlock the power of the ʱĹÚŸěŅĹƤŞų±ÏƋĜÏåţ
command line. While the current magpi.cc/educativebash
edition was written for an earlier
version of Raspbian/Raspberry Pi
OS, and some of the directories AUTOMATION SCRIPTS
have been changed (e.g. there’s USING BASH
no MagPi directory in /home/pi Learn how to write Bash
any more), you could always scripts to automate long and
substitute them with others. users, connecting removable tedious tasks on the command
Beginning with navigating storage, networking, stopping line in this two-hour project-
wkh#Ľoh#v|vwhp/#lw#pryhv#rq#wr# a process, remote access with based course featuring a
hglwlqj#Ľohv/#lqvwdoolqj#sdfndjhv# SSH, compiling software, and virtual interactive terminal.
with APT, and manipulating text. even browsing the web from the magpi.cc/
Other topics include creating command line. courseraautobash

Learn Terminal with Raspberry Pi magpi.cc 85


INTERVIEW

Kevin
McAleer
A master of robotics, Kevin has built many kinds and can
also teach you how to make your own, all with Raspberry Pi

> Name Kevin McAleer > Occupation Freelance Project Manager


> Community role Maker and educator > URL magpi.cc/kevinmcaleer

O
ne of our most “I’ve always been into computing; I bought an Arduino
passionate readers is making things as far back as from Maplins and made
Kevin. He always has I remember,” Kevin tells us. some LEDs blink. However,
something to share with us on “From making things with I’ve always been passionate
#MagPiMonday, and notices cereal boxes (the best source of about computing and making
little bits and pieces we put robust and available cardboard) things, so building robots is
in the magazine, including to creating robots and futuristic the ultimate Venn diagram,
accidental patterns in the zruogv#lq#Ohjr/#dw#djh#hljkw$# with my happy place right in
Kevin getting his colour of the spine. He’s also an There was probably a gap of the middle.”
original Raspberry Pi
excellent maker and teacher of about 30 years before I got
signed by Eben during
the tenth anniversary robotics on YouTube. back into making and practical What is your history
with making?
When I was growing up, our
house always had electronics
and disassembled TVs and
things as my father was a TV
repair engineer. He had a lab
full of repair equipment such
as an oscilloscope, spectrum
analyser, and a soldering
station. So, understanding how
electronic things work and how
to repair them when they don’t
lv#sduw#ri#p|#GQD1#L#vshflĽfdoo|#
remember reading a book on
superheterodyne receiver
theory from his room during
high school and following along
with it.

Zkhq#glg#|rx#Ľuvw#ohduq#
about Raspberry Pi?
Early 2012 - I checked my inbox
and can see that I ordered my
Ľuvw#Udvsehuu|#Sl#edfn#lq#Mxqh#
5345#iurp#UV#Frpsrqhqwv$#

86 magpi.cc Kevin McAleer


INTERVIEW

Some recent animal robots


built by Kevin, with a real
animal for scale
Find Kevin
online!
I remember my uncle asking connect up the two N20 motors, of actions. This includes telling
if I’d heard about this credit a 9V battery for power, and uses jokes, telling you the weather YouTube
magpi.cc/
card-sized computer that could dq#xowudvrqlf#udqjh0Ľqghu#wr# forecast, adding things to a
kevinmcaleer
run Linux and was around detect objects in front of it. to-do list, and adding items to
†53#+†54193#0#L#mxvw#fkhfnhg$,1# This is an excellent robot for a calendar (that you can sync to Website
kevsrobots.com
Having recently bought the getting started with robotics; your phone).
8-bit Arduino Uno for more it doesn’t take too long to I liked this project the most Twitter
ehfdxvh/#dw#Ľuvw/#lw#zdv#d# @kevsmac
stretch for me to write. I was
My first robot was a 3D-printed then able to simplify the code
Instagram
@kevinmcaleer28

SMARS robot designed by Kevin to the extent I could teach


others how to build it, too – it’s
TikTok
@kevinmcaleer6

Thomas, an engineering student much easier than you’d think,


and I’ve shared the code on
¥ŅƚϱűĬŸŅĀĹÚ
him on Pimoroni’s
GitHub. I share all my code on ƵåÆŸĜƋåÚŅĜĹč
than that, this seemed too good 3D-print out all the parts and is GitHub; I’m a huge advocate of ŞųŅÚƚÏƋĜĹƋųŅƴĜÚåŅŸţ
to be true, so I placed my order. easy to get up and running with open-source projects.
Wkdw#Ľuvw#Udvsehuu|#Sl#kdv#qrz# some simple code.
been signed by Eben Upton.
Eben kindly autographed it at What is your
wkh#43wk#Dqqlyhuvdu|#Udvsehuu|# favourite project?
Pi exhibit launch early this My favourite project is a
year at The National Museum Python-based AI assistant I
ri#Frpsxwlqj1 fuhdwhg#iru#Udvsehuu|#Sl1#Wkh#
software is now embodied
Zkdw#zdv#|rxu#Ľuvw#urerw# within the robot I call Isaaca
project? (named after Isaac Asimov,
P|#Ľuvw#urerw#zdv#d#6G0sulqwhg# my favourite robotics author).
VPDUV#urerw#ghvljqhg#e|# I created a couple of videos
Kevin Thomas, an engineering about this project on YouTube,
vwxghqw1#+Fkhfn#rxw#p|#idqvlwh# and it’s also the most popular
for this little robotic marvel one I’ve made to date. The AI A cluster computer
built from Raspberry
- smarsfan.com.) It uses an assistant can listen to spoken
Pi Zero and based
Arduino Uno, a motor shield to commands and perform a range on the Cray-2

Kevin McAleer magpi.cc 87


THIS MONTH IN RASPBERRY PI

MagPi 01

Monday
Amazing projects direct from our Twitter!

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

01. This very cute camera build is also a fun bit


of upcycling
02. Carl can now move around without hurting
themselves, only furniture
03. Slow or not, we’re really impressed with
this apple-picking robot design
04. People seem to be making cool gaming
things with Pico this month
05. Quite a simple looking robot controlled
over serial is quite cool
06. A good use of automation and LEDs: 03
model railways
07. This is exceptionally useful for those
wanting to control NeoPixels remotely from
Raspberry Pi
08. This is an exceptionally compact project for
a great display
09. A fairly simple board for a very usable
MIDI controller
10. Running BASIC on Raspberry Pi Pico is no
mean feat!
11. This is an incredible achievement! And the
graphics aren’t half bad either

88 magpi.cc This Month in Raspberry Pi


THIS MONTH IN RASPBERRY PI

05

06
04

08 09

07

11
10

This Month in Raspberry Pi magpi.cc 89


THIS MONTH IN RASPBERRY PI

13

12

14

16

15

17

12. We love the mixture of 1960s futurist tech


with the map, and modern e paper screen
for tracking times
13. Another MIDI box or two, and a controller in
this case? We like the naming convention
14. A very simple stand that does the job
perfectly
15. This compact, portable looking TV
console build reminds us a bit of the
Nintendo GameCube
16. 4RISJ'VMERƶWǻVWX7EWTFIVV]5MTVSNIGXW
was a zoetrope, and this new Pico version
looks incredible
17. This 3D-printed robot is very cute!

90 magpi.cc This Month in Raspberry Pi


THIS MONTH IN RASPBERRY PI

Crowdfund this! Raspberry Pi projects you


can crowdfund this month

PicoBricks
SQ1 case
”Pico Bricks is an electronic development board + software
which is designed for use in maker projects. With ten “SQ1 is a Raspberry Pi case you want to put right beside your
detachable modules included, Pico Bricks can be used to create headamp, DAC, and media centre. The elegant design is
a wide variety of projects. It also includes a protoboard that you meant to be seen but not be distracting. Great for Raspberry Pi
can use to add your own modules.” ±ĀÏĜŅűÚŅŸ±ĹÚ±ƚÚĜŅŞĘĜĬåŸţŰ

kck.st/3M9Q036 kck.st/3MGQHRl

RadSense
“The WeatherSense RadSense is built around a Geiger counter
that counts the number of energetic particles hitting the gas
inside the tube. Software on the Grove Mini Pro Plus board reads
these counts and produces a CPM count. The computer then
encodes the data and sends it via a 433MHz radio signal (no
radio license required!) to your Raspberry Pi.”

kck.st/3LG5USK
YOUR LETTERS

Your
Letters Model B query
I recently purchased a Raspberry Pi 4
Model B to show announcement slides
rq#d#ľdw0vfuhhq#WY#lq#wkh#ir|hu#ri#rxu#
church. I was curious about how to get
lw#vwduwhg#iuhvk#iurp#wkh#er{B#Dovr/#L#
zdv#zrqghulqj#li#Udvsehuu|#Sl#zdv#
Parts unknown xqqhfhvvdulo|#vrsklvwlfdwhg#iru#p|#
surmhfw/#dqg#zdqwhg#wr#nqrz#li#|rx#
L#qrwlfhg#lq#lvvxh#44:#wkh#duwlfoh#FGS#Vwxglr#0#dssduhqwo|#wklv#lv#sduw#wzr#exw/#iru#wkh# wkrxjkw#d#vlpsoh#wkxpe#gulyh/#zlwk#whq#
olih#ri#ph/#L#fdqqrw#Ľqg#zklfk#lvvxh#sduw#rqh#zdv#lqB#Lġyh#vshqw#derxw#63#plqv# volghv#grzqordghg#iurp#SrzhuSrlqw/#
orrnlqj#dw#wkh#frqwhqwv#ri#hdfk#lvvxh#rq#wkh#zhevlwh#jrlqj#edfn#derxw#d#|hdu#exw# zrxog#eh#deoh#wr#orrs#rq#d#vpduw#WY#
fdqġw#Ľqg#lw111#fdq#|rx#jlyh#ph#d#foxh#dv#wr#zklfk#lvvxh#lwġv#lqB zlwkrxw#wkh#whfk#ri#Udvsehuu|#SlB

Dave via email David via email

Wkh#Ľuvw#sduw#zdv#lq#lvvxh#449#rq#sdjh#89#Ğ#lq#wkh#frqwhqwv#lwġv#odehoohg#dv#ĠOHG# It is exceptionally easy to get a


patterns with web GUI’, but in the tutorial it is called part one of a CDP Studio series. Raspberry Pi working out the box –
We’re sorry this ended up being confusing! That particular series is complete, and you you can either check out this link
fdq#Ľqlvk#wkh#zkroh#wklqj#qrz1 (magpi.cc/imager) on how to install the
operating system, or grab the Raspberry
Here’s what you can make with the two-part CDP Studio series
Pi Beginner’s Guide as a book or as a free
PDF here: magpi.cc/beginnersguide.
The book will guide you through initial
vhwxs/#dorqj#zlwk#rwkhu#vwxļ#|rx#fdq#gr#
with Raspberry Pi.
As far as
we’re aware,
smart TVs don’t
generally work
with PowerPoint
presentations, so
Raspberry Pi is
probably the best
thing to use in
this instance!

92 magpi.cc Your Letters


3 ISSUES
FOR £5

The contributions page allows for several payment options


– and also lets you just skip it too

PDF over paper


Zkloh#L#grqġw#zdqw#wr#sd|#iru#wkh#sdshu#hglwlrq#ri#The
MagPi/#Lġg#jodgo|#pdnh#d#frqwulexwlrq#iru#wkh#iuhh#SGI#
yhuvlrq/#exw#L#grqġw#vhh#dq|#srvvlelolw|#rq#|rxu#vlwh#+Lġp#
suredeo|#qrw#orrnlqj#dw#wkh#uljkw#sodfh,1

Mehren via email

Zkhq#|rx#folfn#rq#ĠGrzqordg#iuhh#SGIġ#iurp#rxu#zhevlwh#dqg#
on the back issues page (magpi.cc/issues), it will come up Subscribe by phone:
01293 312193
with a screen asking if you’d like to make a contribution to the
magazine. If you’ve done this before and want to do it again,
you may need to clear your browser’s cache for our website.
You can also make a recurring contribution if you wish. You

Subscribe online:
can also just continue on and get the PDF for free.

Contact us! magpi.cc/subscribe


> Twitter @TheMagPi
> Facebook magpi.cc/facebook
> Email magpi@raspberrypi.com
> Online forums.raspberrypi.com Email: magpi@subscriptionhelpline.co.uk
Join us as we lift the lid
on video games

Visit wfmag.cc to learn more


COMPETITION

WIN A
CUTIEPI
We reviewed this
excellent Compute
Module-powered tablet
last issue. It’s powerful,
very user-friendly, and
even has a neat handle
that can be used to prop
it up. Now is your chance
to win one.

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

Terms & Conditions


Competition opens on 25 May 2022 and closes on 30 June 2022ţ{ųĜDŽåĜŸŅýåųåÚƋŅޱųƋĜÏĜޱĹƋŸƵŅųĬÚƵĜÚå±čåÚŎƐŅųŅƴåųØåƻÏåŞƋåĵŞĬŅƼååŸŅü±ŸŞÆåųųƼ{ĜXƋÚØƋĘåŞųĜDŽåŸƚŞŞĬĜåųØ
ƋĘåĜų ü±ĵĜĬĜåŸØ Ņų üųĜåĹÚŸţœĜĹĹåųŸƵĜĬĬ Æå ĹŅƋĜĀåÚ ÆƼ åĵ±ĜĬ ĹŅ ĵŅųå ƋʱĹ ƐLj Ú±ƼŸ ±üƋåų ƋĘå ÏŅĵŞåƋĜƋĜŅĹ ÏĬŅŸåŸţ Ƽ åĹƋåųĜĹč ƋĘå ÏŅĵŞåƋĜƋĜŅĹØ ƋĘåƵĜĹĹåų ÏŅĹŸåĹƋŸ ƋŅ ±ĹƼ ŞƚÆĬĜÏĜƋƼ
čåĹåų±ƋåÚüųŅĵƋĘåÏŅĵŞåƋĜƋĜŅĹØĜĹŞųĜĹƋ±ĹÚŅĹĬĜĹåţ{±ųƋĜÏĜޱĹƋŸ±čųååƋŅųåÏåĜƴåŅÏϱŸĜŅűĬĹåƵŸĬåƋƋåųŸüųŅĵ‰Ęåa±č{Ĝĵ±č±DŽĜĹåţœåÚŅĹűƋĬĜĩåŸŞ±ĵ×ޱųƋĜÏĜޱĹƋŸűÚåƋ±ĜĬŸƵĜĬĬ
ųåĵ±ĜĹŸƋųĜÏƋĬƼÏŅĹĀÚåĹƋĜ±Ĭ±ĹÚƵŅĹűƋÆåŸĘ±ųåÚƵĜƋĘƋĘĜųÚޱųƋĜåŸţ{ųĜDŽåŸ±ųåĹŅĹěĹåčŅƋĜ±ÆĬå±ĹÚĹŅϱŸĘ±ĬƋåųűƋĜƴåƵĜĬĬÆåŅýåųåÚţœĜĹĹåųŸƵĜĬĬÆåÏŅĹƋ±ÏƋåÚÆƼåĵ±ĜĬƋŅ±ųų±Ĺčå
ÚåĬĜƴåųƼţeĹƼƵĜĹĹåųŸƵĘŅʱƴåĹŅƋųåŸŞŅĹÚåÚƅLjÚ±ƼŸ±üƋåųƋĘåĜĹĜƋĜ±Ĭåĵ±ĜĬĜŸŸåĹƋƵĜĬĬʱƴåƋĘåĜųŞųĜDŽåųåƴŅĩåÚţ‰ĘĜŸŞųŅĵŅƋĜŅĹĜŸĜĹĹŅƵ±ƼŸŞŅĹŸŅųåÚØåĹÚŅųŸåÚŅų±ÚĵĜĹĜŸƋåųåÚÆƼØ
Ņų±ŸŸŅÏĜ±ƋåÚƵĜƋĘØFĹŸƋ±čų±ĵŅų8±ÏåÆŅŅĩţ

Competition magpi.cc 95
HELP! MY COMPUTER
IS BROKEN
,S[HS-Ƥ\MX#

Help! My Computer Is Broken


takes the most common
computer problems and tells you
how to fix them. It’s as simple
as that! If you’ve ever wondered
why your laptop won’t turn on,
you can’t get a WiFi connection,
your printer isn’t printing, or why
everything is so slow – well, this
is your book…

Buy online: magpi.cc/helpbook


NEXT MONTH
EDITORIAL
Editor
Lucy Hattersley
lucy@raspberrypi.com
Features Editor
Rob Zwetsloot
rob@raspberrypi.com

E
Sub Editor

B L
Nicola King

A R K A ADVERTISING

REM
S!
Charlotte Milligan

T
charlotte.milligan@raspberrypi.com

O
+44 (0)7725 368887

OB
DESIGN

R
criticalmedia.co.uk

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

CONTRIBUTORS
David Crookes, PJ Evans,
Rosemary Hattersley, Edwin
Jones, Nicola King, Phil King,
Sean McManus, Nik Rawlinson,
Stephen Smith

PUBLISHING
Publishing Director
Russell Barnes
russell@raspberrypi.com

Director of Communications
Liz Upton
CEO
Eben Upton

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

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

THE MAGPI #119


ON SALE 30 JUNE This magazine is printed on paper sourced
from sustainable forests and the printer
operates an environmental management
system which has been assessed as

Plus! DON’T MISS OUT!


conforming to ISO 14001.
The MagPi magazine is published by
Raspberry Pi Ltd, Maurice Wilkes Building,

Reuse an old St. John’s Innovation Park, Cowley Road,

Raspberry Pi magpi.cc/subscribe Cambridge, CB4 0DS. The publisher,


editor, and contributors accept no
responsibility in respect of any omissions
or errors relating to goods, products, or
Make KITT @TheMagPi
services referred to or advertised in the
magazine. Except where otherwise noted,
real with AI content in this magazine is licensed under
a Creative Commons Attribution-
fb.com/MagPiMagazine
Building your
NonCommercial-ShareAlike
3.0 Unported

ArtEvolver magpi@raspberrypi.com (CC BY-NC-SA 3.0).


ISSN: 2051-9982.
THE FINAL WORD

Everybody needs
a hobby(ist)
The Raspberry Pi community makes it all worthwhile. By Lucy Hattersley

O
ne of the big talking points at I’m talking about. Which often makes The big tech-chat at the moment is
the moment is Raspberry Pi two of us. But he appreciates a the supply chain. Last issue we
for hobbyists and Raspberry Pi detailed-orientated chat, especially if I mentioned a website called RPI
for industrial experts. include some historical connection to Locator (magpi.cc/rpilocator) that
Of course, these two things are the pre-digital era that he can more provides alerts for when stores have
rarely separate. My father-in-law, easily connect with. Raspberry Pi in stock. We’re happy to
Richard, is a practical sort that likes I suspect a few years younger and see it joined by Hardware Locator
to have all kinds of projects he’d have been into computing and (magpi.cc/hwlocator).
around the house. Sure, they may Raspberry Pi. As it stands, his hobby is It’s something of a relief to note
qrw#eh#doo#Ľqlvkhg#|hw/#exw#wkh|# steam trains. So much so, he rescued a that Raspberry Pi isn’t the only
are interesting. long-disused Belgian Cockerill Steam company with more customers than it
He’s built an incredible garage with Tram with a fellow rail enthusiast can supply. On the other hand, it’s
a dual-action sliding door, and (magpi.cc/cockerill), and brought it disheartening to hear of our readers’
renovated an old wooden canoe with over to the UK by sea and road on the struggle to pick up, for example, Coral
his daughter Rosie, who is insistent we back of a lorry for renovation. USB Accelerator kits to go with their
will eventually bring it down to our new Raspberry Pi computers.
terraced house in London. There’s no Practical people do I hope this situation picks up soon.
space; unless we put it on the roof! In the meantime, you can get a
He has a stone dragon gargoyle on practical things Raspberry Pi by signing up with RPI
his roof and a train layout, for which Locator for an alert. Or, of course, by
he built several landmark buildings It’s currently powering up and down subscribing to The MagPi magazine
from scratch. wkh#Plg0Vxļron#Oljkw#Udlozd|# (magpi.cc/subscribe).
In his younger days, he inspected teaching a younger generation about Zh#zloo#frqwlqxh#wr#pdnh#wkh#Ľqhvw#
and reported on nuclear power the steam age. We showed Richard a magazine for the best hobbyist
stations and MOD nuclear recent YouTube video of it in action on computer around. The hobbyists make
installations, a very important job Easter Weekend (magpi.cc/mslrYT). Raspberry Pi what it is. More than just
that required extreme focus to keep Practical people do practical things. a useful tool, but a loved computer.
his nation safe. These power stations Long may they tinker.
are handy, and I suspect we could use a Full steam ahead
few more of those at the moment. Somebody who is wholly into a hobby
Lucy Hattersley
AUTHOR

He is also one of the few people I watches the business side of things.
know who will listen to me when I Steam train fans are railway fans, and Lucy is back in “that there” London after a
start talking about NAND gates and the industrial and consumer network brief stint visiting family in the North. She’s
Z80 and ARM Assembly and Raspberry is something they know an awful lot torn between home and hearth.

Pi. He hasn’t the faintest idea what about. I chat chips; he chats coal. magpi.cc

98 magpi.cc Everybody needs a hobby(ist)


1J,7. .BOBHFZPVSTFSWFSTPS
XPSLTUBUJPOTSFNPUFMZ

"DPTUFŗFDUJWFTPMVUJPOGPSEBUBDFOUFST 
*5EFQBSUNFOUTPSSFNPUFNBDIJOFT

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

3FBMUJNFDMPDLXJUISFDIBSHFBCMFTVQFSDBQBDJUPS0-&%%JTQMBZ#PPUBCMFWJSUVBM$%30.
ŚBTIESJWF4FSJBMDPOTPMF0QFOTPVSDF"1*JOUFHSBUJPO0QFOTPVSDFTPGUXBSF

$YDLODEOHDWWKHPDLQ5DVSEHUU\3LUHVHOOHUV

3FTFMMFSTVHHFTUJPOTBOEJORVJSJFT
XIPMFTBMF!IJQJJP

You might also like