How to setup a VC MIPI MODULE on a Raspberry PI Compute IO Board 3
Hardware Setup
1.1 Hardware Pre-Check: Install Raspbian
1.2 Connect the MIPI module
1.3 Optional: Trigger input (if supported)
1.4 Optional: Connect a second MIPI module
1.4.1 Additional cable setupSoftware Setup
2.1 Get the driver and demo code
2.2 Install necessary Raspberry Pi OS packages
2.3 Driver Installation
2.4 First Image Acquisition Test
2.5 Running the Demo
2.5.1 Compile the programs
2.5.2 Execute the demo
2.6 Switching Sensor Configuration
2.6.1 Sensor modes
2.6.2 Sensor modes description
2.6.3 IO configuration
2.6.4 Self-triggered modeTroubleshooting and Background Information
3.1 Q/A
3.2 Driver Knowledge
3.2.1 Providing device tree overlays
3.2.2 Set up the I²C bus for driver-sensor communication
3.2.3 Providing the sensor driver as kernel module
3.2.4 Reserving Contiguous Memory for the Image Captures
1 Hardware Setup
The power supply must at least provide 2.5A at 5V.
1.1 Hardware Pre-Check: Install Raspbian
First step is to install Raspberry Pi OS from
Operating system images – Raspberry Pi
The driver is known to work with the kernel version 5.10 and 5.15, so download the appropriate Raspberry Pi OS version. Raspberry Pi OS Buster Lite is sufficient, and this guide expects this version to be installed not only for the framebuffer output handling.
For more installation instructions see the Raspberry Pi OS Installation Manual; the procedure depends on the platform type where the OS is going to be installed.
The display shows a login prompt after successful installation. If this is not the case, you have to check your Raspberry Pi OS installation. The most relevant information to succeed can be found at the Raspberry Pi OS website or on the web.
1.2 Connect the MIPI module
Always disconnect all cables before connecting or disconnecting the MIPI module!
The ends of the MIPI module connector cable is marked with the hardware to connect to. Open the socket connectors first by raising their lid, insert the cable and press their lid back when mounted correctly. You should then not be able to pull the cable out.
The connection at this type of socket is not protected against bad alignment, so always check the orthogonality, and if it is bent, correct it! Also watch out for the right orientation of the cable! The MIPI module or the board connected on the other side can be irrevocably damaged if the cable is not inserted the right way, and warranty is lost!
The socket type is also not protected against wrong orientation, so compare your setup to the figures below before switching the power on.
Connect the MIPI sensor to the socket named CAM1.
The I²C bus named VC is used for sensor communication and must be connected by a cable bridge to the CAM1 socket's I²C bus pins.
Therefore connect the
pin named 44 with the pin named CD1_SDA as well as the
pin named 45 with the pin named CD1_SCL
at the J6 GPIO connector.
Do not connect other devices to the I²C bus named VC, since it can affect the communication between the camera sensor and the driver!
For example, running the touch screen of the Raspberry PI 7 inch display will lead to communication problems between driver and camera sensor. The display may work with the following line appended to the /boot/config.txt, but test first without connecting it to the Raspberry PI to be sure everything works so far:
disable_touchscreen=1
Reconnect the other peripherials to the Raspberry Pi.
You should have the login prompt back after switching the system on.
1.3 Optional: Trigger input (if supported)
If the MIPI sensor supports it, you can trigger it externally for an image capture. To do so, connect - for example - a frequency generator between CAM1_IO0 and GND.
To trigger the sensor,
choose an appropriate sensor mode which supports external triggering (see the driver's setmode), and
give a +3.3V impulse on the CAM1_IO0 pin
The impulse voltage may not exceed +3.3V, or the hardware will be damaged and warranty is lost!
1.4 Optional: Connect a second MIPI module
We assume that the same type of sensor is connected to the other port, but this is no limitation. You may connect a different sensor to the other socket.
It is best practice to start with one single sensor first, and if it works to come back here.
You have to understand how the I²C bus is configured and how the CSI port is selected as well as how to edit and handle device tree overlays to get the second MIPI module working -- see the Driver Knowledge section for that
1.4.1 Additional cable setup
The second sensor will be connected to the socket named CAM0. Its corresponding I²C pins at the J6 GPIO connector are CD0_SDA and CD0_SCL. We will use the second I²C bus i2c_arm to connect to the second sensor. Its data lane is at pin 2 while its clock signal resides at pin 3 of the J5 GPIO connector.
Therefore connect the J5 GPIO connector's
pin named 2 with the pin named CD0_SDA as well as the
pin named 3 with the pin named CD0_SCL
at the J6 GPIO connector.
2 Software Setup
2.1 Get the driver and demo code
You can download the driver and demo code from the following links.
Demo code: vcmipidemo_0.7.0.zip
2.2 Install necessary Raspberry Pi OS packages
Before beginning with the installation, do the following steps first. This requires your Raspberry PI to already have an internet connection; otherwise you have to install the packages mentioned manually, search the web for the procedure needed.
Update the raspberrypi-kernel package and your system by calling:
sudo apt-get update && sudo apt-get upgrade
Reboot.
Install the raspberrypi-kernel-headers and device-tree-compiler package by using the following command:
sudo apt-get install raspberrypi-kernel-headers device-tree-compiler
Test if the version of the running kernel matches the version of the kernel headers, the following command should show the directory for compiling the sensor module kernel module driver:
ls "/usr/src/linux-headers-$(uname -r)"
Install the dkms package with:
sudo apt-get install dkms
2.3 Driver Installation
If you already installed an older version of the driver, an update will not modify the device tree files and the configuration files, in case customers made their own changes. If you wish to update the device tree files and the configuration files together with the driver it is necessary to deinstall the driver first and to delete the device tree files with the following commands:
sudo apt-get purge vc-mipi-driver-bcm2835-dkms sudo rm -rf /boot/config_vc* sudo rm -rf /boot/overlays/vc-mipi*
It is important that the date and time of your Raspberry Pi are set correctly! You can set the date and time using NTP:
sudo apt-get install ntpdate ntpdate ip_address_of_ntp_server
Or you can use the command "date":
sudo date -s "2021-08-20 09:41:00"
In both cases store the time and date in the hardware clock:
sudo hwclock -w
Copy the driver debian package (vc-mipi-driver-bcm2835-dkms_x.x.x_armhf.deb) to the /tmp folder on the Raspberry Pi.
Install the driver package by calling (replace x.x.x by the current version number):
sudo dpkg -i /tmp/vc-mipi-driver-bcm2835-dkms_x.x.x_armhf.deb
Edit the file /boot/config_vc-mipi-driver-bcm2835.txt (for example with nano with the command: sudo nano /boot/config_vc-mipi-driver-bcm2835.txt).
choose the correct platform by uncommenting the corresponding line
choose the correct overlay according to your MIPI module and platform by uncommenting the corresponding line
choose the desired sensor mode (see chapter Sensor modes below for mode description)
change the IO configuration if necessary (see chapter IO configuration below for IO description)
activate the self-triggered mode (see chapter Self-triggered mode below)
All these settings can be done for cam0 and cam1 in case you are using a Raspberry Pi CMIO or a VC CMIO.
Part 2:
4. Reboot.
2.4 First Image Acquisition Test
A sensor device should be listed as Video input at the following command output (from the Video4Linux-Control):
v4l2-ctl --all
The following command dumps sensor data:
v4l2-ctl --stream-mmap --stream-count=-1 -d /dev/video0 --stream-to=/dev/null
It will output subsequent lines ending with a frames-per-second information (in the example named [number]) until pressing CTRL-C:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [number] fps <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [number] fps <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< [number] fps <<<<<<<<<<<<<<<<<<<<<<<^C
2.5 Running the demo
The demo itself is a program named vcmipidemo and its source code is mainly in the file vcmipidemo.c. However more programs are provided, namely the vcimgnetsrv, a network image server, and its counterpart vcimgnetclient.py. The vcimgnetsrv is started as background service, and the vcmipidemo connects to it. Then you can use the vcimgnetclient.py on your PC to view live captured images.
But for the first run it is better to just run the vcmipidemo and check if it shows the ascii representation. This works without any network cable attached. You can then output the captured image to the framebuffer of the display by using the -f command line switch.
2.5.1 Compile the programs
Unpack the previously downloaded archive vcmipidemo_x.x.x.zip and copy the folder vcmipidemo to the Raspberry Pi (for example to /home/pi/)
Change to the subdirectory named vcmipidemo/src.
The source directory contains a Makefile to compile the driver. Do so by calling:
make clean all
2.5.2 Execute the demo
Just run the demo itself:
./vcmipidemo
or with framebuffer output:
./vcmipidemo -f
or with live view over ethernet:
./vcimgnetsrv & ./vcmipidemo
For live view over ethernet, execute the vcimgnetclient.py at the client. This needs Python 2 and PyGTK. Install both following packages in this order (Windows):
Python 2: https://files.vision-components.com/ImageTransfer/python-2.7.11.msi
PyGTK: https://files.vision-components.com/ImageTransfer/pygtk-all-in-one-2.24.2.win32-py2.7.msi
You can change exposure and gain values by vcmipidemo command line arguments. To get a listing of possible parameters, just call it with a -?:
./vcmipidemo -?
2.6 Switching Sensor Configuration
2.6.1 Sensor modes
The sensor driver provides different modes which support several features. They can be switched by changing values of sensor driver parameters.
To list available parameters of the sensor driver kernel module, you can use the following command:
dmesg
You can also check the table below (Sensor modes description) for a complete list of available sensor modes.
To set the desired mode, edit the file /boot/config_vc-mipi-driver-bcm2835.txt (for example with nano with the command: sudo nano /boot/config_vc-mipi-driver-bcm2835.txt). Change the sensor mode by modifing dtparam:
dtparam=cam0_sensor_mode_1
The number after the underscore is the sensor mode. For mode 0 the correct setting would be dtparam=cam0_sensor_mode_0.
2.6.2 Sensor modes description
This table lists the available modes for all MIPI modules.
VC MIPI OV7251 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 10 | 2 | Streaming | 640x480 |
| 1 | 8 | 2 | Streaming | 640x480 |
| 2 | 10 | 2 | External trigger | 640x480 |
| 3 | 8 | 2 | External trigger | 640x480 |
VC MIPI OV9281 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 10 | 2 | Streaming | 1280x800 |
| 1 | 8 | 2 | Streaming | 1280x800 |
| 2 | 10 | 2 | External trigger | 1280x800 |
| 3 | 8 | 2 | External trigger | 1280x800 |
VC MIPI IMX178 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 8 | 2 | Streaming | 3104x2076 |
| 1 | 10 | 2 | Streaming | 3104x2076 |
| 2 | 12 | 2 | Streaming | 3104x2076 |
| 3 | 14 | 2 | Streaming | 3104x2076 |
| 4 | 8 | 2 | External trigger | 3104x2076 |
| 5 | 10 | 2 | External trigger | 3104x2076 |
| 6 | 12 | 2 | External trigger | 3104x2076 |
| 7 | 14 | 2 | External trigger | 3104x2076 |
| 8 | 8 | 4 | Streaming | 3104x2076 |
| 9 | 10 | 4 | Streaming | 3104x2076 |
| 10 | 12 | 4 | Streaming | 3104x2076 |
| 11 | 14 | 4 | Streaming | 3104x2076 |
| 12 | 8 | 4 | External trigger | 3104x2076 |
| 13 | 10 | 4 | External trigger | 3104x2076 |
| 14 | 12 | 4 | External trigger | 3104x2076 |
| 15 | 14 | 4 | External trigger | 3104x2076 |
VC MIPI IMX183 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 8 | 2 | Streaming | 5440x3648 |
| 1 | 10 | 2 | Streaming | 5440x3648 |
| 2 | 12 | 2 | Streaming | 5440x3648 |
| 3 | 8 | 2 | External trigger | 5440x3648 |
| 4 | 10 | 2 | External trigger | 5440x3648 |
| 5 | 12 | 2 | External trigger | 5440x3648 |
| 6 | 8 | 4 | Streaming | 5440x3648 |
| 7 | 10 | 4 | Streaming | 5440x3648 |
| 8 | 12 | 4 | Streaming | 5440x3648 |
| 9 | 8 | 4 | External trigger | 5440x3648 |
| 10 | 10 | 4 | External trigger | 5440x3648 |
| 11 | 12 | 4 | External trigger | 5440x3648 |
VC MIPI IMX226 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 8 | 2 | Streaming | 3840x3046 |
| 1 | 10 | 2 | Streaming | 3840x3046 |
| 2 | 12 | 2 | Streaming | 3840x3046 |
| 3 | 8 | 2 | External trigger | 3840x3046 |
| 4 | 10 | 2 | External trigger | 3840x3046 |
| 5 | 12 | 2 | External trigger | 3840x3046 |
| 6 | 8 | 4 | Streaming | 3840x3046 |
| 7 | 10 | 4 | Streaming | 3840x3046 |
| 8 | 12 | 4 | Streaming | 3840x3046 |
| 9 | 8 | 4 | External trigger | 3840x3046 |
| 10 | 10 | 4 | External trigger | 3840x3046 |
| 11 | 12 | 4 | External trigger | 3840x3046 |
VC MIPI IMX250 | Mode | Image format (bits) | Lanes | Capture mode | Resolution |
---|---|---|---|---|---|
| 0 | 8 | 2 | Streaming | 2432x2048 |
| 1 | 10 | 2 | Streaming |