Trigger Cameras
The Behavior board can generate TTL signals for cameras that support external triggering on DO0 and DO1. This is useful for synchronizing multiple cameras and capturing camera frame timestamps on the device clock. Refer to the connections article to set up a compatible camera on DO1, which we will use for the rest of these examples.
This article covers how to configure the trigger frequency, start and stop the cameras, and visualize frame events in Bonsai.
The complete workflow is shown below. Copy and paste it into Bonsai or build each section by following the step-by-step instructions below.
Tip
Configure your camera to trigger on the rising edge of the pulse, and avoid modes that use the trigger pulse width to control exposure. Check that the voltage level is compatible with the camera's external trigger voltage level. The trigger signal is a 5 V square wave with a 50% duty cycle and the pulse width is not configurable.
Configure Trigger Frequency
Set the trigger frequency of each camera with the appropriate register for the port (e.g. Camera1Frequency for a camera connected to DO1).
- Insert a
KeyDownoperator and set theFilterproperty toA. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectCamera1FrequencyPayload.Camera1Frequency- Set the trigger frequency in Hz (e.g.30). Valid values are 2 to 600.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow and press A to set the trigger frequency. Configure the frequency before starting the camera. Once camera triggering starts, the frequency cannot be modified without stopping the camera.
Start and Stop Cameras
Enable and disable the camera triggering with the StartCameras and StopCameras registers:
- Insert a
KeyDownoperator and set theFilterproperty toS. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectStartCamerasPayload.StartCameras- Select the camera output to start (e.g.CameraOutput1for DO1).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
In a separate branch:
- Insert a
KeyDownoperator and set theFilterproperty toD. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectStopCamerasPayload.StopCameras- Select the camera output to stop (e.g.CameraOutput1for DO1).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow, press S to start the camera trigger on DO1 and D to stop it. Check the image stream in either Bonsai with a camera source operator like CameraCapture or in your camera vendor's acquisition software to confirm that the external trigger is working.
Note
Camera triggering stops automatically when the Bonsai workflow stops and the device goes into standby mode. This behavior is specific to camera triggering, other digital outputs keep their last state when the workflow stops. Remember to start the camera trigger again when you restart the workflow.
Visualize Frame Events
Each trigger pulse broadcasts a frame event tied to the port like Camera1Frame. Use it to verify that the trigger signal is being generated. Each message will also carry the recorded timestamp for the pulse on the device clock:
- Insert a
SubscribeSubjectoperator namedBehavior Events. - Insert a
Parseoperator and configure theRegisterproperty toTimestampedCamera1Frame. - Insert a
VisualizerWindowoperator.
Run the workflow and press S. The visualizer displays:
FrameAcquired@10.351072
The first value confirms the frame trigger and the second is the timestamp on the device clock. Match the logged timestamps against the frames saved by your video capture software to align video with the rest of the data.
Last updated with:
Hardware v2.1
Firmware v3.3
Bonsai Package v0.2