Routine advance unreliable: requires multiple fmri triggers instead of one

OS (e.g. Win10): Win11
PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.1.1
Standard Standalone Installation? (y/n) If not then what?: y
Do you want it to also run online? (y/n): n

What are you trying to achieve?:
Hi everyone, we are running an fMRI experiment in PsychoPy (Builder) where the MRI scanner sends a “t” trigger every TR (≈1.53 s) via keyboard emulation. We want PsychoPy to be tightly synchronised with the fMRI scanner, and after 8 dummy scans, the main experiment starts.

What did you try to make it work?:
After the instruction screen at the start of the experiment, the Wait_DummyScan routine is placed inside a loop with 8 repeats, corresponding to 8 dummy scans. A visual countdown is displayed, starting from 8. Each iteration of the loop should end when a scanner trigger (“t”) is received via a Keyboard component. The intended behaviour is therefore:

The first trigger ends the first iteration, changing the display from 8 → 7 (i.e. 8-t-7)

The second trigger ends the second iteration, changing 7 → 6

After 8 triggers, the main experiment starts

So each TR (one “t”) should advance the countdown by exactly one step.

What specifically went wrong when you tried that?:
We observed that while this worked as expected for some runs, for others it became 8 → t → t → t → t → 7. In other words, the scanner was sending triggers, and they were being recorded in the log file, but the PsychoPy routine did not advance until several triggers had been received (see the log file screenshot below).

Interestingly, this only happens when the scanner is connected. When I press “t” manually on my laptop’s built-in keyboard or on an external USB keyboard, the problem does not occur.

What is the recommended way to fix this? Many thanks in advance for any advice or suggestions.

Hello @luoxiangqi

I suppose we need to know how you implemented this.

Best wishes Jens

Thank you so much for your reply!

The trigger issue has been fixed! The solution was to adjust one setting in the keyboard component that receives the fMRI trigger: change “register keypress on” from the default “press” to “release.”

Hopefully, others won’t fall into the same trap again. It really does take quite some time to track down the cause :smiling_face_with_tear: .

Best,
Xiangqi