Difference between revisions of "Gx series camera appnotes 4 rpi"

From wiki_veye
Jump to navigation Jump to search
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[https://wiki.veye.cc/index.php/Gx_series_camera_appnotes_4_rpi/zh 查看中文]
+
[[Gx series camera appnotes 4 rpi/zh|查看中文]]
  
 
'''<big>How to use the GX series cameras on the Raspberry board</big>'''
 
'''<big>How to use the GX series cameras on the Raspberry board</big>'''
Line 14: Line 14:
 
|GX系列
 
|GX系列
 
|GX-MIPI-IMX662
 
|GX-MIPI-IMX662
|complete
+
|Done
 
|}
 
|}
  
===Hardware Preparation and Installation===
+
===Hardware Setup===
 
The GX-series cameras utilize a Raspberry Pi-compatible 22-pin interface but require an independent 5 V DC power supply.
 
The GX-series cameras utilize a Raspberry Pi-compatible 22-pin interface but require an independent 5 V DC power supply.
  
====The connection method of GX series cameras with 22-pin interface Raspberry Pi====
+
====The connection diagramof GX series cameras with 22-pin interface Raspberry Pi====
 +
<br />[[File:Gx to raspberry5 resized.png|center|thumb|800x800px|GX Camera to RaspberryPi 5]]
 
<br />
 
<br />
  
====The connection method between the GX series cameras and the 15-pin interface Raspberry Pi====
+
====The connection diagram between the GX series cameras and the 15-pin interface Raspberry Pi====
 +
<br />[[File:Gx to raspberry4 resized .png|center|thumb|800x800px|GX Camera to RaspberryPi 4]]
 
<br />
 
<br />
  
===Drive Installation and Verification===
+
===Driver Installation and Verification===
  
 
====Download the driver package====
 
====Download the driver package====
 
<code>wget <nowiki>https://github.com/veyeimaging/raspberrypi_v4l2/releases/latest/download/raspberrypi_v4l2.tgz</nowiki></code>
 
<code>wget <nowiki>https://github.com/veyeimaging/raspberrypi_v4l2/releases/latest/download/raspberrypi_v4l2.tgz</nowiki></code>
 
Domestic users can download it from Gitee:
 
 
https://gitee.com/veyeimaging/raspberrypi_v4l2/releases/
 
  
 
====install the driver====
 
====install the driver====
Line 51: Line 49:
  
 
====Uninstall the driver====
 
====Uninstall the driver====
If you want to switch to a different model of the camera module driver, you must first uninstall the current driver.<br /><code>sudo ./uninstall_driver.sh veye_gxcam</code>
+
To use a driver for a different camera module model, the currently installed driver must be uninstalled first.<br /><code>sudo ./uninstall_driver.sh veye_gxcam</code>
  
 
====System status verification====
 
====System status verification====
Line 60: Line 58:
 
<code>camera is: GX-MIPI-IMX662</code>
 
<code>camera is: GX-MIPI-IMX662</code>
  
And the /dev/video0 node exists, which proves that the camera is functioning properly.
+
And the /dev/video0 node exists, which proves that the camera is probed properly.
 
 
Note: Trigger script [https://github.com/veyeimaging/mvcam_raspberrypi/tree/main/mv_tools_rpi link].
 
  
===Detect the status and configure the environment variables===
+
===Check the status and configure the environment variables===
 
[https://github.com/veyeimaging/raspberrypi_v4l2/tree/main/gx_i2c_tools Here], we provide a script named gx_probe.sh, which is used to automatically detect the recognized camera and configure the default model, width, height, frame rate and other information of the camera into the environment variables.  
 
[https://github.com/veyeimaging/raspberrypi_v4l2/tree/main/gx_i2c_tools Here], we provide a script named gx_probe.sh, which is used to automatically detect the recognized camera and configure the default model, width, height, frame rate and other information of the camera into the environment variables.  
  
Line 104: Line 100:
 
<code>Plese get frame from /dev/video0 and use /dev/v4l-subdev2 for camera setting.</code>
 
<code>Plese get frame from /dev/video0 and use /dev/v4l-subdev2 for camera setting.</code>
  
After a reboot of the Raspberry Pi 5, the media node and video node assignments for the cameras may change. Therefore, it is recommended to run <code>./find_entity.sh</code> prior to performing subsequent operations to explicitly identify the device nodes.
+
After a reboot of the Raspberry Pi 5, the media node and video node assignments for the cameras may change.  
 +
 
 +
Therefore, it is recommended to run <code>./find_entity.sh</code> prior to performing subsequent operations to explicitly identify the device nodes.
  
 
As shown in the above diagnostic output, the system has detected two connected cameras, along with their corresponding device nodes.
 
As shown in the above diagnostic output, the system has detected two connected cameras, along with their corresponding device nodes.
Line 128: Line 126:
 
<code>    Once completed, you can directly use /dev/video0 or /dev/video8 to obtain image data.</code>
 
<code>    Once completed, you can directly use /dev/video0 or /dev/video8 to obtain image data.</code>
  
Before proceeding with the subsequent operations, this script must be executed to complete the configuration of the parameters.  
+
'''Before proceeding with the subsequent operations, this script must be executed to complete the configuration of the parameters.'''
  
 
For example, for the GX-MIPI-IMX662 that is connected to the CAM0 port:
 
For example, for the GX-MIPI-IMX662 that is connected to the CAM0 port:
Line 136: Line 134:
 
===Real-time preview===
 
===Real-time preview===
  
====Use veye_viewer to play the images====
+
====veye_viewer====  
veye_viewer is an open-source client software based on QT5.  
+
The <code>veye_viewer</code> is an open-source, Qt-based client application that allows users to easily evaluate cameras and configure parameters.  
  
For the code and usage, please refer to:https://github.com/veyeimaging/veye_viewer。
+
Its operation logs, register listings, and open-source nature provide a convenient reference for users and support custom development.
  
Domestic users can access the [https://gitee.com/veyeimaging/veye_viewer Gitee] repository.
+
The source code of <code>veye_viewer</code> can be downloaded [https://github.com/veyeimaging/veye_viewer here], or platform-specific executable programs are available directly in its [https://github.com/veyeimaging/veye_viewer/releases release packages].
  
====Use qv4l2 to play images====
+
====qv4l2====
 
First, install qv4l2
 
First, install qv4l2
  
Line 156: Line 154:
 
<br />
 
<br />
  
===Gstreamer Application Examples===
+
===Gstreamer Examples===
 
export DISPLAY=:0
 
export DISPLAY=:0
  
Line 166: Line 164:
 
<code>sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3</code>
 
<code>sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3</code>
  
====Run the gstreamer videotest command====
+
====Using GStreamer====
<code>gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink</code>
+
Through the script in [https://github.com/veyeimaging/raspberrypi_v4l2/tree/main/samples/gstreamer/yuv_camera GStreamer], functions such as image preview, picture capture, H264 video encoding and saving in MP4/MKV format can be realized.
 +
 
 +
===yavta===
 +
 
 +
====Installing yavta====
 +
<code>git clone <nowiki>git://git.ideasonboard.org/yavta.git</nowiki></code>
 +
 
 +
<code>$ cd yavta;make</code>
 +
 
 +
====yavta routine====
 +
<code>./yavta -c1 -F"y8-${WIDTH}x${HEIGHT}.yuv" --skip 0 -f UYVY -s "${WIDTH}x${HEIGHT}" /dev/video0</code>
 +
 
 +
example
 +
 
 +
<code>$ ./yavta -c1 -Fuyvy_1920X1080.yuv --skip 0 -f UYVY -s 1920x1080 /dev/video0</code>
 +
 
 +
===Importing Camera Data into OpenCV===
 +
 
 +
====Use OpenCV to preview images in UYVY format====
 +
 
 +
*install opencv
 +
 
 +
<code>$ sudo apt install python3-opencv</code>
  
====Capture a picture (GX-MIPI-IMX662 @ 1080p mode)====
+
*To import camera data from a V4L2 device into OpenCV, we provide several [https://github.com/veyeimaging/raspberrypi_v4l2/tree/main/samples/opencv/yuv_camera sample] programs.
<code>gst-launch-1.0 v4l2src num-buffers=1 device=/dev/video0 ! 'video/x-raw, format=(string)UYVY, width=1920,height=1080' ! jpegenc ! filesink location=test_image.jpg</code>
 
  
====Frame rate test (GX-MIPI-IMX662 @ 1080p mode)====
+
<code>$ python ./v4l2_opencv_show2.py --width 1920 --height 1080 --fps 30</code>
<code>gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! videoconvert ! fpsdisplaysink video-sink=fakesink -v</code>
 
  
====Video preview (GX-MIPI-IMX662 @ 1080p mode)====
+
For the Raspberry Pi 5, an additional parameter <code>--ctldev /dev/v4l-subdev*</code>needs to be added to specify the <code>subdev</code> for the configuration parameters.
<code>gst-launch-1.0 v4l2src io-mode=dmabuf device=/dev/video0 ! "video/x-raw,format=(string)UYVY, width=(int)1920, height=(int)1080,framerate=(fraction)30/1" ! v4l2convert capture-io-mode=dmabuf output-io-mode=dmabuf ! autovideosink sync=false -v</code>
 
  
===V4L2-CTL Application Examples===
+
===v4l2-ctl Examples===
  
 
====Install v4l2-utils====
 
====Install v4l2-utils====
Line 227: Line 244:
 
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl [ctrl_type]=[val]</code>
 
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl [ctrl_type]=[val]</code>
  
<code>v4l2-ctl -d /dev/v4l-subdev2 --get-ctrl [ctrl_type]</code>
+
<code>v4l2-ctl -d /dev/v4l-subdev2 --get-ctrl [ctrl_type]</code><br />Note: For Raspberry Pi 5, all the commands in this section that use v4l2-ctl configuration parameters need to add the -d parameter to specify the subdevice used for the configuration parameters.
 
 
<br />Note: For Raspberry Pi 5, all the commands in this section that use v4l2-ctl configuration parameters need to add the -d parameter to specify the subdevice used for the configuration parameters.  
 
  
 
For example, when executing <code>./media_setting_rpi5.sh</code> or <code>./find_entity.sh</code>, it prompts to use <code>/dev/v4l-subdev2</code> for parameter configuration.
 
For example, when executing <code>./media_setting_rpi5.sh</code> or <code>./find_entity.sh</code>, it prompts to use <code>/dev/v4l-subdev2</code> for parameter configuration.
Line 235: Line 250:
 
Then, the command <code>v4l2-ctl -L</code> should be changed to <code>v4l2-ctl -L -d /dev/v4l-subdev2</code>
 
Then, the command <code>v4l2-ctl -L</code> should be changed to <code>v4l2-ctl -L -d /dev/v4l-subdev2</code>
  
Note: All the above functions can be achieved by using the script [https://wiki.veye.cc/index.php/Gx_mipi_i2c.sh_user_guide gx_mipi_i2c.sh].  
+
Note: All the above functions can be achieved by using the script [[Gx mipi i2c.sh user guide|gx_mipi_i2c.sh]].  
  
 
It should be noted that the above parameters cannot be modified once the image capture process begins. The following will provide detailed explanations for each one:
 
It should be noted that the above parameters cannot be modified once the image capture process begins. The following will provide detailed explanations for each one:
Line 272: Line 287:
 
<code>$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>trigger_src=0</small></code>
 
<code>$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>trigger_src=0</small></code>
  
<br />
+
======Start acquisition======
 +
<code>v4l2-ctl --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=5 --stream-to="uyvy-${WIDTH}x${HEIGHT}.yuv"</code>
 +
 
 +
======Perform soft trigger operation======
 +
In other shell terminals, you can execute the following command multiple times for multiple triggers.<br /><code>$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>soft_trgone=1</small></code>
 +
 
 +
=====Hardware trigger mode=====
 +
Here, using GPIO21 of the Raspberry Pi as the analog trigger source and with the rising edge as the trigger condition, is exemplified.
 +
 
 +
The rich trigger parameter settings can be carried out by using the [[Gx mipi i2c.sh user guide|gx_mipi_i2c.sh]] script.
 +
 
 +
======Set mode======
 +
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>trigger_mode=1</small></code>
 +
 
 +
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>trigger_src=1</small></code>
 +
 
 +
======Start acquisition======
 +
<code>v4l2-ctl --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=5 --stream-to="uyvy-${WIDTH}x${HEIGHT}.yuv"</code>
 +
 
 +
======Perform hardware trigger operation======
 +
In other shell terminals, you can execute the following command multiple times to trigger it repeatedly.
 +
 
 +
<code>$ python gpio_trigger.py</code>
 +
 
 +
Note: Trigger script [https://github.com/veyeimaging/raspberrypi_v4l2/tree/main/gx_i2c_tools link].
 +
 
 +
====Video Streaming mode====
 +
 
 +
=====Set frame rate=====
 +
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl frame_rate=$FPS</code>
 +
 
 +
=====The following command can be used for frame rate statistics=====
 +
<code>v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=-1 --stream-to=/dev/null</code>
 +
 
 +
=====Save image to file=====
 +
 
 +
*UYVY
 +
 
 +
<code>v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to="y8-${WIDTH}x${HEIGHT}.yuv"</code>
 +
 
 +
or
 +
 
 +
<code>./yavta -c-1 --skip 0 -f UYVY -s ${WIDTH}x${HEIGHT} /dev/video0</code>
 +
 
 +
====Synchronous Mode====
 +
The <code>subdev</code>below needs to be differentiated based on the actual situation.
 +
 
 +
=====Set synchronous mod=====
 +
<code>$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl work<small>_mode=4</small></code>
 +
 
 +
=====Set the camera as the master or slave=====
 +
master camera:
 +
 
 +
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>sync_role=0</small></code>
 +
 
 +
slave camera:
 +
 
 +
<code>v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl <small>sync_role=1</small></code>
 +
 
 +
=====Start taking pictures=====
 +
The image capture method in synchronous mode is identical to that used in video streaming mode.
 +
 
 +
===Shell script for parameter configuration===
 +
We provided shell scripts to configure the parameters.
 +
 
 +
[[gx_mipi_i2c.sh user guide]]
 +
 
 +
===Recommendations for Customer Integration and Development===
 +
 
 +
====Initialization Stage====
 +
Resolution and frame rate configuration must be completed. It is recommended that customers perform these configurations during the program initialization phase by invoking the <code>v4l2-ctl</code> commands and the <code>media_setting_rpi5.sh</code> script. This ensures that resolution, frame rate, and data format are properly set.
 +
 
 +
Avoid using <code>gx_mipi_i2c.sh</code> to directly modify camera registers, as changes made at the register level may not be properly reflected in the Raspberry Pi Linux driver stack.
 +
 
 +
====Operation Stage====
 +
Depending on the programming language used, customers can refer to the code samples and tools described earlier in this document.
 +
 
 +
Regarding timestamps, <code>v4l2_buffer.timestamp</code> provides the exact time when the Raspberry Pi SoC receives a complete frame. This can be used as a reference timestamp for camera synchronization or for synchronizing with external sensors.
 +
 
 +
====Parameter Configuration====
 +
The GX series cameras offer rich and flexible configuration options, primarily implemented through direct register settings via <code>gx_mipi_i2c.sh</code>. Please refer to the register documentation and the <code>gx_mipi_i2c.sh</code> manual for details.
 +
 
 +
The <code>gx_mipi_i2c.sh</code> script includes a <code>paramsave</code> feature, which stores all configured parameters in the camera’s flash memory. Frequent invocation of this function within programs is not recommended.
 +
===This document's revision history===
 +
 
 +
*2025-12-06
 +
 
 +
The first version

Latest revision as of 14:13, 30 December 2025

查看中文

How to use the GX series cameras on the Raspberry board

1 overview

The GX series cameras are designed for embedded AI applications. They offer high-performance ISP capabilities, support multiple operating modes, provide a wide range of configurable features, and are built with a robust and reliable design. The cameras use the MIPI CSI-2 interface and are well suited for embedded computing platforms.

1.1 Supported modules

series model state
GX系列 GX-MIPI-IMX662 Done

2 Hardware Setup

The GX-series cameras utilize a Raspberry Pi-compatible 22-pin interface but require an independent 5 V DC power supply.

2.1 The connection diagramof GX series cameras with 22-pin interface Raspberry Pi


GX Camera to RaspberryPi 5


2.2 The connection diagram between the GX series cameras and the 15-pin interface Raspberry Pi


GX Camera to RaspberryPi 4


3 Driver Installation and Verification

3.1 Download the driver package

wget https://github.com/veyeimaging/raspberrypi_v4l2/releases/latest/download/raspberrypi_v4l2.tgz

3.2 install the driver

tar -xzvf raspberrypi_v4l2.tgz

cd raspberrypi_v4l2/release/

chmod +x *

  • For Raspberry Pi 5

sudo ./install_driver.sh veye_gxcam

Then restart the Raspberry Pi.

Note: If it is indicated that the corresponding version of the driver cannot be found, it means that we do not provide the compiled driver program corresponding to your PiOS version. Please try to compile from the source code.

3.3 Uninstall the driver

To use a driver for a different camera module model, the currently installed driver must be uninstalled first.
sudo ./uninstall_driver.sh veye_gxcam

3.4 System status verification

Take GX-MIPI-IMX662 as an example:
dmesg | grep gxcam

It can be seen that the camera model probed during the Linux startup stage is:

camera is: GX-MIPI-IMX662

And the /dev/video0 node exists, which proves that the camera is probed properly.

4 Check the status and configure the environment variables

Here, we provide a script named gx_probe.sh, which is used to automatically detect the recognized camera and configure the default model, width, height, frame rate and other information of the camera into the environment variables.

The usage method is:
$ source ./gx_probe.sh i2c_bus

A typical output is as follows:

$ source ./gx_probe.sh 10

The gxcam driver is loaded on i2c-10, but the camera is not detected!

Found veye_gxcam camera on i2c-10.

Setenv CAMERAMODEL = GX-MIPI-IMX662

Setenv FPS = 60

Setenv WIDTH = 1920

Setenv HEIGHT = 1080

You can verify the output result of the environment variable by using the command echo $CAMERAMODEL. Note that this environment variable is only valid for the current session.

5 Configuration of Raspberry Pi 5

On the Raspberry Pi 5, the camera driver now operates via the Media Controller API, necessitating proper configuration of the media graph beforehand. This involves correctly setting the formats of the media pads and establishing appropriate pad links.

A set of scripts implementing this functionality is provided and stored in the rpi5_scripts directory.

  • ./find_entity.sh

$ ./find_entity.sh

This is a Raspberry Pi 5.

Kernel version is 6.12.47, use i2c-10 for CAM0 and i2c-11 for CAM1.

Found gxcam @ i2c-10 entity on /dev/media3

Plese get frame from /dev/video0 and use /dev/v4l-subdev2 for camera setting.

After a reboot of the Raspberry Pi 5, the media node and video node assignments for the cameras may change.

Therefore, it is recommended to run ./find_entity.sh prior to performing subsequent operations to explicitly identify the device nodes.

As shown in the above diagnostic output, the system has detected two connected cameras, along with their corresponding device nodes.

The CAM0 port on the board corresponds to i2c-10, and the CAM1 port on the board corresponds to i2c-11.

  • media_setting_rpi5.sh

$ ./media_setting_rpi5.sh

This is a Raspberry Pi 5.

Kernel version is 6.12.47, do not support unpacked format.

Kernel version is 6.12.47, use i2c-10 for CAM0 and i2c-11 for CAM1.

Usage: ./media_setting_rpi5.sh veyecam2m/csimx307/cssc132/mvcam/gxcam -fmt [UYVY/RAW8/RAW10/RAW12] -x [roi_x] -y [roi_y] -w [width] -h [height] -c [cam 0|1]

This shell script is designed to detect the connection of a camera on Raspberry Pi 5.

    It utilizes media-ctl and v4l2-ctl commands to configure the linking relationships and data formats of the media pad.

    Once completed, you can directly use /dev/video0 or /dev/video8 to obtain image data.

Before proceeding with the subsequent operations, this script must be executed to complete the configuration of the parameters.

For example, for the GX-MIPI-IMX662 that is connected to the CAM0 port:

./media_setting_rpi5.sh gxcam -fmt UYVY -x 0 -y 0 -w 1920 -h 1080 -c 0

6 Real-time preview

6.1 veye_viewer

The veye_viewer is an open-source, Qt-based client application that allows users to easily evaluate cameras and configure parameters.

Its operation logs, register listings, and open-source nature provide a convenient reference for users and support custom development.

The source code of veye_viewer can be downloaded here, or platform-specific executable programs are available directly in its release packages.

6.2 qv4l2

First, install qv4l2

sudo apt install qv4l2

Note: For Raspberry Pi 5, you need to execute the aforementioned media_setting_rpi5.sh script before starting the qv4l2 image playback to complete the necessary preparations.

Enter "qv4l2" in the command line to start the V4L2 player.

2. Click the ▶ (play) button to bring up the opened media window.

Play gx camera using qv4l2 on RPI


7 Gstreamer Examples

export DISPLAY=:0

7.1 Install GStreamer

sudo apt-get install gstreamer1.0-tools

sudo apt-get install libx264-dev libjpeg-dev

sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3

7.2 Using GStreamer

Through the script in GStreamer, functions such as image preview, picture capture, H264 video encoding and saving in MP4/MKV format can be realized.

8 yavta

8.1 Installing yavta

git clone git://git.ideasonboard.org/yavta.git

$ cd yavta;make

8.2 yavta routine

./yavta -c1 -F"y8-${WIDTH}x${HEIGHT}.yuv" --skip 0 -f UYVY -s "${WIDTH}x${HEIGHT}" /dev/video0

example

$ ./yavta -c1 -Fuyvy_1920X1080.yuv --skip 0 -f UYVY -s 1920x1080 /dev/video0

9 Importing Camera Data into OpenCV

9.1 Use OpenCV to preview images in UYVY format

  • install opencv

$ sudo apt install python3-opencv

  • To import camera data from a V4L2 device into OpenCV, we provide several sample programs.

$ python ./v4l2_opencv_show2.py --width 1920 --height 1080 --fps 30

For the Raspberry Pi 5, an additional parameter --ctldev /dev/v4l-subdev*needs to be added to specify the subdev for the configuration parameters.

10 v4l2-ctl Examples

10.1 Install v4l2-utils

$ sudo apt-get install v4l-utils

10.2 v4l2-ctl routine

  • Capture a raw UYVY data image (in 1080p mode)

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to=uyvy-1920x1080.yuv

  • Capture 10 original UYVY data images (in 1080p mode)

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=UYVY --stream-mmap --stream-count=10 --stream-to=uyvy-1920x1080_stream.yuv

10.3 List the data formats supported by the camera

v4l2-ctl --list-formats-ext

ioctl: VIDIOC_ENUM_FMT

        Type: Video Capture

        [0]: 'UYVY' (UYVY 4:2:2)

                Size: Discrete 1920x1080

        [1]: 'YUYV' (YUYV 4:2:2)

Note: For Raspberry Pi 5, the actual supported image formats depend on the camera's capabilities, rather than being limited to the list provided here.

10.4 Configure parameters using v4l2-ctl

v4l2-ctl -d /dev/v4l-subdev2 -L

User Controls

                   trigger_mode 0x00981a01 (int)    : min=0 max=4 step=1 default=0 value=0 flags=volatile, execute-on-write

                    trigger_src 0x00981a02 (int)    : min=0 max=1 step=1 default=1 value=1 flags=volatile, execute-on-write

                    soft_trgone 0x00981a03 (button) : value=0 flags=write-only, execute-on-write

                      sync_role 0x00981a04 (int)    : min=0 max=1 step=1 default=0 value=0 flags=volatile, execute-on-write

                     frame_rate 0x00981a05 (int)    : min=0 max=60 step=1 default=60 value=60 flags=volatile, execute-on-write

The parameters can be set and retrieved using the following methods.

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl [ctrl_type]=[val]

v4l2-ctl -d /dev/v4l-subdev2 --get-ctrl [ctrl_type]
Note: For Raspberry Pi 5, all the commands in this section that use v4l2-ctl configuration parameters need to add the -d parameter to specify the subdevice used for the configuration parameters.

For example, when executing ./media_setting_rpi5.sh or ./find_entity.sh, it prompts to use /dev/v4l-subdev2 for parameter configuration.

Then, the command v4l2-ctl -L should be changed to v4l2-ctl -L -d /dev/v4l-subdev2

Note: All the above functions can be achieved by using the script gx_mipi_i2c.sh.

It should be noted that the above parameters cannot be modified once the image capture process begins. The following will provide detailed explanations for each one:

10.4.1 Trigger mode

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl work_mode=[0-2]

0: Streaming Mode

1: Ordinary Trigger Mode

4: Multi-camera Synchronization Mode

10.4.2 Trigger Source

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=[0-1]

0: Soft Trigger

1: Hard Trigger

10.5 Software trigger command

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl soft_trgone=1

10.5.1 Set frame rate

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl frame_rate=[1-max]

As the resolution is adjusted, the maximum frame rate will be automatically updated.

10.6 Trigger mode

10.6.1 Soft Trigger Mode
10.6.1.1 Set Mode

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl work_mode=1

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=0

10.6.1.2 Start acquisition

v4l2-ctl --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=5 --stream-to="uyvy-${WIDTH}x${HEIGHT}.yuv"

10.6.1.3 Perform soft trigger operation

In other shell terminals, you can execute the following command multiple times for multiple triggers.
$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl soft_trgone=1

10.6.2 Hardware trigger mode

Here, using GPIO21 of the Raspberry Pi as the analog trigger source and with the rising edge as the trigger condition, is exemplified.

The rich trigger parameter settings can be carried out by using the gx_mipi_i2c.sh script.

10.6.2.1 Set mode

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_mode=1

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=1

10.6.2.2 Start acquisition

v4l2-ctl --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=5 --stream-to="uyvy-${WIDTH}x${HEIGHT}.yuv"

10.6.2.3 Perform hardware trigger operation

In other shell terminals, you can execute the following command multiple times to trigger it repeatedly.

$ python gpio_trigger.py

Note: Trigger script link.

10.7 Video Streaming mode

10.7.1 Set frame rate

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl frame_rate=$FPS

10.7.2 The following command can be used for frame rate statistics

v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=-1 --stream-to=/dev/null

10.7.3 Save image to file
  • UYVY

v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to="y8-${WIDTH}x${HEIGHT}.yuv"

or

./yavta -c-1 --skip 0 -f UYVY -s ${WIDTH}x${HEIGHT} /dev/video0

10.8 Synchronous Mode

The subdevbelow needs to be differentiated based on the actual situation.

10.8.1 Set synchronous mod

$ v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl work_mode=4

10.8.2 Set the camera as the master or slave

master camera:

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl sync_role=0

slave camera:

v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl sync_role=1

10.8.3 Start taking pictures

The image capture method in synchronous mode is identical to that used in video streaming mode.

11 Shell script for parameter configuration

We provided shell scripts to configure the parameters.

gx_mipi_i2c.sh user guide

12 Recommendations for Customer Integration and Development

12.1 Initialization Stage

Resolution and frame rate configuration must be completed. It is recommended that customers perform these configurations during the program initialization phase by invoking the v4l2-ctl commands and the media_setting_rpi5.sh script. This ensures that resolution, frame rate, and data format are properly set.

Avoid using gx_mipi_i2c.sh to directly modify camera registers, as changes made at the register level may not be properly reflected in the Raspberry Pi Linux driver stack.

12.2 Operation Stage

Depending on the programming language used, customers can refer to the code samples and tools described earlier in this document.

Regarding timestamps, v4l2_buffer.timestamp provides the exact time when the Raspberry Pi SoC receives a complete frame. This can be used as a reference timestamp for camera synchronization or for synchronizing with external sensors.

12.3 Parameter Configuration

The GX series cameras offer rich and flexible configuration options, primarily implemented through direct register settings via gx_mipi_i2c.sh. Please refer to the register documentation and the gx_mipi_i2c.sh manual for details.

The gx_mipi_i2c.sh script includes a paramsave feature, which stores all configured parameters in the camera’s flash memory. Frequent invocation of this function within programs is not recommended.

13 This document's revision history

  • 2025-12-06

The first version