psychopy.org | Reference | Downloads | Github

Very lost on how to get a trigger sent using parallel port

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): most recent
Standard Standalone? (y/n) If not then what?: yes
What are you trying to achieve?: For simplicity sake, let’s say I am simply trying to get 2 stimulus triggers sent to my EEG system. When the participant sees stimulus A, it sets the port to 2. When the participants sees stimulus B, it sets the port to 3. The port numbers in specific are not important, it’s just important that they are different.

What did you try to make it work?: I have tried following various tutorials online to accomplish this. I verified that I am using the correct port address. I installed the necessary drivers to retrieve the port address. I inserted a code chunk where my experiment loop begins (where participants see stimulus A and B repeatedly and randomly). It looks like this

Begin Experiment: from psychopy import parallel
port = parallel.ParallelPort(address = 0xCFF8)
port.setData(0)

Each Frame:
if text == ‘A’:
…port.setData(2)

if text == ‘B’
…port.setData(3)

port.setData(0).

I also added an IO component to the routine. I set the port address, and set start data to 1. I set the duration to 2.5 seconds (which is the length of the entirety of the frame)

What specifically went wrong when you tried that?:
There is no error message, and it appears that the experiment is running, however, no trigger codes are appearing in the EEG file. I am very lost on how to fix this. Does anyone have any advice?

Since you have inserted a graphical parallel port component in Builder, the code you have in the “begin experiment” tab is redundant, and may conflict with the code created by the component. So delete the code from that tab of your code component.

In your “each frame” tab, then just make sure you use the name of the graphical port component. e.g. if it is called p_port then refer to that name in your calls like p_port.setData(2) etc.

Lastly, in your “each frame” code, you are setting the pins to have a certain value (e.g. 2 or 3) and then immediately setting it to 0 again. Parallel port signals need to have a certain pulse width (i.e. duration) if they are to be detected. It is possible that you are setting and then re-setting it so quickly here that the receiving hardware has no chance of detecting the change in value. The easiest thing to do here is to use your code as above to set the value to 2 or 3 but only set it back to 0 in the “End routine” tab. That means that the pulse with will be quite long (the duration of the trial) and hence will easily be able to be detected.

You can also be a bit clever and keep track of whether the initial change has been made, and only set the value once per trial, but in this case, there is no real problem with setting it on every screen refresh, as it is effectively staying constant at that value for the duration of the trial as long as you only zero it at then end of the routine.