raspberrypi.org/magpi The Official Raspberry Pi Projects Book 79
MESMERIC MIRROR Projects
>STEP-01
The handy compartment
The electronic components sit inside this removable,
easily accessible shelf. It includes a Raspberry Pi,
backplane connector, speaker, laser rangefinder, AC
power in, and power supply. The decorative brass
grille provides ventilation.
>STEP-02
Fixing the lights
The LEDs fit behind the mirror’s frame. “Problem is,
they have a tiny computer running in each pixel, so
extra power taps are needed every metre or so to
keep the voltage level high,” says Roberto.
>STEP-03
Connecting everything up
The key I/O components use four-wire connections: I^2 C
for the LIDAR-Lite and SPI for the DotStar. Thankfully,
the Pi can handle both. Roberto soldered the
connections to an easily attachable Perma-Proto HAT.
LET THERE BE LIGHT
repositories. He liked the fact that
the Pi was a fully specced Linux
platform. “It meant I could use the
tools and languages I was familiar
with,” he says.
His next step was to research the
best lighting, and he eventually
chose Adafruit’s DotStar Warm
White LED strips. “They are more
expensive than simple strips, but
they use a pretty straightforward
wiring system,” Roberto explains.
“Adafruit also supplies a nice
Python library to control the strip
from the Pi.”
Motion sensing
From there, he looked for a way of
detecting the presence of a person,
before hitting on the idea of a laser
rangefinder. “It occurred to me
that if I had a laser rangefinder
pointing straight down from the
top to the bottom of the mirror, in
the same axis as the LEDs, it could
sense how high up anything was,”
he continues.
This would allow the LEDs to
light up to the height of a person,
or work out if they were stretching
their arm up, and illuminate
further. “I decided to use the
LIDAR-Lite rangefinder, which is
a pretty cool but pricey sensor that
encodes digital fingerprints into
the bursts of laser light it sends
out,” he tell us. “This means it
can uniquely identify the pulses of
light that bounce back, so it’s not
confused by secondary reflections.”
To tie everything together,
Roberto created a simple program
in Python: “The code polls the laser
rangefinder to work out if there is
an object closer to the top of the
mirror than the mirror base. If there
is, it increments the brightness in
an array that tracks how bright all
the LEDs should be.” But it wasn’t
entirely straightforward. Creating
the body of the mirror proved a
daunting task.
Learning by doing
“Before I started, I had zero
woodwork skills – I’d been terrible
at it at school,” Roberto admits. He
watched several YouTube videos
about making mirror frames (“the
opposite sides really need to be
the same length,” he laughs) and
he also ended up buying all kinds
of powerful tools to get really
accurate mitre joints.
Still, it was worth it. During the
grand unveiling, accompanied
by the sounds of 2001: A Space
Odyssey, he watched the delight
on his children’s faces. “It had
become an almost embarrassing
addiction,” he says of the process.
“But my children love it, and they
show it off to their friends when
they come round.”
My children love it, and they
show it off to their friends
when they come round