Getting started with PiCamera module with your Raspberry Pi

Do you use your Raspberry Pi to take pictures or Recording videos? Now, you will be able to do just that using the PiCamera module.

The Raspberry Pi Camera Module is a custom designed add-on for Raspberry Pi. It attaches to Raspberry Pi by way of one of the two small sockets on the board upper surface.

Picamera description

Connect the Camera Module:

  • First of all, your Pi must be switched off. Then connect the Camera module in the socket as shown in the next image.

Pi camera Socket

  • Start Up the Pi.
  • Select “ Preferences” from the main menu on the upper left side of the Desktop, then select “Raspberry Pi Configuration Tool”.

Pi camera software configuration

  • Now, We will make sure that the Camera software is Enabled, and If not choose Enabled then click “OK” and REBOOT your PI.

Preview your Camera

After your camera is connected and your software is enabled and rebooting the Pi, you can get started by trying out the camera preview.

  1. Open Python 3 from the main menu

 

Pi camera preview

  1. Open a new file and save it as py . It’s important that you do not save it as picamera.py .

3. Enter the following code:

CODE 1

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

NOTE:

the camera preview only works when a monitor is connected to the Pi, so remote access (such as SSH and VNC) will not allow you to see the camera preview.

 

Take a Picture

  • Open a new file or edit the previous one to be like this code:-

CODE 2

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 the preview adjust to a different resolution momentarily as the picture is taken.
  • You’ll see your photo on the Desktop. Double-click the file icon to open.

Recording a Video

  • We can make a simple modification to the previous code to record a video to be like this:-

CODE 3

  • Run the code; it will record 10 seconds of video and then close the preview.
  • To play the video, Open the terminal window and Type the following command and press Enter to play the video:

omxplayer video.h264

Recent Posts