This repository contains guiding examples for sending trigger signals via serial communication to Biosemi trigger interface and Arduino devices. While an utility class is provided for each device, it's also possible to achieve the same functionality using the serial.Serial object directly, in a simpler way. (See last example in SerialTriggerBiosemi_example.py
)
It's particularly useful for experimental setups requiring precise timing and trigger signals. Some examples on how to send bytes to the interfaces are provided in the how_to_byte_python.ipynb
notebook.
The setup and scripts were tested with an oscilloscope. Biosemi trigger interface results in a 3.3V pulse of 8ms duration, and the Arduino trigger interface can be modified as desired (see trigger_pulse_5ms_arduino/
for example code).
- Utility classes for Biosemi and Arduino trigger interfaces, based on the pyserial library.
- Example scripts for sending trigger signals.
- Thread-safe operations
- Comprehensive examples and documentation.
- Install the required Python package:
pip install serial
- For Arduino setup:
- Connect your Arduino to your computer via USB
- Upload the
trigger_pulse_5ms_arduino.ino
sketch to your Arduino via the Arduino IDE.
- On Linux/Mac: Run
ls /dev/tty*
in terminal - On Windows: Check Device Manager or run
python -m serial.tools.list_ports
in terminal
from SerialTriggerBiosemi import BiosemiTrigger
# Initialize the trigger interface
biosemi = BiosemiTrigger("COM7", initial_delay=3) # Adjust port as needed
# Test the connection
biosemi.test_trigger(signal_byte=0b00000001) # Activates trigger 1
# Don't forget to close the connection
biosemi.close()
from SerialTriggerArduino import ArduinoTrigger
# Initialize the trigger interface
arduino = ArduinoTrigger("COM8") # Adjust port as needed
# Send trigger signals
arduino.send_signal(True) # HIGH signal
arduino.send_signal(False) # LOW signal
# Close the connection
arduino.close()
SerialTriggerBiosemi.py
- Main class for Biosemi trigger interfaceSerialTriggerArduino.py
- Main class for Arduino trigger interfaceSerialTriggerBiosemi_example.py
- Example usage for BiosemiSerialTriggerArduino_example.py
- Example usage for Arduinotrigger_pulse_5ms_arduino/
- Arduino sketch for trigger functionalityhow_to_byte_python.ipynb
- Jupyter notebook explaining byte handling in Python
- Supports 8-bit trigger signals
- 3.3V output
- 8ms trigger pulse duration
- Configurable trigger patterns
- Thread-safe operations available
- 5V output (modifiable: You can experiment with PWM
analogWrite()
function) - 5ms pulse duration (modifiable: Change delay between signals)
- Simple HIGH/LOW triggering
- Visual feedback via built-in LED