How To Use Raspberry Pi Camera Module 3 with Python Code
The Raspberry Pi has many of the best accessories and one that is sure to appear on that list is the new Camera Module 3. In our Raspberry Pi Camera Module 3 review, we said that we love the fast autofocus and HDR images and we want to share these features with you in this how to.
If you have never used a Raspberry Pi camera before, our beginner’s guide to Picamera2 is a great primer to get your Pi taking great pictures. In this how to, we shall explore the many ways that we can use the Camera Module 3’s focus system with Picamera2 and learn how to take HDR images with a quick and simple script that automates the process. If Python isn’t your thing then the Camera Module 3 can also be controlled using libcamera via the terminal.
Getting to Know Autofocus
Autofocus has three modes in which it operates.
- Manual: Requiring the user to specify the LensPosition control to alter the focus of the lens. A value of zero will produce an infinite focus. Values up to 10 are accepted with 10 setting the focus to 1/10 of a meter (10CM).
- Auto: The typical autofocus which uses AfTrigger to start an autofocus cycle.
- Continuous: The camera will hunt for a target, refocusing on the target when the algorithm detects it.
Project 1: Using Continuous Focus

Continuous focus uses an algorithm to search the image stream for a target. It doesn’t matter if the target is near (around 10cm) or far, the algorithm will find the target and lock on. But how do we use it? Let’s run a quick test. We’ll use a continuous focus mode to hunt for the best possible focus on our target. It would be useful to have an object that you can hold to the camera, we used a dollar bill.
Read More: How To Use Raspberry Pi Camera Module 3 with Python Code | Tom’s Hardware