psychopy.org | Reference | Downloads | Github

Serial Port EEGbiosemi

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')) 

Yes, i tried that and it didnt work.

Hmm ok I am afraid it is a bit tricky for me to advise without being able to test your specific set up - it sounds as though you have tried all the correct steps!

When you mention that it didn’t work - what happened exactly? was an error thrown? or was it just the same pattern as before?

Thanks,
Becca

Hi becca
This didn’t work
port.write(trigger.to_bytes(length = 1, byteorder = ‘little’))
When I only have the task with two triggers, the script works perfectly. But when I have three or more triggers sometimes I have 224 as a trigger

Hello,

I wonder if you need a flush statement after the trigger is sent? like this Triggering from Serial port - #2 by mdc

Hi Becca
This flush statement should be in begin routine?

I think immediately after you make your call to write

Becca

Hi Becca,
So the Flush didnt work,
i dont know if i put it in the correct place though, I have it like this
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()