When needed

These features are available from version 3.6.5

When you need to connect your PsyToolkit experiment to a system for measuring physiological measures, such as an EEG, fMRI, or Biopac system.

In this case, you want that PsyToolkit sends a digital trigger signal when something specific happens in the PsyToolkit experiment.

This is possible, but only Google Chrome (and derivatives such as the open source Chromium browsers and others based on it, like Edge and Brave) supports it and on that system it needs to be enabled it.

What is needed

For this, you need a simple USB to Serial cable. These are known under different names but mean the same. Here are example names you find them on Amazon. They are inexpensive.

  • FTDI USB RS232

  • USB to serial TTL

  • FT232

I recommend one where you have USB (A or C connection on to connect to your PsyToolkit PC and loose cables on the other side). On Amazon, type in the search box "usb to TTL serial cable".

Below is a copy of the one we tested at PsyToolkit as well as some "male-to-male" jumper cables you can use to connect the "female" out cables to another device.

serialcable

Set Browser permissions

Permission 1: The browser

Browsers can work with serial cables but at least on Chrome, you need to allow this via the settings as follows:

Chrome/Chromium

In the address line of your browser copy:

chrome://flags/#enable-experimental-web-platform-features

And then select "enabled"

Windows browser (Microsoft Edge)

In the address line of your Brave browser copy:

edge://flags/

And find Experimental Web Platform features and enable that

Brave

In the address line of your Brave browser copy:

brave://flags/

And find Experimental Web Platform features and enable that

Check Dialout permissions

If you connected the USB TTL cable to your PC or laptop, you need to make sure you can access it as a user.

On Microsoft Windows

No special permissions are needed unless the port is:

  • Already in use by another program

  • Blocked by antivirus or university policies (in that case check with your technical team)

On MacOS

No special permissions are needed

On Linux

At least on Fedora Linux systems, you need to make sure to add yourself to the "dialout" group (at least on Fedora Linux). You only need to do this once, but you might need to relogin to have this working.

sudo usermod -aG dialout yourusername

Test this as follows (we assume the cable is /dev/ttyUSB0

echo "test" > /dev/ttyUSB0

If you don’t get an error message, the persmissions are set correctly.

Set up cables

You need two of the thin output cables:

  1. GND (Ground), this is likely a black cable

  2. RTS, this will be the trigger pulse signal

There are more cables, but you do not need those.

If you connect to the 25 BioPac (BioPacs DB25) ribbon cable, you need to make sure to connect your serial GND line to biopac line 25 (which is ground). And your serial RTS to pin 10 or 12.

If you are concerned about voltage matching, you can put a resistor in the RTS line. It is easy and you do not need to solder for this, just use the jumper cables and a breadboard. On the image below you see an example of how it is done.

serial diagram

Permissions

If you want the browser to connect with this cable and send information, you need to allow some browser permissions to be set. The PsyToolkit experiment/website should automatically ask for this (so don’t be surprised).

Coding

In your PsyToolkit code, you can simply use the instruction serial out. This will send a 10 ms trigger to the output device.

  • serial out

Note that when you call serial out, the code goes forward directly. If you want to wait for a while (e.g., when sending multiple consequtive signal triggers), you can add delay 20 ms as is done in the example below.

Example code

In the following

task testBioPac
  keys space
  serial out (1)
  show text "Hello"
  readkey 1 2000
  serial out
  delay 1000
  for $i in 1 to 3
    serial out   (2)
    delay 20
  for-end
  save RT TIME (3)

block
  message instructions
  serial out (4)
  delay 20
  serial out
  delay 20
  serial out
  delay 20
  serial out
  delay 20
  serial out
  delay 20
  task testBioPac 10
1 This instruction sends a 10 ms trigger
2 At the end of the trial, we send 3x a trigger separated by 20 ms intervals, just to later easily find trials in BioPac/EEG
3 At end of trial, we save important data. Saving the exact time of day (HH:MM:SS) can help to match with BioPac/EEG files
4 In block, we can also send out a number serial triggers, for example 4x trigger can indicate start of block. Separating them by 20 ms intervals is important, otherwise you just have one long trigger.