Time lapse with Raspberry Pi HQ Camera Module
Learn how to connect the Raspberry Pi HQ Camera Module to your Raspberry Pi and take pictures, record video, and apply image effects.
Raspberry Pi High Quality Camera
12.3 megapixel Sony IMX477 sensor, 7.9mm diagonal image size, and back-illuminated sensor architecture, with adjustable back focus and support for C- and CS-mount lenses
Interchangeable lenses
The High Quality Camera is designed to accept CS-mount lenses and, with the supplied adapter, C-mount lenses. The CGL 6 mm CS-mount and 16mm C-mount lenses are examples of third-party products that are compatible with the High Quality Camera; see step-by-step instructions for fitting these CS-mount and C-mount lenses.
Check out this great guide to print your own case
Operating instructions
To get your camera up and running, see this online Getting started guide. Including
- back focus adjustment,
- tripod mounting,
- connecting your camera to a Raspberry Pi computer,
- and operating camera software in Raspberry Pi OS to capture images,
What you will need
Raspberry Pi computer with a Camera Module port, all current models of Raspberry Pi have a port for connecting the Camera Module. To run your Raspberry Pi, you will need, at the very least:
- Power supply
- SD card with the OS loaded
- Finally you will also need your Raspberry Pi HQ Camera Module with a compatible lens
Note: If you want to use a Raspberry Pi Zero, you need a Camera Module ribbon cable that fits the Raspberry Pi Zero’s smaller Camera Module port.
Raspberry Pi HQ Camera Module
Connect the Camera Module
Turn off your Raspberry Pi.
- Locate the Camera Module port
- Gently pull up on the edges of the port’s plastic clip
- Insert the Camera Module ribbon cable; make sure the connectors at the bottom of the ribbon cable are facing the contacts in the port.
- Push the plastic clip back into place
Setting up your Raspberry Pi
In this post we will assume you have already set up your Raspberry Pi. If you need any help with this, head over to our post.
- Start up your Raspberry Pi.
- Go to the main menu and open the Raspberry Pi Configuration tool.
- Enable the camera by selecting the Interfaces tab
- Reboot your Raspberry Pi.
How to control the Camera Module via the command line
Now that your Camera Module is connected and the software is enabled. Try out the command line tools raspistill and raspivid.
- Open a terminal window by clicking the black monitor icon in the taskbar
- Type in the following command to take a still picture and save it to the Desktop:
raspistill -o Desktop/image.jpg
- Press Enter to run the command.
- When the command runs, you can see the camera preview open for five seconds before a still picture is taken.
- Look for the picture file icon on the Desktop, and double-click the file icon to open the picture.
How to control the Camera Module with Python code
The Python picamera library allows you to control your Camera Module and create amazing projects.
- Open a Python 3 editor, such as Thonny Python IDE
- Open a new file and save it as camera.py.
- Note: it’s important that you never save the file as picamera.py.
- Enter the following code:
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(5)
camera.stop_preview()
- Save and run your program. The camera preview should be shown for five seconds and then close again.
Take still pictures with Python code
Now use the Camera Module and Python to take some still pictures.
- Amend your code to add a camera.capture() line:
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()
- Note: it’s important to sleep for at least two seconds before capturing an image, because this gives the camera’s sensor time to sense the light levels.
- Run the code.
You should see the camera preview open for five seconds, and then a still picture should be captured. As the picture is being taken, you can see the preview briefly adjust to a different resolution.
- Your new image should be saved to the Desktop.
- Now add a loop to take five pictures in a row:
camera.start_preview()
for i in range(5):
sleep(5)
camera.capture('/home/pi/Desktop/image%s.jpg' % i)
camera.stop_preview()
- The variable i counts how many times the loop has run, from 0 to 4. Therefore, the images get saved as image0.jpg, image1.jpg, and so on.
- Run the code again and hold the Camera Module in position.
- The camera should take one picture every five seconds. Once the fifth picture is taken, the preview closes.
- Look at your Desktop to find the five new pictures.
- Finally we will simply change the loop to a while loop. This will make your code run infinitely.
#import libraries
from picamera import PiCamera
import time
#Set up variables:
interval = 15
frame = 0
#Set up & start camera, & let it settle
camera = PiCamera()
camera.resolution = (4056, 3040)
camera.start_preview()
time.sleep(2)
while True:
camera.capture('/home/pi/Videos/Frames/ice_%04d.jpg' % (frame))
frame = frame + 1
time.sleep(interval)
For a great Youtube video on the subject check this one from ExplainingComputers out and you can also download the code
For more information reach out to us on [email protected].