Cameras for Raspberry Pi

  1. Home
  2. Docs
  3. Cameras for Raspberry Pi
  4. Arducam (Userland Driver) MIPI Camera Modules
  5. Analysis of typical problems

Analysis of typical problems

Exposure and gain settings only changing on one of the two cameras when using 1-2 UC444 adapter board

For the 1-2 (UC444) adapter board, there is an i2c switch chip on board, which ensures that only one camera can communicate with the main control platform (PI) through the i2c bus at the same time, and the camera’s control parameter settings (exposure, Gain, etc.) need to be set through the i2c bus. Therefore, we must first ensure that the corresponding i2c channel is switched before setting the control parameters. Otherwise, the correct parameters cannot be written normally. Referring to the following source code:

import arducam_mipicamera as arducam
import v4l2 #sudo pip install v4l2
import time
import cv2 #sudo apt-get install python-opencv
import RPi.GPIO as gp
import sys
import os

gp.setup(7, gp.OUT)
gp.setup(11, gp.OUT)
camera_info = {
    "A" : {
        "i2c" : "i2cset -y 1 0x70 0x00 0x01",
        "gpio": [0, 0, 1],
    "B" : {
        "i2c" : "i2cset -y 1 0x70 0x00 0x02",
        "gpio": [1, 0, 1],

def switch_camera(index):
    info = camera_info.get(index)
    if info == None:
        raise TypeError("Unknown parameter.")
    gpio_info = info["gpio"]
    gp.output(7, gpio_info[0])
    gp.output(11, gpio_info[1])
    # gp.output(12, gpio_info[2])

def init_all_camera(mipi_camera, width, height):
    for i in range(2):
        switch_camera(chr(65 + i))
        fmt = camera.set_resolution(width, height)
    return fmt

def align_down(size, align):
    return (size & ~((align)-1))

def align_up(size, align):
    return align_down(size + align - 1, align)

def set_controls(camera):
        print("Reset the focus...")
    except Exception as e:
        print("The camera may not support this control.")

        print("Enable Auto Exposure...")
        camera.software_auto_exposure(enable = True)
        print("Enable Auto White Balance...")
        camera.software_auto_white_balance(enable = True)
    except Exception as e:

if __name__ == "__main__":
        # Open the first channel of I2c 
        camera = arducam.mipi_camera()
        print("Open camera...")
        print("Setting the resolution...")
        fmt = init_all_camera(camera, 1920, 1080)
        # switch to A channel
        index = ord('A')
        camera.set_control(v4l2.V4L2_CID_EXPOSURE, 12000)
        # switch to B channel
        index = ord('B')
        camera.set_control(v4l2.V4L2_CID_EXPOSURE, 12000)
        while cv2.waitKey(10) != 27:
            frame = camera.capture(encoding = 'i420')
            height = int(align_up(fmt[1], 16))
            width = int(align_up(fmt[0], 32))
            image = frame.as_array.reshape(int(height * 1.5), width)
            image = cv2.cvtColor(image, cv2.COLOR_YUV2BGR_I420)
            image = cv2.resize(image, (640, 360))
            cv2.imshow("Arducam {}".format(chr(index)), image)
            index += 1
            if index > ord('B'):
                index = ord('A')
        # Release memory
        del frame
        print("Close camera...")
    except Exception as e:

Was this article helpful to you? Yes 1 No