Sending triggers to EEG via Brain Vision Triggerbox by using the serial Port Component

Hello all,

I am trying to make PsychoPY send triggers to EEG through the Brain Vision Triggerbox

I am using the serial Port component. In the pictures below you can see what I’m doing (there are 3 different visual stimuli and I want to send three different triggers for each):

(Here I also tried setting the duration as 1 second, did not work)

However, I get this error message when I run the experiment:

File “C:\Users\kppadmin\Desktop\Metin_Paradigm_2\”, line 260, in
serialPort = serial.Serial(
File “C:\Program Files\PsychoPy\lib\site-packages\serial\”, line 33, in init
super(Serial, self).init(*args, **kwargs)
File “C:\Program Files\PsychoPy\lib\site-packages\serial\”, line 225, in init
self.parity = parity
File “C:\Program Files\PsychoPy\lib\site-packages\serial\”, line 336, in parity
raise ValueError(“Not a valid parity: {!r}”.format(parity))
ValueError: Not a valid parity: None

Anyone maybe has an idea what causes the problem? Any help would be appreciated. Thanks!

1 Like

So I have realized I put the wrong port name here (it should have been COM3). However, I still get the same error when I use the serial Port component.

That’s why I tried to communicate with the port with a code. I used the code described here: Sending triggers via a Serial Port — PsychoPy v2022.2.2

And my code is as follows:

Begin Experiment:
import serial
port = serial.Serial('COM3') 

Begin Routine:
pulse_started = False
pulse_ended = False

Each Frame:
if face_hab.status == STARTED and not pulse_started:
    port.write([trigger_values_hab]) # trigger_values_hab is the header of an excel coloumn where I define the triggers
    pulse_started = True
    pulse_ended = False
    pulse_start_time = globalClock.getTime()

if pulse_started and not pulse_ended:
    if globalClock.getTime() - pulse_start_time >= 0.005:
        pulse_ended = True

However I have some issues / questions and any help would be appreciated:

1. I want to use the win.callOnFlip function as described in the link above and as can be seen below:


But I receive this error:

“C:\Users\kppadmin\Desktop\Metin_Paradigm_2\”, line 1451, in


File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 1219, in flip

callEntry['function'](*callEntry['args'], **callEntry['kwargs'])

TypeError: ‘int’ object is not callable

I have also tried to change the settings in the properties of the excel coloums (I defined the values as “Text”, rather than “Standard”. Because otherwise the first code I wrote above did not work either…) But then, I receive this error:

data = to_bytes(data)

File “C:\Program Files\PsychoPy\lib\site-packages\serial\”, line 68, in to_bytes

return bytes(bytearray(seq))

TypeError: ‘float’ object cannot be interpreted as an integer

Any idea how I can make the win.callOnFlip function work while indexing to my trigger list on the excel sheet?

2. I have realized that not all the triggers are sent to the EEG. And I have figured out a pattern: If, let’s say, two identical triggers (I give the triggers values like 1,2 and 3 on the excel sheet) appear sequentially, then only the first one is being sent. For example, if I have stimuli_2 appear two times sequentially (meaning have two "2"s on the trigger_list_hab coloumn one coming after the other in rows), then a trigger called S2 is sent for the first stimuli_2, but not for the second stimuli_2. Do you know maybe what causes this?

Thanks in advance!

I meet the same problem and hope someone can help us with it :slight_smile:

Hi @Ange

For the first problem, @Becca suggested this solution in another topic: Sending multiple triggers in one routine using serial port - #4 by Becca

I stopped receiving errors afterwards however, the triggers were not shown regardless. You could try simply using port.write (without a win.callOnFlip() function). That worked for me. But it is said that this may lead to less preceise timing so timing verification with a phototide etc might be considered here.

For the second problem, I realized I did not reset the port back to 0 and when I did that, the problem was solved:

if pulse_started and not pulse_ended:
    if globalClock.getTime() - pulse_start_time >= 0.005:
        port.write[0x00]  # !
        pulse_ended = True
1 Like