How To Use The Raspberry Camera Module PI 3 B+ With CSI

1.1 Basic introduction to Raspberry Pi Platform

Currently Raspberry PI ( Also call RPI) + Raspberry camera module provides three applications: raspistill, raspivid, and raspistillyuv. Among them, raspistill and raspistillyuv are very similar, and both are used to capture images, while raspivid is used to capture video. The raspberry 2018.04.18 stretch version of the raspberry pi 3B+ system already comes with raspistill and raspivid, the other one does not support.

All applications run based on the command line and are written through OpenMAX’s mmal API. OpenMAX’s mmal API provides easier-to-use system components. Note that mmal is an API customized by Broadcom for the Videocore 4 system.

The application uses four OpenMAX (mmal) components: camera , preview, encoder, and null_sink. All applications use camera components, raspistill uses image encoding components, raspivid uses video encoding components, raspistillyuv does not use encoding components, but directly outputs YUV or RGB from the camera component to the file.

The preview display is an optional parameter, but it can be used in full screen or output to a designated display area for display. If the preview is disabled, the null_silk component will “absorb” the preview frame. This is because although the camera is not required to generate preview frames for display, they still need to be used for exposure calculation and white balance settings.

In addition, you can also omit the file name parameter, so you can directly preview and display without writing the file, or directly output to the standard output device. Command-line help can be obtained by directly entering the application name.

1.2 How to Install the Raspberry Pi Camera module

Warning: The cam module is very sensitive to static electricity. If you don’t have an anti-static wristband when installing the camera board, you can try to touch a faucet, metal sink, or other similar things.

The camera board and the Raspberry Pi are connected through a 15-pin cable by CSI interface.  So as to know the camera is a MIPI camera module with CSI-2. Only two connectors need to be connected, and the cable needs to be mounted on the camera circuit board and the Raspberry Pi. You need to install it correctly, otherwise, the cam module will not work. For the camera circuit board, the blue mark on the end of the cable should face the circuit board. For Raspberry Pi, the blue mark should be facing the direction of the network interface.

Although the two parts of the connector are not the same, they work in a similar way. For Raspberry Pi, pull up the buckles on both ends of the connector. It should be easy to pull up and able to move slightly. Fully insert the cable into the connecting seat, and make sure it is upright, and then gently press the buckles at both ends. For the camera circuit board, you also need to pull the buckle to the opposite direction of the circuit board, then gently insert the cable, and finally push the buckle back. Here is the difference between the connector of the board camera and the Pi.

1.3 Install RPI Cam Module Software


Execute the command line described below to download and install the latest kernel, GPU firmware and applications. You need to be connected to the Internet to achieve the following operations.

  1. $sudo apt-get update
  2. $sudo apt-get upgrade


Next, you first need to enable RPI cam module support in the raspi-config program of Raspberry Pi.

1) Connect the camera module and Raspberry Pi

2) Modify the Raspberry Pi configuration and turn on the camera module.

sudo raspi-config

Move the cursor to the Camera option and select Enable. Restart when exiting raspi-config. Enabling the option is to ensure that the GPU firmware can run correctly after restarting (including the camera driver and adjustment circuit), and the GPU is divided from the main memory to enough memory for the camera to run correctly.

The test system has been installed and working normally, you can try the following commands:

$raspistill -v -o test.jpg

This command will display the preview image from the camera for 5 seconds, and take a photo, and then save it as a file test.jpg, save it under the directory of /home/pi, and display the required information.

2.1 How to Take a Picture with Raspberry pi Camera

We use the rapistill command to take a screenshot (when you run this command, the indicator light on the Raspberry Pi will be on~):

raspistill -o image.jpg

Image as follows:

Here we see that the size of the picture is 2592X1944=5038848, which is about 5MP.

The relevant parameters of raspistill command and the specific effects of the experiment:

-v: view debugging information

-w: image width

-h: image height

-rot: Image rotation angle, only supports 0, 90, 180, 270 degrees (  found that the input of other angles will be converted to these four angles)

-o: Image output address, such as image.jpg, if the file name is “-“, send the output to the standard output device

-t: wait time before acquiring images, the default is 5000, which is 5 seconds

-tl: How often to perform image capture

Execute the following command:

raspistill -o image%d.jpg -rot 180 -w 1024 -h 768 -t 20000 -tl 5000 -v

Then the following will output a series of captured information:

Such as the size of the picture

Total capture time of the picture

Whether the image is rotated

Whether to reverse horizontally and vertically

Here is the final captured result

Note: Here is an explanation of the relationship between the number of pictures collected and the -t parameter and -tl parameter: N_Picture = -t (waiting time before acquiring the image)/-tl (how often the capture time is executed) + 1. So there are 20000/5000+1 = 5 pictures

2.1 How to Record Video with Raspberry pi Camera

Use raspivid command to generate .h246 file

raspivid -o wannnatek.h264 -t 10000 -w 1280 -h 720

This will generate wannatek.h264 file under the current folder:

If you want to change the shooting duration, just use the “-t” option to set the length you want (the unit is milliseconds).

If you want to change the resolution of the image, use the “-w” and “-h” options to reduce the resolution to 1280×720 and so on.

2.3 How to Stream With Raspberry Pi Camera

  1. First, you need to install the VLC software on your Raspberry Pi

sudo apt-get update

sudo apt-get install vlc –fix-missing

sudo apt-get install vlc

  1. Start your Raspberry Pi camera

sudo raspivid -o–rot 180 -t 0 -fps 30|cvlc -vvv stream:///dev/stdin –sout’#standard{access=http,mux=ts,dst=:8080}’ :demux= h264

  1. Open the VLC software on your PC, select to open the network stream (Ctrl+N), enter the port number of the above command and the IP address of the corresponding Raspberry Pi

(As shown in the figure below, the IP address of my Raspberry Pi is, the result of the operation is shown in the figure below. Of course, I found that the Http video stream is indeed relatively slow. Of course, the quality of the video I used is a 500W pixel picture. Therefore, the quality of the video is relatively poor. When I adjust the quality of the video to 720*360, it feels very smooth. (@LAN test environment)

3.1 Conclusion

For camera module applications, in addition to taking static images, the most commonly used is to capture dynamic images or record videos. Raspberry Pi is a powerful development board, which can be combined with different camera modules. It should be like Raspberry Pi B+ motion to build a camera security monitoring system. Raspberry Pi can realize motion capture, capture and store photos, IR camera, webcam camera …welcome to testing our camera module in the following links.

About the author