Raspberry Pi 5 Camera Control

This section describes how to run the camera input selection demo script for the PAL–MIPI CSI-2 Bridge Board on the Raspberry Pi 5. The control script communicates with the bridge board over I2C to dynamically select between the three composite video inputs during live streaming.

Download the Control Script

Download the control_pal_mipi.py script on your Raspberry Pi 5 or copy the full code below.

Download Link: control_pal_mipi.py

Note:

If file is not able to download, go through Full Script section below.

Install Dependencies on Raspberry Pi 5

Before running the script, install the required libraries. Since Debian 13 (Trixie) enforces a PEP 668 externally managed environment, you can install the packages using apt or use the --break-system-packages flag with pip3.

Update Package List

sudo apt update

Install pip3

sudo apt install python3-pip

Dependency — smbus2

pip3 install smbus2 --break-system-packages    # for i2c communication
I2C Interface Enable

Open the Raspberry Pi configuration utility:

sudo raspi-config

Please follow the following steps to enable I2C interface:

Interface Options -> I2C -> Yes -> OK -> Finish
Run the Control Script

Once the dependencies are installed, navigate to the directory where the script was copied and execute it using Python3 in terminal

python3 control_pal_mipi.py

Note

The camera is connected to CAM0 (CSI0), which uses I2C bus 6 (smbus2.SMBus(6)).

Script Overview
FunctionDescription
I²C InitializationOpens I²C bus 6 (CAM0), connects to the PAL–MIPI bridge board
Input SelectionSelects between three independent composite video inputs via I²C register write
Live SwitchingEnables dynamic input switching without interrupting the video stream
Full Script

Save the following code as control_pal_mipi.py on your Raspberry Pi:

import smbus2
import time
 
bus = smbus2.SMBus(6)
I2C_ADDR = 0x48  # Bridge board I2C address
 
def write_reg(reg, data):
    bus.write_byte_data(I2C_ADDR, reg, data)
 
def select_input(channel):
    # channel: 0, 1, or 2 for composite inputs 1, 2, or 3
    write_reg(0x00, channel & 0x03)
 
# Select input 0 (composite channel 1)
select_input(0)
time.sleep(2)
 
# Select input 1 (composite channel 2)
select_input(1)
time.sleep(2)
 
# Select input 2 (composite channel 3)
select_input(2)
time.sleep(2)