psychopy.org | Reference | Downloads | Github

Serial Port EEGbiosemi

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)

Hi Stephanie,

OK the top one looks pretty good/close! (at least that is how I was used to seeing my triggers)

Please could you try the attached? I made an edit to the code in the Test1 routine (you can see my comments - let me know how you get on.

Becca
LexDecisionPhD.psyexp (81.2 KB)

Hi Becca,
So I tried your code,
even though it recorded all of the stimuli (80 in total) still there are problems with the triggers.

so there is an extra number there which is 230. I realize that is in some Spanish words and only happened with 3 words. what do you think this can be?
Also, is it a serial port thing that recognizes 1 as 49 and 2 as 50? Can that make any trouble at the moment of a amazing the data with EEGLAB? because when I used a p.port, it recognized the triggers like in the excel file.

Hi There,

OK it feels like we are getting closer! What happens if you write the integers instead of writing a string?

Try replacing:
port.write(b’1’)
with:
port.write(1)

I see this write method takes bytes and strings pySerial API — pySerial 3.4 documentation

But if you use integers does it appear in the data as expected?

I am less sure on what the stray trigger is - does the total number of triggers correspond to the total number of stimuli you expect? or are these extra?

Thanks,
Becca

Note: here is another method to try writing to the port Sending markers to EEG through serial port - #2 by Michael I think this was the solution for this user Sending markers to EEG through serial port - #12 by lindayu

Hi Becca,
So, to sum up, the new code
port.write(1) does not work.

I ended up adding this port.write(str.encode(chr(trigger))) codeand all of the 80 words are recorded. but still, sometimes i get 204 as a trigger. with this script my triggers are the same as in the excell file.
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)))

OK how frequently is the 224 occurring? is the sum of the other triggers the sum of your trials?

Thanks,
Becca

Hi Becca,
So sometimes it happens 3 times during the whole experiment, sometimes more.
All my trials are recorded. When the 224 appears, this replaces one of the other triggers, so instead of 1, 2 or 3 is 224. This number because is replacing one of the other triggers, does not add other trials. So I end up having 80 trials recorded (what I need) but with some 224 in between.
Also, this only happens when I have 3 triggers or more.

interesting - OK to worst comes to worst triggers can be posthoc labelled with their corresponding condition in the analysis - but I know that is not what we want ideally.

Looking on the actiview support site I see that someone had a similar issue and they fixed it using the a write byte approach rather than a write integer method Trigger Codes Missing Sporadically - BioSemi.nl

In this post @Michael translates a trigger code to bytes Sending markers to EEG through serial port - #2 by Michael could we try that?

So it would be something like:

port.write(trigger.to_bytes(length = 1, byteorder = 'little'))