| Reference | Downloads | Github

callOnFlip and timeOnFlip for an serial EEG trigger

OS: Win10
PsychoPy version: 3.1.5
What are you trying to achieve?:
I’d like to send a trigger when a monitor flips to show a stimulus. I’d also like to log the time of trigger in the excel data file to be able to double check its being sent at the same time of the flip.

What did you try to make it work?:

before routine:

trigger_start = []
win.callOnFlip(port.write, b'1')

end routine:

thisExp.addData('trigger_start', trigger_start.triggerStart)

What specifically went wrong when you tried that?:

The function port.write(b’1’) works to send a trigger, but there is lag and I realized it would be ideal for the trigger to be sent when the screen flips. I’m just confused how I would use callOnFlip and timeOnFlip sync the trigger with the screen flip and log the time in the excel file. Will the callOnFlip code I’ve written wait for when my stimulus is shown on the screen?

What I tried gave this error message:

TypeError: timeOnFlip() missing 1 required positional argument: 'attrib'

I’ve tried to give trigger_start and attribute.


I solved my callOnFlip and timing issues. For an EEG experiment, I used the same participant and gauged the lag by compare his peak P100 with two different scripts. In one I just used port.write(b’1) and the other I used win.callOnFlip(port.write, b’1’). The difference in P100 was about 32ms.

I then timed the difference between when the trigger command was used and when the screen flipped to the scene stimulus. The excel data already showed when the scene was presented because I’m using builder.

To get when the trigger occurred in the Begin of Routine tab I put:

trigger_start = core.monotonicClock.getTime()

And put this at the End of Routine tab:

thisExp.addData('trigger_start', trigger_start)

The difference between the trigger and the scene in the excel sheet was about 32ms so problem solved.