# Reading MRI trigger with DataPixx

**URL:** <https://psychtoolbox.discourse.group/t/reading-mri-trigger-with-datapixx/5020>\
**Category:** Programming Help\
**Created:** [June 22, 2023, 1:33pm UTC](https://psychtoolbox.discourse.group/t/reading-mri-trigger-with-datapixx/5020 "2023-06-22T13:33:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valia](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Valia](https://psychtoolbox.discourse.group/u/Valia)\
**Post date:** [June 22, 2023, 1:33pm UTC](https://psychtoolbox.discourse.group/t/reading-mri-trigger-with-datapixx/5020/1 "2023-06-22T13:33:20Z")

</div>

Hi all!  
I am new to PsychToolbox (I migrated from Cogent). Could someone please tell me how to wait for the MRI trigger to synchronise visual presentation using DataPixx and ResponsePixx in Matlab?

Whether here or by email [v.rodriguez@aston.ac.cuk] I will be very grateful.

Warm regards, Valia

---

<div class="post-metadata">

**Author:** ![dmichaud](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@dmichaud](https://psychtoolbox.discourse.group/u/dmichaud)\
**Post date:** [June 22, 2023, 6:28pm UTC](https://psychtoolbox.discourse.group/t/reading-mri-trigger-with-datapixx/5020/2 "2023-06-22T18:28:41Z")

</div>

Hello Valia,

VPixx has a couple of VOCAL (VPixx Online Classroom and Library) guides to get you started on using TTL triggers in your code.

You can take a look at [https://vpixx.com/vocal/rt\_responsepixx/](https://vpixx.com/vocal/rt_responsepixx/) and [https://vpixx.com/vocal/introduction-to-registers-and-schedules/](https://vpixx.com/vocal/introduction-to-registers-and-schedules/)

Both of these guides will describe how to use digital inputs and how to read their values and monitor them.

Feel free to email us directly too!

Danny M  
VPixx Technologies

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [June 23, 2023, 2:35am UTC](https://psychtoolbox.discourse.group/t/reading-mri-trigger-with-datapixx/5020/3 "2023-06-23T02:35:36Z")

</div>

This also depends on what type of trigger the MRI is sending out. Several scanners I’ve worked with use a keyboard signal and so you need to use e.g. `KbCheck` in a loop to wait for the character before starting:

```matlab
PsychDefaultSetup(2);
KbCheck(-1); %make sure KbCheck is loaded into memory
trigger = KbName('s'); %MRI sends the 's' key
while true
	WaitSecs(0.001); % wait 1ms between checks
	[pressed, ~, key] = KbCheck(-1);
	if pressed && key(trigger); break; end
end
% your draw code here...
```
