Linux Format - UK (2020-03)

(Antfer) #1
http://www.techradar.com/pro/linux March 2020 LXF260 33

Raspberry Pi projects


he Raspberry Pi is a truly magical device. It has
been used in some fantastic applications –
flying machines, revolutionising classrooms,
voyages to the bottom of the sea, etc. But just as
programming often begins with a program that prints
“Hello World”, so your first maker project might also be
something that appears fairly trivial. Don’t worry, these
humble beginnings can be built upon, and before you
know it you’ll be makering up a storm. Also, it’s common
for first attempts at programming to result in a series of
baffling error messages, and it’s likewise common too
for our first makes to go awry.
But don’t be put off – syntax errors will continue to
haunt you throughout your programming career, and
even seasoned makers inadvertently melt the wrong
thing from time to time. Soldering mistakes can more
often than not be undone, and where they cannot, it’s
usually only an inexpensive component that needs to
actually be replaced.
The PiCam is a great place to begin if you’re looking
for inspiration. It connects easily via a ribbon connector
and requires virtually no setup. To use it in your
programs is a simple matter of:
import picamera
cam = picamera.PiCamera()
cam.capture(‘/tmp/picam.jpg’)
If you can find a small-enough power supply (or a
big-enough jar), then connecting it and a camera to a Pi
Zero and sealing the whole arrangement in a jar can
help you get nice nature photography. The No-IR edition
of the camera (which has no IR filter) can even see at
night, which makes it great for capturing badgers, owls
(if you’re lucky) or other nocturnal species (like
technical editors writing this at 5am the day before
deadline you mean – Ed). Making a rudimentary motion
detection program in Python is straightforward, so you
don’t need to worry about filling up your SD card with
the same photo of the eerie, still darkness.
Aside from building wonderful projects, you can also
invest in some wonderful accessories to make your Pi
look pretty. Pimoroni’s PiBow cases are extremely
popular and come in a range of shapes and sizes. We
favour the slimline Coupé models, which enable access
to the GPIO pins and have a cut-out on the lid so that a
heatsink can be installed on the SoC. If you’re going to
be doing prototyping, you can replace the base with a
larger one that accommodates a 400-pin breadboard
(or two 170-pin breadboards). This keeps your projects
a little neater and tidier.
If you have access to a 3D printer or a 3D-printing
service, then you can go one step further and design
your own case. The quality and range of materials
available have evolved an awful lot in the last few years.
Gone are the days where your print, if it worked, would
be a lumpy, off-white insult to your design. The wood-
finish materials are particularly impressive, and you’ll

Getting started


Prepare yourself and your Pi for high adventure!


T


Kits like these are
a great way to
get started with
electronics without
having to worry
about soldering
or high-voltage
accidents.

find all kinds of designs on sites such as Thingiverse
(www.thingiverse.com) so you can start with something
that has the correct dimensions.

WHERE DID YOU GET THAT HAT?


The GPIO (and power pins) have led to another innovation – HATs
(hardware attached on top). As the name suggests, these fit snugly
on top of the Pi, attaching to (but not necessarily using) all of the
pins. These can add LCD/E Ink display, audio, environmental sensing
and all sorts of other capabilities to your Pi, and installing them is
generally much easier than fiddling with wires, breadboards and
solder. Some of these enable other HATs to be stacked on top of
them, or offer pass-through for unused pins. If they don’t, you can
connect them (albeit in a most un-hat-like manner) with a ribbon
connector. Just make sure you don’t get your pins confused. If you
start sending bits meant for one device to another then probably
neither will work and something will likely break.
We are fond of RGB LED arrays, such as Pimoroni’s Unicorn HAT
HD, which features a 16x16 matrix of RGB LEDs in HAT form. Apart
from looking great, these are a great way to learn about graphics.
The example Python code includes a candle flame, scrolling text and
old-school C64-style demos. LEDs draw quite a bit of current, so if
you’re using an older Pi with a less powerful power supply, upgrade it
to at least a 2A supply before donning this HAT.

Bedazzle your
friends and be
the envy of your
co-workers with
the combined
power of 256
colourful LEDs.

3332March 0 h2rSenshSnigtom March 2020LXF260 33


Raspberry Pi projects


heRaspberryPiisatrulymagicaldevice.Ithas
beenusedinsomefantasticapplications–
flyingmachines,revolutionisingclassrooms,
voyagestothebottomofthesea,etc.Butjustas
programmingoftenbeginswithaprogramthatprints
“HelloWorld”,soyourfirstmakerprojectmightalsobe
somethingthatappearsfairlytrivial.Don’tworry,these
humblebeginningscanbebuiltupon,andbeforeyou
know it you’ll be makering up a storm. Also, it’s common
for first attempts at programming to result in a series of
baffling error messages, and it’s likewise common too
for our first makes to go awry.
But don’t be put off – syntax errors will continue to
haunt you throughout your programming career, and
even seasoned makers inadvertently melt the wrong
thing from time to time. Soldering mistakes can more
often than not be undone, and where they cannot, it’s
usually only an inexpensive component that needs to
actually be replaced.
The PiCam is a great place to begin if you’re looking
for inspiration. It connects easily via a ribbon connector
and requires virtually no setup. To use it in your
programs is a simple matter of:
import picamera
cam = picamera.PiCamera()
cam.capture(‘/tmp/picam.jpg’)
If you can find a small-enough power supply (or a
big-enough jar), then connecting it and a camera to a Pi
Zero and sealing the whole arrangement in a jar can
help you get nice nature photography. The No-IR edition
of the camera (which has no IR filter) can even see at
night, which makes it great for capturing badgers, owls
(if you’re lucky) or other nocturnal species (like
technical editors writing this at 5am the day before
deadline you mean – Ed). Making a rudimentary motion
detection program in Python is straightforward, so you
don’t need to worry about filling up your SD card with
the same photo of the eerie, still darkness.
Aside from building wonderful projects, you can also
invest in some wonderful accessories to make your Pi
look pretty. Pimoroni’s PiBow cases are extremely
popular and come in a range of shapes and sizes. We
favour the slimline Coupé models, which enable access
to the GPIO pins and have a cut-out on the lid so that a
heatsink can be installed on the SoC. If you’re going to
be doing prototyping, you can replace the base with a
larger one that accommodates a 400-pin breadboard
(or two 170-pin breadboards). This keeps your projects
a little neater and tidier.
If you have access to a 3D printer or a 3D-printing
service, then you can go one step further and design
your own case. The quality and range of materials
available have evolved an awful lot in the last few years.
Gone are the days where your print, if it worked, would
be a lumpy, off-white insult to your design. The wood-
finish materials are particularly impressive, and you’ll


Getting started


PrepareyourselfandyourPiforhighadventure!


T


Kits like these are
a great way to
get started with
electronics without
having to worry
about soldering
or high-voltage
accidents.

find all kinds of designs on sites such as Thingiverse
(www.thingiverse.com) so you can start with something
that has the correct dimensions.

WHEREDIDYOUGETTHAT HAT?


TheGPIO(andpowerpins)haveledtoanotherinnovation–HATs
(hardwareattachedontop).Asthenamesuggests,thesefitsnugly
ontopofthePi,attachingto(butnotnecessarilyusing)allofthe
pins.ThesecanaddLCD/EInkdisplay,audio,environmentalsensing
andallsortsofothercapabilitiestoyourPi,andinstallingthemis
generallymucheasierthanfiddlingwithwires,breadboardsand
solder.SomeoftheseenableotherHATstobestackedontopof
them,orofferpass-throughforunusedpins.Iftheydon’t,youcan
connectthem(albeitinamostun-hat-likemanner)witharibbon
connector.Justmakesureyoudon’tgetyourpinsconfused.Ifyou
startsendingbitsmeantforonedevicetoanotherthenprobably
neitherwillworkandsomethingwilllikelybreak.
WearefondofRGBLEDarrays,suchasPimoroni’sUnicornHAT
HD,whichfeaturesa16x16matrixofRGBLEDsinHATform.Apart
fromlookinggreat,theseareagreatwaytolearnaboutgraphics.
TheexamplePythoncodeincludesacandleflame,scrollingtextand
old-schoolC64-styledemos.LEDsdrawquiteabitofcurrent,soif
you’reusinganolderPiwithalesspowerfulpowersupply,upgradeit
toatleasta2AsupplybeforedonningthisHAT.

Bedazzle your
friends and be
the envy of your
co-workers with
the combined
power of 256
colourful LEDs.
Free download pdf