Triggers via PsychoPy Mislabeling in ActiView

Post Reply
ashgilm
Posts: 1
Joined: Thu Sep 29, 2022 4:17 pm

Triggers via PsychoPy Mislabeling in ActiView

Post by ashgilm »

I am trying to get my experiment in PsychoPy to work with ActiView using coding in Python. I've been able to effectively send triggers to the system, but I get a few random numbers that replace actual condition labels. There doesn't appear to be any pattern to them (they don't appear at specific time points or for specific trigger values/conditions).

These incorrect numbers are 242 and 192. They are replacing any one of the trigger codes I specified for each condition (1, 2, or 3).

Anyone have any experience with this or ideas on how to keep these errors from occurring in the first place? Are there certain values that would be better for the BIOSEMI system when coding triggers?

I'm hoping I don't have to change them manually during preprocessing of the EEG data for every participant. I can share my experiment file if that helps. Below is my code in PsychoPy for triggers


"Begin experiment"
import serial
port = serial.Serial("COM4", 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)))
port.flush()

"End experiment"
port.close()



Thanks!

Gerben
Posts: 26
Joined: Fri Sep 24, 2010 4:36 pm

Re: Triggers via PsychoPy Mislabeling in ActiView

Post by Gerben »

Hi,

I usually make my code in c so I am not 100% sure if this is exactly the same in python.
In order to sent a valid trigger you should send a single byte for example 0x01 and then wait for two times the sample rate before sending a new trigger, with the default sample rate of 2khz you should wait at least 1ms before sending a new trigger.

I've added the minimum waiting times to your example code below, also make sure your sending the triggers in binary format and not with ascii encoding.
"Begin experiment"
import serial
port = serial.Serial("COM4", baudrate = 115200)

"Begin routine"
port.write(trigger)
port.flush()
sleep(1ms)


//I'm not sure how to tell python to sent triggers in a binary format but if port.write(1) gives the wrong result you could try port.write(0x01)
port.write(0x01)
port.flush()
sleep(1ms)


if trigger == 1:
port.write(1)
port.flush()
sleep(1ms)

elif trigger == 2:
port.write(2)
port.flush()
sleep(1ms)

elif trigger == 3:
port.write(3)
port.flush()
sleep(1ms)


//you can not sent a string to the usb triggerinterface
//port.write(str.encode(chr(trigger)))
//port.flush()

"End experiment"
port.close()

Post Reply