| Reference | Downloads | Github

Response triggers to EEG

OS : Windows 7
PsychoPy version: 1.84.2
Standard Standalone? Yes
What are you trying to achieve?:

I have a question about how to send response triggers from a testing computer to an EEG recorder in a task designed in Builder mode . I’m using a direct parallel port connection to connect the testing computer and EEG (Biosemi EEG system).

In my task, participants have to press a key (1 or 2) in order to determine if the stimulus presented in the screen is a word or a non-word (the responses are collected using Keyboard component). I used the I/O component for sending the triggers associated with the type of stimulus and created a column [ID] in my excel file which determine the integer [111, 112, 211, etc.] for each type of stimulus (I have different conditions within word and non-word stimuli but I’ve simplified it for the purposes of solving the trigger issue).

The problem is that, while I’m able to send triggers for each stimulus with the I/O component (screenshot below) -and therefore I’m sure that there is no problem between the parallel port and the EEG-, I couldn’t find a solution for sending the triggers associated with the participant’s response.


What did you try to make it work?:

I have used the Code component inserted in Builder, however this does not generate any trigger.

In code properties, I typed this:

Begin Experiment

from psychopy import parallel

parallel.setPortAddress (0x0378)

Begin Routine

if len(key_resp_3.keys)>0 and response.corr:

if key_resp_3.keys[0] == corrAns:





End Routine


What specifically went wrong when you tried that?:

While the triggers for type of stimulus created from the I/O component are properly sent, the response triggers –created from the Code component- are not generated.

What should I do/change (in the Code component or wherever) to get the response triggers sent through the parallel port?

Any thoughts/comments/advices would be veeeery appreciated!

Many thanks!

You are using some old-fashioned code to set properties of the parallel module itself, rather than a specific instance of a parallel port. In your case, you already have a parallel port created graphically (your p_port component), so you don’t need to import the parallel library or set the port address: all of that is already done for you. So delete your “Begin experiment” code.

I don’t really know the structure of your experiment, but I suspect your current “begin routine” code should actually be in the “End routine” tab instead: at the start of the routine, there will not have been any key pressed yet: it only makes sense to check this later. Then I’d suggest that your code could then be something like:

if len(key_resp_3.keys) > 0:

    if key_resp_3.keys[0] == corrAns:
        p_port.setData(98) # send via a specific object

Note that I also removed the and response.corr check from the first if statement. Otherwise, you would never send a 99 value. Actually, maybe the first if len(key_resp_3.keys) > 0: isn’t necessary at all either? If the keyboard component is set to force the end of the routine, then I guess by definition there must be a response by this stage?

If so, the code could perhaps just be:

if key_resp_3.corr:

Please note I edited your post above so the code is properly formatted, as per the link below. Please do this in the future. In particular, it allows us to see the indenting, which carries meaning in Python, and appears to be absent in the code snippet above.

1 Like

Dear Michael,
Many thanks for your quick reply. I’ve been testing your recommendations and it finally works!
I only did some modifications in the code, because it only sent one of the triggers [99] but the other [98] didn’t. So I included [int] in the code in order to “explain” that the variables were integers and not text.
Eventually, the code that better works in my case was:
End Routine (Indeed, the code should be here instead of Begin Routine)

if int(key_resp_3.keys[0]) == int(corrAns):

Thank you so much for your help!

1 Like

i am trying to send trigger from psychopy to eeg acquisition machine via parallel port

using same set of code

but it is not showing any trigger or error.
do i need some other set of files in support to this.

it is not giving any error also.

any help would be appreciated.

Thank You