Skip to main content
Skip table of contents

Collect data from the TRACKPixx3

This demo presents a simple fullscreen window with a red square, and collects eye tracking data until the participant executes a keypress. Data is saved to .csv in the working folder

This demo assumes you have already calibrated your TRACKPixx3. To do so, you can use our automated calibration in PyPixx (PyPixx > Demo > TRACKPixx3) or see A comprehensive TRACKPixx3 calibration and A simple TRACKPixx3 calibration.

If the eye tracker is uncalibrated, the following script will return null data.

PY
#Beginning of experiment - initialize
from psychopy import visual, event
from pypixxlib import _libdpx as dp
import pandas as pd

#Connect to eye tracker and turn on lamp
dp.DPxOpen()
dp.DPxSetTPxAwake()

#At the beginning of a trial/block/experiment – start recording
myDict = dp.TPxSetupSchedule()
dp.TPxStartSchedule()
dp.DPxUpdateRegCache()

# Create a window
win = visual.Window(fullscr=True, color='black', units='pix')

# Create a stimulus (e.g., a red square)
stimulus = visual.Rect(win, width=100, height=100, fillColor='red', pos=(0, 0))
stimulus.draw()
win.flip()

# Wait for a key press & then close the window
event.waitKeys()
win.close() 

#At the end of the trial/block/experiment – stop recording
dp.TPxStopSchedule()
dp.DPxUpdateRegCache()
dp.TPxGetStatus(myDict)
data = dp.TPxReadData(myDict, myDict['newBufferFrames'])

#Save some data
column_headers = ['TimeTag','LeftEyeX','LeftEyeY','LeftPupilDiameter','RightEyeX','RightEyeY',
                  'RightPupilDiameter','DigitalIn','LeftBlink', 'RightBlink', 'DigitalOut',
                  'LeftEyeFixationFlag','RightEyeFixationFlag','LeftEyeSaccadeFlag','RightEyeSaccadeFlag',
                  'MessageCode','LeftEyeRawX','LeftEyeRawY','RightEyeRawX','RightEyeRawY']

# Create a DataFrame using pandas
data_frame = pd.DataFrame(data, columns=column_headers)

# Save the DataFrame to a CSV file
csv_filename = 'output_data.csv'
data_frame.to_csv(csv_filename, index=False)

#End of experiment – shut down
dp.DPxSetTPxSleep()
dp.DPxUpdateRegCache()
dp.DPxClose()
 
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.