How to set exposure and gain parameters for IMX219 with v4l2-ctl?

I can perfectly get images via

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.raw

after debayering, I found that the obtained image is too dark, so I want to increase the exposure time and gain to get clearer images, so I set

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl=exposure=33333,gain=130,bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.raw

but after debayering, I still found the image is dark, this setting doesn’t seem to be useful, How can I set the parameters correctly? thanks

The command is not correct should be like below. “–set-ctrl exposure=xxx” instead of “–set-ctrl=exposure=33333”

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl exposure=33300,gain=110,bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.raw

thank you, I tried your command, but it still doesn’t work

Enable the debug print to check the dmesg to confirm the driver set control

echo file imx219.c +p > /sys/kernel/debug/dynamic_debug/control

You may need to account for the fixed point scaling used within the camera drivers.

Look at v4l2-ctl -l to see the min, max, and step values for the exposure control. I think you will find that the units are not micro seconds.

here is :

v4l2-ctl -l

Camera Controls

                 group_hold 0x009a2003 (bool)   : default=0 value=0 flags=execute-on-write
                sensor_mode 0x009a2008 (int64)  : min=0 max=5 step=1 default=0 value=0 flags=slider
                       gain 0x009a2009 (int64)  : min=16 max=170 step=1 default=16 value=130 flags=slider
                   exposure 0x009a200a (int64)  : min=13 max=683709 step=1 default=2495 value=333333 flags=slider
                 frame_rate 0x009a200b (int64)  : min=2000000 max=21000000 step=1 default=21000000 value=2000000 flags=slider
                bypass_mode 0x009a2064 (intmenu): min=0 max=1 default=0 value=0
            override_enable 0x009a2065 (intmenu): min=0 max=1 default=0 value=0
               height_align 0x009a2066 (int)    : min=1 max=16 step=1 default=1 value=1
                 size_align 0x009a2067 (intmenu): min=0 max=2 default=0 value=0
           write_isp_format 0x009a2068 (bool)   : default=0 value=0
   sensor_signal_properties 0x009a2069 (u32)    : min=0 max=4294967295 step=1 default=0 [30][18] flags=read-only, has-payload
    sensor_image_properties 0x009a206a (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
  sensor_control_properties 0x009a206b (u32)    : min=0 max=4294967295 step=1 default=0 [30][36] flags=read-only, has-payload
          sensor_dv_timings 0x009a206c (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
           low_latency_mode 0x009a206d (bool)   : default=0 value=0
               sensor_modes 0x009a2082 (int)    : min=0 max=30 step=1 default=30 value=5 flags=read-only

yes, the units are not micro seconds. But a larger exposure or gain should improve the luminance.

I would suggest to enable or add debug print in the sensor driver to confirm the REG setting is correct.

Thank you very much, I will try!

hello, I found another question, when I set bypass_mode=1(default is 0) or override_enable=1(default is 0), the below command will be stuck

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl bypass_mode=1 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.raw

and

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl override_enable=1 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.raw

what do these two parameters mean? and how to set them?

You can only use bypass_mode=0 for v4l2-ctl.
Also after you set the bypass_mode=0 the override_enable=1 should be worked.

thanks for quick reply, when I set bypass_mode=0, override_enable=1, it will also be stuck, I want to what these two parameters mean.

For the bypass_mode for switch the VI driver ownshipt from the argus camera v4l2,
For the override_eanble mode you should be able check with the sensor driver for the detail information.

hi, Shane, I found an interesting issue, I try blow command to control IMX219,

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12’ ! nvvidconv flip-method=0 ! ‘video/x-raw,width=960, height=616’ ! nvvidconv ! nvegltransform ! nveglglessink -e

it works very well, so I check the camera parameter, and I get

Camera Controls

                 group_hold 0x009a2003 (bool)   : default=0 value=0 flags=execute-on-write
                sensor_mode 0x009a2008 (int64)  : min=0 max=5 step=1 default=0 value=0 flags=slider
                       gain 0x009a2009 (int64)  : min=16 max=170 step=1 default=16 value=128 flags=slider
                   exposure 0x009a200a (int64)  : min=13 max=683709 step=1 default=2495 value=46765 flags=slider
                 frame_rate 0x009a200b (int64)  : min=2000000 max=21000000 step=1 default=21000000 value=21000000 flags=slider
                bypass_mode 0x009a2064 (intmenu): min=0 max=1 default=0 value=1
            override_enable 0x009a2065 (intmenu): min=0 max=1 default=0 value=1
               height_align 0x009a2066 (int)    : min=1 max=16 step=1 default=1 value=1
                 size_align 0x009a2067 (intmenu): min=0 max=2 default=0 value=0
           write_isp_format 0x009a2068 (bool)   : default=0 value=0
   sensor_signal_properties 0x009a2069 (u32)    : min=0 max=4294967295 step=1 default=0 [30][18] flags=read-only, has-payload
    sensor_image_properties 0x009a206a (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
  sensor_control_properties 0x009a206b (u32)    : min=0 max=4294967295 step=1 default=0 [30][36] flags=read-only, has-payload
          sensor_dv_timings 0x009a206c (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
           low_latency_mode 0x009a206d (bool)   : default=0 value=0
               sensor_modes 0x009a2082 (int)    : min=0 max=30 step=1 default=30 value=5 flags=read-only

I found bypass_mode=1 and override_enable=1, so I try v4l2-ctl command, as

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl=sensor_mode=0, --stream-mmap --stream-count=1 --stream-to=test9.raw

because the bypass_mode=1, so this command is stuck, then I run below command,

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set ctrl=sensor_mode=0,bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test9.raw

it works, and now the parameters of camera are

                 group_hold 0x009a2003 (bool)   : default=0 value=0 flags=execute-on-write
                sensor_mode 0x009a2008 (int64)  : min=0 max=5 step=1 default=0 value=0 flags=slider
                       gain 0x009a2009 (int64)  : min=16 max=170 step=1 default=16 value=128 flags=slider
                   exposure 0x009a200a (int64)  : min=13 max=683709 step=1 default=2495 value=46765 flags=slider
                 frame_rate 0x009a200b (int64)  : min=2000000 max=21000000 step=1 default=21000000 value=21000000 flags=slider
                bypass_mode 0x009a2064 (intmenu): min=0 max=1 default=0 value=0
            override_enable 0x009a2065 (intmenu): min=0 max=1 default=0 value=1
               height_align 0x009a2066 (int)    : min=1 max=16 step=1 default=1 value=1
                 size_align 0x009a2067 (intmenu): min=0 max=2 default=0 value=0
           write_isp_format 0x009a2068 (bool)   : default=0 value=0
   sensor_signal_properties 0x009a2069 (u32)    : min=0 max=4294967295 step=1 default=0 [30][18] flags=read-only, has-payload
    sensor_image_properties 0x009a206a (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
  sensor_control_properties 0x009a206b (u32)    : min=0 max=4294967295 step=1 default=0 [30][36] flags=read-only, has-payload
          sensor_dv_timings 0x009a206c (u32)    : min=0 max=4294967295 step=1 default=0 [30][16] flags=read-only, has-payload
           low_latency_mode 0x009a206d (bool)   : default=0 value=0
               sensor_modes 0x009a2082 (int)    : min=0 max=30 step=1 default=30 value=5 flags=read-only

yes, as you can see, the override_enable =1 and it works, but if I just set override_enable=1 via v4l2-ctl, the command will be stuck, it seems that gst-launch-1.0 nvarguscamerasrc can set override_enable successfully, and next, I try to change the exposure and gain parameter, and both these two parameter can work very well.

now I am confused that why the v4l2-ctl cannot set override_enable=1 directly via the command:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl=sensor_mode=0,override_enable=1,bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test9.raw