For this guide, we're going to be using the Raspberry Pi Camera. If you've done it before, connecting the camera is easy. If not, you might want to follow our more detailed guide on connecting the camera to the Raspberry Pi.
To connect the camera, first shut down the Pi. Then locate the camera port, and lift up on the tab. Slide the camera's flex cable into the port, and then close the tab to lock it in place. Then you can power the Pi back on.
To use the camera you'll have to enable it using raspi-config.
Once raspi-config opens, use the arrow keys to navigate to the line that says "Enable Camera" and hit enter. Then select "Yes" and hit enter again. Select "OK" and then "Finish".
You'll be prompted to restart the machine. In order for the camera to work, you'll have to reboot.
We're going to create a Python script to snap a picture called "camera.py".
You can do this right in the pi user's home directory (which is where you should be if you ssh'd in). To create the file, type:
Then you can edit the file in your favorite editor. Add the following to camera.py.
#!/usr/bin/env python from picamera import PiCamera from time import sleep camera = PiCamera() camera.start_preview() sleep(5) camera.capture('/tmp/picture.jpg') camera.stop_preview()
As you can see, this file is pretty simple. We use the picamera module to control our camera. First, we start a preview. This turns on the camera and allows it to begin to focus. We wait 5 seconds to give it enough time to focus, and then we capture the picture. For this example, we save the picture to /tmp/picture.jpg.
To see the picture there are a few options. First, you can log in to the Pi using VNC and view the image from the Pi desktop. Or you can simply scp the file to your local machine and view it there.
To do so use:
scp pi@raspberrypi:/tmp/picture.jpg ~/Downloads/
This will place the image in your Downloads folder. Enjoy this picture of the succulent on my desk.
The Raspberry Pi Pico and Raspberries Pi Zero are miles apart when it comes to specs, form factor, and software support.