Do you have a Raspberry Pi but you don’t know what to use it for? Do not waste time, connect it to a camera and let the imagination fly.
I will explain it taking as an example a * Raspberry Pi 3 * and a * PiCamera 2.0 *. But for all other cases it is the same or very similar.
I will explain how to use it with * Python *.
What I need?
You will need a Raspberry Pi 3 and a PiCamera 2.0.
Also, if you know Python it will be great for you later. In case you have no idea what I am talking about, do not worry, it will be easy!.
1) Install Raspbian in the RPi3. In case you don’t know how to do that, you can visit my other post First steps with Raspberry Pi donde te explico paso a paso como comenzar.
2) Connet the PiCamera into the correct slot
Make sure that the Raspberry Pi is turn off!.
3) Turn on the RPi3. Now is time to enable the camera.
How can I do that? It’s very easy, you need to do:
- Raspberry Pi configuration
- Make sure to enable the camera.
Use the camera
Programming with Python 3
Como instalamos Raspbian, aprovecharemos que ya tiene instalado Python
3) Python 3
- New file
- Save as camera.py (Don’t save it as picamera.py).
- Enter the following code:
from picamera import PiCamera from time import sleep camera = PiCamera() camera.start_preview() sleep(10) camera.stop_preview()
Save with Ctrl + S and run with F5. The camera preview should be shown for 10 seconds, and then close. Move the camera around to preview what the camera sees.
But before finishing this tutorial why not explain the most common function of a camera?
TAKE A PICTURE!!
Amend your code to reduce the sleep and add a camera.capture() line.
camera.start_preview() sleep(5) camera.capture('/home/pi/Desktop/image.jpg') camera.stop_preview()
It’s important to sleep for at least 2 seconds before capturing, to give the sensor time to set its light levels.
Run the code and you’ll see the camera preview open for 5 seconds before capturing a still picture.
You’ll see your photo in /home/pi/Desktop named image.png