Serial Port EEGbiosemi

Hi Evryone,
Im using a windows 10 and psychopy 3 to create a lexical decision task. the task is done, and Im just adding the triggers and serial port.
The USB serial port I’m using is this one
image
and I download the driver that was on the Biosemi web page. This port is recognized in my computer as COM 3



and it has the following configuration

So now, I try to connect the port to psychopy, but I get this error and it doesn’t work

and my triggers are added like this in the builder vew

So I want to know what Im doing wrong, Im following all the steps but there are no videos available in youtube and all the answers here are related to coding and I don’t know how to code in python.
I install the same driver in other computer and try the experiment with e prime and triggers work, but i don’t want to use E-prime (to expensive)
Please, I need help ASAP
Thanks!

Hi There,

Unfortunately the parallel port component doesn’t yet support communication with the serial port. You will need to use a code component something like this

import serial

#serial port settings - Begin Experiment tab in a code component
s_port = serial.Serial()         #serial port name
s_port.port = 'COM3'             # chosen serial port 
s_port.timeout = 1               # timeout 1 second (give 1 second to the board to initialize port)
s_port.open()                    #open serial port to start routine

# to mark the trigger - Each frame tab of code component (note you will probably need an if statement to make sure onset it the time you want)
win.callOnFlip(s_port.write, str.encode('1'))# where '1' is the start value

# to stop the trigger- Each frame tab of code component (note you will probably need an if statement to make sure offset it the time you want)
win.callOnFlip(s_port.write,  str.encode('0'))# where '0' is the stop value

- end experiment tab
s_port.close() #in the end the serial port must be closed

Let me know if this works,
Becca

Hi Becca,
I managed to send triggers from psychopy to activeview. The only problem is that I need the triggers to be 1, 2 and 3 , but I only get the same.
I have this

So I’m doing a stroop task, and every time the participant answers, I need that trigger to be sent to activeview.im using a biosemi EEG seria port to send triggers from psychopy to activeview. What I need to know is how to make sure that the triggers are the ones that I need. For example, In a Stroop task, I have two types of triggers, 1, for condition A and 2 for condition B.
What do I need to add to my script to make sure that responses are connected to the trigger?
Thanks.

Hi There,

Brilliant to hear you have progressed! OK I suspect in your Begin Routine tab you need something like;

port.write(trigger)

Where trigger is the name of your trigger for this trial in your conditions file (i.e. 1 2 or 3). Does that work?

Thanks,
Becca

Hey, thanks for all your help, so now I have this





It works, but this is the type of trigger I get are this

So how do I know if there are the triggers that I need?
By the way my excel file that I added for the stimuli is this

Do you only want the trigger to mark the onset or be sent throughout the duration of something? if so you don’t need it in the each frame tab (at the moment the trigger send in your Begin Routine tab will correspond to the unique trigger label, but the triggers sent in Each Frame will still be 1)

Sorry, my English and coding language is not that good!
so what I need is the trigger to be sent to activeview when the participant answers or press the correct key, in this case, if the word is a congruent condition, it needs to be trigger 1 and if they answer an incongruent condition trigger 2
or in a lexical decision task, if they answer A for words, the trigger needs to be 1 and if they answer L for non-words, the trigger needs to be 2. This needs to happen only when the participant press the key does this make sense? while they see the prime word or while they are in a break, no triggers need to be send, just at the moment when the stimuli is answered

ok, so for my practice trial I have this code,




and for the test part, the code is the same, except that i didn’t include anything in the begin experiment, and end experiment.
I need to replicate that code for 4 different loops that I have

hey, so I managed to make it work, but my triggers at the moment of filter the data in eeglab look like this


So basically this means that the trigger are not recognize as different triggers?

Hi There,

Pleased to see you are making progress so far! I think this is still because you have the same trigger being sent in the each frame tab

port.write(b'1')

What happens if you set the code to be the same as that in the Begin Routine tab? (i.e. using the trigger variable)? Also, so you really want to be sending a trigger on every frame? or just at the onset of a stimulus/event?

Thanks,
Becca

Hi Becca,
So if I write
port.write(trigger)
in the begin rutine and in each frame tab, it doesn’t mark anything. it doesn’t even send the triggers. But when I had port.write(b’1’)
I was getting something like this


I have tried adding something like
port.write(b’1’)
port.write(b’2’)
but it gets messier.
so because I’m measuring RT, I need to see how long it takes the participant to answer that stimulus, so that means that the trigger needs to appear when the stimulus is shown and disappear when the participant press the response key.

Hi Becca,
So my guess about what’s going wrong is that either it’s sending too many triggers, I only need 2 or it’s sending them at the right time but leaving the port open too long. I need the port to be open just for 2 seconds. So because this is an experiment for kids, I have the stimuli presented for 3 seconds, but I need the port to be open for 2 seconds or until the participant answers (during those 2 seconds that the port will be open)

Hi There,

Have you tried flushing the port like this? Triggering from Serial port - #2 by mdc

Becca

so that needs to be where? because if I take the “each frame” it doesn’t send any triggers, so there must be something wrong in that part.

OK to clarify, if you only have one trigger sent in the begin routine tab that doesn’t send?

ok, so far this is what I have

begin experiment
import serial
port = serial.Serial(“COM3”, baudrate = 115200)

begin routine
port.write(trigger)
port.write(b’1’)

each frame
port.write(trigger)

I have three different loops, each of them with a fixation cross, testing and blank.


So I have the same for each “loop”. I recorded data and it shows 49 for words in English, including nonwords (when I put the triggers format as a decimal in actiview and 204 Spanish words. But, it didn’t record all of the stimuli, I only had 45 out 80 recorded, meaning that when some words are presented, triggers do not appear, and if doesn’t matter if it’s a word in English or Spanish or NonWord.
Now the triggers do not appear as a messy chunk in ActiView, but as a “line”
Also, In my trigger list, I have out different triggers for each category, so for English words (ENG in my type list in excel) I have 1, for Spanish words (SP) I have 2 and for Non Words (NW) i have 3
But to make it simple, i can just have Words and NonWords. Im happy with that.

triggers are synched to the stimulus presented. As soon as the stimulus appears, the trigger appears and as soon as the correct key is press, it disappears. Also, it stays for the same amount of time as the stim, so 3 seconds. I need this to be 2 seconds

Hi Stephanie,

Could you possibly share the .psyexp file as it is now and I’ll take a look :slight_smile:

Also for thie Now the triggers do not appear as a messy chunk in ActiView, but as a “line” to clarify you want a single “line” at the start of each stimulus rather than a messy chunk? I suspect the messy chunk is from sending a trigger on each frame?

Thanks!
Becca

in relation to the triggers, this is how they look now in ActiView

and this was yesterday


I recorded data and it shows 49 for words in English, including nonwords (when I put the triggers format as a decimal in actiview and 204 Spanish words. But, it didn’t record all of the stimuli, I only had 45 out 80 recorded, meaning that when some words are presented, triggers do not appear, and it doesn’t matter if it’s a word in English or Spanish or NonWord.

Hi Becca
Im uploading the .psyexp file
LexDecisionPhD.psyexp (80.9 KB)