Triggers from Psychopy to ActiView via a serial port


Hi everyone,

I am struggling to send triggers from Psychopy to the EEG software ActiView via a serial port.

Can please ask if someone knows a potential solution?

I use this cable:

https://www.biosemi.com/faq/US B%20Trigger%20interface%20cabl e.htm

I wrote the following script in Psychopy, and program itself can be run, but Actiview could not get any trigger.

My PC recognizes the cable as a serial port (COM10).

import serial

port = serial.Serial("COM10",baudrate =115200)

port.write(1)
port.flush()
port.close()

I tried the following script in Matlab, and Actiview could get triggers every 3 seconds. Therefore the problem is with my script in Psychopy. Can anyone please give advice? Thank you very much


if ~isempty(instrfind)

     fclose(instrfind);

      delete(instrfind);

end

OBJ = serial('COM10', 'Baudrate', 115200);

set(OBJ, 'InputBufferSize', 2, 'OutputBufferSize', 4);

fopen(OBJ);

pause(0.1); 

tic

while toc<30 

fwrite(OBJ, 1); 

pause(3)

end

fclose(OBJ);

My desktop PC:Windows 7, 64 bit, No parallel port

Psychopy:v1.90.3(StandalonePsy choPy2_Py3)

Matlab:2017b


1 Like

Hello,

What is the Actiview expecting as input data? Potentially the value of 1 is being coerced into bytes differently. PySerial would convert 1 to 0x01 prior to sending it over the serial port, try port.write('1') (or port.write(b'1')) instead if the trigger is expecting a character.

Hi mdc,

Great!!!
port.write(b’1’) works very well!!
Perfect!
(port.write('1') didn’t work)

Thanks very much!

Hi, I have this problem, so my script is
begin experiment

import serial
port = serial.Serial("COM5", baudrate = 115200)

begin routine

port.write(trigger)
if trigger ==1:
    port.write(1)
elif trigger ==2:
    port.write(2)
elif trigger ==3:
    port.write(3)
port.write(str.encode(chr(trigger)))


end of experiment
`port.close()`
it works great, it records triggers, but sometimes i have number "224" added and it replace one of the triggers. is not extra, because i end up with the 80 trials that i need.