Adding EEG Triggers to keyboard responses

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.1.3
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I’m trying to add EEG triggers/markers (via cpod) whenever I have a keyboard press (either button ‘1’ or ‘2’)

What did you try to make it work?:
I’ve tested the eeg trigger code separately and it works, but when i try to insert a code component to specify for the EEG trigger whenever a keyboard button is pressed, it doesn’t work. keyResponse is the name of my keyboard press. Code component as follow:

if keyResponse.keys == ‘1’:
for bm in range(1):
mask = 2 ** bm
print("activate_line bitmask: ", mask)
dev.activate_line(bitmask=mask)
elif keyResponse.keys == ‘2’:
for bm in range(1):
mask = 2 ** bm
print("activate_line bitmask: ", mask)
dev.activate_line(bitmask=mask)

What specifically went wrong when you tried that?:
The paradigm runs but i dont get the EEG trigger on my EEG recording software. I am however able to get a trigger if i just run the following:

for bm in range(1):
    mask = 2 ** bm
    print("activate_line bitmask: ", mask)
    dev.activate_line(bitmask=mask)

Hi There,

Is there a reason to communicate with your device via code component rather than the inbuild parallel/serial port components? (Details here)

If your keyboard response is ending the routine you can then have a second routine with a parallel/serial port at the start?

Becca

Hi Becca,

Thanks for the reply!

I didnt use the inbuild parallel port as we are using a cpod, not sure if it is compatible with the parallel/serial port components?

The keyboard response isn’t ending the routine, it is a loop that repeats where different stimuli will be shown one after another and keyboard response is required for each stimuli.

Have tried using the inbuild parallel port but it doesn’t seem to work with cpod and doesn’t seem to have a trigger/marker produced.

I would try adding the code component then where you have something like this in the begin routine tab:

key_count = 0

then in the each frame tab

if len(key_resp.keys)>key_count:
    # send your trigger here
    key_count += 1

Where I’ve marked “send your trigger” use the usual code snippet you have been using to interact with your device if that is working!

Becca

1 Like