Your Raspberry Pi should be running the latest version of the Raspberry Pi OS (Buster at the time of writing), and the camera and I2C interfaces must both be enabled (check the Interfaces tab of the Raspberry Pi Configuration tool, from the Preferences menu). First ensure your system, firmware and all its applications and repositories are up to date by entering the following commands into a terminal window.
sudo apt update
sudo apt full-upgrade
Currently (May 2020) the necessary libcamera support has not yet been merged into the standard Raspberry Pi OS release, therefore it is necessary to install the latest release candidate. To do this, first reboot your Pi, and then use
sudo rpi-update
WARNING: Note that the release candidate is not as thoroughly tested as an official release. If your Raspberry Pi contains important or critical data we would strongly advise that it is backed up first, or that a fresh SD card is used for the purpose of trying libcamera.
Next, the /boot/config.txt
file must be updated to load and use the camera driver, by adding the following lines to the bottom. Currently we also need to update the GPU's core_freq_min
though this will become unnecessary in due course after further updates.
dtoverlay=imx219
core_freq_min=250
If you are using a sensor other than the imx219
you will need to supply the alternative name here (for example, ov5647
for the V1 camera, or imx477
for the HQ Cam for which support will be available shortly).
NOTE: after rebooting, control of the camera system will be passed to the ARM cores, and firmware-based camera functions (such as raspistill and so forth) will no longer work. Setting /boot/config.txt
back and rebooting will restore the previous behaviour.
The build system and runtime environment of libcamera have a number of dependencies. They can be installed with the following commands.
sudo apt install libboost-dev
sudo apt install libgnutls28-dev openssl libtiff5-dev
sudo apt install meson
sudo apt install qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
sudo pip3 install pyyaml
We can now check out the code and configure the build for the Raspberry Pi as follows.
git clone git://linuxtv.org/libcamera.git
cd libcamera
and to configure the build (still in the same libcamera directory):
meson build
cd build
meson configure -Dpipelines=raspberrypi -Dtest=false
cd ..
Finally we are ready to build the source code.
sudo ninja -C build install
Images can be captured using the qcam application, which can be started from the libcamera directory by entering:
build/src/qcam/qcam
You can find out more in the Raspberry Pi Camera Algorithm and Tuning Guide, here.
Information on writing your own kernel modules to support new CSI-2 cameras and bridge chips can be found here.