The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

Review


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 179


Let your
Raspberry Pi
and camera
look at
the world
around you
Pimoroni

Maker
Says

PAN-TILT H AT


he Raspberry Pi Camera
Module is one of the best
accessories you can get,
enabling cheap photography on the
Pi. But it doesn’t sit upright on its
own – a stand is required.
The Pan-Tilt HAT fulfils this
function and a whole lot more.
The Camera Module is mounted
on the end of a robotic arm that
sits on top of the HAT. Thanks
to the arm’s horizontal and
vertical joints, the camera can
be angled precisely by the two
servo motors.
The finished effect is adorably
cute, instantly imbuing your
Raspberry Pi with personality
as it looks around the room.
It’s really useful too. You
could set the Pan-Tilt HAT up
to monitor a room, and then
use VNC or SSH to adjust its
viewing position remotely.
Alternatively, you can set up a
Raspberry Pi with face-tracking
software and connect it to the
Pan-Tilt HAT. Pimoroni, the HAT’s
makers, also suggest mounting it
on top of a robot for a set of eyes.

Setting it up
First, you need to set the HAT up.
Fortunately, there is an online
setup guide (magpi.cc/2hR4NFC).
The board has a GPIO connection
on one side, and servo connections
on the other. The two sets of cables
on the arm are connected to Servo 1
and Servo 2 on the board (1 for pan,
2 for tilt). A third servo channel
can be used to control an optional
NeoPixel strip for lighting.

Camera control
You can download all of the code
from Pimoroni’s GitHub page
(magpi.cc/2hRrjyo). You need to
install the pantilthat module to
access the controls.
After importing the pantilthat
library in Python, you use pan()
and tilt() methods to change the
camera position. These accept any
value between -90 and 90. To set
the camera straight forward, for
example, you would use:

pantilthat.pan(0)
pantilthat.tilt(0)

To look up by 45 degrees, use:

pantilthat.tilt(-45)

To look all the way to the
camera’s left, you’d put:

pantilthat.pan(90)

We would have dearly loved more
software examples. There are ones
for motion and NeoPixels, but none
for recording from the camera or
face-tracking. A few more sample
programs and it’d be perfect.
Even so, we had a lot of fun
setting up the Pan-Tilt HAT and
look forward to researching and
coding a face-tracking program.

Raspberry Pi camera stand with horizontal and vertical motion servos


T


RASPBERRY
PI CAMERA
MOUNT
It doesn’t move,
but if all you’re
after is a camera
mount, you can
pick one up
from The Pi Hut
for a tenth of
the price.

magpi.cc/2hRtkdT

Related


£3 / $4


PAN-TILT HAT


magpi.cc/raRzbi


£30 / $33


Last word


A highly enjoyable and
extremely cute accessory.
With a bit of research, you
should be able to create
some fun things with it.
Free download pdf