Synching Tobii pro Glasses 2 via 3.5 mm jack

Hi everyone,

I have in the lab a pair of Tobii pro Glasses 2 that I would like to use to record eye movements while displaying stimuli with Psychtoolbox. As far as I understand, there’s no support for this model to integrate them in Matlab/Psychtoolbox, so I’m trying to understand which possibilities I have.

I do not need to do anything fancy, just present images with Psychtoolbox and have a way to synch them with the gaze acquisition of the Tobii.

I read on the manual that the Tobii Pro Glasses 2 have a synch port via 3.5 mm jack (TTL signal) - tip for receiving a sync signal, middle ring for transmitting the sync signal, the sleeve is ground.

They describe the Sync-in as:

“Sync-in is trigged by the recording unit using a standard TTL 3.3 V signal, described as a high signal (1 (one)), or a low signal (0 (zero)).”

The question is if I can generate this TTL pulse in Psychtoolbox, I guess using an adapter from a USB port (the PC with Matlab/Psychtoolbox does not have a parallel port) to a 3.5mm jack, and which type of lag I might expect relative to the flip.

Does anyone have experience with this type of setup and synching?

Help it’s appreciated!

Ciao,

Antimo

HI Antimo,

A computer parallel port operates at 5V, perhaps you can hook that up quite directly (I don’t know electronics, i don’t know if the G2 will survive 5V, or if you can easily step it down). Then if you google parallel port psychtoolbox there are various options for driving that.

Let me also point you too my software https://github.com/dcnieho/glassesViewer, which can visualize these signals for you, and which comes with example data containing a sync in signal.

Cheers,
Dee

Hi Dee,

thanks for the suggestion! I don’t have a parallel port on my PC unfortunately, so I need to go through USB, I should have mentioned that. Is this possible? I think there are some adapter to do it but I’m not an expert on this regard.

I’m looking at your software and it seems really interesting and useful for analysis! Thanks for pointing this out.

Ciao,

Antimo

Hi Antimo,

we use this cable (from Amazon Germany but should be available in most electronics online shops worldwide) for our first generation Tobii Glasses (not sure whether trigger port has changed and it still works with Glasses 2/3). Important is to use 3.3 V version as already mentioned by Dee.

You can send 1 bit triggers using Psychtoolbox’s IOPort function.

I have some code remote controlling the Glasses (1) via network/REST API from Psychtoolbox. We send 1 bit triggers via serial port together with a network event via REST API including the description. Dee’s toolbox can import both trigger types. In case of strong interest I could clean up the code a bit and put it on Github when I find some time.

Best,
Andreas

Hi Andreas,

this really seems what I need! It would be great if you have some example code I can try out.

One thing I don’t fully understand is the network/REST API that you mention in your reply. Where do you send the network signal? I think that I’m missing one piece of the setup at the moment. Could you please help me to understand?

So far, I have one PC with Matlab/Psychtoolbox to display the images and one computer controlloing the glasses to which send the trigger with the TTL. What else do I need?

Thanks a lot, this is incredible helpful.

Antimo

Hi Antimo,

first, sorry I misremembered, we also do have Glasses 2, thus the cable should indeed work (reason for my confusion was that only some weeks after we ordered our Glasses 2 the next generation was already announced and I was angry that Tobii didn’t indicate before ordering that a new version was to be expected very soon; now I only remember that we have the “old” version and constantly mix up the numbers). Note that I didn’t touch the system for some month, I hope my other memories are more accurate.

So far, I have one PC with Matlab/Psychtoolbox to display the images and one computer controlling the glasses to which send the trigger with the TTL. What else do I need?

The suggested USB-cable directly connects the PTB PC USB port to the Glasses Recording unit 3.5 mm jack. There is no other computer or any network involved. Trigger is only one bit but timing (latency and jitter) is expected to be very good (in low millisecond range).

You have to open the serial port, typically I keep it open during the whole block/experiment, port address depends on OS (this is Ubuntu Linux with a single USB-serial port):

Cfg.porthandle = IOPort( 'OpenSerialPort', '/dev/ttyUSB0', 'FlowControl=None,BaudRate=300' );

BaudRate defines TTL pulse width. Could possibly be optimized but worked well for us. You can then send a TTL pulse:

[ nwritten, when, errmsg ] = IOPort('Write', Cfg.porthandle, uint8( 255 ) );

and close the port at the end of the block/experiment:

IOPort( 'CloseAll' );

One thing I don’t fully understand is the network/REST API that you mention in your reply. Where do you send the network signal? I think that I’m missing one piece of the setup at the moment. Could you please help me to understand?

The Recording unit also provides an ethernet port and a WiFi access point to remote control the Recording unit. The ethernet port allows lower latencies but is IPv6 only (IIRC; making some trouble with our PTB PC). We connect from PTB via WiFi (IPv4) and curl to the Recording unit (REST API). You can then start, pause, and stop recordings from PTB, calibrate, get tracker status, set project/participant information and send event information. This event messages contain an „external" timestamp (here, PTB GetSecs time typically relative to block start; “external” from eye-tracker perspective) and a char string describing the event (here, an integer number converted to char to keep them identical with the EEG triggers). As they go over the WiFi network they typically introduce latencies and jitter in the range of at least tens of milliseconds, thus, unsuitable for precise timing. (Side aspect: I found the MATLAB curl/json/REST implementation really sluggish. We therefore instead use curl via system commands.)

Both event types, TTL and API events are stored in the raw data (including eye-tracker timestamps) and imported by Dee’s GlassesViewer. If you send both types for each event, you can offline match TTL and API events and get the timing from the TTL and the event information from the matched API triggers.

The tablet typically used with the Glasses actually also connects to this REST API to control recording etc. and to the livestream API for the camera signals.

Does this make the general architecture somewhat more clear? Dee, please correct if I misremember any details! The API documentation can be downloaded from Tobii.

Best,
Andreas

Hi again,

this is very clear and as I said before incredibly valuable! Thank you so much for taking the time to answer.

I think I understand the trigger part via mini jack and I should be able to implement it (any possible side effects on the glasses if the trigger has wrong parameters?).

About the REST API I think now I’m understanding the logic, but I need to study a bit how it works because I never tried this approach. From Matlab side where do I find the commands to communicate with the glasses through the network?

Thanks again!

Antimo

Andreas, thanks for sharing all that! It seems to make sense. And its a good way to deal with the trigger being only 1 bit, sending the API events as well allows you to attach extra information. The triggers have good timing accuracy and the API event not, but together they cover the whole need. Nice!

I would not expect that you can break the glasses sync port except for voltages higher than 3.3V but that could also be due to a lack of imagination.

Ok, I tried to collect the relevant code parts and put them into a GitHub repository:

Core is the tobiiGlassesAPI.m function implementing the different REST API calls. tobiiGlassesAPI() expects and returns a structure (“Tobii” in the demo code) collecting all configuration parameters, the different project, participant, recording, status IDs and messages. Besides the Tobii structure tobiiGlassesAPI expects the call name and its required parameters as inputs.

There is no proper documentation yet (contributions welcome!). A demo experiment is provided showing how to put together and use the relevant parts. Unfortunately, I do not have access to the device within at least the next two weeks, so the code is actually untested. I have compiled the code from the relevant parts of a working experiment but I might have missed some details. Thorough testing and feedback is required to make this useable for the more general public.

  • curl must be installed and the executable must be in path (MATLAB webread/webwrite is too sluggish for the purpose).
  • Adapt hardcoded projID in demo_exp.m to a project existing on your SD card (hardcoded as it typically does not change during an experiment).
  • Adapt serial port address in demo_block.m. Change Cfg.initioport to 0 in demo_exp.m in case no USB-serial port adapter is connected (API events only; not recommended if precise timing is required; combining TTL trigger timing and API event information is recommended).
  • Adapt recording unit IP address in tobiiGlassesAPI.m (or better Tobii.URL parameter in the Tobii structure) in case of non-default IP address.
  • Call the demo_exp with an integer participant number.

Please test and give feedback whether everything works as expected.

On the long run I’m afraid I will not have resources to maintain this as a separate toolbox. Dee, Mario, any ideas where this could possibly fit?

Best,
Andreas

Hi Andreas,

this is clearly an amazing contribution! Thank you for taking the time to put this together. I’m going to setup my PC following these instructions and test the Glasses with your code. I’ll provide with my feedback as soon as I have some results.

I think I have one last question though, since the API documentation seems impossible to find on the Tobii website… For this approach to work, do I need to install some SDK (or something else) on the PC where I run PTB ? Or all I need is the glasses, Matlab/PTB, and your code? Sorry if this is a dumb question!

Thanks a lot.

Ciao,

Antimo

I didn’t find it either when I searched for a more recent version yesterday. I can send you a copy of my archived, two year old version by personal mail in case you want to work through.

The SDK is not required.

You need to have curl installed. The PC has to be connected to the recording unit WiFi access point (or ethernet cable and IPv6 including Bonjour/avahi working). Also works on Octave. No other dependencies I’m aware of.

Best,
Andreas

Great, I think there’s all the info to try it out now. Unfortunately the PC I’m using does not have Ubuntu installed yet, so I will try first with Windows 10, hopefully it won’t complain too much.

If you could send me the API documentation it would help I think.

Thanks again, incredible helpful.

Antimo

Antimo, Andreas,

Really nice to see this. I am not sure where the code would fit best, it may well be fine as it is now, especially if you Antimo could test the demo, fix it up where needed to get it running, and contribute that back. Then others can find this code and build on it.

What you are doing here is basically talking to some web api running on the eye tracker, so doing this from windows should be fine. Try first without the sync cable (I guess it takes some time to order) and you should get the lions share working already (you can get curl for windows). Assuming the cable also works on windows, you should be fine. What time timing of ioport over this cable on windows is like i don’t know, but not unlikely decent enough. I also have a copy of the SDK documentation, and i think it is similarly old. It is called Developers Guide - Tobii Pro Glasses 2 API 1.23.0.pdf

I think there is also some python project for controlling glasses 2 from a computer. Together with the API doc, you may learn more about how to control the glasses from there i guess. Ah found it: https://github.com/ddetommaso/TobiiGlassesPyController

Cheers,
Dee