How to use Raspberry Pi Camera

Step by step how to use it

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!.

camara

Picamera 2.0

Enable camera

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

Warning!

Make sure that the Raspberry Pi is turn off!.

connect-camara

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:

  • Menu
  • Preferences
  • Raspberry Pi configuration

menu

  • Interfaces
  • Make sure to enable the camera.

enable-camera

4) Reboot.


Use the camera

Programming with Python 3

Como instalamos Raspbian, aprovecharemos que ya tiene instalado Python

1) Menu
2) Programming
3) Python 3

enter image description here

  • 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

Now you can start to play with your new camera!

Start thinking about innovative projects that involve the use of a camera and surprised your friends!

Leave a comment