Trigger cameras
The Behavior device can generate TTL signals on DO0 and DO1 for cameras that support external triggering. This is useful for synchronizing multiple cameras and logging 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 camera, and visualize frame events in Bonsai.
The complete workflow is shown below. Copy and paste it into Bonsai to get started immediately, or build each section by following the step-by-step instructions in the following sections.
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 the 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 (e.g. Camera1Frame for DO1). Use it to verify that the trigger signal is being generated. Each message includes the timestamp of the pulse's rising edge, as recorded by 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.
Documentation for release v3.4.0