Affiliate Disclosure: By buying the products we recommend, you help keep the lights on at MakeUseOf. Read more.
Many accessories are available for the Raspberry Pi, but among the most popular is the camera module. But how do you safely connect one, and then get the best out of it?
If you haven’t tried Raspberry Pi photography, now is the time. Here’s how to get started with the Raspberry Pi camera module.
Setting Up the Camera Module
Own a Raspberry Pi, and want to get started with the camera module? Perhaps you want to make some time-lapse movies, or build a motion-detecting security camera. Whatever your project, if it requires a camera, your best option is the official camera module. Setup is straightforward, and requires you to:
- Connect the camera module: A ribbon cable connects the camera to the Raspberry Pi.
- Enable the camera: This can be done in the configuration screen.
- Securely mount the camera module: A suitable case is required.
- Take a picture: Use a simply command line instruction.
Before you get started, however, you’ll need to ensure you have everything you need. A Raspberry Pi camera module v2 can be purchased on Amazon.
What You’ll Need
For the best results, gather together the following:
- Raspberry Pi (any model will do, although the Raspberry Pi Zero requires a different ribbon cable)
- Raspberry Pi Camera Module
- microSD card with Raspbian installed (other Raspberry Pi distros can be used)
- Ethernet cable/Wi-Fi dongle where required
- USB Keyboard
- Suitable Raspberry Pi case (see below)
- Reliable power supply (either an adaptor, or a portable solution)
With these items collected, it shouldn’t take long to get your Raspberry Pi Camera Module hooked up to the Pi, and start snapping photos. Before you start, make sure you have installed the latest version of Raspbian on your microSD card.
The Official Raspberry Pi Camera Module
Different versions of the official camera module for the Raspberry Pi have been released over the years. As of 2018, version 2.0 is available, shipping in two flavors.
Standard Raspberry Pi Camera Module: This is the default option, the one you’ll probably choose for standard photos. Color reproduction of this 5MP camera is surprisingly good for what is a comparatively low-cost camera.
NoIR Raspberry Pi Camera Module: The NoIR variant ships without the IR filter, hence the name. This makes it better for night shoots, although a light source is useful.
Connecting the Camera Module
When you unpack your camera module, you’ll find it ships with a ribbon cable. This is usually already connected to the camera itself (although not always) and connects to the Raspberry Pi via a ribbon cable connector.
Before connecting the camera to your Raspberry Pi, be sure to take antistatic precautions. This will avoid accidentally damaging the device with static electricity. You should also take the time to identify the camera connection slot on your Raspberry Pi first.
- Raspberry Pi B: Between the Ethernet port and the HDMI connector.
- Raspberry Pi B+, 2, 3, 3 B+ (what’s the difference?): Between the TRRS/AV socket and the HDMI connector.
- Raspberry Pi Zero: on the short edge opposite the microSD slot.
Next, ensure the cable is connected to the camera. Once this is done, it’s time to carefully open the slot connector, ensuring the small T-shaped plastic is loose. The, slot the ribbon into place, the silver side facing the HDMI connector.
With the ribbon in inserted, carefully press the plastic into place to secure it.
Hooking Up the Camera Module and Raspberry Pi Zero
If you’re using the Raspberry Pi Zero, things are a little different.
On this smaller Raspberry Pi, the connecting port is smaller, and so a different ribbon cable is required. Ensure the silver contacts face upwards; they slot under the T-clip. This can be a little bit fiddly with the narrower ribbon cable.
You can order a suitable cable from Amazon. Also, note that you can find cables of different lengths, which might prove useful for your project.
Powering Up and Enabling the Camera Module
With the camera connected, it’s time to boot up the Raspberry Pi. Whether you’re connected directly to a TV or monitor, or you’re using SSH to remotely access the computer, you’ll need to open the Raspberry Pi Configuration Screen. In the Raspbian PIXEL desktop environment, you’ll find this in the Preferences menu.
However, you may prefer to use the command line and enter:
Whatever method you use, find Interfacing Options > Camera option and select Yes. You’ll be prompted to reboot your Raspberry Pi, so do this and wait for it to reboot.
Mounting the Camera in Your Raspberry Pi Case
Many mounting options are available for the Raspberry Pi Camera Module. You could simply use adhesive putty, for instance, although that’s quite a messy option. Probably the best solution is to find a case with a mounting point for the camera module.
Here are three good options:
1. SmartPi Case and Enclosure
One of the top choices for a Raspberry Pi case and Camera Module enclosure on Amazon is the SmartPi, a Lego-compatible case for the Raspberry Pi B+, 2, and 3. While the case has wall-mounting options and Lego plates, the camera module enclosure can be mounted on the case itself. There is also a GoPro compatible mounting connector.
2. Smarticase Camera Enclosure
If you already own a SmartPi case, then it makes sense to purchase the Smarticase camera module enclosure, on its own from Amazon. With holes to screw the case to a surface, it also features “building block” compatibility for mounting on the SmartPi, or any Lego you may have.
3. Keyestudio Black Case
For a full case solution, ideal for a Raspberry Pi B+, 2, and 3, take a look at this affordable case on Amazon. The Keyestudio case features mounting poles for the Raspberry Pi Camera Module, potentally letting you use the entire Pi as a mountable camera unit.
Snapping a Picture With Your Raspberry Pi
By now you should have a Raspberry Pi hooked up to an enabled camera module, and everything mounted in a case. You’re now ready to take a photo.
Open a terminal window, and enter this simple command:
raspistill -o image.jpg
This test photo can be found in the Pictures directory on your Raspberry Pi desktop. Other commands are possible.
For example, if the photo is upside down, you can use the -vf and -hf flags to flip the vertical and horizontal axes.
raspistill -vf -hf -o image.jpg
For a full list of commands for taking photos, enter the single command:
You Can Even Record Video!
In addition to taking stills, the Raspberry Pi Camera Module can record video. Again, you’ll need to use the right command, this time using the raspivid tool. This command will record a video in HD:
raspivid -o video.h264
(As with raspistill, you can use -vf and -hf if necessary.)
Note that a standard microSD card is likely to be too small for lengthy video recording (although if you have hooked up an external drive, this should provide more than enough space). As such, you might use the -t flag to limit the recording time, using a value in milliseconds:
raspivid -o video.h264 -t 5000
This will record five seconds of footage.
Have Fun With Your Raspberry Pi Camera Module
With your Raspberry Pi connected to its preferred camera option, you’re ready to take photos, and record video. So, what’s next?
Well, you could hook up a thermal printer and create a Polaroid-style instant camera. Or you might use it as the camera in your own stop-motion animation studio.
The choice is yours. For more setup tips, check our unofficial Raspberry Pi setup guide.