Setup IMX519 with any Raspberry Pi OS

Thank you Wong.
I then followed your suggestion and commented dtoverlay=arducam and uncommented dtoverlay=imx519 gave it a reboot.

Picture attached of tail /boot/config and libcamera-jpeg.

From here, I can take pictures, with libcamera-jpeg -o img.jpg

Though, when I run dmesg | grep arducam, it’s an empty line… nothing maybe because arducam is not loaded :slight_smile:

My end goal being, using the arducam through python and opencv, to capture frames with opencv.
As we are, I think this is a on the way to . success using python3.9 and libcamera whl plugin (version 1.0.2) and provided examples run flawlessly (decreasing the resolution to 1280 x 780)

Indeed… v4l2 works as well (Some days ago, I faced some errors trying to make Use of v4l2loopback on line cd ~/libcamera # Installation using deb does not need to be executed.
Re-reading the page I understood today that the git libcamera needed to be done upfront.

What I just did :

Download kernel source code
sudo apt install git bc bison flex libssl-dev
sudo wget https://raw.githubusercontent.com/RPi-Distro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update
rpi-source -d $(uname -r)
Compile driver
git clone https://github.com/umlaeute/v4l2loopback.git
cd v4l2loopback
make clean && make
make && sudo make install
sudo depmod -a

Use v4l2loopback

git clone git://linuxtv.org/libcamera.git
sudo modprobe v4l2loopback video_nr=3
cd libcamera  # Installation using deb does not need to be executed
export GST_PLUGIN_PATH=$(pwd)/build/src/gstreamer # Installation using deb does not need to be executed
gst-launch-1.0 libcamerasrc ! 'video/x-raw,width=1920,height=1080' ! videoconvert ! tee ! v4l2sink device=/dev/video3

I was able to create the v4l2loopback in one thread and use the camera in another thread with opencv

import cv2
cap = cv2.VideoCapture(3)
while True:
	ret, frame = cap.read()
	cv2.imshow("Arducam", frame)
	key = cv2.waitKey(1)
	if key == ord('q'):
		break

That leads me into a good direction for my project… as I reached one of the points, I then have probably simple questions…
1- With this setup, it seems that either python libcamera 1.0.2 or opencv have no autofocus enabled… is that correct ? Can it be fixed with somethign I missed ?
2- When to use or, what is the goal of enabling dtoverlay=arducam (when disabling imx519 in /boot/config.txt) ?
3- Looks like I need to learn more about the v4l2 to use it better in my python camera app … this is another topic :smiley:

Thanks

There doesn’t seem to be a good way at the moment, libcamera gstreamer doesn’t have any controls to set, and no controls can be set when working with v4l2loopback.
To achieve this goal requires a lot of modification.

dtoverlay will choose to load different drivers. For arducam, it loads the Pivariety driver, which is not suitable for imx519, so you need to increase dtoverlay=imx519 to load the imx519 driver.

That explains a lot. Thank you Wong

Is there a way to say, set the focus manualy to a value that would make it the same, that could be relaunched at boot … prior to running libcamera from python for instance?

try:

v4l2-ctl -c focus_absolute=300 -d /dev/v4l-subdev1
1 Like

So, turns out that it makes no sense to use the rpi-source script - installing the “raspberrypi-kernel-headers” instead works

@surak
We have a version that works.We are using the 2022-01-28 version,we have not adapted to the latest version.

Below is an example I wrote.

How to use?

You need to get your hash first.

cd /usr/share/doc/raspberrypi-bootloader/
sudo gzip -df changelog.Debian.gz
sudo cat changelog.Debian | head -n 10 

image

# Do not copy, fill in according to your own system
# --disablecrosscompile : use in raspberrypi
# -p you raspberrypi version
# -b bit of your  raspberrypi,like 32 or 64
# --hash First step you earn 
# example:
python3 setup_rpi_source.py --disablecrosscompile 1 -p Pi4 -b 32 --hash 1e138de65a13c28c04fa4abf37f4c21e231e41b7

Then,

Compile driver
git clone https://github.com/umlaeute/v4l2loopback.git
cd v4l2loopback
make clean && make
make && sudo make install
sudo depmod -a

Use v4l2loopback

git clone git://linuxtv.org/libcamera.git
sudo modprobe v4l2loopback video_nr=3
cd libcamera  # Installation using deb does not need to be executed
export GST_PLUGIN_PATH=$(pwd)/build/src/gstreamer # Installation using deb does not need to be executed
gst-launch-1.0 libcamerasrc ! 'video/x-raw,width=1920,height=1080' ! videoconvert ! tee ! v4l2sink device=/dev/video3

I was able to create the v4l2loopback in one thread and use the camera in another thread with opencv

import cv2
cap = cv2.VideoCapture(3)
while True:
	ret, frame = cap.read()
	cv2.imshow("Arducam", frame)
	key = cv2.waitKey(1)
	if key == ord('q'):
		break

I have some questions:

  1. how do I know which one I am running? It seems like you picked up the second from your list, but I don’t know which one is right for me

  2. don’t we have a raspberrypi-kernel-headers package with the right kernel being used at the moment, or am I missing something here?

  3. I am using the 64 bit version of the OS. Does it work there?

Meanwhile, I am trying your method, and I get:

raspberrypi-firmware (1:1.20220331-1) bullseye; urgency=medium

  * firmware as of 61966732d03de9b71baf561f920e018b54c241ac
  * Linux version 5.15.32

 -- Serge Schneider <[email protected]>  Fri, 01 Apr 2022 07:57:07 +0100

raspberrypi-firmware (1:1.20220328-1) bullseye; urgency=medium

  * firmware as of 69277bc713133a54a1d20554d79544da1ae2b6ca

Everything seems to go on well, the module loads fine. But then I try to run, and I get this

gst-launch-1.0 libcamerasrc ! 'video/x-raw,width=1920,height=1080' ! videoconvert ! tee ! v4l2sink device=/dev/video3
Setting pipeline to PAUSED ...
[27:10:11.700063089] [35176] ERROR IPAModule ipa_module.cpp:286 ipa_rpi.so: IPA module is not an ELF file
[27:10:11.700239111] [35176]  WARN IPAManager ipa_manager.cpp:149 No IPA found in '/usr/local/lib/aarch64-linux-gnu/libcamera'
[27:10:11.700462967] [35176]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3667-1c9dc0fd
[27:10:11.707141062] [35179]  WARN CameraSensorProperties camera_sensor_properties.cpp:174 No static properties available for 'imx519'
[27:10:11.707510087] [35179]  WARN CameraSensorProperties camera_sensor_properties.cpp:176 Please consider updating the camera sensor properties database
[27:10:11.707931446] [35179] ERROR RPI raspberrypi.cpp:1236 Failed to load a suitable IPA library
[27:10:11.708544883] [35179] ERROR RPI raspberrypi.cpp:1167 Failed to register camera imx519 10-001a: -22
ERROR: from element /GstPipeline:pipeline0/GstLibcameraSrc:libcamerasrc0: Could not find any supported camera on this system.
Additional debug info:
../src/gstreamer/gstlibcamerasrc.cpp(232): gst_libcamera_src_open (): /GstPipeline:pipeline0/GstLibcameraSrc:libcamerasrc0:
libcamera::CameraMananger::cameras() is empty
ERROR: pipeline doesn't want to preroll.
Failed to set pipeline to PAUSED.
Setting pipeline to NULL ...
Freeing pipeline ...

I see this on dmesg:

[    6.398965] imx519 0-001a: failed to read chip id 519, with error -5
[97758.650312] v4l2loopback: loading out-of-tree module taints kernel.
[97758.653730] v4l2loopback driver version 0.12.5 (v0.12.5-260-g56cca90) loaded

I don’t know what I am doing wrong anymore.

@surak
Are you using a pi3?

1 Like

No, a pi4 8gb. I need a 64bit system for pytorch.

This is really lacking.

I downloaded this old version of raspbian, and started doing it. Obviously I need more than that. For a start, flex and bison and openssl-dev, which are not on the system by default.

Will we be ever able to simply use these cameras? I’m not by far a beginner, but this is driving me mad.

@surak

okey , i’m sorry to hear it’s still doesn’t work now.
if you just want to let camera drawing.The link below is very easy.

At present, the Raspberry Pi has fully used the libcamera camera stack and framework. If you just want to use v4l2loopback:

  1. it’s not easy and we no longer maintain.
  2. But i can make an image of the installed environment for you.
  3. you can try picamera2 https://github.com/raspberrypi/picamera2

hope this will help you.

Your solution writes -b 32, which I didn’t notice - and I mentioned I was using a 64-bit kernel.

Those missing functions are related to that.

The post here: https://github.com/aircrack-ng/rtl8812au/issues/933#issuecomment-1105499408 helped me see that.

v4l2loopback compiles cleanly when using the -b 64. Thanks.

So, from zero to running it in opencv:

First: Download this version of Raspbian and DO NOT UPDATE THE KERNEL: https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2022-01-28/2022-01-28-raspios-bullseye-arm64.zip

sudo apt install openssl-dev \
     flex \
     bison \
     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 

wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p libcamera_dev
./install_pivariety_pkgs.sh -p libcamera_apps
./install_pivariety_pkgs.sh -p imx519_kernel_driver

Here it will reboot.

After reboot,

git clone https://github.com/umlaeute/v4l2loopback.git # I am using the tag 0.12.5
cd v4l2loopback
make clean && make
make && sudo make install
sudo depmod -a

cd

git clone git://linuxtv.org/libcamera.git
sudo modprobe v4l2loopback video_nr=3
cd libcamera  # Installation using deb does not need to be executed
export GST_PLUGIN_PATH=$(pwd)/build/src/gstreamer # Installation using deb does not need to be executed
gst-launch-1.0 libcamerasrc ! 'video/x-raw,width=1920,height=1080' ! videoconvert ! tee ! v4l2sink device=/dev/video3

This will be running on a window. You need a second terminal to do something else.

For python:

cd
python3 -m venv py3-cv2
source py3-cv2/bin/activate
pip install opencv-contrib-python

For every python code one should activate the previous virtual environment with a source ~/py3-cv2/bin/activate, so the opencv is found. I prefer to not install random stuff on .local.

This is what worked for me from scratch to having the camera running as I need on Raspbian 64… THANKS A LOT!!!

@surak
Thanks for sharing, I think this is a great write up and I’m sure it will help more people.

Hey Edward, will this camera have ever a normal driver on Raspberry OS so one won’t need all this process just to use it?

@surak

Sure, you need latest bulleye system Operating system images – Raspberry Pi
and then you need install driver and then reboot.

wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
./install_pivariety_pkgs.sh -p imx519_kernel_driver_low_speed

a simple example
libcamera-still -t 0

more use
IMX519 自动对焦相机和树莓派 libcamera 指南 - Arducam

UPDATE

This simplifies everything.

The libcamerify from libcamera-dev solves the opencv compatibility issue, and cab be twice as fast as the gstreamer method.

So, if you have a python code which uses openCV, simply call libcamerify python YOUR-CODE.py and it will run. No need for v4l2loopback or gstreamer or compiling anything.

So, how do make it work on a Raspberry Pi 5 with the latest Bookworm and Kernel 6.1.0?

The install_pivariety_pkgs.sh fails at the beginning, and all it does is to say that the driver is already there and does not need to be installed.

The git repo for the pivariety in GitHub - ArduCAM/Arducam-Pivariety-V4L2-Driver: This driver is used for Arducam mipi camera with Pivariety board points to GitHub - ArduCAM/IMX519_AK7375, but this fails completely to compile.

Could one show how to make this camera work on a clean install of Bookworm on a Pi 5?

Thanks!

Hi
First of all, you need to add “dtoverlay=imx519” on the config file.
Then you need to install the libcaemra from arducam.

./install_pivariety_pkgs.sh -m libcamera
./install_pivariety_pkgs.sh -m libcamera_apps

Please give it a try.

1 Like

That is there. Sorry to mislead you. In fact, the install_pivariety already does that. There’s another thread which says support for bookworm isn’t there yet.

Have you tried on a pi5 with bookworm and a 6.x series kernel?

Hi
On Raspberry Pi 5, the imx519 can work on it but the pdaf is not compatible.