psychopy.org | Reference | Downloads | Github

Adding ptb.waitsec breaks the stimulus in psychopy builder

Dear Folks,

I am a beginner of psychopy and start with builder. There’s an issue between my trigger signal to neuroscan and breaking stimulus that I hope I could get some help in this lovely community.

My experiment is simple: the stimulus is text and sound that presents every second for the experimenter to apply the tactile stimulus precisely.

What did you try to make it work?:
Successfully send triggers to both neuroscan and stimtracker with completed experiment material.

What specifically went wrong when you tried that?:
Here is the trigger code, and the strong indication is the key point:


#Before Experiment:
import psychtoolbox as ptb
from numpy import uint8
import pyxid2
import serial
from psychopy import core

#Begin Experiment
port = 'COM3'
baudRate = 115200
InputBufferSize = 8
readTimeout = 1

portSettings = 'BaudRate=%d InputBufferSize=%d Terminator=0 ReceiveTimeout=%f ReceiveLatency=0.0001'%(
baudRate, InputBufferSize, readTimeout)
[handle, errmsg] = ptb.IOPort('OpenSerialPort', port, portSettings)
ptb.IOPort('Flush', handle)

#Begin Routine
x=0
trigger=97
[nwritten, when, errmsg, prewritetime, postwritetime, lastchecktime] = \
ptb.IOPort('Write', handle, uint8([109,104,uint8(trigger),uint8(0)]))

#Each Frame

[nwritten, when, errmsg, prewritetime, postwritetime, lastchecktime]=ptb.IOPort('Write', handle, uint8([109,104,uint8(trigger),uint8(0)]))
**ptb.WaitSecs(1)**
ptb.IOPort('Write', handle, uint8([109,104,uint8(0),uint8(0)]))

#End experiment
ptb.IOPort('Write', handle, uint8([109,104,uint8(0),uint8(0)]))
ptb.IOPort('close',handle)

The issue we had for this code without ptb.WaitSecs(1) adding in each frame was the trigger didn’t appear on neuroscan but successfully appear in stimtracker, everything in experiment works as it should be.

After we successfully send the trigger to both stimtracker and neuroscan by adding ptb.WaitSecs(1), though the trigger time is always a sec earlier than it should be*, the stimulus material both sound and text doesn’t function as it originally is. The stimulus I set is text and sound with counterbalance conditions from csv, and it loops every sec. The stimulus doesn’t loop the sound and text properly but still run in the sequence I set after adding ptb.WaitSecs(1).

I’ve tried open a new file and add the trigger code in new presented material. It always breaks the material and send the trigger to both neuroscan and stimtracker successfully after adding ptb.WaitSecs(1) and vice versa.

Thank you in advance for reading this question and hopefully, this question is also helpful for others.

*The other issue with ptb.WaitSecs(1) of sending trigger is that it will send the trigger 1 sec eariler than the stimulus appears. In our case, I’ve set the trial A loop with trigger 97 and trial B loop with trigger 98. The first trigger 98 sends to neuroscan in the last loop of trial A and the second trigger 98 sends to neuroscan in the first loop of trial B.

Ann


OS (e.g. Win10): Win 10
PsychoPy 3 (e.g. 1.84.x): Psychopy3
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:: Sending the triggers to both EEG neuroscan and stimtracker with all the completed material .