Software apps and online services
In this project, I'm going to show you how you can have a headless setup of your Pi with a Camera, in particular the new High Quality Camera with its interchangeable lens with adjustable Focus and Aperture and improved picture quality!Introduction
After getting my hands on the new Raspberry Pi High Quality Camera (along with a "wide angle" 6mm CS mount lens), I thought I could jump right in with the photography and playing around with it. I must admit I hadn't really tried out the Pi Camera before, even though I had an older generation one sitting around.
That's when I realized two things:
1. It is not that straightforward to operate the Pi camera remotely, especially when trying to compose a shot. This is especially exacerbated in the new High Quality Camera because you now have control over focus and aperture and therefore would like to see and compose the shot first! The Camera Preview only works when it is directly connected to a display via HDMI/Composite/DSI so you would either need a portable display or need to be tethered and within range of your display. (......don't worry, there IS a workaround, otherwise this article won't exist! 😊)
2. There aren't a whole lot of resources on getting started with the High Quality Camera, yet. This makes it difficult for someone just starting out. Combine that with problem #1, and it prompted me to write this project, to help YOU get started!Getting Started
I'm going to assume that you have a headless setup of the Raspberry Pi (A+/B+/4B/Zero) with SSH enabled, and that you have ssh on your laptop to login to your Raspberry Pi and also know its IP address (or know how to find out!).
Why a headless setup? The High Quality Camera promises great things, with a 12MP camera sensor and the ability to use any C/CS Mount lens with it (and even more lenses using other adapters such as C to EF mount). It comes with the option to buy two Raspberry Pi recommended lenses - a 6mm CS Mount lens and a 16mm C Mount "telephoto" lens.
This really means that you don't want to be tethered to a display. Yes, you can spend some buckaroos and get a portable HDMI/DSI display to use with your Raspberry Pi. But how nice would it be to not have your Pi Camera tethered to a display and use it headless, and leverage your laptop or mobile phone display? Yes, it's possible!Step 1 - Mount the Raspberry Pi High Quality Camera
The goal of the headless Pi setup with the High Quality Camera is to have a portable setup to leverage the features of the camera and lens. For that, I want my Pi to be collocated with the High Quality Camera and mobile with it. For that, I'm using a ProtoStax Enclosure with the Camera Kit for Raspberry Pi High Quality Camera.
The ProtoStax Enclosures for Raspberry Pi support the different flavors of Raspberry Pi - A+, B+/4B or Zero/ZeroW. For the purpose of this demo, I'm using a Raspberry Pi A+ with the ProtoStax Enclosure for Raspberry Pi A+
I'm also using the ProtoStax Camera Kit for Raspberry Pi High Quality Camera - an extension kit that adds a Top Plate with camera mount holes for the High Quality Camera (with spacers and mounting screws and nuts), and a tripod mount side-wall (so you can mount the whole enclosure, including the camera sensor and lens on a tripod). This kit will work with any of the ProtoStax enclosures, which means you can use it with your Raspberry Pi A+, B+, 4B or Zero.
With this kit, I can now mount my High Quality Camera to my enclosure, and also mount my enclosure to any standard tripod.
A picture is worth a thousand words, so here's what it looks like:
You will need to plug the camera cable into the relevant camera slot on your Raspberry Pi board.
You will also need to mount the lens to the Camera Sensor.
Here are the steps to setup your High Quality Camera with the enclosure and your Pi. It also has instructions on how to set up and adjust the focus and aperture on your camera (Step 4)
Raspberry Pi Foundation's "Getting started with the Camera Module" Project Guide is also a good primer. Click https://projects.raspberrypi.org/en/projects/getting-started-with-picamera/2 for instructions.Step 2 - Enable the Camera module and VNC on your Raspberry Pi
Here, I'll assume that you have your Raspberry Pi ready to go in a headless setup, so I'll show all the setup steps using ssh and the command-line raspi-config tool, so you can run all of these from the terminal on your laptop.
You will want to enable the Camera interface on your Raspberry Pi, of course. You will also want to enable VNC.
Yes, you're probably thinking "He wants me to run a headless setup and then have VNC running? Why??"
Patience, young grasshopper!
You see, there is one issue with running the Raspberry Pi headless and not being connected to a display via HDMI/Composite/DSI. Whether you take a preview of the camera using raspistill, raspivid or PiCamera Python library, etc, the preview is rendered directly on the display via the GPU.
In fact, the Raspberry Pi Project Page on "Getting started with the Camera Module" states:
the camera preview only works when a monitor is connected to your Raspberry Pi. If you are using remote access (such as SSH or VNC), you won’t’ see the camera preview.
Ok. Wait, what?! It says you won't see the preview using remote access such as SSH or VNC. Wasn't VNC supposed to be savior?
Yes, sir, it is the savior! The project page is older, and VNC (more specifically realVNC that's bundled with Raspbian) has a new feature, that's all!
The realVNC server that is bundled with the latest Raspbian Distro has an option to enable remote previews - but we're getting ahead of ourselves here! Trust me, all will be explained!
Since we want to leverage VNC, we now need to ensure that not only do we need to enable VNC on the Pi, we also need to boot to Desktop so that main VNC display is available.
So we set the "Boot to Desktop" option in raspi-config, as shown below:
Next, we enable Enable Camera Module and VNC
For VNC to work correctly and display the Desktop, we also want to set the Screen Resolution (raspi-config Advanced Option -> Resolution). Set it to anything but the Default! (i.e. DO NOT choose Default!!). This is because there is no display attached to the Raspberry Pi in our headless setup, and therefore with the Default setting, it does not know what to do and won't display the remote Desktop when trying to connect from our laptop.
RealVNC Server has two different modes - a Service Mode and Virtual Mode. It is possible to run the VNC server on the Raspberry Pi in a virtual desktop ("Virtual Mode") wherein you can specify the screen resolution when running the VNC server from your RPi. However, when running VNC in a virtual desktop environment, you will not see the option to enable the remote preview settings that we want. Therefore, we want to use the VNC server in non-virtual-desktop mode (i.e. Service Mode)! To do that in our headless setup, we want to set the Screen Resolution as above!Step 3 - Enable Remote Preview settings via VNC
Next step, we'll want to enable the Remote Preview of the camera to show up on the VNC Client. To do this, we need to set the "Enable direct capture mode" option on the VNC Server.
Login to the Raspberry Pi Desktop using RealVNC Viewer from your laptop/phone.
In your RPi Desktop environment, click on the VNC logo on the top tool bar on the right-hand side.
Select VNC -> Hamburger Menu -> Options
Select Troubleshooting on the left. Make sure "Enable direct capture mode" is checked.
The steps are shown below. Swipe through for all the steps:
You can test it out by running the following in your terminal window on your Desktop environment on your VNC Viewer.
raspistill -t 0
This should show your Camera's preview! If you are using your High Quality Camera for the first time, the picture will likely be quite blurry. But at least you know that it works, AND more importantly, you can see the Camera Preview on your laptop remotely and wirelessly! 😊Step 4 - Adjust the Focus and Aperture on your High Quality Camera
Ok, now we can really start playing around with the High Quality Camera from our laptop!
First thing we'll want to do is adjust the Focus and Aperture on the High Quality Camera so our image quality is crisp and as expected.
We can run raspistill -t 0 to generate a preview without capturing the image to disk, and use that to focus the camera.
raspistill -t 0
The steps to set Focus and Aperture for the C/CS Mount lens recommended by the Raspberry Pi Foundation are explained in the documents below. One pet peeve that I have is that it is not immediately obvious for one to look for these guides - they are buried at the bottom of the camera sensor product page and not very obvious. But here you go! 😊
Of course, reading these is not quite the same as seeing one do it, especially if its the first time you are handing the High Quality Camera and the C/CS Mount lens!
Here is the video I made to show how to set up the High Quality Camera with the enclosure and the Pi, and I also explain how to setup and adjust the Focus and Aperture. This is a hands-on visual demo to augment the documents above. Watch from 9 mins 13 seconds for the part on Focus and Aperture setup (Hackster is not honoring the start time that I set for the video).
One thing that you will find with the new Camera (at least I did) is that you become quite tentative with how much force/torque to apply when installing and turning the different parts to achieve the desired Focus and Aperture, because you don't want to damage the delicate system. Initially, because it is new, you will have to apply a little more force/torque to get things moving smoothly. Once the rings are moving, they become much easier to work with.Step 5 - Off to the races!
Now you can run VNC on your laptop (or phone), interface with the camera using raspistill, raspivid or PiCamera and easily see the preview on your screen and control your camera, all remotely and wirelessly! This will allow for greater freedom in positioning your camera for the best shot!
You can set now your Focus and Aperture on your new High Quality Camera and see the preview right away on your laptop wirelessly, so enjoy experimenting and I would love to see your next masterpiece photo! Feel free to post it here in the comments section below! 😊
I'll be sure to share some of my own as well! 😊
Happy Making! 😊