Skip to content

External Trigger Mode for Raspberry Pi Cameras

Use an external pulse to control when an Arducam global shutter camera captures a frame. This guide covers the Pivariety cameras below and the native B0165 OV9281, including wiring, preview verification, and returning to continuous capture (Free Run).

Supported cameras

SKU / product page Sensor Resolution Image type
B0348 OG02B10 2 MP Color
B0353 AR0234 2 MP Color
B0381 OV2311 2 MP Monochrome
B0526 Mira220 2.2 MP Monochrome
B0165 OV9281 1 MP Monochrome

Choose the software procedure for your camera:

Camera Enable external trigger Return to Free Run
Pivariety — B0348, B0353, B0381, B0526 Set the V4L2 trigger_mode control to 1. Set the same control to 0.
B0165 OV9281 Add trigger-mode=1 to the ov9281 overlay in config.txt, then reboot. Remove trigger-mode=1 from that overlay, then reboot.

B0165 requires Linux kernel 6.18.50+ or later

B0165 external trigger is selected at boot. Both enabling external trigger and returning to Free Run require a configuration change and a reboot. The V4L2 trigger_mode switching procedure applies to the four Pivariety models above.

Pivariety connector and optical specifications

These four models use M12 lenses with manual focus. Connector contact positions describe the camera end of the cable.

SKU Camera connector Field of view (H × V) IR-cut filter
B0348 22-pin, top contact 85° × 69° 650 nm IR-cut filter
B0353 22-pin, top contact 90° × 56° None
B0381 22-pin, top contact 83° × 67.5° None
B0526 15-pin, bottom contact 68° × 53° None

For B0165 connection and camera setup, see the OV9281 guide.

Before you begin

You need a supported camera with a working CSI connection, a pulse generator or Raspberry Pi GPIO output, a local display, and two terminal windows.

Install the tools used in this guide:

sudo apt update
sudo apt install v4l-utils wget unzip python3-gpiozero python3-lgpio

Before enabling trigger mode, verify camera detection and continuous preview:

rpicam-hello --list-cameras
rpicam-hello -t 5000

The camera should be listed and show a live preview. If B0165 already boots in trigger mode, it will wait for pulses instead. Follow B0165: Return to Free Run to restore continuous capture when needed.

If several cameras are connected, use --camera N to select the intended camera in preview commands. The Pivariety control commands must target that camera's corresponding subdevice.

Step 1: Connect the trigger signal

  1. Shut down the Raspberry Pi and disconnect power from the Pi and trigger source.
  2. Locate the camera's trigger input and GND using the board's pinout. Depending on the board, the input is labelled XVS, FSIN, or Trigger.
  3. Connect the pulse output to the camera input at the required logic level, then connect the grounds.
  4. Check the CSI cable and trigger wiring before restoring power. Keep the pulse output off during camera configuration.

Raspberry Pi GPIO outputs use 3.3 V logic. The Pivariety connection shown below uses 1.8 V at the camera input, with a level shifter between the Pi and camera. For B0165, follow the XVS electrical specification for your camera board revision when choosing the output level and pulse timing.

Source connection Destination for the 1.8 V Pivariety connection
Raspberry Pi GPIO output Level shifter 3.3 V-side input
Level shifter 1.8 V-side output Camera trigger input
Raspberry Pi / trigger-source GND Camera GND and level shifter GND

For the documented Pivariety interface, use a high pulse width of at least 2 µs. Keep the frequency within the camera mode's supported trigger rate. Set the active edge according to the camera's timing specification.

External trigger timing diagram

The supplied script uses BCM GPIO 3, which is physical pin 5 on the Raspberry Pi's 40-pin header. Use an available GPIO and match the script's LED_PIN setting to your wiring.

Pin-location and wiring examples

Match each illustration to your camera board revision and include the required level conversion.

XVS — UC-788 board example

Use this illustration to locate XVS and ground on matching OV9281, OG02B10, and OV2311 board revisions. Select the software procedure by SKU using the table at the top of this page.

XVS location on a UC-788 camera board

FSIN — example board labels

FSIN label on an example camera board FSIN connection detail on an example camera board

Trigger — B0526

Trigger input on the B0526 camera

Raspberry Pi connection example

Raspberry Pi and camera trigger wiring example

Step 2: Prepare the trigger source

For the Raspberry Pi example, download the script:

mkdir -p "$HOME/arducam-external-trigger"
cd "$HOME/arducam-external-trigger"
wget -O trigger.py.zip https://cdn.arducam.com/downloads/trigger.py.zip
unzip -n trigger.py.zip trigger.py

The script uses the GPIO Zero Python library with the following defaults:

Setting Meaning
LED_PIN = 3 BCM GPIO 3, physical pin 5.
INITIAL_FREQUENCY = 30.0 Starts sending pulses at 30 Hz.
FIXED_ON_TIME = 0.001 Nominal HIGH pulse width of 1 ms. Set camera exposure separately.

Start the script after opening the camera preview in Step 4. If using a separate pulse generator, prepare its output level, pulse timing, and frequency for the selected camera.

Step 3: Increase the frame-wait timeout

The pipeline must keep waiting while the camera receives no trigger pulses. Create a local timeout configuration:

mkdir -p "$HOME/arducam-external-trigger"

Copy one file for your Raspberry Pi's pipeline.

Pi 5 / CM5 (PiSP):

cp /usr/share/libcamera/pipeline/rpi/pisp/example.yaml \
    "$HOME/arducam-external-trigger/timeout.yaml"

VC4 pipeline on other Raspberry Pi models:

cp /usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml \
    "$HOME/arducam-external-trigger/timeout.yaml"

Edit the copy:

nano "$HOME/arducam-external-trigger/timeout.yaml"

Find camera_timeout_value_ms, remove its leading # if commented out, and set its value to 100000 (100 seconds). Edit the existing entry while preserving the surrounding YAML structure.

Timeout configuration example

Camera timeout configuration entry

Choose a timeout longer than the expected delay before the first pulse and the longest gap between pulses.

Step 4: Enable external trigger

Follow the procedure for your camera.

Pivariety — B0348, B0353, B0381, B0526

In Terminal 2, find the subdevice that exposes trigger_mode:

for device in /dev/v4l-subdev*; do
    [ -e "$device" ] || continue
    printf '\n%s\n' "$device"
    v4l2-ctl -d "$device" --list-ctrls
done

When several cameras are connected, use the media topology to identify the matching subdevice:

for device in /dev/media*; do
    [ -e "$device" ] || continue
    media-ctl -d "$device" -p
done

Set CAMERA_SUBDEV to that node. The following example uses /dev/v4l-subdev2:

CAMERA_SUBDEV=/dev/v4l-subdev2
v4l2-ctl -d "$CAMERA_SUBDEV" --get-ctrl=trigger_mode

Subdevice numbers depend on the system configuration. Keep Terminal 2 open so the following control commands use the same variable.

In Terminal 1, load the timeout configuration and start a preview:

export LIBCAMERA_RPI_CONFIG_FILE="$HOME/arducam-external-trigger/timeout.yaml"
rpicam-still -t 0 --shutter 1000

The camera initially shows a continuous preview. In Terminal 2, enable external trigger:

v4l2-ctl -d "$CAMERA_SUBDEV" --set-ctrl=trigger_mode=1
v4l2-ctl -d "$CAMERA_SUBDEV" --get-ctrl=trigger_mode

The control should report 1, and the preview should stop updating while waiting for a pulse. Continue to Step 5.

B0165 OV9281

Check the running kernel:

uname -r

External trigger on B0165 requires kernel 6.18.50+ or later. Use a supported kernel and matching ov9281 overlay before continuing.

Open the boot configuration. On current Raspberry Pi OS:

sudo nano /boot/firmware/config.txt

Edit the existing dtoverlay=ov9281 entry for the connected camera and add trigger-mode=1:

dtoverlay=ov9281,trigger-mode=1

Keep any existing camera-specific parameters, such as cam0 or arducam, on the same line. Apply the change to the existing entry in its active configuration section.

Save the file and reboot:

sudo reboot

After reboot, open two terminals again. In Terminal 1, load the timeout configuration and start the preview:

export LIBCAMERA_RPI_CONFIG_FILE="$HOME/arducam-external-trigger/timeout.yaml"
rpicam-still -t 0 --shutter 1000

B0165 now boots in external trigger mode. The preview waits for a valid pulse, so the window can remain blank or hold its last frame until pulses arrive. Continue to Step 5.

B0165 mode changes require a reboot

To return to Free Run, remove trigger-mode=1 from the overlay and reboot. See B0165: Return to Free Run.

Step 5: Send pulses and verify capture

In Terminal 2, start the script:

cd "$HOME/arducam-external-trigger"
python3 trigger.py

Pulses start immediately at 30 Hz. Enter a number at the > prompt to change frequency, then press Enter. For example, enter 1 for 1 Hz. Enter q or press Ctrl+C to stop.

If using a separate generator, enable its pulse output now.

Move an object in the scene and check the preview:

Trigger source Expected result
Pulses arriving The preview updates within the camera mode's supported rate.
Frequency changed The update rate changes within camera and processing limits.
Pulses stopped The preview stops updating and waits.

Resume pulses before the frame-wait timeout expires. For precise timing, use a hardware pulse generator and measure the signal at the camera input.

--shutter 1000 requests a 1 ms exposure. Use an exposure short enough for the selected trigger interval and sensor mode. The trigger script's HIGH pulse width is configured separately.

Step 6: Return to Free Run

Pivariety — B0348, B0353, B0381, B0526

Stop the trigger source. In Terminal 2, disable trigger mode on the same camera subdevice:

v4l2-ctl -d "$CAMERA_SUBDEV" --set-ctrl=trigger_mode=0
v4l2-ctl -d "$CAMERA_SUBDEV" --get-ctrl=trigger_mode

The control should report 0 and the preview should resume continuous updates. Restart the preview if it has timed out.

B0165 OV9281

Stop the trigger source and close the preview. Open the same boot configuration:

sudo nano /boot/firmware/config.txt

Remove ,trigger-mode=1 from the camera's overlay entry. For the basic configuration, the line becomes:

dtoverlay=ov9281

Keep any other parameters that were already present. Save the file and reboot:

sudo reboot

After reboot, confirm that the preview updates continuously without pulses:

rpicam-hello -t 5000

Finish the session

Close any remaining preview. In a terminal where you exported the custom timeout configuration, clear it when finished:

unset LIBCAMERA_RPI_CONFIG_FILE

Troubleshooting

Symptom Check and action
Camera is missing or continuous preview fails Check the CSI cable and the camera's driver and boot configuration. If B0165 is already in trigger mode, restore Free Run to test continuous capture.
Pivariety trigger_mode is missing Verify the selected subdevice and the installed camera driver. Use the subdevice associated with the intended camera.
B0165 has no V4L2 trigger_mode control Follow the B0165 boot-configuration procedure. It selects the mode through the ov9281 overlay.
B0165 still streams continuously after enabling trigger Check uname -r for kernel 6.18.50+ or later. Verify the active overlay entry includes trigger-mode=1 and reboot after editing.
Preview times out while waiting Load timeout.yaml in the terminal launching the preview. After a B0165 reboot, export LIBCAMERA_RPI_CONFIG_FILE again. Extend the timeout if needed.
Preview stays still while pulses arrive Verify the selected GPIO, common ground, signal level and pulse timing. For Pivariety, read back trigger_mode. For B0165, check the boot configuration and reboot status.
Frames are missed Lower the pulse rate and check exposure and sensor-mode limits. Measure the signal at the camera input.
Python reports a GPIO error Check GPIO Zero and lgpio installation, permissions, and pin conflicts. Use a backend supported by your Raspberry Pi model.
Free Run does not resume Pivariety requires trigger_mode=0 on the correct subdevice. B0165 requires removal of trigger-mode=1 and a reboot. Restart the preview after changing modes.

The preview commands verify frame delivery. To save images, use a capture application that writes the received frames.

For support, include the SKU, board revision, Raspberry Pi model, kernel version, camera driver or overlay configuration, wiring photo, signal timing, and exact error output.

uname -r
rpicam-hello --version
rpicam-hello --list-cameras

For Pivariety, also include the selected subdevice and its control list. For B0165, include the active ov9281 entry from config.txt and whether you rebooted after the change.