EEG response trigger: brain products serial port

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!

Two thoughts:

  1. Using “callOnFlip” works for the stimuli because it syncs the trigger to when the stimulus actually appears on the screen. However, I think in this case you are queuing up multiple triggers on the same flip, which may be why they both fail because it tries to execute them simultaneously.
  2. The reason they’re going simultaneously is because the “STARTED” status for a keyboard element records when it starts listening for a keyboard response, not when the key is pressed. As such I think it’s trying to send both of these triggers right at the start of the trial.

If you want to send the trigger when the key-press is recorded, use:

if response.keys and not response_pulse_started:
   send_triggers([0,0,0,1,0,0,0,0])
   response_pulse_start_time = globalClock.getTime()
   response_pulse_started = True 

if response_pulse_started and not response_pulse_ended:
   if globalClock.getTime() - response_pulse_start_time >= 0.005:
       send_triggers([0,0,0,0,0,0,0,0])
       response_pulse_ended = True

By decoupling the response trigger from the screen refresh and making sure that it only happens on the actual response instead of when the keyboard is initialized, it should ensure that you don’t end up with a trigger-collision situation.

However note that this will only send the trigger on key release by default, so you may need to set the keyboard component to “register keypress on press” in the builder, depending on when exactly you want the trigger to appear in your EEG data.

1 Like