Hi, I’m trying to set up the UCTRONICS B0402 64MP Autofocus Quad-Camera Kit on a Raspberry Pi 4, but when I run the install script I get:
bash: ./install_pivariety_pkgs.sh: Permission denied
Not sure what I’m doing wrong. Any help?
Hi, I’m trying to set up the UCTRONICS B0402 64MP Autofocus Quad-Camera Kit on a Raspberry Pi 4, but when I run the install script I get:
bash: ./install_pivariety_pkgs.sh: Permission denied
Not sure what I’m doing wrong. Any help?
That’s a permissions issue. You need to run the script with elevated privileges, so prepend sudo to the install command:
sudo ./install_pivariety_pkgs.sh
Also, the packages are hosted on GitHub, so if you’re in mainland China you’ll likely need a VPN for the download to complete.
Thanks, that got the install script running. Now I’m following the PiCamera2 Focus Controller tutorial and got stuck on the second step where it installs Picamera2 dependencies. Running sudo pip3 install numpy --upgrade throws an error (I only have a screenshot of it). The driver is installed and preview/photo capture already work fine. I ultimately want to set the focus point individually for two of the four cameras.
Don’t install picamera2 via pip for this setup — that’s not the right method. Use apt instead:
sudo apt install python3-picamera2 --upgrade
That should get the correct package installed.
I’ve switched to apt, thanks. But now I’m testing autofocus and it can’t lock focus at around 10 cm, even though the product page says the focusing range is 8 cm to infinity. What settings should I change?
Each camera can have slight mechanical focus motor variance from the factory, so that can play a role. It’s also worth checking whether you’re actually running a PDAF-capable libcamera build.
First check your kernel and libcamera versions. The stable kernel is 6.1.21 (32-bit/64-bit). Check libcamera with:
dpkg -l | grep libcamera
If the libcamera dev build is dated 7/24, that’s the PDAF version.
As a fallback, you can also focus manually:
libcamera-still -t 0 --autofocus-mode manual --lens-position 5
Then slowly increase or decrease the --lens-position value until you find the focus point.
I can focus manually at around 8 cm with that command, but I really need to focus multiple cameras separately — the first one at 24 cm from the object, the second and third at 10 cm. Doing it manually is too tedious. Can I do this in Python, focusing and capturing each camera one by one? Also my current kernel is 6.1.0-rpi7-rpi-v8 (Pi 4, 8GB RAM). How do I upgrade to 6.1.21 for PDAF? I was imagining something like --lens-position 5 for camera 1, then 9 for cameras 2 and 3.
For the quad 64MP module, all four cameras’ focus is controlled through the RX0 camera on the HAT board, so you can’t give each camera a different lens position — focus is shared across them.
To get PDAF working you need to flash the 6.1.21 system and install the PDAF-capable libcamera. Steps:
[all] in the config file:dtoverlay=arducam-64mp
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
After reboot, test with libcamera-still -t 0. Switching channels still lets you capture each camera individually, just not with independent focus.
OK, I understand now — the focus is linked across all cameras, so I always end up with two sharp and the others not. I’ve now got the 6.1.21 system and PDAF is enabled, and the focus is very sharp. But I’d like a Python flow that does: select camera 1 → autofocus, capture and save → switch channel to camera 2 → autofocus, capture and save → switch to camera 3, etc. I can do all this manually but I haven’t found suitable Python examples.
In theory that’s doable, but I can’t write the program for you. You’ll want to switch the camera into single-channel mode and then save images from each channel. There are commands for that here:
I’ve now written my own Python program that switches channel 1 → focus and shoot → channel 2 → focus and shoot → channel 3 → shoot. But to avoid buffer issues I set the preview to a low resolution (800x600), and now the preview only shows the center crop of the frame — like it’s cropping the middle of the 64MP sensor. Is there a way to get a low-resolution preview that still shows the whole frame?
That center-crop behavior at 800x600 happens because the preview is cropping the 64MP frame. Set the preview resolution to 2312x1736 instead — that keeps the full frame and shouldn’t trigger the buffer allocation shortage.
I tried 2312x1736 but I’m still getting the buffer allocation shortage, even with only one camera previewing. Also, I need to extend the cable between the camera and the HAT by about 1 m. Does the SKU B0091 module recommended on the site work with the 64MP camera, and what specs should the extra HDMI cable have?
Looking at the error, the preview resolution wasn’t actually set to 2312x1736 — that’s why the buffer allocation failed. Make sure the preview is really at 2312x1736, and if you can, share your Python script so I can take a look.
On the cable side, B0091 is fine for the ~1 m extension with the 64MP camera, and for the extra HDMI cable I’d recommend an Ugreen brand cable.
Here’s the script I’m using. Preview is set to 2312x1736, capture to 8000x6000, I2C bus 10, device address 0x24, register 0x24, data 0x02 to switch to channel 0:
import smbus2
import time
from datetime import datetime
from picamera2 import Picamera2, Preview
# ===============================1st camera==============================
# switch channel to 0
def write_i2c_register(i2c_bus, device_address, register_address, data):
try:
bus = smbus2.SMBus(i2c_bus)
bus.write_byte_data(device_address, register_address, data)
bus.close()
print(f"Successfully wrote {hex(data)} to register {hex(register_address)}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
i2c_bus = 10
device_address = 0x24
register_address = 0x24
data_to_write = 0x02
write_i2c_register(i2c_bus, device_address, register_address, data_to_write)
#capture image 1
picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
preview_config = picam2.create_preview_configuration(main={"size": (2312, 1736)})
capture_config = picam2.create_still_configuration(main={"size": (8000, 6000)})
picam2.configure(preview_config)
picam2.set_controls({"AfMode": 2})
picam2.start()
time.sleep(5)
current_time = datetime.now()
timestamp = current_time.strftime("%Y%m%d_%H%M%S")
picam2.switch_mode_and_capture_file(capture_config, f"image_{timestamp}.jpg")
picam2.close()
I reproduced this on a Pi 4 and it looks like a memory allocation shortage. The same script runs fine on a Pi 5, so this appears to be Pi 4-specific and we’re still investigating the root cause. For now, keep the preview at 2312x1736 — that should be the value that avoids the buffer error while we dig into it.