Focus the Pi High Quality Camera Remotely!

Ever since I started messing about with the Raspberry Pi High Quality Camera I’ve been trying to think of a way to focus it remotely, so that I could just pop it down in the garden and worry about focusing it later – and this weekend I cracked it!

I was sure if I found the right Lego Technic piece I’d be able to drill a hole in it and fix it to the camera lens, and a test part arrived from eBay late last week, a 60 tooth gear. Cutting a lens-sized hole in it was surprisingly easy, and it was an absolutely perfect push-fit.

The Lego compatible continuous servo works perfectly

I ordered a Lego-compatible servo from Pimoroni straightaway, and once it had arrived I spent a pleasant couple of hours rummaging for Lego pieces to make it all fit together. I was really lucky that the little servo cog and the lens cog fitted together so nicely, that could easily have been very tricky.

Testing the remote focus via Real VNC, controls on the right.

Next I made a long, thin focus button menu in GUIzero, so that it’d be visible to the side of the camera preview window, when viewed via RealVNC. This works really well, you can click the focus buttons on the side and see the effect immediately on the previewed image. The beauty of RealVNC is that it works equally well on a phone or tablet, which is extremely handy when keeping an eye on a wildlife trap in the garden.

As a proof of concept it’s a lot of fun, I can imagine adding this functionality to an existing pan/tilt camera bracket, or to a robot that needs to constantly re-focus as it moves around. Of course the best part of all was combining Lego with Raspberry Pi, two of my favourite things!

More details are on Instructables and Hackster, and the code I used for the focus and capture menus is all on GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *