Hi all! I am incredibly new to PsychoPy and coding in general. I am attempting to send serial triggers to BrainVision to mark my data. In the study participants are presented a word, and I want a trigger to mark when it is actually being presented in the data. I am using the serial port component, and do not get any errors while running the script, yet am not seeing any triggers on the EEG data. I may be missing something completely obvious either on the side of BrainVision or PsychoPy, but any help would be greatly appreciated!
Hi There!
We’ve seen some cases where Brain Vision expects trigger values a little differently. Attaching some resources and test files here that might be helpful - if you download the .psyexp and excel sheet and put them in a folder, then try and open the .psyexp in builder. In the first routine there is a code component, you might need to change the port address here:
port = serial.Serial(“COM3”)
and there is a guide on this page from Brain Products which might provide useful information too.
Please could you let us know if this does the trick!
Thanks,
Becca
trigger_test_list.psyexp (20.2 KB)
prac.xlsx (8.6 KB)
Hi Becca! Thank you so much for the reply. When I run the script with my Serial box port number I see one trigger but only when the experiment first launches (directly after the frame rate adjustment phase). I don’t yet see any triggers later in the experiment when we call on them. Any ideas would be great! ![]()
How are you sending triggers? With the BP TriggerBox or another device? I recently had to switch from using parallel codes to using a Neurospec MMBT-S and I had a bit of trouble getting Recorder to correctly read my codes. With the help of claude, I implemented the attached function for sending serial event triggers. The function needs to be in a Begin Experiment code component. In the same component I run this at Begin Routine:
# Initialize trigger box with proper error handling
try:
trigger_box = TriggerBox()
# Add cleanup to experiment exit handlers
runAtExit.append(lambda: trigger_box.close())
except Exception as e:
print(f"Critical Error initializing trigger box: {str(e)}")
logging.error(f"Failed to initialize trigger box: {str(e)}")
core.quit()
To send a trigger I use the send_trigger function defined in the attached file as follows: win.callOnFlip(trigger_box.send_trigger, stimCode). For a stimulus, this needs to be put in a code component that starts with your stimulus. For a response trigger, you’ll need something like this in the Each Frame tab of a code component:
if target_resp.keys:
if not keyPressed:
keyPressed = t
respCode = ord(target_resp.keys.upper())
trigger_box.send_trigger(respCode)
elif t > keyPressed + .1:
continueRoutine = False
with keyPressed = False and respCode = None at the beginning and end of the routine so that the trigger only sends once with the key press.
This might be more code than you were wanting to use, but it works as intended.
Be sure to also check your Recorder Digital Port settings. Depending on your trigger device you might need different settings.
triggerbox.py (3.4 KB)
Thank you Joseph! I will give that code a shot. We are using a BP TriggerBox to send triggers - in that case, what settings would I have to adjust in the Digital Port Settings? Thank you so much!
I don’t know anything about the BP TriggerBox sorry
I just wanted to share that I have been working with a client who is also using a Brain Products + Trigger Box set up and using @Joseph_Orr solution we got it working! I am attaching a .psyexp file here that worked.
Note that you may need to adjust the COM port and the baudrate in the class_setup code component for your system.
Would be keen to hear if this works so please let us know!
trigger_test_trigger_box_class.psyexp (36.9 KB)
