# First time using eyelink and psycho toolbox

**URL:** <https://psychtoolbox.discourse.group/t/first-time-using-eyelink-and-psycho-toolbox/5743>\
**Category:** Programming Help\
**Created:** [July 31, 2025, 5:53pm UTC](https://psychtoolbox.discourse.group/t/first-time-using-eyelink-and-psycho-toolbox/5743 "2025-07-31T17:53:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scientist](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@scientist](https://psychtoolbox.discourse.group/u/scientist)\
**Post date:** [July 31, 2025, 5:53pm UTC](https://psychtoolbox.discourse.group/t/first-time-using-eyelink-and-psycho-toolbox/5743/1 "2025-07-31T17:53:01Z")

</div>

Hi,

A newbie to eyelink here.

I’m trying to do pupillometry simultaneously with a resting-state scan. I’m attaching my Matlab script that I’m trying to use to start eyelink to record below. But it’s unclear to me what happens after I do calibration and accept fixation on the host PC. After I’ve accepted fixations, do I press any buttons on the host PC before running by Matlab script? Do I have to press the “output record” button before running the script? Would appreciate any advice. Also, would appreciate any feedback on the script!

function edfFile = eyetracker(use\_eye\_tracker)

% EYETRACKER Initialize Eyelink and wait for fMRI TR trigger before recording

% edfFile = eyetracker(true) initializes and returns EDF file name

% edfFile = eyetracker(false) does nothing and returns empty string

if use\_eye\_tracker

% Generate a unique EDF filename using date/time

```
c = datetime("now");

yearChar = char(65 + year(c) - 2014);

monthChar = num2str(dec2hex(month(c)));

dayChar = sprintf('%02d', day(c));

hourChar = char(65 - 1 + hour(c));

minuteChar = sprintf('%02d', minute(c));

secondChar = char(65 + floor(second(c) / 3));

edfFile = \[yearChar monthChar dayChar hourChar minuteChar secondChar\];

edfFile = upper(edfFile);

edfFile = edfFile(1:min(end,8));

fprintf('EDF File name: %s\\n', edfFile);

```

% Initialize Eyelink connection

if ~EyelinkInit(0, 1)

```
    fprintf('Eyelink initialization failed.\\n');

    edfFile = '';

```

return;

end

% Open EDF file on host

```
Eyelink('OpenFile', edfFile);

```

% Configure data collection

```
Eyelink('Command', 'file_sample_data = LEFT,RIGHT,GAZE,AREA');

Eyelink('Command', 'link_sample_data = LEFT,RIGHT,GAZE,AREA');

Eyelink('Command', 'pupil_size_diameter = YES');

Eyelink('Command', 'heuristic_filter = 1 2');

Eyelink('Command', 'button_function 5 "accept_target_fixation"');

Eyelink('Message', 'DISPLAY_COORDS 0 0 1024 768');

```

% === Wait for first TR triggerEyelink

% ===

```
KbName('UnifyKeyNames');

triggerKey = KbName('5%'); % Adjust if different scanner key (prisma B is "5")

fprintf('Waiting for fMRI trigger key (%s)...\\n', KbName(triggerKey));

```

while true

```
    \[keyIsDown, \~, keyCode\] = KbCheck;

```

if keyIsDown && keyCode(triggerKey)

```
        fprintf('Trigger received. Starting Eyelink recording.\\n');

```

break;

end

end

% Start Eyelink recording after trigger

```
Eyelink('StartRecording');

WaitSecs(1);

Eyelink('Message', 'SYNCTIME');

```

else

```
edfFile = '';

```

end

end

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [July 31, 2025, 7:39pm UTC](https://psychtoolbox.discourse.group/t/first-time-using-eyelink-and-psycho-toolbox/5743/2 "2025-07-31T19:39:11Z")

</div>

Have a look at the eyelink demos, such as EyelinkBubbleDemo. You’ll see the lines  
el=EyelinkInitDefaults(w);  
and  
EyelinkDoTrackerSetup(el);

That’ll handle calibration and hand off back to your script once done. You need to press output/record

---

<div class="post-metadata">

**Author:** ![scientist](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@scientist](https://psychtoolbox.discourse.group/u/scientist)\
**Post date:** [July 31, 2025, 10:07pm UTC](https://psychtoolbox.discourse.group/t/first-time-using-eyelink-and-psycho-toolbox/5743/3 "2025-07-31T22:07:28Z")

</div>

Hi! Thank you for the advice. I’ll definitely look at those…

Do you think my script will work in its current form, assuming calibration and all the connections are done right and the Triggerbox passes along the key?

Thanks again
