Hi,
I wanted to send triggers upon stimulus presentation and response (upon pressing a button) for an EEG study. I use BrainProducts device (serial port). Following this article: Communicating with Brain Products Devices — PsychoPy v2024.2.4, the stimulus trigger worked perfectly.
However, upon adding the code for response trigger below the stimulus trigger, both triggers stop working (i.e., triggers are not send anymore)
This is what I have done - I call the keyboard component ‘response’. I modified the code as follows:
In the trial, I inserted a code component, and in each frame is the below code:
##STIMULUS TRIGGERS##
#Check to see if the stimulus is presented this frame
#and send the trigger if it is
if stimulus.status == STARTED and not stimulus_pulse_started: #If the stimulus component has started and the trigger has not yet been sent. Change ‘stimulus’ to match the name of the component you want the trigger to be sent at the same time as
win.callOnFlip(send_triggers, [0,0,0,0,0,0,0,1])#Send the trigger, synced to the screen refresh
stimulus_pulse_start_time = globalClock.getTime()
stimulus_pulse_started = True #The trigger has now been sent, so we set this to true to avoid a trigger being sent on each frame
#If it’s time to end the pulse, reset the value to “0”
#so that we don’t continue sending triggers on every frame
if stimulus_pulse_started and not stimulus_pulse_ended:
if globalClock.getTime() - stimulus_pulse_start_time >= 0.005:
win.callOnFlip(send_triggers, [0,0,0,0,0,0,0,0])
stimulus_pulse_ended = True
#response TRIGGERS##
#Check to see if the response is given this frame
#and send the trigger if it is
if response.status == STARTED and not response_pulse_started: #If the stimulus component has started and the trigger has not yet been sent. Change ‘stimulus’ to match the name of the component you want the trigger to be sent at the same time as
win.callOnFlip(send_triggers, [0,0,0,1,0,0,0,0])#Send the trigger, synced to the screen refresh
response_pulse_start_time = globalClock.getTime()
response_pulse_started = True #The trigger has now been sent, so we set this to true to avoid a trigger being sent on each frame
#If it’s time to end the pulse, reset the value to “0”
#so that we don’t continue sending triggers on every frame
if response_pulse_started and not response_pulse_ended:
if globalClock.getTime() - response_pulse_start_time >= 0.005:
win.callOnFlip(send_triggers, [0,0,0,0,0,0,0,0])
response_pulse_ended = True
Could you please tell me how this problem could be solved?
Thanks!