Mag Pi 91
Mag Pi 91
Mag Pi 91
CC/USA
Raspberry Pi 4 Starter
Electronics
2GB upgrade! Create your first circuit
with Raspberry Pi
Base model now 2GB! Still just $35
O f M aking
#Month
t’s build
Le er!
togeth
£5.99
Top 10
magpi.cc/store
WELCOME
to The MagPi 91
T
he MagPi ran its first #MonthOfMaking last March almost on a Lucy
EDITOR
Hattersley
whim. We had lots of cool ideas for projects, and wanted to get on
Lucy is editor of
with them. Then Rob had the bright idea of doing a maker special The MagPi magazine.
all month: a time where we would all commit to getting on with that She’s just discovered
how much her
thing we’d been planning for months. Game Boy Micro is
worth, while holding
It was a rip-roaring success, and we’ve been looking forward to this a screwdriver in
one hand and an
month ever since. So #MonthOfMaking is back (page 32). If you’re Adafruit 1.3-inch
bonnet in the other.
on Twitter, make sure you search for the hashtag (and our other one: Thanks, Twitter.
#MyLatestBuild) and get in touch with other The MagPi makers. magpi.cc
magpi.cc 03
Contents
> Issue 91 > March 2020
Cover Feature
32 #MonthOfMaking
Regulars
06 World of Raspberry Pi
92 Your letters
f M a king
#MonthtO’s build
97 Next Month
98 The Final Word
Le r!
Project Showcases togethe
14 NeoPixel LED Mirror
18 AdventurePi
20 Reachy
22 El Carrillon
26 Bellagio Water Show
28 Raspberry Pine 32
20 14
DISCLAIMER: Some of the tools and techniques shown in The MagPi magazine are dangerous unless used with skill, experience, and appropriate personal protection equipment. While
we attempt to guide the reader, ultimately you are responsible for your own safety and understanding the limits of yourself and your equipment. Children should be supervised. Raspberry
Pi (Trading) Ltd does not accept responsibility for any injuries, damage to equipment, or costs incurred from projects, tutorials or suggestions in The MagPi magazine. Laws and regulations
covering many of the topics in The MagPi magazine are different between countries, and are always subject to change. You are responsible for understanding the requirements in your
jurisdiction and ensuring that you comply with them. Some manufacturers place limits on the use of their hardware which some projects or suggestions in The MagPi magazine may go
beyond. It is your responsibility to understand the manufacturer’s limits.
42 51
Tutorials
42 Raspberry Shake
46 Magic Mirror – part 2
Raspberry Shake Hex-A-Pad – part 2
51 Hex-A-Pad – part 2
74 60 C and GTK cheat sheet
NexDock 2
Starter Electronics
82
Reviews
74 NexDock 2
76 RedBoard+
78 Top 10 wearable projects
80 Learn SQL
Community
82 Ben Nuttall interview
84 This month in Raspberry Pi
Ben Nuttall interview 88 Events calendar
A SIGNED RASPBERRY PI 95
WIN
DESKTOP KIT
THE WORLD OF RASPBERRY PI
Raspberry Pi 4
now comes with
2GB RAM minimum
Say hello to the new entry point for the family: Raspberry Pi 4 comes
with 2GB (and we say farewell to the 1GB model). By Gareth Halfacree
W
hen Raspberry Pi 4 launched, it came
with the family’s first choice of RAM
(random-access memory) capacities:
1GB, 2GB, and 4GB. Thanks to falling RAM
prices, Raspberry Pi 4 with 1GB is being retired;
Raspberry Pi 2GB is now the new entry point to
the family.
The Raspberry P4 with 2GB has had a price
reduction: it now matches the $35 recommended
retail price of the former 1GB model. Entry-level
newcomers get double the amount of RAM at no
T he additional RAM Raspberry Pi 4 with 2GB and 4GB models are identical designs,
makes using Raspberry Pi bar the memory module used, and fully compatible with each
other’s software and accessories
free -h
Interview
with Eben Upton
Eben discusses the retirement of Raspberry Pi 4 with 1GB, and the amazing
growth Raspberry Pi has seen while maintaining its signature $35 price point
W
e moved to 2GB as the entry point pixels on-screen and you’ve got two screens,
for Raspberry Pi 4 because memory and you’ve added dual-band WiFi and Bluetooth
prices have come down, and we can – and your $35 from 2012 is about $40 now,
afford to,” explains Eben Upton, founder of the accounting for inflation, so you’ve kind of got a
Raspberry Pi Foundation. five-dollar real-terms price cut as well.
This market shift has allowed a doubling of the “It was really important to us to keep pushing
RAM without an increase in price. “We couldn’t the envelope in terms of what’s doable – that’s
afford it when we launched Raspberry Pi 4. We’ve the story behind the move to 2GB: trying to make
had to breathe in quite a long way to make it sure we keep pushing forward so we have the
Eben Upton has seen work at $35, but it’s really important because best possible desktop experience at the signature
Raspberry Pi increase that’s what we do. price point. 2GB is a much more viable desktop
in performance by an
order of magnitude “If you look at the past eight years,” Eben platform than 1GB; 1GB is great for embedded,
since the original
launch eight years ago
continues, referring to the original launch but for a desktop platform it’s just a little bit
of Raspberry Pi Model B with its single-core too tight. So what it means is we’re now back to
700MHz processor and just 256MB of RAM, having a really, really viable desktop machine at
“you’ve now got eight times as much memory, our signature price point.”
you’ve got about 40 times as much processing In a world where desktops are frequently
power, about ten times as much input/output equipped with 4GB, 8GB, or even 16GB of RAM,
bandwidth. You’ve got four times as many there’s a reason Raspberry Pi performs so well,
even with just 2GB: frugality. “If you look at
Windows, or even a traditional Linux desktop
distro, there’s been a sort of relaxation,” says
Eben. “As there’s been more memory available,
people have loosened their belts a little bit and
sort of flumped down and started consuming
M
oving to 2GB makes more memory, when we really haven’t. We’re still
Raspberry Pi 4 much using an LXDE-derived desktop environment;
more responsive
during multitasking you know, we care about every 10MB of memory
– running several
usage. That’s the reason why the 2GB model is a
applications at the
same time really, really useful desktop.”
ELECTRONICS Strong 3D
prints
Finding the
settings to make
plastic last
BUILD Raspberry
BETTER Pi Audio
Make your
CIRCUITS
projects sing
PLUS
tor
TESTING
Projeck
mas
COMPONENTS
TOOTHPICKS
CIRCUIT gnition
PYTHON cial reco
Foil fa printing and
D
BELT DRIVES w ith 3
erry Pi
Zero
a Raspb
Offer available in the USA only, subject to change or withdrawal at any time. All payment will be taken in US Dollars. 12-month subscription is for HackSpace
magazine OR The MagPi. Free Raspberry Pi Zero W and accessories with 12-month The MagPi subscription; Free Adafruit Circuit Playground Express with
12-month HackSpace magazine subscription (free gifts are not transferable)
THE WORLD OF RASPBERRY PI
A
Pupils at Kabuku school in Kenya with no prior computing discovered that computing was not part of the
Primary School in
Kenya enjoy weekly experience has won over an initially curriculum there or in neighbouring schools.
Code Club sessions sceptical community, and now runs a The first hurdle was convincing the local
thriving Code Club. community and Kabuku’s headteacher that
The Code Club at Kabuku Primary School, devoting time to computing would be of value,
two hours north of Nairobi, is run by Lena. compared to the practical skills they saw as
Lena works for an education-focused charity, critical to the children’s future prospects. Six
partnered by Code Club in Kenya, called Kids months of presentations and meetings followed.
Comp Camp (kidscompcamp.com). Its aim is to Next, they had to source the hardware
improve digital literacy and computing skills in needed. Kids Comp Camp donated 15 Raspberry
rural parts of the country. Pi 2 computers. Necessity being the mother of
Kids Comp Camp approached the state-run invention, these were connected to monitors
school about setting up a Code Club, having with chicken wire!
With no existing
ttendees have no existing
A computing curriculum,
this stone building
Pi Wars 2020
robots raring to go
Glorious chaos awaits as organisers declare Pi Wars 2020 is going
to be a disaster. Enjoy the show, says Rosie Hattersley
P
Catastrophe and i Wars 2020 is going to be an absolute range of non-destructive battles and challenges.
chaos will proliferate
at this year’s Disaster train wreck – at least that’s the hope Both autonomous and remote-controlled robots
Zone-themed Pi of its organisers, Mike Horne and Tim jostle for victory by completing up to seven
Wars. This is the new
Eco Disaster course Richardson. With a somewhat apocalyptic fiendishly complex tasks.
atmosphere swirling when it came time to
choose a theme, Pi Wars organisers declared the DIY designs
2020 event would have a Disaster Zone theme. Newbies, veterans, and school teams each have
Scarab won the
dedicated competition days, helping to ensure
Beginner’s league
in Pi Wars 2020 F ans of zombie films, everyone has a fair shot of victory. Teams from 17
countries are taking part. Unlike TV’s Robot Wars
dystopia, and event horizons (the original inspiration), there’s no celebrity
version, and each team is expected to design,
rubbed their hands in glee build, and test their own robot. Competitor
entries to this year’s event, held over the final
Fans of zombie films, dystopia, and event weekend of March at the University of Cambridge
horizons rubbed their hands in glee. The most Computer Laboratory, filled up months ago, and
switched-on 76 teams (of the 128 that applied) teams have been blogging about their robot’s
nabbed a place in the three-day competition build progress: magpi.cc/piwars2020blogs.
which sees competitor Raspberry Pi-controlled Spectator tickets are available from
robots pit their skills against each other in a magpi.cc/piwars2020.
www.UniPiCase.com
M
agic mirrors seem to now be a rite of
passage for many makers and Raspberry
Pi aficionados. It’s a fun project, but we
Alex
MAKER
People were taking PCB, 3D-printed and laser-cut several parts, and
selfies of themselves
with their ‘reflection’ connected 24 strips of 24 LEDs to make the magic
576 number. A Raspberry Pi was used to power it
due to its size, ability to run Python and address
all the LEDs, along with the Raspberry Pi Camera
Module which makes it all possible.
This image is then converted to greyscale,
02 after which the code extracts one of the On display
image’s colour planes from the image as an array. With such an unconventional project, you might
This array contains the brightness information for
expect some issues when it was finally unveiled.
each pixel of the extracted 24×24 region. This square
However, it went down very well.
array is then reshaped into a 1×576 vector, and
brightness values are assigned to LEDs. “The project made its debut at the 2019
Cleveland Maker Faire, where it ran for over
eight hours during the event without a single
hiccup,” says Alex. “An advantage of being
able to run everything via Python code is that I
could adjust camera settings on the fly based on
lighting conditions in the location where I was at,
Quick FACTS
> Nearly 600 parts
Diffuser plates are were 3D-printed
required on all the LEDs
– a job for a glue gun or laser-cut for
the mirror
AdventurePi
Zach Levine’s portable arcade project lets you choose
your own AdventurePi, as David Crookes explains
A
s big fans of gaming, Zach Levine and his
brother ended up owning a good number
of video game consoles, including the
Game Boy, Virtual Boy, NES, Nintendo 64, and
Sega Saturn. “But we also frequented the arcade at
the local bowling alley quite often,” Zach tells us,
and this love of coin-operated gaming machines
never left him.
Zach
MAKER
18 magpi.cc AdventurePi
PROJECT SHOWCASE
A cased Raspberry
Pi 3B+ sits on top of
an iMuto 30,000 mAh
portable power bank
AdventurePi magpi.cc 19
PROJECT SHOWCASE
Reachy
Meet the expressive and flexible open-source robot
powered by a Raspberry Pi. David Crookes reaches out
S
ay hello to Reachy – a humanoid robot that Reachy is open-source and developers can
you’re likely to love to bits when you first program it using Python, which opens up the
set eyes on it. Blessed with futuristic styling possibilities of what it can potentially do. Indeed,
and able to carry out many tasks with precision, Pollen Robotics initially created the robot to help
it can interact with the environment and with us researchers study arm-control in humans, but it’s
humans, making for a rather endearing creation. evolved a lot since.
Which part of Reachy you’ll love, however, will “When we started Reachy in 2016, our former
Pierre mostly depend on the configuration you decide to researcher colleagues had wanted to see how an
MAKER
Rouanet buy – assuming you have enough money, given amputee could easily control a prosthetic arm,
that the prices start at €9990. and they needed something that could closely
Pierre Rouanet The basic model, for instance, comes with just reproduce human motion and shape,” Pierre says.
studied human- a torso and one arm, while ‘expressive’ adds a “But we developed new features, including using
robot interaction
and AI for eight
Johnny Five-like head. An advanced option gives machine learning for control. We also wanted to
years in the INRIA Reachy an extra arm, but in each case there’s a fine work on its ease-of-use to extend the range of its
Flowers research heart beating inside: a Raspberry Pi 4 running the potential users.”
lab, where he
Raspbian operating system.
obtained his PhD.
He co-founded We developed new features,
Pollen Robotics to Ideal choice
imagine new
robotic creatures.
According to Pierre Rouanet, co-founder and CTO including using machine
of Reachy creator Pollen Robotics, the decision to
pollen-robotics.com use Raspberry Pi 4 came after much debate. “We learning for control
wanted to provide a simple and well-known setup
with a supportive community that would let our To that end, Pollen Robotics has pre-installed
users quickly understand, adapt, and modify the its own Python API and some extra tools for
basic tool we were providing. Raspberry Pi has communicating with all the motors and sensors via
always been a very good solution for this.” USB-to-serial communication.
“[Raspberry] Pi is actually running the whole
synchronisation loop that retrieves all of the
sensors values, and it publishes new commands
for the effector (it runs at ~100Hz for Reachy,
which is higher than most synchronisation loops
in humans),” says Pierre. “On top of that, we run a
higher-level application.”
Machine learning
Key to the robot is its built-in artificial
Reachy played
tic-tac-toe against intelligence. “We wanted to provide high-end
humans at CES 2020,
running entirely on
and efficient tools for machine learning,” Pierre
Raspberry Pi. Reachy continues. “Our users require lots of power to
would image-analyse
the board, recognise perform analysis from the sensors, such as live
the pawns, and use object recognition and tracking, voice recognition,
simple AI to choose
what to play next. It complex trajectory generation, and so on.”
would use higher- As luck would have it, work on Reachy coincided
level control to grasp
a pawn and place it with the arrival of the Google Coral AI accelerator
20 magpi.cc Reachy
PROJECT SHOWCASE
Quick FACTS
> Reachy is
A 2GB Raspberry Pi 4
designed to be
runs Raspbian and
plug‑and‑play
makes use of an open-
source Python library
> It includes a
microphone
and speaker
and the new USB 3 ports in Raspberry Pi 4. “It was > The innards are
perfect timing,” says Pierre. “We could run all the covered by fabric
machine learning we needed, while still providing
> Google’s Coral
a simple ready-to-use setup and on top of that, we
AI accelerator is
don’t need to rely on a cloud service.”
also inside
Pierre says Reachy currently shines best when
it is manipulating simple objects and interacting > Only a handful are
with humans. As such, it’s primarily intended initially being made
for use in food and customer service, research,
and development. But Pollen Robotics envisages
a lower-cost version for hobbyists at some
stage which would make for a rather exciting
The software, design
development for the Raspberry Pi community. of all 3D parts, and the
data used to pre-train
“This is definitely something that I would like to
Reachy on some tasks
encourage and see emerge,” Pierre says. are all open-source
Reachy magpi.cc 21
PROJECT SHOWCASE
El Carrillon
Tired of hearing the same tune year after year, two
makers hacked the bells of an enormous tower to
ring the changes. Rosie Hattersley hears how
M
ost Raspberry Pi projects we feature debut
privately and with little fanfare – at least
until they’re shared by us.
The El Carrillon project, however, could hardly
have made a more public entrance. In September
2019 it was a focal point of Argentina’s 49th
annual Fiesta Nacional de la Flor (National Flower
Festival), where its newly overhauled bell tower The original circuit board is
proudly rang out a brand-new, Raspberry Pi- now used only for a few GND
connections the team reused
enabled tune.
Many years ago, festival organisers created
custom hardware with a PIC (programmable
interface) microcontroller to control 18 tuned
bells. Each bell is associated with a musical note,
Mariano
MAKER
from A3 to D5 with all the semitones. Until its rung the tune to Ayer, also known as Yesterday
Martinez Peck
& Gerardo long overdue update, the tower’s 18 bells had by The Beatles. They now have a brand-new
Richarte repertoire of MIDI-based tunes, including the
theme from Star Wars.
Buenos Aires-based For Gerardo Richarte, the originator of the
systems engineer project, there was a little extra pressure: his dad
and instantiations
software specialist is on the board of the NGO that organises Fiesta
Mariano enjoys Nacional de la Flor, and challenged his son to come
Raspberry Pi- up with a way to update the bells so different songs
based IoT projects.
could be played.
Gerardo founded
satellite and
geospatial solutions Ringing the changes
company Satellogic.
With the challenge accepted, Mariano Martinez
Raspberry Pi and
Arduino reignited his Peck explains, “We chose Raspberry Pi because
love of electronics. it was inexpensive, yet powerful enough to run
@MartinezPeck The El Carrillon bell tower forms a striking backdrop to the
Linux, Python, and VA Smalltalk. We could find
satellogic.com flower festival and other cultural events ready-made HATs that actually matched the pinout
22 magpi.cc El Carrillon
PROJECT SHOWCASE
El Carrillon magpi.cc 23
PROJECT SHOWCASE
Coding a classic
The decades-old chimes were controlled by
assembly code. This was superseded by Python
when the team made the switch to Raspberry Pi
Zero. Mariano explains, “Raspberry Pi allowed
us to use Python to directly interface with both
the old and new hardware and get the initial
project working.”
However, the Python code was itself replaced
by object-oriented VA Smalltalk code – an
environment both Mariano and Gerardo are
adept at using. Mariano says, “Smalltalk’s live
programming environment works really well for
fast, iterative development and makes software
A MIDI keyboard is connected to the setup, enabling a user to play live and record songs updates quick and easy without the need for
24 magpi.cc El Carrillon
PROJECT SHOWCASE
El Carrillon magpi.cc 25
PROJECT SHOWCASE
W
hen his employer wanted a Las Vegas-
themed float for the local parade, Nick
Rogness was approached by the team for
engineering assistance. “The decision to recreate the
Bellagio water show started out as many good ideas
start… a joke during a brainstorming session!” he
recalls. “I knew it was technically possible in principle
but would require overcoming some challenging
Nick Rogness
MAKER
engineering hurdles.”
Nick works in the
Nick had just 30 days to come up with a technical
Attached to half-inch PVC piping, each 12V DC water solenoid
telecom industry, solution to recreate the water show. “In reality, it
is connected back to the control board by way of a mechanical
but his true passion ended up taking two weekends of assembling the relay, operated by Raspberry Pi
is spending time
hardware and two weekends of writing the software,”
with his family
and taking on he says. which maps high fidelity signals (bass, mid-range,
challenging projects etc.) to particular solenoids or solenoid groups,”
as an avid maker. Pump it up says Nick. “In summary, you just put WAV files in
magpi.cc/bellagio A pump pushes water from a reservoir (children’s a songs directory and start the Python code, which
paddling pool) through PVC piping attached to water did all the heavy lifting in real-time.”
solenoids connected to sprinkler tubing pointed up in One technical challenge was solving the timing
the air. A Raspberry Pi controls the solenoids, creating discrepancy between the solenoid firing water and
the effect of water jetting out in sync with the music the musical note being heard by the audience. “The
being played. water had to be shot out of the jets approximately
“A total of eight solenoids were connected back 600 ms ahead of the audio for the water to appear
to a mechanical relay, which in turn was controlled to be in sync with the music.”
by Raspberry Pi,” says Nick. Seven out of the eight Another issue was safety, as mixing water and
solenoids were connected to brass reducers to fit into electricity can be hazardous. “The power for the
garden sprinkler tubing. The eighth solenoid was system was a 12 V automotive battery,” reveals
a pressure control (relief) valve, which was used to Nick, “so I used fuses to protect things, just as
control back pressure in the system. you would find in a family vehicle. I also tried
“When I wanted to ‘fire’ one of the seven solenoids to keep the dangerous gear out of reach of the
to shoot water, Raspberry Pi would close the pressure general public.”
solenoid,” explains Nick. This built up pressure Everything went well on the day, albeit with
in the PVC pipe, at which time Raspberry Pi would a few bugs: “There were certain sequences of
trigger a relay to open the desired solenoid so a jet of musical notes where the FFT analysis would
water would shoot out. “This was required to get any produce changes too rapidly for the back pressure
distance with very little water. I also didn’t want to and corresponding solenoid firing to produce much
burn out the pump, so the relief valve was open when of a water jetting effect.” The result was a variance
Warning! no other solenoid was open.” in water height from song to song.
Electricity & water “I rode on the float during the parade, so the
Water music public reaction was the most rewarding part of the
Take extra care when
combining electricity The music is synchronised to the solenoid firing by project for me,” he adds. “After people figured
and water in a project: using FFT (fast Fourier transform) analysis performed out what they were looking at, the responses
the two should be kept
well apart! on the audio in real-time. “I wrote a sequencer in ranged from laughter to astonishment. The public
magpi.cc/
Python to perform the analysis and determine which response made my day and all the efforts of the
electricalsafety solenoids to turn on and off, based on a config file team worthwhile!”
A
side view of the finished project on the
back of the float, ready to join the parade
> Software is
available on GitHub:
magpi.cc/ghbws
Raspberry Pine
Think all computers are boring black boxes? You’ve not seen Raspberry
Pine, the desktop computer with a bit of class. PJ Evans gets all fancy
T
o many, a broken laptop would be a source of LCD panel driver board from a UK supplier on eBay.
annoyance and hassle, but not Neil Shepherd, Unfortunately, the only documentation you get is
who saw nothing but opportunity. After a brief from the tiny screen printing on the board itself.”
respite at the bottom of his wardrobe, Neil dismantled The rest of the electronics supply and manage
the laptop looking for useful spares and maybe some power. The main supply is the original PSU brick
inspiration. He hit upon the idea of building a desktop from the donor laptop, providing 19.5 V at 4.5 A.
computer that would fit in with the surrounding Two DFRobot PSU boards are used to drop the 19.5 V
Neil Shepherd furniture, rather than being yet another drab black to 5 V for Raspberry Pi, and 12 V for the LCD driver
MAKER
box. “What do you do with a 17-inch LCD panel? Put a board, enough to power the backlight.
Neil has been frame round it,” he says. “It’s got to be different, so There is also the option of battery power, from
working with wooden… pine to be precise. Add a Raspberry Pi 3B+ three Li-ion cells recovered from another laptop.
computers since
the 1970s. Upon and my love of awful puns gives us Raspberry Pine.” A battery management system (BMS) board sits
retiring, he joining on top of it and ensures the cell charge states are
U3A (University Wood-n’t it be nice balanced. Finally, a charger board provides the
of the Third Age).
The screen is mounted in a custom pine frame and correct constant current and voltage charge profile.
Their electronics
group rekindled stand. The frame is built using strips of small pine
his interest in architrave backed by pine strips, offset to give a
Raspberry Pi.
suitable rebate for the panel to fit and hiding the hat do you do with a
W
border. The side supports are modified pine staircase
spindles. A Perspex sheet is used to mount the
17-inch LCD panel? Put a
electronics and, when powered, the panel backlight
creates a warm glow. Finally, short lengths of foam
frame round it. It’s got to
draft excluder secure the panel sandwiched in
the frame.
be different, so wooden…
The LCD panel has a driver board with HDMI, DVI, pine to be precise
and VGA inputs. This is connected to the project’s
he rear is an exposed
T
collection of controller Raspberry Pi 3B+ by a short HDMI lead, with left- and
board and, of course,
the project’s
right-handed adapters. This caused a headache for A tree-mendous result
Raspberry Pi 3B+ Neil: “I think the biggest challenge was sourcing the The result is a very different take on the classic
desktop project: a computer that would look just as
at home on the bedroom dressing table as it would
in the study. Neil was certainly pleased with the
results, as well as an unplanned effect: “The choice
of raspberry-coloured Perspex as the support
for the electronics produced a pleasant surprise.
When powered on, the LCD backlight gives a
raspberry glow.”
Regarding planned further refinements, he
tells us: “When the Raspberry Pi 4B+ gets the
update to boot from USB, there may be a rebuild
to refine the layout so the SSD doesn’t stick out
the side. Currently, the donor laptop keyboard is
being developed with an Arduino Due and more
pine. There are thoughts of matching mouse
and speakers.”
PROJECT SHOWCASE
Quick FACTS
> The screen is
A salvaged 17-inch
a 2007 HP 17″
LCD screen from a
A real pine frame laptop panel
dead laptop
constructed from standard
parts normally used for > The computer will
skirting and staircases soon be joined by
a pine-encased
keyboard
A matching keyboard,
also from the laptop, is a
work-in-progress
SUBSCRIBE TODAY
FROM ONLY £5
USA
OFFER! Subscriber Benefits
12-ISSUES
NOW $60* FREE Delivery
Get it fast and for FREE
Exclusive Offers
Great gifts, offers, and discounts
Great Savings
Save up to 67% compared to stores
FREE Raspberry Pi
Zero W Starter Kit
WITH YOUR SUBSCRIPTION
Subscribe in print
for 12 months today
and you’ll receive:
Raspberry Pi Zero W
Raspberry Pi
Zero W case with
three covers
USB and HDMI
converter cables
Camera Module
connector
Offer subject to change or
withdrawal at any time
SUBSCRIBE
on app stores
magpi.cc 31
f M aking
#Month O
s build
et’ L er!
togeth
32 magpi.cc #MonthOfMaking
We’re building and sharing
again in the #MonthOfMaking.
Let Rob Zwetsloot show you how
I
f you’re reading this magazine, it’s safe to say you like making
in some way. The hobby has exploded in popularity over the
last few years, thanks in no small part to a burgeoning online
community and the introduction of low-price computing with
Raspberry Pi.
Last year we decided to celebrate making with a month-long online
event called #MonthOfMaking. The idea was simply to get people
to share what they’re making online, whatever it was. Whether
you’re turning on your first LED with code or sending rockets to the
moon, we want to create a space where you can share your proud
achievements. So, let’s get making.
What is #MonthOfMaking?
The #MonthOfMaking is simply an excuse to get people inspired to
make something. And by make, we mean electronics, engineering,
arts, and craft projects. Get your creative powers buzzing and make
something that you can show to the world.
There’s no level of skill threshold to participate either. We like
to think if you’ve been wanting to start to learn, this can be your
jumping-on point. By sharing your builds with the community, you
can learn and grow. Here are some simple rules to sum it all up:
magpi.cc 33
FEATURE
Getting ideas
and inspiration
What do you want to build?
W
e’ve all been there. Sat down at a
work bench or desk, staring at some Tools for the job
components and thinking… what can I Not everyone has a full workshop of tools
make with this? What would I like to make? Like and gizmos, especially if this is your first foray
any other creative pursuit, you’ll need some into making. Check out issue 89 of The MagPi
inspiration. If the projects in the magazine (magpi.cc/89) for our 50 Tips & Tools feature,
which has plenty of tool suggestions.
haven’t inspired you, then here are some
website suggestions…
Project websites
Hackaday
For more serious hacks for more
advanced makers, Hackaday has some
great projects that really take a deep
dive into a project. If you’re curious
as to the limits of electronics and
programming, this may be the place
to look. Equally, if you want to do
something huge with a lot of computer
Instructables power, this should be your first stop. Raspberry Pi Projects
Instructables is one of the oldest sites There are so many amazing things
out there for finding amazing project hackaday.io on the Raspberry Pi Projects site that
guides and ideas, and we’ve been fans can help you with your first steps
of it for years. The best part is you can in just about any field of making.
search by specific project types as well, It’s also home to loads of great and
including Raspberry Pi if you’d like simple home-grown projects that are
to keep it on-brand. They’ve recently perfect for young makers and older
added more arts and crafts stuff if you makers alike.
fancy trying your hand at knitting.
rpf.io/projects
instructables.com
ideas
34 magpi.cc #MonthOfMaking
FEATURE
O2 Order supplies and maker kits and accessories over the years,
Write a list of what you need. Always and stock a lot of Adafruit’s stuff for UK buyers
double‑check you have the component you think as well.
you have. Sometimes you may need to buy from
shop.pimoroni.com
separate places, so just make sure the delivery
times work for you.
Adafruit
A legendary stop for North American makers, not
just for all their excellent products, but also for an
#MonthOfMaking magpi.cc 35
FEATURE
Becoming part
of the community
Makers, Raspberry Pi users, coders, developers,
and more can easily be found online!
Offline communities
B
eing part of a community is an amazing Not really into being online? Raspberry Jams, Code
thing. Getting to make new friends, learn Clubs, and CoderDojos, along with other Raspberry
Pi and maker events, can be found around the
new skills, and be inspired by those around
world! Check out our events calendar on page 88
you is wonderful. Here are some of the places you for more details on upcoming events!
can find Raspberry Pi fans and makers, or get a bit
of help if needed.
Online community
Raspberry Pi forums
The official forums are an incredible
place to go for finding out more info
about Raspberry Pi, or even getting
some help. There’s always a buzz of
activity and a lot of the users are very
friendly. Make use of the forum search
function and you may find the answer to
36 magpi.cc #MonthOfMaking
FEATURE
Getting help
If you need help, there’s plenty available from other makers online
E
ven the greatest makers need help
sometimes – their secret is that they have
found great ways to get support when
they’re stuck. Aside from having the right
friends and the right reputation, there’s no real
secret as to where you can get your help from on
the internet.
Search engines
Your first port of call should always be your
preferred search engine. Whether you want to
know if something is possible (and maybe get a
tutorial for it) or need help with a specific coding
issue, you’re likely to find a solution.
Be careful with your keywords, though – being
specific can help you out a lot, and if you know
the exact wording or phrasing of the issue you’re
searching for, it can make sorting out your
tack Overflow gives
S
problems much quicker. bottom of a problem faster than trying to refine people incentives to
your Google search. answer questions
#MonthOfMaking magpi.cc 37
FEATURE
Sharing
your projects Send it to us!
If you’d prefer to send us your
builds, send us an email to
[email protected] with the
The point of #MonthOfMaking is to share what you’re building! subject line #MonthOfMaking.
38 magpi.cc #MonthOfMaking
FEATURE
O1 List of components
We like to first make sure that people know
it in your tutorial. We suggest putting it at the end
usually. Give folks any other instructions related to
what they need for a project. We’ll list specific the code (i.e. where to put it in the file system, how
components like buttons, add-ons, HATs, etc., to launch it at boot, etc.) and get them to test it if
along with basic components such as wire and they can.
resistors, and sometimes add tools you might
need as well. This gives people an idea if they have
the right stuff to make something.
magpi.cc 39
presents
IN THE PROCESS,
YOU’LL DISCOVER HOW TO:
Set up and use the free Create and texture 3D Make enemies that follow
software you’ll need character models and attack the player
Build a seismograph
with Raspberry Shake
Make an earthquake detector using Raspberry Pi and Shake sensors, then
connect to a global network to get involved in citizen science at its finest
W
e love Raspberry Shake here at This month we’re looking at assembling
The MagPi. This geology project uses a Raspberry Shake and sharing your data with the
powerful geophone sensor attached to a wider Shake community.
Lucy
MAKER
Raspberry Pi to detect earth tremors. You can buy all the parts for Raspberry Shake
Hattersley
The geophone converts ground movement into separately (see the ‘You’ll Need’ info) or pick
Lucy is editor voltage; this analogue signal is then converted up a turnkey system with all the parts included
of The MagPi into a digital read-out (by the Raspberry Shake (shop.raspberryshake.org). You can even buy a
magazine and part-
board) and the data is stored on Raspberry Pi. fully assembled system, but we think that takes
time tinkerer. She
is quite happy just Raspberry Shake is a great project for budding all the fun out of things.
to hang out and do geologists and citizen scientists because it’s
nerd stuff. relatively simple to assemble (although you
magpi.cc do need to be careful to handle and level the
Wire up the geophone
parts correctly).
Once built, it’s low maintenance, sitting in a
01 Start by wiring up the RGI-4.5Hz geophone.
You’ll Need quiet part of your home or office, waiting for the Ours has two wires: grey and blue. Make sure the
earth to move. And all that time, Raspberry Shake wires are twisted and connect the grey cable from
> R
aspberry Pi 2 / 3 is gathering data, which you can investigate using the positive ‘+’ connection on the geophone to the
Model B (or Zero). the new web interface – or you can dive in and ‘+’ pin on the RS1D Raspberry Shake board. Next,
See supported play around with the data directly. connect the blue wire to the ‘-’ connection. Take
models:
We interviewed Branden Christensen, CEO of care not not over-tighten the screws, otherwise
magpi.cc/
shakespecs Raspberry Shake and seismologist, back in 2018 you may damage the wires.
(magpi.cc/shakeinterview). We also did a tutorial
> S
hake RS1D board
magpi.cc/shakers1d
in The MagPi issue 60 (magpi.cc/60).
In the last two years, Raspberry Shake has
Y ou can investigate the
> R
acotech RGI-20DX
geophone
come along leaps-and-bounds and it now has data gathered using the
magpi.cc/ a powerful web interface, app interface, and a
shakesensor thriving international community. We think it’s new web interface
time to revisit Raspberry Shake.
> E
nclosure: laser
Put Raspberry Pi in the enclosure
cutter / 3D
printer files
02 Take the bottom of the enclosure and attach
magpi.cc/ the four shorter stand-offs. Tighten them by hand.
shakeenclosure Place your Raspberry Pi board on top of the four
> S
crews, stand-offs, stand-offs using the holes in the Raspberry Pi.
washers magpi.cc/ On top of three of the holes, you need to place a
shakescrews washer and the longer stand-offs (the hole in the
> m
icroSD card middle has just a washer and screw). Take a look
at the assembled Raspberry Shake (Figure 1) to
> R
aspberry Shake OS
The Racotech RGI-20DX geophone is the heart of the
magpi.cc/shakeos see which one doesn’t need the large stand-off.
Raspberry Shake device. It’s connected to Raspberry Pi
using the Raspberry Shake board Now insert your microSD card. If you bought it
Figure 1
It’s important to keep the device inside The Raspberry Shake board
the enclosure as it prevents interference. connects the geophone to
The geophone is held in place using a Raspberry Pi and converts
clear strap with screws on either side the analogue signal to
digital for data logging
from Raspberry Shake, it will be pre-installed with correct pins. The board connects to the end of the
Raspberry Shake software. Otherwise, flash a card GPIO pins where the microSD card is (leaving those Top Tip
with the image file (magpi.cc/shakeos). pins towards the USB sockets free).
Make sure the Raspberry Shake board orientation DIY tutorials
is correct (the wires to the geophone should be
near to the USB ports). If in doubt, take a close look Raspberry Shake
Attach the geophone sells a turnkey
03 Place the geophone in the hole on the
at the main image above (Figure 1).
Now clip in the sides of the enclosure. Look
system, but if
you’d rather build
bottom of the enclosure with the wires on the top. carefully at the holes in each side: the small hole
everything from
Separate the two wires so there is a gap between is for the microSD card, the medium hole is for the scratch, then
them. Now place the plastic strap on top of the HDMI port and power, and the large hole is for the take a look at its
geophone to hold it in place. Use two washers Ethernet and USB sockets. wide range of
and two screws to fix the clear plastic strap to the The lid of the enclosure has three holes in it, DIY tutorials.
magpi.cc/shakediy
bottom of the enclosure. which will line up with the long stand-offs (from
Step 02). Use three screws to hold the lid in place.
It’s recommended to ensure the Raspberry Pi
Shake is fully enclosed to prevent any wandering
Attach Raspberry Shake
04 Connect the RS1D Raspberry Shake board
of the results.
day, monitoring
Power up
You’ll need to run an Ethernet wire directly from
Raspberry Shake to your router. We used Devolo
07 With Raspberry Shake in position and
DLAN Powerline adapters (devolo.co.uk) to extend connected to your router, use the power adapter
our Ethernet connection across the electrical to turn on Raspberry Pi. A blue light will appear on
wiring. We positioned our Raspberry Shake in the top of the Raspberry Shake board.
conservatory to the rear of our home. You don’t access Raspberry Pi directly with a
According to the makers of Shake: “For best keyboard and screen – instead, it is set up for
results, install your Raspberry Shake on a bare remote connection over your network. Open a web
Raspberry Shake
Earthquake View is
used to track seismic
activity detected by
other users around
the world
Configuring your
Part 02
magic mirror
Last month we built a mini magic mirror. Now it’s time to upscale
and take a tour of the powerful software that drives it
I
n The MagPi #90, we built a simple magic with Raspberry Pi 4’s fancy new graphics support,
mirror using a semi-transparent piece of this is no longer possible. To rotate your display
PJ acrylic and a cheap picture frame. Mounting 90º so it fits your mirror, open a Terminal and
MAKER
cd ~/MagicMirror/modules/default
cd compliments
nano compliments.js
It may be easier to
configure your screen
Look at the various text strings and change
before mounting it in
the mirror them to whatever you like. Save the file and
Figure 1 DOWNLOAD
THE FULL CODE:
> Language: JSON magpi.cc/mm2config
001. modules: [
002. {
003. module: "MMM-DailyPokemon",
004. position: "top_center",
There are many, many modules available for all kinds of 005. config: {
uses. This one shows you a daily Pokémon!
006. updateInterval: 600000,
007. minPoke: 4,
restart MagicMirror2 to see your new messages. 008. maxPoke: 151,
A sample compliments.js file can be seen at 009. grayscale: true,
magpi.cc/mm2compliments. 010. showType: true,
011. language: "en",
012. genera: true,
013. gbaMode: true,
More modules 014. nameSize: 26
10 Great news: you are not restricted to 015. }
the default modules. There are hundreds of 016. },
community-built modules that are free to
download and install. They cover all kinds of
useful information, including stock prices, local nano ~/MagicMirror/config.js
transportation, prayer guides, and even how your
local Minecraft server is holding up. Luckily, a Create a new line after modules: [ and add the
directory of MagicMirror2 modules is maintained code from the Figure 1 listing (or use the download
on the main site’s wiki: magpi.cc/mirrormodules. link for the full, edited config.js file). Make sure
Most modules will require some configuration, you end with a comma. Restart MagicMirror2 and
so make sure you look at the README file and admire your daily Pokémon.
follow the instructions carefully. There’s no
limit to how many modules you can have, bar the
positions available on the screen.
More modules
12 As we’ve already said, there’s a dizzying
array of modules to choose from, and you can
Installing modules
11 Sadly, we don’t have a nice package
even write your own. If you’re in the mood for
customising, here are a few of our favourites.
manager for MagicMirror2, so installing modules You can find all of them, along with installation
tends to involve using Git to fetch the code. For an instructions at magpi.cc/mirrormodules.
example, we’re going to install ‘Daily Pokemon’.
From the Terminal, we’ll go to the modules magpi.cc/mmmstocks
directory, then get the code from GitHub. Every information screen needs a stock
ticker, right?
cd ~/MagicMirror/modules
git clone https://github.com/NolanKingdon/ magpi.cc/mmmwiki
MMM-DailyPokemon Up your knowledge as you get ready to leave the
cd MMM-DailyPokemon house with these random snippets from Wikipedia.
npm install
magpi.cc/mmmukrail
The final command gets all the libraries that the Is your train going to be on time? If you’re in the
module needs to run. Once completed, edit the UK, this module will let you know. Many other
config file: countries have equivalent modules too.
with Hex-A-Pad
Hex-A-Pad is a stylish, capacitive touch sensor for triggering sounds. In this
tutorial we add the ability to record a 16-step sequence, plus a MIDI option
L
ast month we looked at how to make the samples or MIDI messages. The idea being that the
Hex-A-Pad, and we showed you simple software will only be used to set up various modes
Mike
MAKER
software to trigger sound samples. This of operation; after that, all playing is controlled
Cook
month we will look at software that makes better by the Hex-A-Pad itself. On the Hex-A-Pad, there
Veteran magazine use of the LEDs, and allows the recording and are eight touch-sensitive triggers: six on each the
author from the old playback of a 16-step sequence. Not only that, we hexagon’s sides and two in the middle. The sensors
days, writer of the will add a MIDI option and discuss the best way to on the side always trigger notes, and the two in the
Body Build series,
plus co-author of
arrange notes on this box. middle can trigger notes as well, or record and play
Raspberry Pi for back a 16-step sequence. See Figure 1.
Dummies, Raspberry
Pi Projects, and
Raspberry Pi Projects
Software concept
for Dummies.
01 Trigger LEDs
magpi.cc/mikecook
The idea of the software is that it acts as a
control panel to select which bank of sounds the
02 Each of the eight touch sensors has an LED
pad will produce, and which sequence recording associated with it. In the code we presented last
mode to use, along with whether to use sound month, the LEDs turned on when a sensor was
Figure 1
Trigger
Trigger
2 Trigger
2 2 Trigger
Trigger
3 Trigger
3 3
Control LEDs
Control
Control LEDs LEDs
Trigger
Trigger
mode
Trigger
mode mode
Sound playing
Sound Sound
playingplaying
Sound stopped
Sound Sound stopped
stopped
Start Start
Recording
Recording
StartSequence
Recording
Sequence
Step
Sequence
Step Step
Sequence
SequenceSequence
/ Play/ Back
Play Back
/ Play Back
Sequence recorder
Top Tip
touched, triggering a sound, and turned off when
the sensor became untouched. However, we felt
04 Incorporated into the software is a 16-step
a much more pleasing effect would be generated sequence recorder. The current step in indicated
Why pentatonic? if the LED remained on for the duration of the by a virtual LED being lit on a ring. As we need to
sound. This could be done for samples because use the two central touch sensors for playback and
A pentatonic Pygame has a function to check if a sound channel recording, a sequence is only possible in the six-
scale is good
is busy or not, providing you made a note of sample trigger mode. The sequence can be entered
for improvising,
the channel being used when you set the sound in two ways: live recording or single step mode.
as simple runs
of notes sound playing. For MIDI notes, the LEDs are turned off With live recording, once the recording control
good. It has been when the MIDI note off message is sent. has been touched, and the red LED lights next to
independently it, the recording only starts when the first note is
developed in triggered. After that, any notes played are entered
lots of cultures,
into the current sequence step until it has gone
and so lends
Polyphony
itself to world (as
well as Western)
03 Polyphony is the ability to play more than
through every step.
This is the
external speaker
for the project
Here’s our
USB to MIDI
interface lead
A MIDI sound
generator to
make our beats
8 Triggers
Figure 2
Control LEDs Trigger LEDs
6 Triggers
your control. C 11
B
C
1
B C /D ♯ ♭ 10
2 2
3
D
10 2 9 A
2 3
♯
A / B♭ D 2
3
Step sequence
E
06
8 4
G F
allows you to enter as many or few notes into Clock Notation Circle ♯ ♭ Major pentatonic key of C
9 A D/E 3
each sequence step. In this mode, once the record
sensor is touched, each note played is stored in the 0
0
11 1
1
C
2 2
10
D
Top Tip
B
2
4
6 8 4
off message
0
C
Playing a sequence
11 1
07
11 1
C
1
C
B
when touched
B
B
♯ ♭
C can
/ D be in three 10
2 2 2
The sequence playback 3
D 10
D
2
again. This is for
♯ ♭ 2
G/A
states: not playing, playing, and stopping. The E triggering drone
10 8 2 9 A
2 3 2
4
9 A 3
first
♯ two are self-explanatory and the control
D notes or ambient
A / B♭ 2
3 2 pads whose
LED is either green or red. Once the sequence is E
1
F
E
G
8 4 8
2
4
G F sound develops
playing, it will continue to loop round, playing it G F
♯ ♭ 5
and changes over
F /the
G
7 5
7
7 a long cycle.
trigger control again and the LED will turn
♯ yellow/
♭ Major pentatonic key of C Major heptatonic key of C
9 A D/E 3
6
1
C
♯ ♭ 2
G/A E
TUTORIAL
Figure 4 Figure 5 the F♯/G♭ and play just the black notes, we get the
major pentatonic scale of F♯/G♭. One of the most
popular major pentatonic scales is that of C, and
we have used that to choose our notes.
Building a scale
10 The intervals, or distances between the
notes, of a scale are expressed in semitones; there
are twelve semitones in an octave. The notes in
the major pentatonic key of C are C, D, E, G, A,
and back to C, so these can be represented as
intervals or number of semitones between notes as
2 | 2 | 3 | 2 | 3. Figure 3 shows the circular or clock
method of representing scales: each hour position
is one semitone away from the next, so it’s easy
to generate a key by starting at a point and using
the sequence of intervals for the scale you want.
Figure 4 Software orange. This indicates that the sequence will stop Note that the shape made by joining the notes of a
screen for
sample sounds at the end of the current cycle. The use of the pentatonic scale is a pentagon. Starting at any other
LEDs in recording a sequence is shown in Figure 2 note and keeping the same sequence of intervals
Figure 5 Software
screen for sample (previous page), but let us assure you that this just rotates this figure and changes the key.
sounds and
MIDI output looks far more complicated than it is: in real use,
these controls quickly become natural.
The software
11 We have written two pieces of software
Choosing notes
08 If you are using the Hex-A-Pad for just
for driving the Hex-A-Pad: one that handles
only sound samples and the other that includes
percussion, then you will not have the problem of MIDI note generation as well. The screen
choosing which six notes to trigger. However, if displays of each are shown in Figures 4 and 5.
you do want to produce tunes, you have to pick the The sound-sample-only version is shown in the
notes and a key. In Western music this is normally hexapadsamples.py listing, and both are available
a heptatonic scale, i.e. an octave is split up into on our GitHub pages. They run under the Pygame
seven notes. We normally think of there being framework, and require the MPR121 touch sensor
eight notes in an octave, but the first note and library we used in last month's code.
last note are the same note, just an octave apart.
However, the six triggers on the Hex-A-Pad are
ideal for another type of scale: a pentatonic scale.
Customisation
T his looks far more complicated than it 12 Changing the sound samples and MIDI
mapping is the most useful way in which you
is: in real use, these controls quickly can customise the instrument. Samples should
be added to the sounds directory, and their new
become natural names included in the declaration of the sound
banks. Similarly for MIDI, the note and velocity
Pentatonic scales
09 With a pentatonic scale, the octave is split
values are in the declaration of the five mMap
lists, with the different instrument names and
into five notes; having the first and last notes the program change numbers in the mInstName and
same but an octave apart gives us six notes in a mInst lists respectively. You can explore different
scale. The first, or root note, of any scale gives it its sounds and scales. The use of MIDI requires you
key name. A simple example of a pentatonic scale have a USB-to-MIDI interface cable and a MIDI
is all the black notes on a piano; if we start with sound generator.
DOWNLOAD
hexapadsamples.py THE FULL CODE:
> Language: Python magpi.cc/pibakery
hexapadsamples.py
> Language: Python
109. def updateTrigger(i,on): 163. drawWords("8 triggers", 36, 340, black, backCol)
110. if i < 6 : col = (0,97,255) 164. drawWords("6 triggers", 240, 340, black, backCol)
111. else : col = (255, 222, 0) 165. drawWords("Record Step", 36, 370, black, backCol)
112. if on : 166. drawWords("Record Live", 240, 370, black, backCol)
113. pygame.draw.circle(screen, col, dLED[i], 4, 0) 167. drawWords("BPM Playback", 36, 400, black, backCol)
114. else : 168. drawWords("X10", 305, 400, black, backCol)
115. pygame.draw.circle(screen, black, 169. drawWords("Bank 1", 36, 430, black, backCol)
116. dLED[i], 4, 0) 170. drawWords("Bank 2", 36, 460, black, backCol)
117. pygame.display.update() 171. drawWords("Bank 3", 36, 490, black, backCol)
118. 172. controlLEDs(0, 2) ; controlLEDs(1, 2)
119. def updateChoices(): 173. updateChoices()
120. for i in range(0, len(choices)) : 174.
121. pygame.draw.rect(screen, backCol, 175. def updateStep(s) :
122. choiceRect[i], 0) 176. s = (s - 3) & 15
123. pygame.draw.rect(screen, black, 177. scol = (0, 0, 255)
124. choiceRect[i], 1) 178. pygame.draw.circle(screen, scol, sLED[s], 8, 0)
125. if choices[i] : 179. s -= 1
126. screen.blit(yes, (choiceRect[i].left, 180. if s < 0 : s = 15
127. choiceRect[i].top)) 181. pygame.draw.circle(screen, black, sLED[s], 8, 0)
128. else : 182. pygame.display.update()
129. screen.blit(no, (choiceRect[i].left, 183.
130. choiceRect[i].top)) 184. def drawWords(words,x,y,col,backCol) :
131. for i in range(0,len(incRect)) : 185. textSurface = font.render(words, True,
132. pygame.draw.rect(screen, backCol, 186. col, backCol)
133. incRect[i], 0) 187. textRect = textSurface.get_rect()
134. pygame.draw.rect(screen, black, 188. textRect.left = x # right for align right
135. incRect[i], 1) 189. textRect.top = y
136. if i & 1 : 190. screen.blit(textSurface, textRect)
137. screen.blit(minus, (incRect[i].left, 191. return textRect
138. incRect[i].top)) 192.
139. else : 193. def init():
140. screen.blit(plus, (incRect[i].left, 194. global i2c, cap, capSenseNew, LEDs, sounds
141. incRect[i].top)) 195. global pygame, soundNames, playing, contPlay
142. 196. global pad, sWide, sHigh, screen, backCol, seqNotes
143. pygame.draw.rect(screen, backCol, ((188, 400), 197. global padCo, dLED, sLED, black, font, ccol
144. (32, 16)), 0) 198. global choiceRect, yes, no, choices, incRect
145. drawWords(str(bpm), 190, 400, black, backCol) 199. global plus, minus, bpm, stepTime, playback
146. pygame.display.update() 200. global nextStep, recording, stepCount, savePos
147. 201. global bank, recordedBank, stopping
148. def drawFixed() : 202. i2c = busio.I2C(board.SCL, board.SDA)
149. screen.fill(backCol) 203. cap = adafruit_mpr121.MPR121(i2c)
150. pygame.draw.circle(screen, (138, 229, 229), 204. capSenseNew = io.DigitalInOut(board.D4)
151. (sWide // 2, padCo[1] + 113), 149, 0) 205. capSenseNew.direction = io.Direction.INPUT
152. pygame.draw.circle(screen, backCol, (sWide // 2, 206. capSenseNew.pull = io.Pull.UP
153. padCo[1] + 113), 127, 0) 207. LEDs = []
154. screen.blit(pad,padCo) 208. LEDpin = [board.D17, board.D18, board.D27,
155. for i in range(0,8) : 209. board.D22, board.D23, board.D24]
156. pygame.draw.circle(screen, black, 210. for i in range(0, len(LEDpin)):
157. dLED[i], 4, 0) 211. led = io.DigitalInOut(LEDpin[i])
158. for i in range(0,16) : 212. led.direction = io.Direction.OUTPUT
159. pygame.draw.circle(screen, black, 213. LEDs.append(led)
160. sLED[i], 8, 0) 214. cap.reset()
161. pygame.draw.circle(screen, (0, 0, 255), 215. i2c.scan() # this is needed
162. sLED[12], 8, 0) 216. # Initialise Pygame system
hexapadsamples.py
> Language: Python
200 PAGES OF
RASPBERRY PI
Use Raspberry Pi 4 as a desktop
PC and 4K home media centre
Be inspired by incredible
projects made by other people
C programming
Part 11
quick reference
Make use of these handy cheat sheets
In all loops, the keyword break can be used to exit Format Specifiers
the loop and resume execution immediately after
the loop. In all loops, the keyword continue can be Specifier Format / type
used to skip code remaining in the body of the loop
and resume execution at the next iteration of the %c Alphanumeric character / char
loop test.
%d Signed decimal value / int
Variable Types
%ld Signed decimal value / long int
Name Description Size
(bytes)
%u Unsigned decimal value / int
Single
char alphanumeric 1 %lu Unsigned decimal value / long int
character
%o Octal value / int
Signed 8-bit
signed char 1
integer (-128 – 127)
%lo Octal value / long int
Unsigned 8-bit
unsigned char 1
integer (0 – 255) %x, %X Hexadecimal value / int 1
Unsigned 32-bit
unsigned int integer (0 – 4 The width (or minimum number of characters
4294967295) printed) can be set by inserting a number between
the % and the letter; this will pad a value shorter
Signed 32-
than this with spaces at the start. To pad with
long, signed bit integer
4 spaces at the end, insert a – between the % and
long (-2147483648 –
the number. To pad with leading zeroes, insert a 0
2147483647)
between the % and the number.
Unsigned 32-bit For example, to print an integer variable with
unsigned long integer (0 – 4 the value 42, using the format specifier "%5d" will
4294967295) print 42 with three spaces before it. The format
specifier "%-5d" will print 42 with three spaces
Floating-point
after it. The format specifier "%05d" will print it
float value (+/- 3.402823 4
was 00042.
× 1038)
The number of decimal places shown for a
Double-precision floating-point or exponential value can be set by
double floating-point 8 inserting a decimal point followed by a number
value (+/- 10308) between the % and the letter; this can be combined
with a width by putting the width before the
decimal point.
Depending on platform, int can be either a short int For example, to print a floating-point variable
(16 bits) or a long int (32 bits); on Raspbian, as per with the value 76.54321, using the format specifier
the table above, int is a long (32-bit) integer value. "%.2f" will print it as 76.54. The format specifier
a + b Addition a -= b Decrement a by b
a - b Subtraction a *= b Multiply a by b
a * b Multiplication
a /= b Divide a by b
a / b Division a = remainder of a / b
a %= b
a % b Modulo (remainder of a / b)
a &= b Bitwise AND a with b
a & b Bitwise AND
a |= b Bitwise OR a with b
a | b Bitwise OR
~a Bitwise 1’s complement 2. The difference between a++ and ++a is that if they are used in a test,
such as if (a++), a++ tests the value and then increments it, while ++a
increments the value first and then tests the incremented value.
!a Logical NOT
Symbol Function
Symbol Function
== Is equal to
a++ Increment a by one 2
!= Is not equal to
Starter
Electronics
WITH RASPBERRY PI
If you bought a Raspberry Pi to learn how to make electronic gizmos,
you’re in for a treat. Here are some tips to get started. By Mark Vanstone
O
ver the past few years, Raspberry Pi connect electronics to a Raspberry Pi, you can use
has gone from a small experimental the same techniques to start inventing your own
computer to a very capable all-round gadgets and electronic tools. If these are your first
system, while still retaining its small footprint. steps into electronics, you have a very exciting
It has embedded itself in the hearts and minds journey ahead.
of makers, coders, educators, inventors, and
electro-artists around the world. Its flexibility Expand and experiment
and computing power now makes it the In the early days of home computers, most
What go-to platform for embedded systems models had expansion ports of one sort or
You’ll Need (like smart devices) and workhorse another and, very often, upgrading them
tasks such as controlling other network involved opening up the case and soldering new
If you are lucky
enough to have a systems or even robotics. The range of circuits, or at least plugging in chips into empty
local electronics or tasks Raspberry Pi can achieve becomes slots. These days, you are lucky if your home
hobby store, you will wider all the time as the community computer has USB connectors for accessories,
no doubt be able to creates new ways to use it. and plugging in home-made contraptions is
find all the electronic definitely not recommended.
components we will
talk about for a few
Gateway to the new frontier Raspberry Pi is different because its design
pounds, dollars, or
Raspberry Pi has made a huge impact, encourages the owner to plug in extra devices
euros. Failing that, not only on computer science education and even experiment with your own prototype
there are many fully but also in the realm of makers and circuits. Raspberry Pi has standard USB and
stocked online outlets inventors. As well as being a really Ethernet ports, a camera connector, WiFi, and
that can provide good-value computer, it gives the owner HDMI video output. But the crowning glory of
them. All you will
endless possibilities of connecting connectivity is its GPIO (general-purpose input/
need to start with
other electronics to it to produce useful output) 40-pin header, which provides the
is a breadboard,
some jumper leads, gadgets and impressive demonstrations. tinkerer with access to the inner workings
a resistor (200 Ω to Raspberry Pi is your gateway to the of Raspberry Pi. You can even write
470 Ω), and an LED. new frontier of creative technology. code to control electronics that are
If you can master the basics of how to plugged in to the GPIO pins.
GPIO pins
You can use Raspberry Pi’s GPIO
pins to pass electrical voltage to and
from other components. Some of the
pins have specific uses, such as power
or ground connections, and others can be
configured with software programs to send
signals between Raspberry Pi and the rest of
the circuit. Above is a breakdown of all the pins.
Look carefully at physical pins 1 and 6: these will
be the pins we use in our LED circuit later. Note
that the pin numbers aren’t the same as the GPIO
numbers; for example, GPIO 2 is actually physical pin 3.
Breadboards
Breadboards come in several different sizes and
are made of plastic with a matrix of holes. In
each hole is a connector which joins it to other
holes on the same row.
The larger breadboards have two long rows of
holes at the top and bottom. Sometimes called
‘rails’, these are generally used for power and
ground connections. They are connected together
as indicated on the diagram above.
The inner part of the breadboard has two
sections of holes. Each section has rows of five
holes which are connected as indicated on the
diagram. The two halves of the breadboard are a
mirror image of each other.
The break along the centre of the breadboard,
often known as the ‘gutter’, enables mounting
of integrated circuits (chips) with the legs of the
Breadboards come in several sizes
chip going either side of the break.
to enable prototyping of a wide
See magpi.cc/breadboard for more info. variety of projects
Everything can be
found in the CamJam
EduKit #1 (£5)
magpi.cc/edukit
Basic prototyping
components
Jumper leads Switch
These connect your components to the Raspberry Switches make and break circuits. When
Pi. They can either have male or female end connected in series in a circuit, a switch will
connectors (you need female for the GPIO pins) allow or stop the flow of electricity. You can get
and it’s a good idea to have a mix of both. switches that stay in the position in which they
are set, or ones that you need to keep your finger
on to keep the circuit connected.
LED
Light-emitting diodes come in various
colours. They glow when electricity Speaker
flows through them. Because they Speakers can be huge and very loud or they can be
are a diode, the current will only very small – small enough to fit on a breadboard.
flow in one direction, so make sure These small speakers are called piezoelectric and
that it is connected the right way round: are great for making robotic noises, but not much
the longer leg is the positive one and good for hi-fi music applications.
should be connected to the power (or GPIO output)
pin. Always use a resistor in series with LEDs,
otherwise they are likely to draw more current
than they can handle and burn out. Capacitor
Capacitors store and release electrical
charge. They can be used to even
out the electrical current or provide
Resistor a greater flow for a short time. Be
Resistors are available in various formats, but careful when using capacitors, as
this is the most common format for prototyping. they can still hold charge after the circuit has
The coloured rings around the resistor been disconnected.
indicate how much resistance it
provides. For more details
about how to read resistor
values, see magpi.cc/64. Transistor
Transistors are used in many types of circuits.
They can be used either as an amplifier, which
means that a small current goes in but a bigger
current comes out, or as an electrical switch
to change the amount of electricity
flowing through circuit. A
transistor has three legs or
connectors: the emitter, the
collector, and the base.
Servo
Servos are used a lot in robotics for making
things move. They can be connected directly to
A small piezoelectric speaker is good for
making simple noises Raspberry Pi via the GPIO pins, but there are also
Prototyping
A servo is a special type of motor that allows for precise
control of its rotational (or linear) position
Batteries
Batteries can be all kinds of shapes and sizes, but
for simple electronics projects you will normally
be using 1.5 V AA or AAA type cylindrical batteries
or 9 V square ones. Make sure you always have CamJam EduKits
some spares or perhaps you may want to use There are currently three CamJam EduKits
rechargeable ones. Rechargeable batteries cost available: a starter kit with all the components
more, but can be used over and over. Make sure and more to make our LED circuit, a sensors kit to
you connect batteries correctly and never directly explore getting input from the world around you,
connect the two contacts together, as even small and a robotics kit with wheels and motors to make
voltage batteries can get very hot or even explode your Raspberry Pi into a robot.
if ‘short-circuited’. magpi.cc/camjamkits
A potentiometer
produces an
analogue output
Elecrow CrowPi Educational Kit
that may be This is the daddy of all-in-one
converted to experimentation kits. There are
digital by an ADC
chips and sensors, dials, speakers,
numeric displays, and even a 7-inch
HDMI touchscreen. It was developed with a
Kickstarter appeal and is available directly from
Elecrow in the US, or Amazon in the UK.
magpi.cc/crowpi
Getting started
with electronics:
LEDs and switches
Simon Use Raspberry Pi's GPIO pins to buid two simple
MAKER
Monk
electronic projects. By Simon Monk
Simon divides
his time between
I
writing and
n this tutorial, you will learn how to make Running Mu ensures that the mu_code
designing products
for MonkMakes two simple projects that use LEDs and push- directory is created, into which we will now copy
Ltd. Some of his button switches that are controlled by a the program code. To do this, open a Terminal
better-known books
Python program running on your Raspberry window and run the commands:
include Programming
Raspberry Pi (TAB) Pi. The first project uses an RGB (red, green,
and The Raspberry Pi blue) LED to interface to the popular Cheerlights wget http://monkmakes.com/downloads/pb1.sh
Cookbook (O’Reilly). project. Cheerlights (cheerlights.com) allows sh pb1.sh
simonmonk.org users all over the internet to set each other’s LEDs
to different colours just by tweeting. This will copy the programs used in this tutorial
The second project is a reaction timer using into the mu_code directory, along with some
LEDs and push-buttons to test the speed of other programs.
your reactions.
You’ll Need
ush the component legs
P
Set up some Cheerlights
> The Mu
Python editor into the breadboard at the
codewith.mu
> Solderless 01 Install the code positions shown
breadboard Before fetching the code from the internet,
Place components
> 5 × female-to-male
jumper wires
you should run Mu, which you will find in the
Programming section of your main menu. If it’s
02 onto breadboard
not there, update your system to the latest version Using Figure 1 as a reference, push the component
> Male-to-male
of Raspbian (magpi.cc/raspbianupdate). legs into the breadboard at the positions shown.
jumper wire
Bend the resistor legs so that they fit into the holes.
> 2 × red LEDs Each hole in a row of five holes on the
> RGB common breadboard is connected together under the
cathode LED plastic. So, its very important to get the right row
> 3 × 470 Ω resistors for your component leg.
The resistors can go either way around, but the
> 2 × tactile
RGB LED must go the right way around, with its
push-buttons
longest leg to row 2 (the one without a resistor).
The push-button used in the MonkMakes kit has
These components
just two legs, but many similar buttons have four
are all included in a
MonkMakes kit: legs. If you have a four-legged version, put it on
magpi.cc/pibox1
Figure 1 The Cheerlights wiring diagram the breadboard in the orientation that leaves
to a Raspberry Pi
and pins on the other are used to connect
the GPIO (general-purpose input/output)
pins of Raspberry Pi to the breadboard
just one free row between the pins. You will also
need to place a linking male-to-male jumper wire
between rows 2 and 10.
Connect breadboard
03 to Raspberry Pi
Again, using Figure 1 as a reference, connect the
GPIO pins on the Raspberry Pi to the breadboard.
A GPIO template will make this easier – if you
Your programs can tell that a switch has been
don’t have one, you will need to carefully count
pressed by connecting a switch to a GPIO pin
the pin positions. It doesn’t matter what colour
and reading that GPIO pin as an input
jumper leads you use, but if you stick to the
colours used in the diagram, it’s easier to check
that your wiring is correct.
Tweet a new colour
05 Now that your Raspberry Pi is looking out
for changes to the Cheerlights colour, anyone can
Running the program
04 To use this project, your Raspberry Pi must
simply send a tweet mentioning @cheerlights
and the name of a colour; your LED should then
be connected to the internet. Load and run the change to that colour. You can test this out by
program 04_cheerlights.py using Mu. After a few sending a tweet such as ‘@cheerlights red’ and
seconds, the LED will automatically set itself to after a few seconds your LED should change
the current Cheerlights colour, checking every ten colour. You will find that after a few minutes, the
seconds. Pressing the button will turn the LED off colour probably changes as someone else sets the
until the Cheerlights colour changes. Cheerlights colour.
04_cheerlights.py DOWNLOAD
THE FULL CODE:
> Language: Python 3 magpi.cc/pibox1git
07_reactions.py
> Language: Python 3
NexDock 2 is a laptop
dock that acts as a
keyboard, mouse, and
screen for Raspberry Pi
(and Android phones)
SPECS
DIMENSIONS:
NexDock 2
317×215×15.9 mm
WEIGHT:
1420 g
DISPLAY:
13.3-inch
IPS screen,
1920×1080 FHD
resolution, 16:9 NexDock nexdock.com £226 / $259
aspect ratio
BATTERY:
51 Wh, 7.6 V, This laptop dock could be just the portable Raspberry Pi
6800 mAh
solution we’ve been looking for. By Lucy Hattersley
INPUT PORTS:
1 × USB-C
N
3.1 with
DisplayPort, exDock 2 is a laptop dock, or ‘lapdock’ as full-sized backlit keyboard is equally impressive,
1 × HDMI-in some folks have taken to calling them. with responsive chiclet-style keys that are suitably
(1.4a) port These devices are few and far between, but clicky. Typing is a breeze.
compatible ones have considerable charm and The whole thing is set off in a grey and black
PORTS:
1 × USB-C PD value for Raspberry Pi users. style that’s far more professional than its price
Charging Port, Laptop docks are primarily designed to extend tag warrants.
1 × USB-C 3.0, Android phones into working laptops. However, And we’re trying hard to ignore the unfortunate
1 × USB-A 3.0, 1
plug your Raspberry Pi 4 into NexDock 2 and bulge in the plastic hinge above our F2 key.
× 3.5 mm audio,
1 × microSDXC you get a fully-functioning Raspberry Pi laptop. Perhaps we got an early run that slid through
reader Raspberry Pi provides the brains; NexDock 2 is the the checks.
keyboard, mouse, and screen.
AUDIO: And what a lovely screen it is: the 13.3-inch IPS Battery life
4 × 1 W
speakers 1920×1080 display is a delight to look at, even if the Inside NexDock 2 sits a 51 Wh battery that provides
chunky borders are a bit retro. The edge-to-edge power to the screen and keyboard and Raspberry
74 magpi.cc NexDock 2
REVIEW
There is a lot of
Pi. We ran our fully charged unit with Raspberry xinput --set-prop "SINO WEALTH USB KEYBOARD
cabling involved
Pi 4 playing YouTube videos from 10:10 to 15:22, Mouse" "Device Enabled" 0 when using
NexDock 2 with
just over five hours of solid playback. Raspberry Pi as
A supplied 60 W USB-C adapter is used To re-enable the trackpad: a laptop
for charging.
xinput --set-prop "SINO WEALTH USB KEYBOARD
Plugging in Mouse" "Device Enabled" 1
In the box is an HDMI cable with a micro-HDMI to
HDMI adapter for Raspberry Pi 4. The lack of hardware and software integration
Meanwhile, a USB-C cable splits out to USB-A
and micro-USB (for power and keyboard/mouse
soon becomes apparent. Closing the screen shuts
off the power to the display, but not immediately Verdict
connection). That’s a lot of cabling compared to a to Raspberry Pi, which carries on running for a
An incredibly
regular laptop. The nest of cables is an issue. short time until the power is yanked. We took to
useful, yet far from
We managed to bend the connection on the using shutdown -h now when done and removing
perfect, solution to
HDMI-to-micro-HDMI adapter, and replaced it all the cables. using Raspberry Pi
with the white extension cable (pictured above). Be on the move.
sure to disconnect everything when you pack up. Digital nomad Despite its flaws,
Using Raspberry Pi with NexDock 2 as your it is, by far, the
Achilles’ trackpad go‑to laptop is stretching credibility. The finicky best solution we
have found to
The weakest link is the trackpad. There’s no trackpad, nest of wires and dongles, and lack of
this particularly
thumb rejection – so as you type, the cursor jumps creature comforts will drive you round the bend.
8
thorny problem.
around the screen. And if you use a thumb to However, NexDock 2 is ideal for users who
click, the cursor jumps from the clicked point. need to power up a Raspberry Pi at an event. We
/10
Our solution is to attach a USB mouse and imagine Pi Jam-goers and folks at Pi Wars will find
disable the trackpad with xinput: NexDock 2 a very handy device to have around.
NexDock 2 magpi.cc 75
REVIEW
RedBoard+
Red Robotics redrobotics.co.uk £31 / $40
SPECS
MOTOR
CONTROL:
A feature-packed robotics board with the ability
2 × 6 amp
H-bridges with
to drive powerful motors. By Phil King
fully proportional
W
speed control
CONNECTIONS:
hile there’s no shortage of robotics
controller boards available for
T he input voltage for
13 × GPIO (plus
power and
Raspberry Pi, this one has two external power is 7 V to
ground), 4 × I2C, main selling points. Firstly, it boasts two really
3 × analogue
inputs, 10-pin
powerful motor drivers. Secondly, an astonishing 24 V, so you have a wide
number of features are crammed onto this full‑size
useful header
board – it seems its designer (Neil Lambeth of Red range of options
POWER: Robotics) has thought of everything you might
7 V – 24 V battery need for a robotics project. Motors are connected via screw terminals, as
input, with is your external power source. The input voltage
reverse polarity
protection
Serious power for this is 7 V to 24 V, so you have a wide range of
Two on-board H-bridges provide up to 6 A of options, from AA battery packs to LiPo cells – LiPo
FEATURES: continuous current per channel to two motors, or is recommended for driving big motors. For a good
Four-channel two sets of motors, with fully proportional speed example of the kind of power it can deliver, with
ADC, four-
control. While there’s no facility to independently the right motors, check out Neil’s test-drive of his
channel 5 V
level shifter, control four motors, as on the ZeroBorg for example, four-wheeled robot zipping around a lawn at great
power switch, this won’t be a deal-breaker for most robot builders. speed: magpi.cc/redboardtest.
programmable
button, optional
daughterboard,
and OLED
A
demo showcasing
the RedBoard+’s
multifunctionality with
twelve servos, NeoPixels,
and motors connected
76 magpi.cc RedBoard+
REVIEW
A cornucopia of
connectivity, the
RedBoard+ has multiple
breakout headers,
including 5 V outputs
and analogue inputs
The external battery also powers your Raspberry The RedBoard+ also features a three-pin header
Pi, RedBoard+’s on-board BEC delivering a steady for analogue inputs (up to 3.3 V) using the on-board
5.2 V at 3 A, which is enough for a Raspberry Pi 4. TI ADS101x four-channel ADC – its other channel is
One nice touch is the inclusion of a power switch dedicated to LiPo battery voltage monitoring.
to turn the battery power on and off. There’s also That’s not all! The board includes a header for
a user-programmable push-button: by default it’s four I2C channels, plus a ten-pin ‘useful header’
set to reboot Raspberry Pi with a medium press, which breaks out I2C, Rx/Tx, 3.3 V/5 V power, and
and shut it down with a longer press. A short press ground pins – this can be used with an optional
will cause an on-board RGB LED to flash repeatedly daughterboard and mini OLED to show battery
in red, green, blue to show the last number in the
IP address – handy for SSHing in.
stats, IP address, etc.
Verdict
Software With its powerful
Servo central Controlling everything is made easy using the motor drivers
The RedBoard+ offers an impressive range of Python software library – if you don’t want to and huge range
connectivity options. The main header breaks out install it manually, there’s even a preconfigured of connections
13 GPIO pins (including SPI, GPIO 7–11), with power Raspbian image available. Plentiful code examples for servos and
and ground for each, so you can connect numerous – including controlling various functions with a electronics, we
can see this
servos and/or other electronics. Making use of an wireless gamepad – should help you get started,
becoming a
on-board voltage level shifter, four of the sets of along with the detailed instructions on GitHub.
favourite board
pins offer 5 V power, while the GPIO 12 pin can be While RedBoard+ is probably overkill if you used in events
used to control NeoPixels with PWM. just want to drive a couple of standard low- like Pi Wars.
10
If you want to use larger 7.4 V robot servos, power motors, it’s an amazing feature-packed
there’s an option to connect a separate power board. To get an idea of what it can really do,
/10
supply via two screw terminals, although this does check out Neil’s demo video showcasing the
set all the main header power pins to 7.4V. multifunctionality: magpi.cc/redboarddemo.
RedBoard+ magpi.cc 77
REVIEW
10 Best:
Raspberry Pi
wearable 3D-printed spy cam bowtie
C
ommercial wearable computing has come a
long way in the last decade. Google Glass was
a thing, virtual reality headsets are still a thing,
while watches can be used just as they were in Dick
Tracy and Power Rangers. With the help of a Raspberry
Pi, you can go far beyond commercially available
products and make your own amazing things.
Impressively classic
Is having Windows 98 on your wrist useful? Probably not, but being able to
build a device that allows it is very cool and quite funny.
magpi.cc/w98watch
DIY Glass
Iron Man Arc Reactor
Augment your reality
No scraps required
While perhaps a little more bulky
Want to make your Iron Man suit really stand out, without than the old Google Glass, this DIY
spending your life savings on a fully articulated suit? Check out version is much cheaper and you can
how to make an Arc Reactor. still actually make/get one!
magpi.cc/arcreactor magpi.cc/diyglass
Raspberry Pi
jacket
Wearable-optimised LEDs
This project uses FLORA, a sewable
bit of IoT tech that can interact with
a Raspberry Pi. Learn how to control
it and add it to a jacket or coat!
VIDEOBLAST_R magpi.cc/pijacket
Handheld projector
Designed to give the user ultimate artistic freedom, it features projection
Social Media
mapping tech and can hold up to eight audovisual pieces that you can project without the Internet
whenever you wish.
Apocalyptic wearable
Recreate the famous wrist computer
from the Fallout game series – it’s a
pretty popular and amazing project!
magpi.cc/pipboy3000
Light-up costuming
Using NeoPixels with a Raspberry
Pi is simpler than some folks
make it out to be. Try out the
easy way with our tutorial, and
soup up your cosplay.
magpi.cc/neopixeleyes
magpi.cc/zerocam
SQLite
SQLite Tutorial
CREATOR
THE DEFINITIVE GUIDE TO SQLITE MYSQL FOR PYTHON MONGODB AND PYTHON
Grant Allen and Michael Owen’s book on Python being the preferred choice of Like the aforementioned MySQL for Python
SQLite is a comprehensive look at this ‘micro’ language of the Raspberry Pi Foundation, book, this one gets right to the point. It
database. Despite its small footprint, the this book is a perfect introduction to using uses the ‘recipe’ format, so you can find
authors reveal an incredibly powerful engine Python’s MySQL wrappers. The book is a close match for the problem you want
and some surprising applications including formatted as a series of tutorials that to solve, and see how using MongoDB
embedded systems. increase with complexity. can help.
magpi.cc/sqllitedef magpi.cc/mysqlpython magpi.cc/mongodbpython
MariaDB/MySQL
MariaDB
CREATOR
Price:
Free
mariadb.com
Udemy
courses
Learn online and
interactively with
The next logical step from Raspberry Pi hardware. Once these courses
SQLite is to move to a full installed, you’ve more to think
relational database server. about than with SQLite, such
A popular choice is MariaDB, as users and permissions.
an open-source project based Thankfully, MariaDB offers
on, and fully compatible with, online courses for free at
MySQL. MySQL is probably one magpi.cc/mariadbtraining – a
of the most popular database nicer way to learn than ploughing INTRO TO SQLITE
servers of all time. Both through dry documentation. This DATABASES FOR PYTHON
variants are free, but MariaDB is a powerful platform: it can PROGRAMMING
boasts a new ‘engine’ that take tables containing millions of A great ‘back to basics’ video
provides significant speed rows in its stride. It’s possible to course which takes you through
increases. Installing the server use MariaDB/MySQL for anything all the steps of installing and
is straightforward and it runs from your own logging project, to using SQLite. Over 90 minutes
surprisingly fast, even on older enterprise-grade applications. of video in bite-size pieces.
magpi.cc/sqlitepythonudemy
USING MYSQL
require a different type of databases offer, then a NoSQL something course on using
Price: database. If you’re looking at (or document) database may be MySQL with Python. The two
Free storing lots and lots of simple for you. This family of databases hours of video usefully cover
mongodb.com data and don’t require the kind specialise in high-volume, installation of the server.
fast data storage and retrieval. magpi.cc/mysqlpythonudemy
They are especially popular
when the job is to ‘just get the MONGODB AND PYTHON:
data and store it as quickly as QUICK START
possible’. Rather than using Crucially, this two-hour video
the traditional model of tables, course covers when to choose
columns, and rows, document a NoSQL (or document)
databases use schemas and key- database and the key
pairs to store data. MongoDB is differences between this and
a popular open-source server. traditional SQL engines.
It’s very easy to install, and you magpi.cc/
can undertake a full course at mongodbpythonudemy
magpi.cc/mongodb.
Ben Nuttall
We catch up with the Raspberry Pi Foundation’s fourth
employee, and one of the creators of Raspberry Jams, who now
works for the BBC in an innovation team called BBC News Labs
H
ave you ever used GPIO project in its infancy – back then booted it up. I had no idea how to
Zero? Installed Python it was just a claim that they were get to the Desktop, and all I
libraries from pip? Visited going to make a small Linux could think to do with it was to
the Raspberry Pi website? Read computer for $25, which sounded type simple commands into the
Raspberry Pi documentation? incredible and very much Python shell. I knew I wasn’t
Been to a Raspberry Jam? Read relevant to my interests.” making the most of it, so I
the events calendar pages in this Like many people on thought I should find a
very magazine? Then you’ve used 29 February 2012, he got up community group to learn from.
something that the legendary bright and early to try to order Back then I was attending
Ben Nuttall has worked on. one of the first run of Raspberry several programming user
After six years working for the Pi computers. He managed to groups at the local tech space in
Raspberry Pi Foundation, Ben place an order, but had to wait Manchester, so I asked them if
has moved on to work for the until June to get his hands on there was going to be a
BBC, so we wanted to celebrate one. That didn’t dissuade him Raspberry Pi group. They said I
his role in helping to build the from using Raspberry Pi, though, should start one – so I did. I
community from day one. and the rest is history. called it Manchester Raspberry
“Throughout my final year at Jam, and other people were
university (2010/11), I started What was your community role setting up their own around the
getting into Linux and began before joining Raspberry Pi? same time – notably Alan
The Birthday Jams are
learning Python,” Ben recalls. “I As soon as my Raspberry Pi O’Donohoe in Preston.
part of the evolution of
Raspberry Jams! heard about the Raspberry Pi arrived, I installed the OS and Raspberry Jams naturally became
Ben could be
found promoting
Raspberry Pi at
many events
around the globe
This Month in
Raspberry Pi
Big birthday list!
Here are just some of the Raspberry Pi events celebrating its eighth birthday
A
s we mentioned last issue, Raspberry Pi is
turning eight this year! Or two, if you only
count leap years. Either way, in honour
UK
of this birthday, any Raspberry Jams taking place Barnstaple Raspberry Jam Leicester Hackspace Raspberry Pi
between Saturday 15 February and Sunday 15 March Barnstaple Birthday Jam
can be used to celebrate Raspberry Pi! Leicester
BLC Raspberry Jam
Here are the events that have been planned by
Buxton London Raspberry Pint
the time we go to print. For a more up-to-date list,
London
head to rpf.io/jam. CamJam
Cambridge Margate Raspberry Jam
Margate
Chelmsford Raspberry Jam
Chelmsford Beeston Raspberry Jam
Nottingham
Chi Raspberry Jam
Chichester South Devon Tech Jam
Paignton
Exeter Raspberry Jam
Exeter Cornwall Tech Jam
Redruth
Gateshead Raspberry Jam
Gateshead Sheffield Raspberry Jam
Sheffield
Huddersfield
Raspberry Jam Southend Raspberry Jam
Huddersfield Southend-on-Sea
Europe
Pakistan
Raspberry Pi Jam Kochi
India Raspberry Jam LIMA
Peru
Raspberry Jam Zelzate AmsterJam Abhinav Raspberry Jam
Belgium Netherlands India Davao Raspberry Birthday Jam
Philippines
Varna Raspberry Jam CoderDojo Baarle Atria Labs Raspberry Jam
Bulgaria Raspberry Birthday Party India Raspberry Jam Lisboa
Netherlands Portugal
Raspberry Jam des inspirés 2020 Bhopal Raspberry Jam
France Hacker Jam Cluj India Suñu Raspberry Jam
Raspberry Pi 8th Birthday Senegal
Raspberry Jam de la Licorne Romania PiWorld Raspberry Pi Jam
France India 3rd Annual Cape Town Raspberry
Raspberry Jam Russafa Jam/Makeathon/Hackfest!!
Pi and More 12½ Spain ResPro Labs Raspberry Pi Jam South Africa
Germany India
PiWars Turkey Raspberry Pi Jam in Taipei 2020
Votanikos Jam Turkey Pi Jam 2020 @ SRiX Warangal Taiwan
Greece India
İstanbul Raspberry Pi Bangkok Raspberry Jam
Torino Raspberry Pi Jam Jam Etkinliği 2020 Raspberry Jam NextTech Thailand
Italy Turkey India
Dubai Raspberry Birthday Jam
RASPBERRY PiZZA Jam Raspberry Pi Jam by ILUG-D & HHC-D United Arab Emirates
Italy India
MagPi Monday 01
E
very Monday we ask the question: have you
made something with a Raspberry Pi over
the weekend? Every Monday, our followers
send us amazing photos and videos of the things
they’ve made. Here is a small fraction of them.
Follow along at the hashtag #MagPiMonday.
03
04
02
06
Best of the rest! Here are some other great things we saw this month
magpi.cc/smartbelt magpi.cc/genome
EVENTS
06
08
Raspberry Jam
07
Event Calendar
Find out what community-organised Raspberry
Pi-themed events are happening near you…
04. Topsham Raspberry Jam 08. 2020 Saddleback Valley Raspberry Jam
Saturday 21 March Saturday 28 March
Nancy Potter House, Topsham, UK Laguna Hills High School, Laguna Hills, CA, USA
magpi.cc/ysrxpx magpi.cc/yttwks
A Code Club turned Jam, you’ll need to call the number Projects will be on display that community members have
at the League of Friends website to enrol. created, as well as beginner workshops on Raspberry Pi.
03
FIND OUT
ABOUT JAMS
Want a Raspberry Jam
in your area? Want to
start one?
[email protected]
05
RASPBERRY PI
Retro Gaming with Raspberry Pi shows you
how to set up a Raspberry Pi to play classic games.
Build your own portable console, full-size arcade
cabinet, and pinball machine with our step-by-step
guides. And learn how to program your own games,
using Python and Pygame Zero.
Your
Letters
USA subs x86 now?
I see there is a new subscription With the upgrade to Raspberry Pi 4 and all the firmware updates I’ve
offer for people in the US! $60 for read about, I was wondering if it was finally powerful enough to run
a year sounds like an amazing x86 operating systems and software? I keep thinking about a
price. How long is it lasting for? Is portable After Effects computer, and it would be amazing if it runs
it for the whole of North America? on Raspberry Pi.
Also, are there any free gifts
with this subscription? I have Dom via email
been eyeing up the older version
that came with a Raspberry Pi Unfortunately, even with all the extra power a Raspberry Pi 4
Zero W, but it was a little out of possesses, it’s still based on an ARM processor, so running x86
my price range. operating systems and software is not something you want to be doing
with a Raspberry Pi.
Liza via email Also, After Effects takes up a massive amount of resources – we’ve
had powerful x86 PCs that have struggled with it at times, so a
Our latest American subscription Raspberry Pi 4 is perhaps not what you’d be wanting. You’ll probably
offer is running until the end of need to get a laptop suited for the job.
March: $60 for an entire year!
Unfortunately, it’s currently only
for the USA, although HackSpace
magazine is also doing a similar
offer until the end of March!
Like our usual yearly
subscription, you get a Raspberry
Pi Zero W, a case for it with a
selection of covers, and a small
set of converter cables for the
smaller ports. ome people
S
have tried running
You can find out about the Windows on
Raspberry Pi
new US subs for The MagPi at
before. It has not
Hurry, the
offer ends
magpi.cc/usa, or for HackSpace gone… speedily
on 31 March! magazine at hsmag.cc/usa.
We don’t control who stocks the magazine – your library will need to
order the magazine; the same with your book store. We can’t force
them to do this, but if you mention it to your library and the shop’s
manager, they might be able to work something out!
Contact us!
> Twitter @TheMagPi
> Facebook magpi.cc/facebook
> Email [email protected]
> Online raspberrypi.org/forums
PC HARDWARE
ENTHUSIASTS
RETRO GAMING REVIVAL ARE CRT MONITORS MAKING A COMEBACK?
THE BEST-SELLING MAG FOR PC HARDWARE, OVERCLOCKING, GAMING & MODDING / ISSUE 198
TITAN
BUILD A
24
CORE
CREATE A MIGHTY THREADRIPPER
RIG THAT DOES IT ALL, FROM
GAMES TO CONTENT CREATION
FULL GUIDE TO
HDR
HDR TECH AND STANDARDS EXPLAINED
HDR GAMING MONITOR GROUP TEST
MARCH 2020 / £5.99
HDR
MARCH 2020 / £5.99
TITAN
VISIT CUSTOMPC.CO.UK TO LEARN MORE
GAMES TO CONTENT CREATION
RIG THAT DOES IT ALL, FROM
CORE
CREATE A MIGHTY THREADRIPPER
COMPETITION
WIN
RASPBERRY PI
DESKTOP KIT
SIGNED BY EBEN UPTON!
The Raspberry Pi Desktop
Kit comes with everything
you need to start using your
Raspberry Pi. This one is extra
special, though: it has been
signed by Eben Upton himself!
Competition magpi.cc 95
SUBSCRIBE AND
SAVEUP
TO
35%
on the cover price
ISSUE #28
OUT NOW
hsmag.cc
NEXT MONTH
EDITORIAL
Editor
Lucy Hattersley
[email protected]
Features Editor
Rob Zwetsloot
[email protected]
Sub Editors
Phil King and Nicola King
ADVERTISING
Charlotte Milligan
[email protected]
+44 (0)7725 368887
RASPBERRY PI 4 DESIGN
criticalmedia.co.uk
Head of Design
Lee Allen
TROUBLESHOOTING
Designer
Sam Ribbits, Harriet Knight
Illustrator
Sam Alder
CONTRIBUTORS
DIAGNOSE AND FIX COMMON PROBLEMS Mike Cook, David Crookes,
PJ Evans, Gareth Halfacree,
Rosemary Hattersley, Simon
Long, Martin Mander, Simon
Monk, Mark Vanstone
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
Plus!
system which has been assessed as
conforming to ISO 14001.
Set up a smart
Raspberry Pi (Trading) Ltd., Maurice Wilkes
sourdough incubator
magpi.cc/subscribe Building, St. John’s Innovation Park, Cowley
Road, Cambridge, CB4 0DS. The publisher,
editor, and contributors accept no
responsibility in respect of any omissions
Weather & pollution or errors relating to goods, products, or
Instagram clock
3.0 Unported
EMAIL [email protected] (CC BY-NC-SA 3.0).
ISSN: 2051-9982.
THE FINAL WORD
I
’m thinking of getting a Raspberry breast cancer, and the family had have the credit – spawning a term we
Pi tattoo. Nothing too fancy, a truly terrible year of waiting, still use, ‘back-seat maker’.
just the logo (given the right worry, and coping with debilitating I was lucky enough to show the VCR
approvals), or maybe a 40-pin header. chemotherapy. What I remember at the Raspberry Pi 3rd Birthday event
It’s scary and would be my first, but throughout, though, was the value of that year, a pretty lonely-looking
it’d be a fitting expression of the having just a few minutes a day when project with a table to itself, but that
depth of feeling I have for the little I could pop to the garage and tinker day opened my eyes to the incredibly
green board. It sounds a bit corny, with the Raspberry Pi project. Often all diverse and positive community that
but discovering Raspberry Pi and the I got done was think a bit, or find two surrounds Raspberry Pi. I’m proud to
culture around it changed my life. matching screws, but doing something be a part of it and am still in regular
Back in 2014, I’d been repurposing creative, with an entire online contact with people I met that day.
broken old tech for a while, but community to turn to, made all the
my projects always needed to be difference to my well-being. Just as you Endless inspiration
Since then, I’ve published a dozen
It mostly still works, though the final assembly projects, focusing on practical uses
for obsolete tech that showcase the
was like sitting on a stuffed suitcase flexibility of Raspberry Pi. I thought
the ideas would dry up eventually,
connected to something else, like remember where you were when you but as more HATs appear, the boards
the vintage phone with Google voice last heard a song, every badly soldered evolve, and the community grows
search that needed a laptop to work. switch and off-centre drill hole has stronger, there’s more to be inspired
Then a chance comment on one of my its own story to tell of those days. We by in 2020 than ever before. I’m also
projects pointed me in the direction struggled, but the making helped me constantly inspired by my wife’s
of Raspberry Pi and I was drawn in carry on and the family pushed through courage, and will always remember
straight away, hatching a grand plan a dark winter together. with gratitude how my own Raspberry
to put a large HD screen in an old VCR Pi journey began. Now where can I find
to make a standalone retro media Back-seat maker a slightly broken 1970s tattoo gun?
centre. I’m gazing wistfully at it now – After a long but successful treatment,
it mostly still works, though the final Claire’s hair started to grow back in
Martin Mander
AUTHOR
assembly was like sitting on a stuffed the spring, and interest grew in the
suitcase, so I don’t dare reopen it to fix finally complete VCR project. With
Martin has a passion for bringing new
the sticky eject mechanism. every positive comment or mention, purpose to broken old technology with
It was a genuine labour of love. she reminded me that spray-painting Raspberry Pi, and shares his projects on
Shortly after starting the VCR project, it Raspberry red had been her sick-bed the ‘Old Tech, New Spec’ YouTube channel.
my wife Claire was diagnosed with idea, and she should consequently kyliemander.com