An inline script for OpenSesame to send EEG triggers via serial port
The OpenSesame user base is skyrocketing but—of course—remains small in comparison to many other user bases that we are used to. Therefore, when developing an experiment in OpenSesame, there are still many opportunities to break the mould. When you need to do something beyond the standard operating procedure, it may take longer to find suitable resources than it takes when a more widespread tool is used. So, why would you still want to use OpenSesame? There are many reasons: it is free, open source, based on Python, stable enough thanks to more than a decade of usage and development, well maintained, and has a community forum.
I recently faced a challenge when developing an EEG experiment that uses event-related potentials. I couldn’t find a way to send triggers through a serial port. Online, I could find several resources, such as a script by Kate Stone that draws on a parallel port, an outdated plugin that also draws on a parallel port, and resources based on Python scripts in PsychoPy and in base Python. By standing on these giants’ shoulders, and on even more shoulders from StackOverflow, I put together the following inline script for OpenSesame. The code must be placed in the Prepare
phase. The Run
phase can be empty.
This script is used to set up the system for sending triggers to the EEG recording software (e.g., BrainVision Recorder). The code automatically looks for an available serial port at the beginning of the session. If there are any available ports, a connection is established to the first port in the list. If there are no available ports, no connection is established, and a warning is shown on the screen, informing the user that no triggers will be sent to the EEG recorder. In the latter case, the triggers are only printed in the OpenSesame console.