📷

Raspberry Pi5で公式カメラとArduCamのToFカメラの二つを接続した

2025/02/07に公開

はじめに😊

最近はカメラモジュールや深度カメラなどがお手頃な値段で手に入りますよね!
一昔前は、深度カメラ使うのにKinectとか用意していましたよ。。

今回は、ノーマルなRGBカメラとToFカメラをラズパイ5に繋げようと思った話です。

用意したもの

RaspberryPi5には、CSIコネクタが二つあるので同時に繋げてみようと思いました。

カメラを接続する

まずはカメラモジュールV3を使ってみる

とりあえず二つとも適当に接続して、カメラモジュールV3を動かしてみました。
OSには、rpicam-hello というサクッと動くコマンドが入っていました。

rpicam-hello
[0:00:15.285218435] [1599]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+99-1230f78d
[0:00:15.297499731] [1697]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
[0:00:15.411460990] [1697]  INFO RPI pisp.cpp:1154 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media0 and ISP device /dev/media1 using PiSP variant BCM2712_C0
[0:00:15.411553786] [1697]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
Preview window unavailable
Mode selection for 2304:1296:12:P
    SRGGB10_CSI2P,1536x864/0 - Score: 3400
    SRGGB10_CSI2P,2304x1296/0 - Score: 1000
    SRGGB10_CSI2P,4608x2592/0 - Score: 1900
Stream configuration adjusted
[0:00:15.433544916] [1599]  INFO Camera camera.cpp:1197 configuring streams: (0) 2304x1296-YUV420 (1) 2304x1296-BGGR_PISP_COMP1
[0:00:15.433658916] [1697]  INFO RPI pisp.cpp:1450 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1B
#0 (0.00 fps) exp 29981.00 ag 1.59 dg 1.00
#1 (30.01 fps) exp 29981.00 ag 1.55 dg 1.01
#2 (30.01 fps) exp 29981.00 ag 1.54 dg 1.02
#3 (30.01 fps) exp 29981.00 ag 1.54 dg 1.02
#4 (30.01 fps) exp 29981.00 ag 1.57 dg 1.00
#5 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#6 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#7 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#8 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#9 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00

とりあえず動いてそうです!

ToFカメラを使ってみる

https://github.com/ArduCAM/Arducam_tof_camera

 ./Install_dependencies.sh
 sudo reboot

これで依存パッケージをインストールし再起動します。

mkdir build
cd build
cmake ..
make
./example/cpp/preview_depth 
$ ./program/Arducam_tof_camera/build/example/cpp/preview_depth 
src/connection/csi/ArducamTOFCSISensor.cpp:96(xioctl) :
  [WARN] UVC: ioctl (-1069525443) failed: Inappropriate ioctl for device
src/connection/csi/ArducamTOFCSISensor.cpp:540(setVideoMode) :
  [WARN] TOFCamera: Could not get current selection(subdev)
open camera with (240x180)
qt.qpa.xcb: QXcbConnection: XCB error: 148 (Unknown), sequence: 192, resource id: 0, major code: 140 (Unknown), minor code: 20
frame: (240x180)
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
select Rect distance: 0
frame: (240x180)
select Rect distance: 0
frame: (240x180)

いけましたね!

もう一度カメラモジュールにつなげようとした時に問題が発生した

rpicam-hello
[0:00:22.152996245] [2051]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+99-1230f78d
[0:00:22.160945726] [2059]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
[0:00:22.185894171] [2059]  WARN CameraSensorProperties camera_sensor_properties.cpp:305 No static properties available for 'arducam-pivariety'
[0:00:22.185916967] [2059]  WARN CameraSensorProperties camera_sensor_properties.cpp:307 Please consider updating the camera sensor properties database
[0:00:22.201550208] [2059] ERROR IPAProxy ipa_proxy.cpp:154 Configuration file 'arducam-pivariety_mono.json' not found for IPA module 'rpi/pisp'
[0:00:22.206168300] [2059] ERROR IPARPI ipa_base.cpp:133 Could not create camera helper for arducam-pivariety
[0:00:22.206184282] [2059] ERROR RPI pipeline_base.cpp:814 Failed to load a suitable IPA library
[0:00:22.206194041] [2059] ERROR RPI pisp.cpp:922 Failed to register camera arducam-pivariety 11-000c: -22
Preview window unavailable
ERROR: *** no cameras available ***

なんとカメラモジュールV3が見つからなくなりました。

配線はこんな感じです。
右がカメラモジュールV3
左がToFカメラです。

沼にハマる😇

/boot/firmware/config.txtをとりあえずいじる

raspberry pi5のデバイス設定は、 /boot/firmware/config.txtで変更や修正をすることができます。

# Automatically load overlays for detected cameras
camera_auto_detect=0
[all]
dtoverlay=arducam-pivariety,cam0

カメラ周りの設定は上記のようになっていました。
camera_auto_detectは1になっていれば、公式カメラを自動で探してくれるらしいです。

不思議に思い、
https://github.com/ArduCAM/Arducam_tof_camera/blob/main/Install_dependencies.sh#L3-L41
こちらをみたところ、 camera_auto_detectを0にし、 dtoverlay=arducam-pivariety,cam0を追記する実装がされていました。

ひとまずこれらを、

# Automatically load overlays for detected cameras
camera_auto_detect=1
[all]
# dtoverlay=arducam-pivariety,cam0

にして、 rpicam-hello を試しました。

[0:00:15.285218435] [1599]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+99-1230f78d
[0:00:15.297499731] [1697]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
[0:00:15.411460990] [1697]  INFO RPI pisp.cpp:1154 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media0 and ISP device /dev/media1 using PiSP variant BCM2712_C0
[0:00:15.411553786] [1697]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
Preview window unavailable
Mode selection for 2304:1296:12:P
    SRGGB10_CSI2P,1536x864/0 - Score: 3400
    SRGGB10_CSI2P,2304x1296/0 - Score: 1000
    SRGGB10_CSI2P,4608x2592/0 - Score: 1900
Stream configuration adjusted
[0:00:15.433544916] [1599]  INFO Camera camera.cpp:1197 configuring streams: (0) 2304x1296-YUV420 (1) 2304x1296-BGGR_PISP_COMP1
[0:00:15.433658916] [1697]  INFO RPI pisp.cpp:1450 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1B
#0 (0.00 fps) exp 29981.00 ag 1.59 dg 1.00
#1 (30.01 fps) exp 29981.00 ag 1.55 dg 1.01
#2 (30.01 fps) exp 29981.00 ag 1.54 dg 1.02
#3 (30.01 fps) exp 29981.00 ag 1.54 dg 1.02
#4 (30.01 fps) exp 29981.00 ag 1.57 dg 1.00
#5 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#6 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#7 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#8 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00
#9 (30.01 fps) exp 29981.00 ag 1.58 dg 1.00

復活しました!!

ですが、

$ ./program/Arducam_tof_camera/build/example/cpp/preview_depth ./preview_depth 
src/connection/csi/ArducamTOFCSISensor.cpp:96(xioctl) :
  [WARN] UVC: ioctl (-1056932863) failed: Invalid argument
Error: I2C bus name doesn't match any bus present!
src/connection/csi/ArducamTOFCSISensor.cpp:1025(setupI2C) :
  [WARN] Failed to find i2c bus()
Failed to open camera

ToFは開けなくなりました。。
それはそうか。。

camera_auto_detectを0にする

/boot/firmware/config.txtにdtoverlayにカメラモジュールを指定することで繋がるらしい。
カメラモジュールV3は IMX708なので、それをしています。

dtoverlay=imx708

どちらも繋がらなかったです。。。

解決🎉

公式カメラの解決

https://www.raspberrypi.com/documentation/computers/compute-module.html#attach-a-camera-module
こちらの公式ドキュメントを参考に、
cam0とcam1はハードウェアのポートに割り当てられているので、
/boot/firmware/config.txt に割り当ててみます。

[all]
dtoverlay=imx708,cam0
dtoverlay=arducam-pivariety,cam1

カメラモジュールV3は動くようになりましたが、
ToFカメラは動きませんでした。

ToFカメラの解決

issueがこちらにありました!!
https://github.com/ArduCAM/Arducam_tof_camera/issues/98

Found the solution here: https://forum.arducam.com/t/installation-tof-camera-fails-on-bookworm-could-not-open-device-node-dev-video0/5883/38
Seems that the device is no 8:
tof.open(TOFConnect.CSI, 8)

exampleのプログラムを修正すると解決できるみたいです。
https://github.com/ArduCAM/Arducam_tof_camera/blob/main/example/cpp/preview_depth.cpp#L110-L113

if (tof.open(Connection::CSI, 0)) {
if (tof.open(Connection::CSI, 8)) {

リビルドして動きました!!

camera_auto_detectを1に戻してみる。

# Automatically load overlays for detected cameras
camera_auto_detect=1
[all]
dtoverlay=arducam-pivariety,cam1

どちらもちゃんと動きました!!

まとめ😤

Raspberry Pi 5で複数のカメラを接続する際のポイントを簡単にまとめると以下の通りです:

  • CSIポートの割り当てを理解する
    cam0とcam1はハードウェアポートに固定されており、それぞれに対応するカメラを正しく指定する必要があります。
  • /boot/firmware/config.txtの設定
    使用するカメラに応じて適切なdtoverlay設定を行います。例:
dtoverlay=imx708,cam0
dtoverlay=arducam-pivariety,cam1
  • プログラムを調整する。
    ArduCam ToFと他のカメラを接続する場合、デフォルトのプログラムに、Connection::CSI, 8 を指定する必要がありました(Issue #98参照)。
  • camera_auto_detectの設定
    camera_auto_detect=1を設定しておくと、公式カメラを自動で検出してくれるため、可能であればこの設定を維持するのが便利です。
ユカイ工学テックブログ

Discussion