The Raspberry Pi High-Quality Camera module opens up all sorts of possibilities for high-resolution image and video photography, but how do you turn it into a practical camera?
This project builds a tripod-mounted Raspberry Pi camera with a button trigger and LED indicator for taking still images and video. It uses off-the-shelf parts requiring no soldering for easy assembly and it shows how to link it to a laptop or tablet for portability.
The open-source Python script controlling the camera can be modified to suit your own specific photographic needs using the many software options for the camera module, including image quality and format, special effects and raw output to name a few.
Note: The camera requires Raspberry Pi OS (Legacy) with desktop.
We enclosed the Raspberry Pi in a camera case and mounted the camera module to the outside. The case included a wall mount bracket that we attached to a standard camera tripod footplate.
Pin | GPIO | Function | Colour |
09 | GND | GND | Black |
11 | GPIO17 | VCC | Red |
23 | GPIO27 | CTL | Orange |
Pin | GPIO | Function | Colour |
16 | GPIO23 | CTL | Orange |
18 | GPIO24 | VCC | Red |
20 | GND | GND | Orange |
Gravity modules have onboard components making them safe to connect as shown. Other types of module connected this way may damage your Raspberry Pi.
Detailed instructions for attaching lenses to the camera module can be found here: https://www.raspberrypi.org/products/raspberry-pi-high-quality-camera/
We used the full desktop version of Raspberry Pi OS on a 32GB microSD card. Use a card with the operating system already installed or flash a blank one using Raspberry Pi’s instructions:
https://www.raspberrypi.org/documentation/installation/installing-images/
To view the camera HDMI output so you can frame and focus your shots, we used a Windows 10 laptop with an HDMI to USB video card adapter. You can also use a tablet or standard HDMI monitor.
Next, you will install and test the Python script that will control the camera using the button. The script can be found on the OKdo GitHub page: https://github.com/LetsOKdo/pi-hq-camera
To install the script on the Raspberry Pi:
git clone https://github.com/LetsOKdo/pi-hq-camera.git
sudo apt install gpac
sudo apt install gpac
python3 hq-camera.py
The camera has been programmed with 3 modes; Shutdown, Still and Video. It starts up in Shutdown mode with no preview, so DON’T press and release the button just yet – the LED will be ON solid indicating the current mode.
Open the Raspberry Pi File Manager and check you have an image in /home/pi/Pictures and an MP4 video in /home/pi/Video
Shutdown mode has preview switched off so the Raspberry Pi can be controlled – If you ever need to get out of preview press and hold the button and cycle though back to Shutdown mode
Images and video are stored on the Raspberry Pi’s microSD card but these can be accessed remotely from any computer on your network using Samba. This allows Windows, Mac and Linux PCs to access the images so you can use a File Manager to easily copy them to your local machine.
sudo apt install samba samba-common-bin smbclient cifs-utils
detailed information about Samba is here: https://www.raspberrypi.org/documentation/remote-access/samba.md
Adjust the Samba config to share the Raspberry Pi Pictures and Video directories:
[Pictures]
path = /home/pi/Pictures
read only = no
public = yes
writable = yes
[Videos]
path = /home/pi/Videos
read only = no
public = yes
writable = yes
If you want the camera script to start automatically when the Raspberry Pi boots up, configure the systemd service unit. This will also allow the keyboard and mouse to be removed from the Raspberry Pi.
cd ~/pi-hq-camera
sudo cp hq-camera.service /etc/systemd/system/
sudo systemctl enable hq-camera.service
Now when the Raspberry Pi boots it will run the script automatically – the camera will be in Shutdown mode with no preview. To start taking photos, change mode by pressing and holding the button.
sudo systemctl stop hq-camera.service
sudo systemctl disable hq-camera.service
You can now shutdown the Raspberry Pi and remove the keyboard and mouse:
Wait until the green LED on the Raspberry Pi board has finished flashing before removing the power.
The advantage of the Raspberry Pi camera is that you can program it to function the way you want. There are loads of modes and effects to try out. Experiment using the command line in Terminal but if you want to change the camera script, create your own functions and replace the existing ones.
Here is the definition of the function that takes still images – this is triggered when the button is pressed and released in Still mode. It stops the preview, creates the filename with a date stamp, takes the shot and starts preview again:
def take_still():
global filename
camera.stop_preview()
filename = datetime.now().strftime('%Y%m%dT%H%M%S')
camera.capture(f'{image_dir}{filename}.jpg')
camera.start_preview()
Create your own function then replace a call in the op() function with your own version:
def op():
global state
if state is 'still':
take_still() # replace with your own function
Hopefully you will now have a Raspberry Pi High-Quality Camera setup to easily take photos and video connected to a laptop or tablet so you can frame and focus the images, giving you the kind of functionality available with high-end cameras.
The Python script demonstrates how to control and automate image capture and can be used as a basis for your own version, adding special effects or making the camera work the way you want it.
Change the button for a motion sensor, fit a wide-angle lens and you have a pet cam that will take pictures or video when it detects movement. Program it to take shots every few minutes and create time-lapse videos or create animations with special effects, the possibilities are endless.
Full details of the Python picamera module is here:n https://picamera.readthedocs.io/en/release-1.13/index.html
As usual Raspberry Pi have produced very high quality documentation on setting up and using the High-Quality Camera module – their official guide can be found here: https://www.raspberrypi.org/products/raspberry-pi-high-quality-camera/
Happy snapping!
From a quick tap to smashing that love button and show how much you enjoyed this project.