Raspberry Pi For Dummies, 4th Edition
Book image
Explore Book Buy On Amazon
Connecting a Raspberry Pi Camera Module is the first step. Once you have connected your Raspberry Pi Camera Module, it’s a good idea to test whether it’s working correctly.

Make sure the camera is enabled: Go into the Raspberry Pi Configuration tool, click Interfaces, and select Enabled beside the Camera option.

Let’s test the camera from the command line interface. Click the Terminal icon at the top of the screen to start. It has a >_ symbol on it. To take a still photo, type in this command:

raspistill -o testshot.jpg

You should see what the camera sees onscreen for a moment before it takes the picture. You can verify that the image was created by looking at the files in your directory with this command:

ls

You can use lots of different options to take still photos, too. This example takes a shot with the pastel filter and flips the picture horizontally (-hf) and vertically (-vf):

raspistill -ifx pastel -hf -vf -o testshot2.jpg

All those hyphens and letter combinations might seem a bit random to you now, but once you have learned a little more, they should make more sense. To see the documentation for raspistill, type

raspistill 2>&1 | less

Use the down-arrow key to move through the information, and press Q to finish.

Your photos are stored in your pi directory. Use the File Manager to find your files and Image Viewer to see them.

To shoot video, you use raspivid. Enter this command to shoot a 5-second film:

raspivid -o testvideo.h264 -t 5000

You can view the video you made using

omxplayer testvideo.h264

The video footage is captured as a raw H264 video stream. For greater compatibility with media players, it's a good idea to convert it to an MP4 file. Start by installing MP4box using this command:

sudo apt-get install gpac

Then you can convert your video file (called testvideo.h264) into an MP4 file (called testvideo.mp4) like this:

MP4Box -add testvideo.h264 testvideo.mp4

You can get help on using raspivid with

raspivid 2>&1 | less

There is also a library you can use in Python to access the camera from your own Python programs. See the documentation for more information on using the Raspberry Pi Camera Module.

About This Article

This article is from the book:

About the book authors:

Sean McManus is an expert technology and business author. His previous books include Mission Python, Coder Academy, and Cool Scratch Projects in Easy Steps. Mike Cook is a lifelong electronics buff, a former lecturer in physics at Manchester Metropolitan University, and the author of more than 300 articles on computing and electronics. You'll often find him monitoring technology forums under the moniker Grumpy Mike.

This article can be found in the category: