psychopy.org | Reference | Downloads | Github

Sending triggers in oddball paradigm through serial port

Win10:
PsychoPy version (1.94.x):
As the tiltle asking about, I have problem in sending triggers through triggerbox to computuer to moniter and record the ERP. There was no mark on my ERP data ,and here is what I have tried:




And I don’t know how to caculate time in frame, so I used the time.sleep(0.4).

Sincerely Hope you can help me figure it out and thanks in adcance.

You shouldn’t use any functions like that in a Builder script (i.e. ones which impose any sort of delay or sleep period). Builder scripts maintains a timing system by actively drawing to the display on every screen refresh, typically at 60 Hz. By sleeping for 400 ms, you will break that drawing cycle (in this case, causing Builder to lose track of at least 24 screen refreshes on a 60 Hz display). This might cause unexpected timing errors for the other component you have created.

Builder maintains its own variable called t that keeps track of the time elapsed in seconds since the start of the current routine (as long as you don’t put it to sleep). So you can check the time and send the pulse, but also need to check that you do it only once. So put this in the “begin routine” tab, deleting the code that is there currently:

trigger_sent = False

and then put this in the “each frame” tab (so that the code will run on each screen refresh):

if not trigger_sent and t >= 0.4:
    port.write(bytes(1)) # or whatever is appropriate
    trigger_sent = True
1 Like

Thanks for your instruction, and I will try again.