Mag Pi 121
Mag Pi 121
CC/STORE
ARN
LE TRONICS
magpi.cc/store
ELECICO W
WITH P
EFINITIVE GUIDE
YOUR D IMENTING
TO EXPERCTRONICS
WITH ELE
BUILD A
RASPBERRY PI
RADIO
CODE HAUNTED
YOUR OWN HALLOWEEN
VIRTUAL PET
PARTY
54 PAGES OF PROJECTS & TUTORIALS
Industrial Raspberry Pi
ComfilePi
WELCOME
WELCOME
to The MagPi 121
E
lectricity is fantastic stuff! It’s used to power
labour-saving gizmos, light up our streets, move
our cars, and perform everyday miracles that would
seem the stuff of magic to our ancestors. Lucy
EDITOR
Understanding electronics is half of the code and digital- Hattersley
making ethos that underpins Raspberry Pi. And few Lucy is editor
of The MagPi
devices are better for learning electronics than Pico W. magazine and is
currently sitting
Designed to sit right at the heart of electronic projects, in the Greenwich
Pico is a low-power microcontroller development board Maritime Museum
wondering how they
with 40 connections on the side – you can connect Pico to made do with sails.
There are some
just about anything. seriously impressive
figureheads on
Learning electronics is a rite of passage for new the wall beside
her though.
Raspberry Pi aficionados. Start by lighting up lights, then @LucyHattersley
create code that responds to buttons, wire up sensors,
pull in information from the internet, and build wild
creations (page 30).
Getting an understanding of code and electronics is GET A
an incredibly important skill to have. With it, you can RASPBERRY PI
control, and understand, all PICO W
the incredible things around
you that make the modern PAGE 28
world work.
magpi.cc 03
Your FREE guide to
making a smart TV
BUILD A RASPBERRY PI
MEDIA PLAYER
Power up your TV and music system
raspberrypi.com
FROM THE MAKERS OF THE OFFICIAL RASPBERRY PI MAGAZINE
magpi.cc/mediaplayer
CONTENTS
Contents
> Issue 121 > September 2022
Cover Feature
30 Learn Electronics 30
with Pico W
Regulars
26 Case Study: Brompton Cycles
92 Your Letters
97 Next Month
98 The Final Word
Project Showcases
08 ZeroBug
10 Big Mouth Billy Bass
14 Digital Zoetrope
16 Fireballs Aotearoa 22
20 LEGO Reaction Wheel Pendulum
22 Boost-Box 0.1
24 LED Sphere
16
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. 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
Tutorials 44 64
38 Explore electronics with Pico
44 MagPet - code a virtual pet
48 Build a Raspberry Pi Radio - part 1
54 Sublimation printing guide
58 Learn ARM Assembly - part 6 MagPet - code a virtual pet Super simple robotics - part 2
64 Super simple robotics - part 2
The Big Feature 78
68
Reviews 86
76 EPD Pico Kit
78 Autonomous Robotics Platform
80 Arducam 64MP Camera Module
82 Top 10 gaming accessories
84 Electronics resources
Community
86 Sam Alder interview
88 This Month in Raspberry Pi Sam Alder interview
CROWPI L 95
WIN A BASIC KIT
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
many of the topics in The MagPi magazine are different between countries, and are always subject to change. You are responsible for understanding the requirements in your jurisdiction
and ensuring that you comply with them. Some manufacturers place limits on the use of their hardware which some projects or suggestions in The MagPi magazine may go beyond. It is
your responsibility to understand the manufacturer’s limits.
06 magpi.cc
PROJECT SHOWCASE
ZeroBug
An inexpensive 3D-printable hexapod that can be programmed or
directly controlled. Rob Zwetsloot checks its micro servos
I
n issue 119 (magpi.cc/119), we reviewed the the robot,” he tells us. “The decision to go with
intimidating SpiderPi, a big hexapod robot four legs instead of six was mainly due to the cost
that tormented our editor’s poor cat. Shortly of servo motors. However, six-legged robots have
after the release of the issue, Maximilian Kern a big advantage: unlike quadrupeds, they can lift
emailed us about the one he’d created himself, three of their legs while the remaining legs form a
called ZeroBug, appropriately powered by a stable tripod. This eliminates the need for constant
Raspberry Pi Zero. weight shifting and balancing.”
“Zero is in charge of the input methods,” The decision to use Raspberry Pi was due to how
Maximilian
MAKER
Maximilian explains. “It runs a custom web easily you can connect Bluetooth controllers to it,
Kern
interface and an instance of Pygame. This making it more accessible than RC controllers. With
makes it possible to control the robot using a this in mind, Maximilian started simulating his robot.
A hardware
developer based in mouse, keyboard, multitouch, or simply an Xbox “With the simulation done, I went on to build
Germany, who likes gamepad... Instead of specialised robotics servos, the physical hexapod robot,” he says. “Since
to do DIY projects this robot uses inexpensive micro servos. Inside there are 18 servos needed for this hexapod, they
in his spare time,
its 3D-printed frame there is just enough room for define the total cost of the robot. I settled for some
including hardware,
software and Raspberry Pi, together with a custom PCB for the cheap Emax ES08A II micro servos which are quite
mechanical design. microcontroller and servo driver.” powerful for their size. I only paid around €80
magpi.cc/zerobug The microcontroller is an STM32, which is for the entire set of servos. When using proper
an ARM-based system which controls the leg smart servos for robotics, a single unit can cost
locomotion through 18 of the affordable servos. this much.”
“All of these calculations run at 50Hz, To drive the servos, 18 PWM outputs are
enabling the hexapod to move smoothly and with needed. “I decided to use the STM32F103 as a
high precision.” microcontroller as it is Arduino-compatible, and
I had already gathered some experience with my
Six degrees macro keyboard (magpi.cc/macrokeypad). To
Maximilian was inspired by earlier connect the microcontroller, PWM driver, and
videos of the Boston Dynamics robot Raspberry Pi, I designed a custom PCB that plugs
experiments, and loved into the back of the GPIO header on Raspberry
the idea of making Pi. To save space, the connector only uses GPIO
robots with legs 1 though 10, which conveniently include 5 V,
– starting with 3.3 V, ground, UART, and a couple extra I/O.
a quadrupedal Voltage regulators on the custom PCB enable the
creation of his microcontroller and Raspberry Pi to be powered
own, before from the battery pack. Both Zero W and the custom
moving to six legs. board are mounted between the servos, so that the
“It turned USB port can be accessed from the outside.”
out to be really
difficult to develop Scuttling along
proper walking gaits, Maximilian claims that building a walking robot is
The simulations
involved wire-frame
and the servos seemed to not that hard; instead, making it look right while
models of ZeroBug struggle with the weight of walking can be a challenge.
08 magpi.cc ZeroBug
PROJECT SHOWCASE
ZeroBug magpi.cc 09
PROJECT SHOWCASE
I
n the early 2000s, Big Mouth Billy Bass – a a Pico W-controlled update to the tuneful
kitschy, 3D plastic fish mounted in a picture animatronic sea creature, hosted at mouthpi.co.
frame that appears to sing, as well as writhe Kevin first fell in love with computing when he
around – became such an in-demand item that became the proud owner of a ZX Spectrum back
there’s reputedly one hanging proudly above the in 1982. He went on to study computer science.
grand piano at the Queen’s Balmoral residence. He had a similarly Damascene encounter when
YouTuber, and Raspberry Pi enthusiast, Kevin he got his first Raspberry Pi not long after it first
McAleer relates this apocryphal tale while launched. “Raspberry Pi has helped me learn and
Kevin
MAKER
introducing his latest Raspberry Pi project: master Linux and inspired me to learn Python,
McAleer
Kevin McAleer
makes robots,
brings them to life
with code, and
makes videos about
them on YouTube.
magpi.cc/
kevinmcaleer
The
site being
constructed during
Kevin’s weekly
YouTube broadcast
Quick FACTS
> Catch Billy Bass in
action to see the
full effect
> K
ev contemplated
livestreaming
Visitors to mouthpi.co
footage of Billy
choose whether Billy
writhing around
should open or close his
Kev used mouth, move his head or
> The current version
Raspberry Pi Pico tail, with audio buttons goes through
W to make Billy soon to be added 9 V batteries
Bass controllable *very* quickly
from a web page
> So Kev will switch
to mains power fish
frolics soon
As a child of the He wanted to see how well it would hold up with
1980s, Kevin couldn’t
resist designing thousands of web page requests per day, and to
a Raspberry Pi- see how well the web pages could handle colour,
based Ghostbusters
wireless scanner fonts, and style sheets. “Pico W doesn’t have an OS
and has minimal memory, so being able to host a
website and control a robot simultaneously is quite
remarkable,” says Kevin. The mouthpi.co site
is hosted on the Pico W, which is in turn hidden
within the fish robot’s body.
Kevin contemplated livestreaming footage of
Billy writhing around, but the current iteration
of the site has buttons that the user can press to
initiate preset movements relating to the head, The WiFi scanner spreads its arms to show signal strength
tail, and mouth. A replacement for the audio files
containing the original Big Mouth Billy Bass theme details, usually with a view to controlling the fish
tunes – Don’t Worry Be Happy and Take Me To The with Alexa, whereas Kevin’s plan was to control
River – is planned for the next version. Kevin has the motors himself. However, a tear-down of Billy
also promised his YouTube followers a Furby-based Bass’s components, in which Kevin stripped out
Pico W-controlled site. the existing wiring, showed a relatively simple
circuit with three motors.
Hacking the hardware Having learnt these were “cheap 5 V DC motors”,
One of the key aspects of this project was Kevin was confident he’d be able to drive them
establishing how the existing animatronic with a couple of L298N H-bridge modules. He
fish worked. Online research revealed some secured them along with Pico W on a mounting
In a flap
plate to hold them in place. These would allow When website visitors click
a button to change Billy’s
him to control powerful motors simply by making pose, the relevant photo
a GPIO pin on the Pico high or low (1 or 0). Code is shown
Digital
Zoetrope
Brian Corteil has created a fresh spin on an age-old
idea and it’s made David Crookes dizzy with excitement
Z
oetropes were invented by a
mathematician called William Horner in The zoetrope has a
1834 and they proved to be an effective way slip-ring in the middle
to produce animations. A set of still images would of the Lazy Susan
line the inside of a rotating drum, and viewers bearing. It maintains a
power connection when
would peer through narrow slits in the side. The
spinning by using a
speed at which they passed the eyes would produce
brush or wiper in contact
an illusion of movement. As the years went by, the
Brian Corteil with a rotating ring
MAKER
Quick FACTS
> This huge build
Brian has designed the zoetrope uses e-ink displays
to be as easy to operate as
possible, and it includes a big > It also involves
red emergency stop button, laser-cutting
controlled by Raspberry Pi Pico plywood
Fireballs Aotearoa
A chance to expand meteor monitoring to New Zealand was made
far simpler with the aid of Raspberry Pi. Rosie Hattersley reports
T
he excitingly named Fireballs Aotearoa in the UK and beyond. A Fireballs Aotearoa
(fireballs.nz) is an ambitious research outreach programme involving New Zealand-
project that aims to make good on the based astronomers and meteor researchers
Global Meteor Network’s aim of ensuring no generated much excitement among would-be
meteor is undetected. The GMN’s worldwide space scientists.
meteor and meteorite tracking endeavours already This online presentation given by Jim Rowe
had sites spread across Europe and the US, but few (magpi.cc/findingmeteorites) explains how a
in the Southern Hemisphere. With international camera attached to a Raspberry Pi locks on to a
news coverage of a fireball over southern England fireball as it travels across the sky, focusing on
in March 2021 that was successfully tracked by the object itself and only processing data relating
citizen scientists, there has been a significant to its constantly changing location. Raspberry
increase in the number of meteor cameras Pi has sufficient processing bandwidth to live-
track and report the meteor’s location. Since
multiple cameras across a region track the same
meteor’s journey, it’s possible to triangulate its
final destination and work out with some accuracy
Dr James Scott,
MAKER
A Raspberry Pi 4 or 3B+
controls each setup, identifies
the meteor within a frame, and
saves only this part of each Quick FACTS
25 fps image to its SD card
> The New Zealand
cameras capture
meteors that would
otherwise be
missed…
he project is already
T
detecting plenty of
meteor activity in the
southern hemisphere,
as this open-source
meteor map reveals
when Dr James Scott of the University of Otago crossed ‘their’ night sky and incorporate that in
succeeded in getting funding for the first ten their schoolwork.
meteor camera kits for use in New Zealand, and “Rather than simply recording pictures of
helped acquire 20 more Raspberry Pi computers meteors, the idea is to collect science-grade
for meteor tracking and university use with a data that can inform researchers, capturing
grant from the MBIE Curious Minds Participatory information about meteor orbits, frequency, flux,
Science Platform. A key part of the funding pitch mass indices, source regions, and so on. This can
is the direct link with schools and their access to be used to refine prediction models and help us
the project data. James says the goal is to record learn more about parts of the solar system nearest
K Fireball Alliance’s
U meteors on every clear night – a single camera to us. All the high-level data products from the
James Rowe’s talk on
meteor tracking showed in Invercargill picked up 114 meteorites crossing GMN project are publicly released under CC BY
how Raspberry Pi-
the sky one evening in early March – with 4.0 and updated every six hours so researchers
powered cameras helped
triangulate locations students able to log in at any time to see what has can have access to near-real-time information,”
explains Jeremy Taylor (aka Tasmanskies) who
has been “a driving force” behind the meteor
camera builds.
that comes into New Zealand through a citizen- ultiple camera systems
M
are cross-referenced to
led initiative.” The meteor cameras are put aid the recover of
together by students from the rocketry club at falling meteors
K
eeping an inverted pendulum aloft is Precision control
a popular challenge in control theory A gyroscope and accelerometer on a mini IMU
– which deals with the behaviour of (inertia measurement unit) board are used to
dynamical systems – and requires precise motion measure the pendulum angle, while Raspberry Pi
control to prevent it from falling over. It’s runs a control loop for filtering data and calculating
something maker and YouTuber Juha, of the Brick PID (proportional–integral–derivative) controller
Experiment Channel, learned about in courses he outputs for adjusting the motor’s speed and
did 20 years ago, which inspired him to try it with direction. Automatically calculating corrections
Juha
MAKER
LEGO and Raspberry Pi. based on feedback, PID is one of the most common
Made of LEGO bricks, his inverted pendulum control methods used in industrial and mechanical
“A Finnish middle-
aged guy,” Juha requires active control to stay upright. A ‘reaction applications, such as in a car’s cruise control
runs the Brick wheel’, also made from LEGO, is mounted on the system. It’s also fairly easy to implement.
Experiment Channel
pendulum and attached to a motor controlled by “Others have used LQR [linear–quadratic
on YouTube,
dedicated to a Raspberry Pi Zero 2 W. “Rotating the wheel will regulator] control for inverted pendulums,” notes
building and generate torque on the pendulum and thereby Juha, “but it looks too mathematical and difficult
experimenting change the pendulum angle,” he explains. “The for me. As for tuning the PID parameters, I didn’t
with LEGO Technic
bricks. He has
rest is just measurement and computation.” have any approach other than ‘try and see.’ It got
worked for over Well, that’s the theory, but in practice it’s good laughs in the YouTube comment section as it
ten years as a not quite so easy and, as shown in his YouTube looks so unprofessional.”
software engineer.
video (magpi.cc/legopendulum), Juha had While Juha opted to use a Raspberry Pi Zero 2 W
magpi.cc/ to alter his Python code repeatedly and make for its fast bootup speed, “CPU load was only 5%
becyoutube
hardware adjustments to get the system to work to running the control loop with a 1 ms interval, so it
his satisfaction. would work with a much less capable board.” He
even tried using a Pico, which “worked OK in terms
of processing power, but then I realised I need to
store tens of megabytes of log data for drawing nice
graphs for the video.”
Amazingly, before this project, Juha had never
used a Raspberry Pi before and had minimal
experience with electronics. “I had to figure out
how GPIO works, what are pull-down and pull-up
resistors, how I2C works, etc.”
Keeping it up
The next major challenge was getting the
pendulum to stay upright for more than two
seconds. “The problem was with the reaction wheel
A Raspberry Pi Zero top speed limitation,”says Juha. “There is a short
2 W runs the Python
code that takes the time window for acceleration before the limit is
sensor readings
reached, so you need to get past the top equilibrium
and controls the
motor accordingly point before that. A plain PID controller would just
A Raspberry Pi Zero
2 W runs Python The LEGO reaction
code featuring a wheel spins at
PID control loop the precise speed
required to keep the
pendulum vertical
Quick FACTS
> The project took
Juha two months to
build and perfect
pendulum angle
minimise angle error and keep the wheel rotating
too fast. I read many studies of different inverted
pendulums, until I found one paper that mentioned
continuously changing the target angle for the PID
controller. That solved it finally.”
So, in the finished system, is it impossible to
push the pendulum off balance so that it falls over?
“No, not at all,” replies Juha. “It will easily fall
over if you push it. The controller will immediately
try to compensate for the push by accelerating
the wheel, but it can correct only for small errors.
With a more powerful motor, higher top speed, and
higher rotational inertia for the wheel, it would
An IMU board attached to the base of the
resist stronger pushes.” pendulum continually measures its angle
Boost-Box 0.1
The antithesis of doom-scrolling, the Boost-Box
could be just the thing to cheer you up. Nicola King
discovers the joy of just watching happy things!
W
e just can’t get enough of Martin
Spendiff and Vanessa Bradley’s
makes – last month the Pico Railway
Clock and, this time, we present the Boost-Box.
The productive pair have upcycled an old 1970s
Hanimex analogue film viewer and turned it into a
YouTube viewing terminal – but they only use it to
watch uplifting cheerfulness!
Martin came across the film viewer in a second
hand store and began to feel nostalgic. “When
I first went to uni a million years ago, we used
terminals to do most of our work,” he recalls. “That
aesthetic is imprinted on my brain. I saw it and
Martin thought ‘I need to do something with that’… but I
MAKER
Quick FACTS
> The Hanimex case
cost around £25…
LED Sphere
Tom Verbeure has brightened up our day with his stunning
sphere peppered with LEDs, as David Crookes discovers
T
here are many practical applications for a Freeform LED Sphere (“but it’s constructed out of
Raspberry Pi Pico microcontroller board, differently sized rings around a central axis, which
but it’s important to have a heap of fun I didn’t want”) and Whity created the Geodesic(k)
too! With his latest project, Tom Verbeure has RGB LED Spheres (“but 180 LEDs, and the LED
literally had a ball, creating a NeoPixel-covered density was too low because he used premade
sphere that dazzles in more ways than one. WS2812B PCBs”).
After all, as Tom says: “LED cubes have been With research, he learned that it’s
pretty popular, but spheres are a much harder mathematically impossible to distribute points
Tom Verbeure
MAKER
On a roll
Printing and assembly issues caused a rethink.
“The breakthrough came when I dropped the
central frame, inserted LEDs from the outside into
the shell, and mounted the PCBs firmly against
the inside shell triangle,” Tom explains. “I used
magnets on each triangle side to form a self-
supported structure. The more sphere elements
snap together, the sturdier it becomes.”
Eventually, he switched from FreeCAD’s GUI to
its embedded Python engine. He also settled on 21
LEDs for each of the 20 sphere elements, designing
A sphere element a custom controller PCB on which to mount them.
containing 21 LEDs. A Raspberry Pi Pico formed the project’s heart and
“You need to insert
the LED through Tom initially coded the project using MicroPython,
the sphere element, later transitioning to regular C.
then try to fit each of
its four metal leads “I needed something that was small, didn’t
through a very tiny
require a lot of power, had a lot of performance,
0.85 mm diameter
hole,” Tom explains was close to the metal, had the ability to drive
Although an ESP8266
wireless networking
microchip was used,
Raspberry Pi Pico W
means this isn’t
necessary any more
Quick FACTS
> The 20 sphere
elements contain
420 LEDs overall
Brompton
Demand for Brompton’s famous folding bicycles has soared.
Raspberry Pi has helped the company meet challenging production
targets at its London manufacturing facility. By Rosie Hattersley
26 magpi.cc Brompton
SUCCESS STORY
Brompton magpi.cc 27
SUBSCRIPTION
SUBSCRIBE TODAY
FOR JUST £10
Get 3 issues + FREE Pico W
Subscriber Benefits
FREE Delivery
Get it fast and for FREE
Exclusive Offers
Great gifts, offers, and discounts
Great Savings
Save up to 35% compared to stores
+
Subscribe for 12 Months
Free Pico W
12 issues of The MagPi
Free delivery to your door
£55 (UK) £90 (USA)
£80 (EU) £90 (Rest of World)
28 magpi.cc
SUBSCRIPTION
A brand new
RP2040-based
$6
Raspberry Pi Pico W
development board
SUBSCRIBE
on app stores
magpi.cc 29
FEATURE
E A R N
LELECTRONICS
P I C O W
WITH N ENTS AND START
COMPO WITH THE NEW
ECTRONIC
EXPLORE EYLOUR OWN PROJECITCSROCONTROLLER.
BUILDINGS RP2040-BASED M
WIRELES HATTERSLEY
BY LUCY
R
aspberry Pi Pico W is an incredible
development board, built around the
powerful RP2040 microcontroller.
On both sides of Pico W sit GPIO (general-
purpose input/output) pins. There are 40 of them
in total. These pins are used to interface Pico W
with the wider world. You use them to wire up
electronics components, attach Pico W to computer
equipment, and build personal projects.
This is the real joy of Pico W (and Raspberry Pi
computers). These pins are where code interfaces
with the real world. You can use Pico to automate
your home, control robots, or manage household
appliances. Or, you can simply mess around with
buttons, buzzers, sensors, and build fun widgets
and gizmos.
Also, thanks to Pico W’s wireless capabilities,
you can now interact with online services,
pulling in data from the internet via APIs
(application programming interfaces), and storing
information wirelessly.
JUMPER LEADS
Jumper leads are
used to connect the
various components to
one another and to the
GPIO pins on Pico W,
forming a circuit.
COMPONENTS
Our board here has two
components: a small LED
(light-emitting diode) and
a resistor (which is used
to reduce the voltage and
protect the LED). Around
the board are some other
components you will
frequently encounter, such
as buttons, light and distance BREADBOARD
sensors, and a small display. A breadboard is a white
slab of plastic populated
with holes. Each hole
in a row is connected,
enabling you to connect
wires and components
by putting them in a hole
in the same row.
CTR O
ELE PARTSNIC
KITS & ICO W ELECTRONICS
ITS
DISCOVERITPH THESE STARTER K
EASILY W
Pico Breadboard Kit
SB Components • £14/$17
> magpi.cc/picobreadboardkit
> magpi.cc/eleckitpicolite
PICO W RESOURCES
Get Started with MicroPython on
Raspberry Pi Pico
MicroPython and Pico
Created by the team
at Raspberry Pi Press,
this book is packed with
official information on how
to program Pico with the
MicroPython language.
magpi.cc/picobook
Pico Documentation
Raspberry Pi’s website has
a stack of documentation
designed to introduce
you to all the details that
> magpi.cc/inventorskit
Inventor 2040 W
Pimoroni • £35/$43
> magpi.cc/inventor2040w
EB SERVE R
W
RUN A PBERRY PI
ON RAS
PICO W NNE CT P IC A BREADBOARD
O W TO ECTION TO
CO
US E A W EB CONN FF
AND
A LIG H T ON AND O
TURN
I
Installing MicroPython
n The MagPi issue #119, we introduced
Raspberry Pi Pico W. Based around
01 The fastest way to get MicroPython is to
Raspberry Pi’s own RP2040 microcontroller, download the pre-built release binary from the
Alasdair Allan
MAKER
R
unning our Python
script on Pico W from
the Thonny editor
Start Thonny
03 Open Thonny, and upload the webserver.py
You should substitute your IP address, which
for most home networks will probably be in the
Python script to your Pico W. If you haven’t used 192.168.1.X range, for the one shown here.
MicroPython and Thonny before, full instructions on
how to do that can be found in the Raspberry Pi Pico
Python SDK book (magpi.cc/picopythonsdk).
Going further
Make sure to replace the ssid and password with
the name and password for your own wireless
05 This example lets you remotely turn an
network at home, and then hit the button to run the LED on, and then off again. However, we can also
script on your Pico W. extend this example to add buttons to the web
Top Tip page we’re serving to allow you to control the LED
directly from a web interface rather than by using
a RESTful server – which, after all, is more suited
Soldering
Light on
You’ll need to
04 After your Pico W connects to your wireless
to programmatic use rather than working from
a web browser. Alternatively we can go further
solder GPIO network, you should see the IP address for your and reimplement our server, so that rather than
pins to Pico W. board appear on the REPL inside the Thonny blocking, it will operate asynchronously.
See Raspberry shell window. More information about connecting your
Pi’s guide to
To control the LED, you can open up a web browser Pico W to the web can be found in the online
soldering:
and go to http://10.3.15.120/light/on to turn the LED documentation and the Connecting to the
magpi.cc/
soldering. on, and http://10.3.15.120/light/off to turn the LED internet with Raspberry Pi Pico W book:
off again. magpi.cc/internetpicow.
webserver.py DOWNLOAD
THE FULL CODE:
> Language: Python magpi.cc/github
I
f the new Raspberry Pi Pico W’s wireless LAN write programs in different ways. We’re using
capability has got you eager to start making MicroPython, a microcontroller flavour of Python,
but you’re not sure where to start, you’re in which greatly simplifies writing code for Pico W.
PJ Evans
MAKER
the right place. We’re going to take a step-by- It also includes everything we need to connect to
step look at simple components for inputs and the internet. To download and install the latest
PJ is a writer,
software engineer outputs, connect them to Pico W, and then fetch version of the MicroPython firmware, follow the
and general data from the internet and display them. We’re instructions here: magpi.cc/micropython.
tinkerer. He can going to do this without any of the difficulty of
currently be found
replacing all his soldering, or even handling components, by using
old microcontroller the SB Components Pico Breadboard kit. This PCB
Get ahead
02
projects with (printed circuit board) comes pre-populated with
Raspberry Pi
buttons and LEDs to make your introduction to To connect to the Pico Breadboard Kit,
Pico Ws.
electronics as simple as possible. you will need to have headers soldered onto your
@MrPJEvans
Pico. If you do not have a Raspberry Pi Pico H (H
for headers), then you need to buy a header kit
and solder them on yourself. These need to be
Pico preparation
01 A great facet of Raspberry Pi Pico W
facing downward so the smaller part of the header
is poking through the top of Pico’s PCB on the
is its support for different languages. By RP2040 chip side. If soldering yourself, remember
uploading different ‘firmwares’ (low-level code to be careful and start by soldering each end pin of
that translates for the RP2040 CPU), we can the header block, then check everything is level.
If not, you can melt the solder to move them into
You’ll Need
place, then solder all the ones in between.
> S
B Components
Pico Breadboard Kit
magpi.cc/
picobreadboardkit
Choosing a development
> 2
× 20-pin headers
03 environment
(if not already To write code for Raspberry Pi Pico W, you need
there)
to use a computer. Nearly any modern operating
magpi.cc/
picoheaders system will do, including Raspberry Pi OS. It’s
possible to write code using a simple text editor, but
> 1 0 × Female-female
it’s a lot easier (and faster) to use an IDE (integrated
jumper cables
magpi.cc/ development environment). Don’t be put off by the
jerkyjunior fancy name – this is a text editor that understands
> M
icro-USB to USB
what a Pico W is and can help transfer programs.
cable suitable for On Raspberry Pi OS we recommend Thonny, but you
Y
ou can write code as files and upload them directly to
your computer can also use Visual Studio Code with the Pico-Go
Pico W. To have code run instantly when Pico W is plugged
in, just name it main.py extension. More info: magpi.cc/gettingstartedpico.
Testing time
04 It’s time to check everything is working.
permanent damage. To stop this happening, we
need an in-line resistor to limit the flow of current.
Connect your Raspberry Pi Pico W to your computer See the little black and silver squares above the
using a USB cable. Open up Thonny and look in the LEDs? They are 330 Ω resistors already in place that
bottom right-hand corner. It should say something are perfect for the job, so we can wire everything
like ‘Python 3.7.9’. Click on this and, if Pico W up without worrying about damaging our LEDs.
has been recognised, you’ll see ‘MicroPython
(Raspberry Pi Pico)’ as an option. Select this and
you’ll see a welcome message on the bottom half e are using the RP2040’s built-in
W
of the screen. Click to the right of the ‘>>>’ prompt
and type: ‘pull-down’ resistor circuit which solves
print('Hello')
this problem
Understanding buttons
…followed by pressing RETURN. If you see ‘Hello’
displayed in response, you’ve just run your first
06 On the left-hand side of the prototyping
program on your Pico W! board are four buttons (and a buzzer, but we’ll
get to that). Each button creates a circuit when
the button is pressed down. By wiring these to
your Raspberry Pi Pico W, you can detect when
Understanding LEDs
05 Have a look at the SB Components
the button is pressed. Buttons can be tricky for
a microcontroller to handle, as the input is so
prototype board. On the bottom-right are four sensitive it can give inaccurate readings; you can
LEDs (light-emitting diodes). These are one of the even trigger it by putting your finger next to it. To
most common components used when beginning prevent this, we are using the RP2040’s built‑in
electronics, as we can make them light up and ‘pull-down’ resistor circuit which solves this
that’s cool! LEDs can be a little naughty and problem. When it comes to coding, you’ll see how
draw too much current if left unchecked, causing we make use of it.
Get wired
07 It’s time to assemble our circuit. Carefully
(in this case - output). Then we go into a loop:
toggling the state of each pin, then waiting a
insert the disconnected Raspberry Pi Pico W into second. If you want, have a play with the sequence
the socket on the prototype board, with the USB or see if you can change timings.
end at the top. The LEDs and buttons connect to
Pico W using jumper cables. Between the buttons
and the LEDs you’ll see two yellow sets of headers,
Push the button
clearly labelled. The jumper cables need to run
from these to the GPIO pins on Pico W. If you’re
09 To check the buttons, create a copy of the
wondering where the ground connection is, look at file you created in Step 8, and call it buttons.py.
the top-right of the board. The GND header must Remove the block starting while True:, then add
have one wire connected to any of the GND pins on the contents of the buttons.py code listing. Save
Pico W. Follow the wiring table (overleaf) carefully. and run the code. Try pressing the buttons one by
one. Each one should now toggle its equivalent
LED. This code uses ‘event’ or ‘interrupt’ handlers,
Top Tip Light up the LEDs
blocks of code that run when a GPIO pin changes
Keep it in order
08 Having checked all your wiring carefully,
state. When a button is pressed, the code runs and
changes the state of the LED. This is a fundamental
connect Raspberry Pi Pico W to your computer. part of physical computing. You are taking external
LEDs or buttons In Thonny, type the leds.py code listing into the input (the button) and creating output (the LED).
not working in the upper window, and then click the ‘Run’ icon.
right order? Check When prompted, ask to save it on the Pico W and
the wiring, it’s
name it leds.py. The code will now be uploaded
really easy to get
Simon says
things the wrong
way around.
to Pico W. Do you see the LEDs coming on one-
by-one? The code starts by telling Pico W which
10 You’ve now seen how Raspberry Pi
GPIO pins are connected and what they are for Pico W can use code to respond to inputs by
leds.py DOWNLOAD
THE FULL CODE:
> Language: Python 3 magpi.cc/ledspy
With a few lines of code, Pico W can connect to your 001. from machine import Pin
wireless network and then to the internet 002. import utime
003.
creating outputs. We could have wired the buttons 004. # Make sure these are the pins connected to your LEDs!
directly to the LEDs to create a similar effect (and 005. leds = {
using the breadboard, you can try that!), but Pico 006. 1: Pin(28, Pin.OUT),
W adds logic that would be hard to implement in 007. 2: Pin(27, Pin.OUT),
raw circuitry alone. To demonstrate this, download 008. 3: Pin(26, Pin.OUT),
memory.py from magpi.cc/memorypy. This is an 009. 4: Pin(22, Pin.OUT),
extension of the code that turns our button script 010. }
into a memory game. Run the code on your Pico W, 011.
and see if you can remember the sequence of LEDs 012. # Loop through the LEDs toggling each one then sleeping a
by playing them back on the buttons. Don’t forget second
to review the code and see how it works! 013. while True:
014. for i, (k, led) in enumerate(leds.items()):
015. led.toggle()
016. utime.sleep_ms(1000)
If you’re wondering where
the ground is, look at the
top-right of the board buttons.py DOWNLOAD
THE FULL CODE:
> Language: Python 3 magpi.cc/buttonspy
Get online
11 Now we have built our circuit, tested it, and 001. # Remove the while True: block and replace with this
played a game, let’s look at what makes Raspberry 002. def button_handler(pin):
Pi Pico W so special. For our weather project, we 003. button_pressed = int(str(pin)[4:6]) - 17
need to connect to the internet, so let’s start with 004. print(str(button_pressed))
that. Create a new file called wifi.py and add the 005. leds[button_pressed].toggle()
contents of the wifi.py listing (overleaf). Replace 006.
the ssid and password values with those for your 007. for gpio_number in range(18, 22):
own network. Now run the code on your Pico W 008. button = Pin(gpio_number, Pin.IN, Pin.PULL_DOWN)
using Thonny. Watch the console output and 009. button.irq(trigger=Pin.IRQ_RISING, handler=
within a few seconds you should get an IP address button_handler)
announcement, meaning you’re on the internet!
GP28 1
E nter ‘lat and long for town’
GP27 2
in a search engine, and
GP26 3
you’ll get the answer
GP22 4
Lightening
GP21 1
15 We don’t have a screen (although you can
GP20 2
add one if you want!), just four lights to show
GP19 3 the data. What we’ll do is divide the results into
ranges and light the appropriate amount of
GP18 4 lights. For instance, If it’s really hot, all four LEDs
will illuminate. Download weather_3.py from
GND Any
magpi.cc/weather3py and run it. Raspberry Pi
wifi.py DOWNLOAD
Buzzin’ THE FULL CODE:
16 Calls to the internet can never be fully
relied on to succeed. There are many things that > Language: Python 3 magpi.cc/wifipy
can go wrong, from your internet connection
being down to the API server having problems. 001. # Based on code by Pete Gallagher
We can catch these errors and signal to the user 002. # https://www.petecodes.co.uk/
that there’s a problem. The next version of our 003. import time
code (weather_4.py from magpi.cc/weather4py) 004. import network
creates a short buzz on successful calls and a 005.
longer buzz if something went wrong. Keep getting 006. ssid = "<Your Wifi Network Name>"
errors? More details will be logged to the console. 007. password = "<Your Wifi Password>"
008.
009. wlan = network.WLAN(network.STA_IF)
010. wlan.active(True)
Put it all together 011. wlan.connect(ssid, password)
17 Let’s bring the buttons and the LEDs 012.
together. Download our final code version, 013. # Wait for connect or fail
weather_5.py from magpi.cc/weather5py, and run 014. max_wait = 10
it up as before. Now when you press each button, 015. while max_wait > 0:
you can get an idea of whether it’s raining, sunny, 016. if wlan.status() < 0 or wlan.status() >= 3:
hot, or windy! Take some time to walk through 017. break
the code to see how we hunt through the data, 018. max_wait -= 1
and see what changes you can make! If you would 019. print('Waiting for connection...')
like to run this independently without a computer 020. time.sleep(1)
attached, just rename this file to main.py. Any file 021.
of that name will run automatically when power 022. # Handle connection error
has been applied to Raspberry Pi Pico W. 023. if wlan.status() != 3:
024. raise RuntimeError('Network connection failed')
025. else:
026. print('Connected')
027. status = wlan.ifconfig()
028. print( 'IP Address = ' + status[0] )
029.
030. # Important to tidy up the connection
031. wlan.disconnect()
T
o get the weather data you need an API key. You’ll find it
on the OpenWeatherMap user page like this
MagPet – code a
Python virtual pet
Virtual pets are back! At least here in the magazine, as Rob Zwetsloot
revives a nineties phenomenon on a Raspberry Pi
D
idya see, didya hear, didya know that
Rob Zwetsloot
MAKER
Game loop
05 Each loop of the game, our pet goes through
a cycle. It will get hungrier, need to relieve itself
more, and also will lose happiness if you’re
not paying it attention. We’ve also set it up so
happiness is affected by hunger and cleanliness,
so make sure to keep your pet fed and clean. When
our pet is at a certain level of hunger, a little
thought bubble appears to prompt you to feed it. Top Tip
The button_pressed function checks to see where
your mouse was when it clicked. This method of What’s in
tracking pixels is a very basic way to press buttons a name
in Pygame.
Tamagotchi is a
portmanteau of
tamago/egg and
tomodachi/friend
Main loop
06 We start the main loop by getting the rest
in Japanese.
They’re shaped
of Pygame set up. This includes a clock to make like eggs after all.
Figure 1 Lines 1 to 35 cover the first two steps.
Here, we get everything set up for the rest of the code sure each frame passes at a certain point, creating
Figure 2 Step 03 is the ‘event’ Pygame receives when you click
covers the last few
lines of Figure 1, and on the X.
also the movement
As for the mouse, we wait until the button goes
part until line 68.
Happiness is shown up, hence MOUSEBUTTONUP is the event. This means
using the hearts
function, explained in it won’t count you having the mouse button
Step 04 depressed as multiple events over several frames
if you don’t click fast enough. You may have
seen variations on this with how buttons work in
GPIO Zero.
Movement philosophy
08 Here’s where we set the cardinal directions
of the pet. We decided that it wouldn’t just
move randomly each frame, and it would in fact
have a 60% chance to carry on in any direction
it started. This is where the random module
comes in. In action, this means our pet will move
the game display, and importing all the variables more naturally.
we need. The cardinal direction and the game_display
variable are sent to the movement function from
e decided that it wouldn’t
W
just move randomly
each frame
Now the full while loop starts. The screen is
filled with colour, the buttons are placed on the
screen, and the mouse co-ordinates are set to 0.
As this part is being called for each frame, it’s
best to keep as little out of it as you can to make
sure your game runs as fast as possible. For this
script, the global parameters and unchanging
Top Tip display aspects were placed before the while loop
for this reason.
Size can
matter
Handling inputs
The size of your
screen and sprites 07 In this project, we have two kinds of
need to match in inputs: a mouse click, which we’re using to press
some way – it’s
the buttons on screen, and also the exit button on
easier to resize
images out of
the Pygame window.
Figure 3 Waste is managed as shown in Step 04, and
Python after all. The pygame.QUIT event is fairly simple. If the X from 106 to the end are the functions that handle your
on the window is pressed, Pygame will stop. QUIT interactions and how your pet lives as shown in Step 05
DOWNLOAD
THE FULL CODE:
Step 3. We pass on game_display so that the
magpi.cc/magpet
function can update it properly.
Button juggling
09 There are three buttons on this pet, which
means there are four states to keep track of.
We’ve tried to keep it simple and understandable
Figure 4 This block
by labelling the buttons 1–3, and no button being of code handles
0. One thing we did was to make sure we couldn’t Step 06 (144 to 158),
Step 07 (160 to 166),
just hammer the Pet button to increase happiness. Step 08 (168 to 177)
and finally Step 09
A timer is set so that you have to wait five frames
for the rest
before using it again.
As each frame is rendered separately, this
Figure 5 The game is
played out through
means if you reset hunger and waste, the this last bit of code,
images for them will not be rendered in the described in Steps 10
and 11
following frame.
Build a
Part 01
Raspberry Radio
Create your own virtual radio station, with a DJ that reads out the
news and weather and announces your songs before they play
W
e love radio, but don’t you ever wish your taskbar to open a terminal window. Then
you had more control over the playlist? enter the following command at the prompt to
With Raspberry Radio, every song is download and install the modules:
Sean
MAKER
aspberry Pi OS
> R
http://api.openweathermap.org/data/2.5/
> I nternet connection weather?q=London,uk&units=metric&APPID
> D
isplay-O-Tron HAT =YOUR_API_KEY
(optional)
magpi.cc/ Change the city name to your own, and add
displayotron your API key after the equals sign at the end. (If
> P
ibow case you’re not near a city, consult the documentation
(optional) at openweathermap.org/current for tips on using
This Python Formatter makes it much easier to understand
the JSON structure of the weather data we’re using longitude and latitude instead.)
The Display-O-Tron
has a 3×16 character
display, ideal for
short news headlines
Prepare to import
10 You might have noticed that Top Tip
rr_newsreader.py does not have any output. It
defines three functions, but they’re not called at Humanise the
any time, and the information they gather isn’t
news
displayed. That’s because we want to make this basic animation, displaying each headline one
You could add a
code reusable across different projects. This issue, character at a time, and brightening the LEDs randomly chosen
you’ll see how to display the news headlines on an when the headline is complete. It makes it feel introduction to the
LCD screen, but next issue your device will read like the news is coming in right now, and is more news to increase
visually interesting than just having it pop up on variety, as we have
for the weather.
e want to make this
W the screen.
rr_newsreader.py DOWNLOAD
THE FULL CODE:
> Language: Python magpi.cc/newsreader
IN THE
WORKSHOP:
Sublimation
printing
By Ben Everard Transfer prints onto mugs and PCBs
A
sublimation printer looks and
works a lot like an ordinary
inkjet printer. You load paper into
it (although it does have to be
proper sublimation paper), plug it
into your computer, and press
print. So far, so ordinary.
The word sublimation means to turn from a solid
into a gas without being a liquid in between. This
stage – the sublimation – is what happens after
you’ve printed onto paper. It means you can turn
the, now solid, ink into gas and transfer it onto
other objects.
When we say other objects – there’s a wide range
of stuff that you can transfer sublimation prints
onto, but not everything. It has to have a coating
that will accept the ink. In most cases, this means
buying a pre-prepared ‘blank’, although you can get
laminates and varnishes that will let you coat the
surface yourself.
Once you have the printed sheet and the object to
Right impress the image on, you just need to stick the
The same PCB is paper on with heat-resistant tape (aka Kapton tape),
used for both left
and right wing and heat-press it on. This is another limitation on the
FEATURE
It’s helpful whole process was a mug heat-press that just kept
beeping at us, but reading the manual and working
out what button to press sorted that out.
process is a
times. As far as I can tell, heavy things like ceramics
that take a long time to heat up require longer than
lighter things, like jigsaw blanks. However, you should
Below
I’ve made mugs for
our sister magazines
little tricky be able to get the right time from wherever you get
your blanks, if not, you’ll just have to experiment for a
bit. About 60 seconds at 190°C was the quickest we
LENS
Left
The butterfly’s
LEDs can light up
any colour
did (jigsaws), and 240 seconds at 205°C was the RGB LEDs. The design was one wing, but I could just
longest (slate blanks). If you get a sepia tint, leaving flip it over to create the other wing.
your images looking like they are a few hundred years These came back a week or so later, and it was
old, then you’ve probably overheated the ink. time to try them out. I didn’t have a specific pattern in
As a final test, we tried sublimating ink onto a PCB, mind (this was still a test, so I didn’t want to spend
just to see what happens. The initial results were ages on it before knowing if it’d work), so I printed off
really good. While the ink did not have a great deal of a swirling colour image that I found online, stuck a
effect on the FR4, it stuck extremely well to couple of wings to it, crossed my fingers, and started
silk-screened areas. the heat-press.
This meant that we couldn’t just sublimate print The result isn’t quite perfect. The image doesn’t
onto any PCB we wanted – we had to design specific quite have the detail that I’ve been able to get on
PCBs covered in silkscreen to take the ink. I’ve some surfaces. I’m not yet sure if that’s a result
always wanted to make a butterfly PCB. Long-term of the inherent properties of the silkscreen, or if I
readers with a very good memory may remember just haven’t yet dialled in the settings (the PCBs This tutorial is from
that HackSpace mag, issue 1, featured a butterfly only arrived a few days before we went to press, HackSpace magazine.
PCB from the now-defunct Boldport Club. In that, so I haven’t been able to properly test the process Each issue includes a
they’d used two different silkscreen colours to create out yet). So far, it seems like the ink is very prone huge variety of maker
the decorative effect but, in mine, I could just print to overheating with PCBs. The best results that I projects inside and
outside of the sphere
whatever I wanted. have had are at 180°C for 60 seconds, but it’s still
of Raspberry Pi, and
This was just a test, so I wanted something that early days. also has amazing
would look good, but not take too long to design. I This is definitely a ripe area for experimentation if tutorials. Find out
settled for a circuit that linked up three through-hole you’re interested in making artistic PCBs. more at hsmag.cc.
Learn ARM
Part 06
assembly: blink
Pico’s on-board
LED using the
Programmable I/O
Learn how to use the Programmable I/O (PIO) processors
on the Raspberry Pi Pico in their native assembly
language to blink the on-board LED
D
Create the program
Stephen irectly controlling hardware devices
01
MAKER
Smith with the ARM CPU, like we did in the Create a folder named tutorial6 in the
previous tutorial (see The MagPi issue pico folder that was created in your home folder
Stephen is a retired #120, magpi.cc/120), uses a lot of processing by the Raspberry Pi Pico SDK’s setup script.
software developer power that you might need for higher-level The source code for this tutorial is in blink.c,
who has written
three books on tasks. The Raspberry Pi Pico contains eight PIO blink.pio and CMakeLists.txt. Copy the file
ARM Assembly processors that you can use to offload I/O related pico_sdk_import.cmake from the SDK’s external
Language processing. In this tutorial, we will blink the folder to the tutorial6 folder. In this folder create
Programming.
Raspberry Pi Pico’s on-board LED. The program a new folder called build. The tutorial6 folder
He is a member
of Sunshine downloads a small assembly language program should now look like:
Coast Search to one of the PIO processors which will then do
and Rescue and
all the work of blinking the LED, letting the main pi@raspberrypi:~/pico/tutorial6 $ ls -l
enjoys mountain
biking, hiking, and ARM CPU proceed to perform other tasks. total 20
running. He is also The PIO processors operate on their own -rw-r--r-- 1 pi pi 972 Jun 25 11:22 blink.c
a member of the assembly language, which is quite different -rw-r--r-- 1 pi pi 925 Jun 25 11:17 blink.
Sunshine Coast
Writers and Editors
from ARM assembly language. This assembly pio
Society (scwes.ca). language only contains nine instructions, and the drwxr-xr-x 7 pi pi 4096 Jun 25 11:22 build
magpi.cc/ maximum program size is 32 instructions, but -rw-r--r-- 1 pi pi 698 Nov 5 2021
stephensmith even with these limitations, PIO can perform quite CMakeLists.txt
powerful I/O operations. There are five registers: -rw-r--r-- 1 pi pi 2763 Apr 9 09:15 pico_
two general-purpose registers, two shift registers sdk_import.cmake
for data transfer, and the program counter.
58 magpi.cc Learn ARM assembly: blink Pico’s on-board LED using the Programmable I/O
TUTORIAL
cd pico/tutorial6/build
make
Run the program
The build folder should now look like the
03 Power on Raspberry Pi Pico by plugging the
example below: USB cable into the power connector while holding
down the BOOTSEL button. When the file explorer
pi@raspberrypi:~/pico/tutorial6/build $ ls window appears, open it, and copy the file pio_
-l blink.uf2 to the Pico. Your Pico reboots, then the
total 1192 program runs. The program prints out information
-rw-r--r-- 1 pi pi 1856 Jun 25 11:19 on how fast the LED is blinking and which iteration
blink.pio.h of the loop it is on. Open a serial port program to
-rw-r--r-- 1 pi pi 18815 Jun 15 13:30 see this output.
CMakeCache.txt
drwxr-xr-x 7 pi pi 4096 Jun 25 11:22
CMakeFiles IO can perform quite
P
-rw-r--r-- 1 pi pi 1670 Jun 15 13:30
cmake_install.cmake powerful I/O operations
drwxr-xr-x 6 pi pi 4096 Jun 15 13:30
elf2uf2
drwxr-xr-x 3 pi pi 4096 Jun 15 13:30 minicom -b 115200 -o -D /dev/serial0
generated
-rw-r--r-- 1 pi pi 77139 Jun 15 13:30 The minicom command displays data being sent
Makefile from the Pico to Raspberry Pi (Figure 1).
You’ll Need
drwxr-xr-x 6 pi pi 4096 Jun 15 13:30 pico-
sdk > Raspberry Pi
drwxr-xr-x 5 pi pi 4096 Jun 15 13:31
> Raspberry Pi Pico
About compiling the PIO module
pioasm
-rwxr-xr-x 1 pi pi 22652 Jun 25 11:22 pio_
04 In previous tutorials, the GNU Assembler > Serial and debug
blink.bin compiled our assembly language files into object connector wires
-rw-r--r-- 1 pi pi 364370 Jun 25 11:22 pio_ modules that were linked into the program’s > Raspberry Pi OS
blink.dis executable file, which would be run directly by 32-bit
-rwxr-xr-x 1 pi pi 351404 Jun 25 11:22 pio_ the operating system. The PIO code needs to be > Raspberry Pi Pico
blink.elf separately downloaded to the PIO program memory SDK
-rw-r--r-- 1 pi pi 234360 Jun 25 11:22 pio_ via Raspberry Pi Pico’s SDK. The PIO assembler
Learn ARM assembly: blink Pico’s on-board LED using the Programmable I/O magpi.cc 59
TUTORIAL
0x6040, // 1: out y, 32
// .wrap_target
0xa022, // 2: mov x, y
0xe001, // 3: set pins, 1
0x0044, // 4: jmp x--, 4
0xa022, // 5: mov x, y
0xe000, // 6: set pins, 0
0x0047, // 7: jmp x--, 7
Figure 1 Running 0xa022, // 8: mov x, y
the program and
// .wrap
observing the
output in minicom };
compiles blink.pio into blink.pio.h, which is The header file includes several helper functions
a standard C header file. This file contains an to set various configuration parameters. The
array of 16-bit numbers that are the compiled program is downloaded via the pio_add_program SDK
values of the program: function called from the main() function in blink.c.
60 magpi.cc Learn ARM assembly: blink Pico’s on-board LED using the Programmable I/O
TUTORIAL
Learn ARM assembly: blink Pico’s on-board LED using the Programmable I/O magpi.cc 61
TUTORIAL
DOWNLOAD
THE FULL CODE:
operations to the PIO, freeing up the ARM CPUs
to perform other useful work. In this case, after
blink.c magpi.cc/learnassembly6
initialising the PIO, the C program executes a loop
where every ten seconds it re-initialises the PIO > Language: C
with a different timing value based on the index
it counts. 001. /**
Raspberry Pi’s SDK examples contain 19 PIO 002. * C Program to set the PIO in motion blinking the LEDs
sample programs. The best way to write a PIO 003. */
program is to use one of these as a starting point, 004.
if there isn’t already one that meets your needs. 005. #include <stdio.h>
Then refer to the ‘Raspberry Pi Pico C/C++SDK’ and 006.
‘RP2040 Datasheet’ manuals for the various SDK 007. #include "pico/stdlib.h"
functions that control the PIO, and for details on 008. #include "hardware/pio.h"
PIO assembly language. 009. #include "hardware/clocks.h"
010. #include "blink.pio.h"
011.
012. const uint LED_PIN = 25;
Modify the program 013.
08 Congratulations! Welcome to the world 014. void blink_pin_forever(PIO pio, uint sm, uint offset,
of PIO programming for Raspberry Pi Pico (and uint pin, uint freq, float clkdiv);
any other board using Raspberry’s RP2040 015.
chip). Without debugging or print statements, 016. int main() {
developing PIO programs can be tricky. The best 017. int i = 0;
way is to start simple, such as taking a working 018.
program like this one and modifying it to change 019. setup_default_uart();
its functionality. Then, as long as you take small 020.
steps, when something breaks, you will know what 021. PIO pio = pio0;
did it and you can go back to a working state. Try 022. uint offset = pio_add_program(pio, &blink_program);
experimenting with the timing of the LED pattern, 023. printf("Loaded program at %d\n", offset);
perhaps have it do a longer flash followed by a 024.
shorter flash. Can you think of a way to expand 025. while(1)
this to transmit Morse code? 026. {
027. i++;
028. blink_pin_forever(pio, 0, offset, LED_PIN, 10, (
031. }
on Assembly Language
032. }
Programming. The most
ing 033.
recent one is RP2040
o g rammBit
Assembly Language Pr h 64- embly 034. void blink_pin_forever(PIO pio, uint sm, uint offset,
Programming for the wit M Ass uint pin, uint freq, float clkdiv) {
AR guage mputer DoebvileeloDpemvices
ent
62 magpi.cc Learn ARM assembly: blink Pico’s on-board LED using the Programmable I/O
THE BEST-SELLING MAG FOR PC HARDWARE, OVERCLOCKING, GAMING & MODDING
PC HARDWARE
ENTHUSIASTS
Build a robot:
Part 02
add sensors to
the chassis
Last month, we started our build of the CamJam Robotics EduKit.
Now we have a roving robot, it’s time to add some smarts!
I
PJ Evans
MAKER
Get sensitive
01 Included with your CamJam kit is a light
sensor. It works by sending out infrared light
(that we can’t see) and detecting how much of
it bounces back to a sensor. If we point it at the
ground and measure the sensor’s output, we
can easily tell when the robot passes over a line.
The key to success is high contrast, so a jet black
line on a white surface is perfect. We’re going to
mount the sensor on the front of the robot, point
down, so we can detect a line.
You’ll Need
> C
amJam Edukit #3
- Robotics A little light wiring
magpi.cc/edukit3 02 To wire up the light sensor, we’re going to
> P
rinter use the breadboard (the small block with lots of
> R
oll of paper holes). Holding it with the longer edge horizontal,
(optional) each column of holes are connected together,
Figure 1 Wire up the line sensor to the HAT.
with a gap in the centre. Breadboards allow us Use the breadboard to create a ‘ground rail’
Testing time
to connect circuits together without soldering,
so we can quickly prototype circuits and correct
04 The sensor will not work without a little
mistakes. You’ll need three wires: two plug-to- code to help it on its way. Enter the code from the
socket, and one plug-to-plug. Wire everything test_line.py listing, overleaf (or download it from
together as shown in the diagram, checking and the GitHub repo: magpi.cc/testlinepy), and save
double-checking. There are three connectors on it in your home directory as test_line.py. Now run
the light sensor for power, grounding, and data. the code:
These all need to match up with the connector on
the robot HAT connected to your Raspberry Pi. python3 test_line.py
Don’t worry, your robot won’t move at this point. Top Tip
What we want to do is check the sensor is working
Mount the sensor Safety First
03 The sensor needs to be in a sensible place
correctly. Using a sheet of paper with a thick
black line through it (magpi.cc/testlinepdf), hold
on the box chassis, and that would be in the centre your robot carefully and pass the paper under the Whenever
connecting
at the front on the base. However, this is also the sensor. If all is working well, you’ll see messages
wires to your
highest point of the body, and the further away on-screen that the line has been detected.
Raspberry Pi
the sensor is from the ground, the less accurate it computer, ensure
will become as ambient light leaks into the sensor. it is completely
Start by making a hole off-centre towards the front powered-down.
Follow that line A mistake when
of the chassis and feeding the three wires through
it. Connect the wires to the sensor as shown in
05 Now our little pal can detect a line, we can the computer
is on can cause
Figure 1, then mount the sensor to the body with make them follow it too! By combining code to
permanent
sticky pads. You may find a couple of LEGO bricks drive the robot forward and steer it left and right, damage.
will sufficiently lower the sensor to the ground. we can make corrections as we go. This listing is a
Colourful of A4 paper together. Make it as big as you can, 008. def lineseen():
resistors without any tight corners to which the robot may 009. print("Line seen")
not be able to respond. Use a pen such as a Sharpie 010. def linenotseen():
Resistors are to create the line to follow, and make it nice and 011. print("No line seen")
identified by thick, like the one on the printout. Now watch as 012.
coloured stripes
your newly smarter robot follows the line in circles. 013. # Tell the program what to do with a
on their body
and can be line is (un)seen
used either way 014. sensor.when_line = lineseen
around. The 470 Ω 015. sensor.when_no_line = linenotseen
Looking into the distance 016.
07
resistor is Yellow,
Violet, Black, If we want our robot to be able to move 017. # Repeat the next indented block
Black, Brown; the
around a room on its own, there’s a significant forever
330 Ω is Orange,
Orange, Black,
problem: walls. Our final modification is to add a 018. while True:
Black, Brown. distance sensor to the robot, so it can take avoiding 019. time.sleep(10)
action when it gets close to an obstacle. The sensor
SMART
AND S P O O K Y
HA L LO W E E N P A R T Y !
Use Raspberry Pi and Pico
H
alloween parties are great. When else
do you have an excuse to eat unusual
to power up your petrifying amounts of sweets while watching a
marathon of The Simpsons episodes, and maybe
party this Halloween with partaking of a beverage that is a) smoking and
HOUSE OF HORRORS
Gruesome garlands to meet your
ghastly guests
LURID LIGHTS
Holiday light show
Luke Dutton
While, yes, technically these are Christmas-themed lights, you just need
to switch the light colours and music to make it truly Halloween-themed.
It uses LightShow Pi, which is a popular library for syncing up music to
programmable LEDs to make your whole setup seem in sync. We imagine
it would look quite scary with the Monster Mash playing.
magpi.cc/holidaylights
magpi.cc/poplawski
DECOR O F T H E
D A M N ED Inte ra ct iv e in te ri o rs that are sure
ed fiends
to intimidate invit
Remote-controlled Billy
david0429
Depending on the kind of party you’re
throwing, you might not want to greet your
guests with this guy from the Saw movies as
they walk through the door. Otherwise, it’s a
fun little thing for people to play with. Maybe
you can build a Kermit on another one and
have them duel like it’s Pi Wars?
This is actually not a bad step up from some
robot kits, and you could make the doll or find
one on Etsy or something.
magpi.cc/billysaw
Possessed Portrait
Dominick Marino
While it may be a little conspicuous to suddenly
have a giant portrait in your home, it would at least
fit a Halloween aesthetic. Either way, whenever
a friend goes to inspect it, they won’t expect the
picture to move and scream at them.
This works largely on the same hardware
principle as a magic mirror, albeit without the
reflections and kind messages. Finding an antique
(looking) frame might be the way to go as well.
magpi.cc/possessedpic
DELIGHTFULLY
DEVILISH
DRINKS
Haunted Jack-in-the-Box These beastly
Sean Hodgins
This one can be hidden away in your home, just in
TRACK PEOPLE beverages are
sight of the party guests. Until… suddenly it starts sure to go down
and scares the living daylights out of someone.
This uses an actual Jack-in-the-box, so make BEFORE GIVING a (trick or) treat
sure it’s one you’re happy to modify with some 3D
printing first.
It also makes for a very effective scare, so A TERRIFYING
perhaps gauge the level of scare-ability of your Eyeball snot-tail
OWL HOOT
guests before subjecting them to it. This mix of lime jelly, apple
and/or pear juice, lemonade,
magpi.cc/hauntedjack lychees, cherries, and raisins
creates a light, tasty citrusy
mocktail that also happens
to look like it’s eyes in
nondescript green goop.
magpi.cc/snottail
Halloween punch
This spiced and spicy cherry
juice punch has a bit of a bite,
and not just from the tangy,
fangy sweets.
magpi.cc/punch
Mulder
Mike Cook
There are pumpkins outside, so how about
something a little different inside? This interactive Mulled
skull may look a little jovial, but it can also be quite
apple juice
scary. The eyes, jaw, and neck move so it can track
If you want to serve something
people before giving a terrifying owl hoot. a little more traditional
You can also remote control it just in case you and a little less gimmicky,
want to give a custom scare to your friends. this mulled apple juice is a
great idea.
magpi.cc/38
magpi.cc/mulledapple
CO S T U M E S
ARE C R E E P Y ith these desp icable duds
Dress to depress w
magpi.cc/voicechanger
magpi.cc/docbrown
FIENDISH
FINGER FEAST
Face-changing projection mask A brutal buffet
Sean Hodgins
From the maker of the haunted Jack-in-the-box featuring both
comes this incredible projection mask that uses
sweet and (un-)
YOU COULD
a small DLP projector hooked up to a Raspberry
Pi connected via a stick. The projector sits in the savoury delights
chin of the mask and uses projection mapping
on specific videos so that they show up as they
would on a screen. It’s a very clever mix of
hardware and software.
ALWAYS USE
Witches fingers
magpi.cc/projectionmask
THE TECH FOR This finger food is quite literally
fingers… or at least breadsticks
with a garlicky tang to them.
magpi.cc/dirtnworms
Disco ball
Wolfie
No one will miss you at the party if you’re walking
around with many strips of LEDs attached to your
person. This one can work on its own, but you can Sausage
also hook it up to your house’s light show if you mummies
want for some wonderful synchronised costuming. Cocktail sausages wrapped
There’s lots of LEDs, chicken wire, foil, and some in spirals of puff pastry – add
3D-printed parts to make this, although you could edible eyes or little dots of
always use the tech for something else. mustard to make them really
stand out.
magpi.cc/discoball magpi.cc/sausagemummies
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.
SCREEN:
2.66” e-ink A cost-effective and easy way to get into
display, 296 ×
152 resolution, using e-ink displays. By Rob Zwetsloot
125 DPI,
T
two colour
his neat little kit is a great way to add a does mean that it has a larger footprint than, say,
DISPLAY small e-ink display to a Raspberry Pi Pico the Badger 2040 from Pimoroni, which is used as a
DRIVER: – in fact one is included in the kit. It uses a fun name badge.
EXT3 board specific extension board to connect to the screen This EPD is aimed at slightly different
with a 90 and then to Pico using provided jumper wires – this applications and users though. With full access to
degree header
the rest of Pico, many more sensors and inputs can
and 8 megabits
of flash be connected to the system, allowing it to be used
memory
SOFTWARE:
Pervasive
ith full access to the
W
Displays Library
Suite software rest of Pico, many more
sensors and inputs can be
connected to the system
for temperature and air-con control – shown off
quite nicely in the demo video and code.
Intense wiring
Putting it all together out of the box can take a
little time. Roughly a dozen GPIO pins need to
be connected to the right spots on Pico, albeit
made easy thanks to a little pinout card that
comes with the kit. These jumper wires connect
The pin mapping to a header which, luckily, slots straight onto the
guide is a handy
extension board, with a ribbon cable connecting to
way to make
wiring up easier the screen.
In its place
It’s all powered off a Raspberry Pi Pico, so you The library for the screen is great and the code is
won’t need to connect extra power to the screen at fairly simple to understand, although it is in C as
all – a decent mobile battery should be sufficient it has roots in Arduino, which might cause some
to power the whole rig. Connect it to a PC and load issues for some people. C seems to run better on
the firmware and demo and, not only will you get Pico though than MicroPython, so it was probably
a look at the aforementioned demo, but a rundown the right choice to get the most out of it.
of the different functions in the code itself with The slightly clunky way it looks when put
together basically does feel a bit of a shame
though. Considering how small Pico is, it would
seem more natural to have something like this
just mounted onto Pico to save on space. Luckily,
with the way it’s all connected, you can do some
sandwiching, but it’s not quite the same.
Verdict
Still, it’s a neat and powerful little display that A very powerful
can be used in a wide array of settings with a bit of and well thought
creative housing. out piece of kit,
that feels like it
could be a bit
more condensed.
The whole set up is a little clunky, but it does allow access to all the features of Pico 9 /10
EPD Pico Kit magpi.cc 77
REVIEW
Autonomous
Robotics Platform
for Raspberry Pi Pico
Kitronik magpi.cc/kitronikpico £41 / $49
SPECS
K
(with tyre): itronik’s Autonomous Robotics Platform slotted in underneath to provide power to the
67.5 mm
caught our attention recently thanks motors and Pico.
SENSORS: to its usage of Raspberry Pi Pico, rather The result is a cute-looking robot that is easy to
Ultrasonic than the more common Raspberry Pi Model B or assemble, making it perfect for younger robotics
distance sensor Zero models. makers. It’s incredibly lightweight and moves
HC-SR04 5 V;
The kit contains a robotics platform chassis with around at a brisk pace.
Kitronik line-
following two TT motors pre-mounted. Two large yellow
sensor board wheels are attached to the side, along with an All aboard
ultrasonic sensor on the top and a line-following There are a few extras on the robot chassis worth
MOTORS: mentioning. On all four corners sit ZIP LEDs that
sensor underneath. Finally, a Pico or Pico W with
2 × TT
geared motors a GPIO header soldered in can be mounted in the add bling (and can be useful for feedback). A hole
middle of the two motors. Four AA batteries are in the middle of the board is used to hold a marker
pen for turtle-like drawing. There is an on/off
switch to cut the power and a button that responds
to code (as opposed to the BOOTSEL button on
Pico W). Finally, there’s an on-board buzzer to
make audio feedback.
We found it easy to set up, thanks to the
included manual. At least to the point where
the physical assembly was complete. Following
the build, the manual skims over the API and
mostly directs you to the Kitronik website
(kitronik.co.uk/pico-arp-motors) for more detail
on how to code and control the robot.
Clone the corresponding GitHub repo
(magpi.cc/kitpicogit), and you’ll discover code to
go with all the tutorials and some great example
programs. Along with tests for all the motors,
sensors, button, and buzzer, there’s code that
Four LEDs light runs the robot around in circles, line-following
up the Kitronik
examples, pen-lifting examples, and a program
Autonomous
Robotics Platform that uses the sensors to control the lights.
Autonomous Robotics
Platform is a good-
looking robot that’s
easy to control
The GitHub page has documentation on the API, These robots are cheap to buy, easy to set up,
and the tutorials are comprehensive. sturdy, and fun to program.
Using Pico instead of Raspberry Pi for the code
has advantages and disadvantages. Even though
Pico W is now available, you cannot remote-
control the robot via a web or smartphone app The PCB board comes
with two TT motors
(as you can with many other robots). Perhaps this
mounted; wheels,
functionality can be implemented down the line. sensors, and Pico are
attached to complete
the build
9
is better value when you factor in running Pico,
rather than a full-blown Raspberry Pi computer).
/10
Autonomous Robotics Platform is ideal
for a cost-minded learning environment.
Arducam 64MP
Autofocus Camera
Module
The Pi Hut magpi.cc/64mpcamera £60 / $60
SPECS
A
LENS: s its ‘Hawk-eye’ nickname implies, the
f/1.8 aperture, 64MP Autofocus Camera Module can
84° view
capture stills with unprecedented detail:
angle, 8 cm–∞
focal range, up to 64 megapixels (9152×6944) on Raspberry
motorised Pi 4 or CM4 (other models are limited to 16MP).
focusing
8
The autofocus (AF) option is a little soft-focus, due to
a welcome feature, although lens diffraction, but this
/10
it doesn’t always work quite as can be fixed by sharpening
expected. For instance, it’ll typically in an image editor.
SAVEUP
TO
35%
on the cover price
ISSUE #58
OUT NOW
hsmag.cc
RESOURCES
10 Amazing:
Gaming
NESPi 4 Case
Retro camouflage
Accessories
This cheeky case will make your Raspberry Pi seem right
at home among other consoles – there’s also a removable
cartridge for extra storage.
W
e know lots of folks that use a Raspberry Pi to play
retro games and homebrew. It’s an easier way to Handheld gaming
hook it up to your TV after all. While you can just
This familiar case is a genuinely
bodge together a gaming Raspberry Pi, there are many things
great way to have a bit of retro
that will help make it just that little bit better. gaming in your (big) pocket. It
even has extra buttons so you can
play more modern games as well.
magpi.cc/massivebutton | £8 / $10
8BitDo Pro 2
Retro controller
With a classic retro design updated with modern conveniences (such
as Bluetooth), the Pro 2 controller is one of the best ways to experience
old games. It works on Raspberry Pi, PC, Switch, and more!
Learn electronics
with Raspberry Pi
Resources to help you get started with electronics on Raspberry Pi. By Phil King
Raspberry Pi Projects
Raspberry Pi While a Raspberry Pi is powerful a wide range
AUTHOR
Cool kits
Grab a bunch of useful components in a handy kit
MONKMAKES PROJECT BOX 1 worksheets take you step-by-step through
Make the ten projects detailed on instruction the projects.
cards in this kit from Simon Monk which includes magpi.cc/camjamkit2
everything you need to make them: LEDs, a
thermistor, phototransistor, switches, and more. WAVESHARE SENSORS KIT
magpi.cc/projectbox1 As used in our Sensory World tutorial series
(issues 111 to 114), this kit comprises 13 sensors,
CAMJAM EDUKIT #2 including gas, moisture, and tilt. You’ll need an
This inexpensive beginner’s kit introduces ADC (analogue-to-digital converter) chip to read
you to sensors: a PIR (movement), LDR (light), analogue signals from some of them.
and DS18B20 probe (temperature). Detailed magpi.cc/wavesensors
Books
CamJam EduKit #1 to read
CamJam / Electronics kits can provide a
AUTHOR
PDF of this handy Essentials electronics and coding, you’ll electronics such as LEDs,
Price: guide from The MagPi website. make fun projects including an push-buttons, and sensors. An
Free PDF
It takes you through the basics internet radio, motion-sensing updated 4th Edition is due out
magpi.cc/ of connecting electronic alarm, LED thermometer, in December of this year.
bookgpiozero
components to Raspberry Pi and and basic robot. Clear wiring magpi.cc/rpicookbook
controlling them, before moving diagrams are provided for each
on to building some more tutorial, along with all the
advanced projects. code needed. GET STARTED WITH
In the first few chapters, MICROPYTHON ON
you’ll learn how to connect RASPBERRY PI PICO
common electronic components, This official guide for
such as LEDs and push-buttons, Pico covers a range of
to Raspberry Pi’s GPIO pins electronics projects for the
and control them with Python microcontroller, as well as
programs. The GPIO Zero Python using the I2C and SPI protocols
library (magpi.cc/gpiozero) and controlling NeoPixel strips
makes it a whole lot easier by with Pico’s Programmable IO.
eliminating a lot of boilerplate magpi.cc/picobook
setup code for the GPIO pins.
Sam
Alder
The in-house illustrator and animator for Raspberry Pi
sets the look for a lot of what you see
Y
ou may have noticed animator for Raspberry Pi.“Or Stimpy, Earthworm Jim, and Rocko’s
that we sometimes have as I like to describe it: I draw Modern Life, and later drawing my
excellent illustrated things and sometimes make own comics and weird artwork.
covers – such as issue 120’s them move - whether they like However, it was never something
robot cover, or even cool it or not,” clarifies Sam. I studied properly at school or
graphics throughout a feature. college. It wasn’t until I got some
If you’ve ever thought they What is your history seriously bad A level results, and
look similar to some official with drawing? was at a loose end as to what to
Raspberry Pi art, you’d be right, Growing up, I was always a do with my life, that my Mum
as they’re also by the excellent massive doodler, first copying my and Step-Dad encouraged me
Sam Alder, illustrator and favourite cartoons like Ren and to sign up to an art foundation
course at my local college. It was
a decision that totally changed
my life.
From there, I went on to study
illustration with animation at
Manchester School of Art and,
after graduating, went on to work
at MTV before starting my own
animation company, with close
friend and collaborator Scott
Lockhart directing music videos
and TV adverts.
The animation from Sam that celebrated ten years of Raspberry Pi: magpi.cc/10yearvid
01
MagPi
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.
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.
Prototyping with cardboard boxes is a
time-honoured tradition
02.
RFID music players are a thing we’ve
seen in the past, and they’re always
pretty great
03.
These infinity mirror goggles on this
hat are ingenious, really making them
stand out from the crowd
04. More folks are making clean train
departure boards, and this one on an 02
e-ink display is great
05. We hope the price of that USB
extension didn’t… sting. We’ll see
ourselves out
06. We do love a good Node-RED project
– using it to light up LEDs is a Dr Lucy
Rogers classic, and it’s great to see it
done with NeoPixels
07. A smart way to maintain the life of this
mini OLED display
08. BirdNET-Pi is used to identify different
bird sounds, so this is a very creative
housing for it
09. Instead of hunting for ghosts, Kevin is
hunting for the optimum WiFi channel,
with a Pico W!
10.
We could absolutely do with this to-do
list some weeks
03
04
05
08
06
07
10
09
13
12
11
11.
Having a slide show display of
different JWST and NASA photos is a
great way to improve your desk
we think
12.
Martin was also able to see the photo
elsewhere a bit more clearly, but this
is great for glancing at
13. If you’re in the UK at the moment,
making sure your paddling pool is
nice and cool is a must
14
14. This Finger LED thing seems to be a
game in the making – check out Dr
Footleg’s Twitter feed for the videos,
they’re very cool
Crowdfund this!
Raspberry Pi projects you can
crowdfund this month
CodeRover EncroPi
This ‘sustainable and programmable robot’ is a great robotics platform
that allows you to build, modify, and program as you wish. It uses a A neat USB data logger and RTC that allows you to
‘core’ that you plug into a Raspberry Pi or a microcontroller and hook up encrypt data on it – and it uses an RP2040 that powers
via jumper cables to the rest of the system. Once that’s done you can Raspberry Pi Pico. It even has a little LCD screen on it
program it with the block-based Code:Bit platform built for the robot. so you can see what time is being kept on the RTC.
magpi.cc/CodeRover magpi.cc/EncroPi
YOUR LETTERS
Your
Letters
More mother clocks Embedded events
[In reply to a tweet about the Pico railway clock from issue 120 - Ed] My I saw that there was a Raspberry Pi presence
old uni had something like this through our building. Someone cut a at Embedded World that I completely missed.
wire somewhere and killed the whole system until it was traced. Are there any other events you’ll be at in the
I thought it received a 1Hz ‘clock’ pulse (you see what I did near future?
there!). The system could send multiple pulses to adjust for summer
time hours. Amy via email
Contact us!
> Twitter @TheMagPi
> Facebook magpi.cc/facebook
> Email [email protected]
This clock needed a pulse to
actually tell the time properly,
> Online forums.raspberrypi.com
provided in this case by Pico
WIN
CROWPI L
BASIC KIT
An amazing laptop body
for your Raspberry Pi,
CrowPi L is the lighter
version of CrowPi2, yet is
still just as useful. It has
a webcam above the
screen, and provides direct
access to specific ports on
Raspberry Pi. We have one
kit to give away.
Competition magpi.cc 95
HELP! MY COMPUTER
IS BROKEN
(How do I fix it?)
R O
Sub Editor
T
Nicola King
RIETH GAMING
ADVERTISING
Charlotte Milligan
[email protected]
+44 (0)7725 368887
DESIGN
criticalmedia.co.uk
Head of Design
Lee Allen
Designers
Olivia Mitchell, Ty Logan,
WICO W
Sam Ribbits, Lee Robinson
Illustrator
CADE
Sam Alder
UTERS, AR
COMP
P
CONTRIBUTORS
BUILD 8-BIT AND HOME CONSOLES
Alasdair Allan, David Crookes,
PJ Evans, Ben Everard, Rosemary
PUBLISHING
Publishing Director
Russell Barnes
[email protected]
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.cc/subscribe
St. John’s Innovation Park, Cowley Road,
Cambridge, CB4 0DS. The publisher,
Build a Magic Mirror editor, and contributors accept no
responsibility in respect of any omissions
Wearing Raspberry Pi
Did you notice that Features Ed Rob Zwetsloot likes to write about
wearables and cosplay? There’s a good reason for that
F
or a very long time, I’ve been to make some great and grand things have much soldering experience.
into dressing up. I vividly for cosplay with Raspberry Pi. My first Despite having done this and helped
remember being 17 and going to foray was some flashing NeoPixels on other pals work on their own cosplay
every charity shop in town looking for a Raspberry Pi Zero for my friend Freya electronics, I still haven’t got around to
specific type of striped trouser I could and her Sans (from video game it myself, despite my previously
wear for an Ace Ventura outfit. It Undertale) cosplay. You can find it at mentioned grand plans.
wasn’t even for a specific or important magpi.cc/neopixeleyes, and it ended
event. It was just fun. up working pretty well. Into action
Fast forward several years, and As you read this, I’ll be in my way to the
suddenly I’m attending comic cons and Bay Area in California for SiliCon with
anime conventions, and seeing a lot of I ’m basically Adam Savage. Raspberry Pi has a booth
people having fun dress up as their there and, as well as showing people
favourite fictional characters, so I join upgrading a Luigi’s Raspberry Pi projects on the stand, I’ll
in. The more I participated and learned
about cosplay, the more I noticed the
Mansion costume to be walking around in a Pico-powered
cosplay. I’m basically upgrading a
creativity and craft behind it – and the
impressive electronics people
be a bit more of Luigi’s Mansion costume to be a bit
more of a spectacle, and I’m really
were installing. a spectacle looking forward to showing it off to you
As the internet, YouTube tutorials, in the next issue, including a tutorial on
and making in general, has blown up how to replicate it!
over the last decade, so too has the Programming NeoPixels has come a It’s really cool how making is
complexity of costumes and props. A long way since then, and is far easier on becoming so much more easier and
friend of mine has 3D-printed a Buster Raspberry Pi Pico. However, I did learn accessible to include in your
Sword from Final Fantasy VII, complete some limitations. Buttons in Python other hobbies.
with glowing Materia orbs from the scripts need to be very carefully
game, something you just wouldn’t see managed to make sure each press is Rob Zwetsloot
AUTHOR