# Sending trigger via parallel port

**URL:** <https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595>\
**Category:** Programming Help\
**Tags:** linux\
**Created:** [September 13, 2022, 8:20am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595 "2022-09-13T08:20:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaprak](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/yaprak/32/385_2.png) [@Yaprak](https://psychtoolbox.discourse.group/u/Yaprak)\
**Post date:** [September 13, 2022, 8:20am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/1 "2022-09-13T08:20:07Z")

</div>

We try to send triggers via the parallel port for our EEG setup. However, we have approximately ten years old Brain Products hardware, and we were unable to use the older functions for parallel ports when we used the newest version of Psychtoolbox and MatLab 2022a.

Then we downgrade Matlab from 2022a to 2014a, and Psychtoolbox from 3.0.17 to 3.0.12. We currently have the following setup: BrainAmp Amplifier (Brain Products), Linux Ubuntu 22.04 “Jammy Jellyfish”, Psychtoolbox 3.0.12, and MatLab 2014a. However, although the trigger command works with the older versions of PTB and Matlab, the code we wrote on newer PTB did not work anymore.

Is there any alternative approach to sending triggers instead of using a Parallel port?  
Do you suggest using older software?

---

<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:** [September 13, 2022, 9:29am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/2 "2022-09-13T09:29:19Z")

</div>

I’ve never used the parallel port, so don’t know what current code may control it on Linux. There are **many** ways to send a trigger. But for many users USB I/O devices work well. In MATLAB there are several ways to control a serial device, including PTB’s IOPort, and comparing performance I found that IOPort is clearly the fastest (~60µs TTL switch time using an Arduino):

> [@Serial port interface code -- a performance comparison](https://psychtoolbox.discourse.group/t/serial-port-interface-code-a-performance-comparison/3781):
>
> MATLAB has a fairly new (R2019B+) serial port interface, [Serialport](https://www.mathworks.com/help/matlab/serial-port-devices.html). Some of my arduino control code had previously used the [serial](https://www.mathworks.com/help/matlab/ref/serial.html) command that MATLAB has now deprecated. So I was curious to compare the old and new interfaces. In addition I also compared IOPort, the PTB serial controller. For the test I basically toggled the state of a digital pin on a [Seeduino Xiao](https://wiki.seeedstudio.com/Seeeduino-XIAO/) as fast as possible. I used the legacy MATLAB [arduino interface sketch](https://github.com/iandol/opticka/blob/master/communication/arduino/adio/adio.ino), which receives and sends the data via USB serial commands…

What are the parameters of the trigger you need to send? Some hardware require strobed words with a trigger bit, others simple TTLs etc…

There is some more info here:

> **[FAQ: TTL Triggers via USB](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ:-TTL-Triggers-via-USB)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

And some specific details for the LabJack:

> **[LabJack](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/LabJack)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

And Arduinos:

> **[Arduino](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/Arduino)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

@xiangrui from this forum made a response button + I/O box with very robust PTB support and high reliability that you can look at here, this would also allow you to compare timings to a photodiode etc:

[https://lobes.osu.edu/rt-box.php](https://lobes.osu.edu/rt-box.php)

---

<div class="post-metadata">

**Author:** ![widmann](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@widmann](https://psychtoolbox.discourse.group/u/widmann)\
**Post date:** [September 14, 2022, 11:24am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/3 "2022-09-14T11:24:16Z")

</div>

> we were unable to use the older functions for parallel ports when we used the newest version of Psychtoolbox and MatLab 2022a

Which "older functions“ you refer to? Could you please specify „unable“? Any error message?

Method 1 here

> **[FAQ](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ#ttl-triggers)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

is still maintained and confirmed to work with recent versions of Psychtoolbox on Ubuntu with Octave. Possibly not recently tested on MATLAB though.

Best,  
Andreas

---

<div class="post-metadata">

**Author:** ![xiangrui](https://avatars.discourse-cdn.com/v4/letter/x/ec9cab/32.png) [@xiangrui](https://psychtoolbox.discourse.group/u/xiangrui)\
**Post date:** [September 15, 2022, 2:33pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/4 "2022-09-15T14:33:44Z")

</div>

Thanks for mentioning the [RTBox](https://github.com/xiangruili/RTBox).  
I would like to add that we recently made the setup between the stimulus computer and Brain Product system (likely the latest version) for simultaneous EEG/fMRI with RTBox. They provided a multi-function but bulky trigger interface for this purpose, but we chose to replace it with RTBox. The only extra hardware is a cable to connect the corresponding pins between RTBox and BrainAmp USB2 Adapter (BUA).  
Don’t hesitate to reach me if you are interested in our solution.

---

<div class="post-metadata">

**Author:** ![Yaprak](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/yaprak/32/385_2.png) [@Yaprak](https://psychtoolbox.discourse.group/u/Yaprak)\
**Post date:** [September 21, 2022, 7:57am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/5 "2022-09-21T07:57:42Z")

</div>

One of the functions that we were not able to use with new versions of MatLab was ‘digitalio’. Following code uses this:

> **[PARALLEL PORT 'LPT'](https://au.mathworks.com/matlabcentral/fileexchange/12676-parallel-port-lpt)**
>
> Shipment and reception of data through parallel port.

---

<div class="post-metadata">

**Author:** ![Yaprak](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/yaprak/32/385_2.png) [@Yaprak](https://psychtoolbox.discourse.group/u/Yaprak)\
**Post date:** [September 21, 2022, 8:32am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/6 "2022-09-21T08:32:35Z")

</div>

we tried to use ‘IOPort’ for the parallel port (at the address ‘c000’ or 49152) with the intention of sending an 8-bit trigger (we set the 8-bit trigger for 0.004 seconds and then reset the pins to 0, I guess it is a simple TTL?), but we could not figure out how to use this function in this context.

---

<div class="post-metadata">

**Author:** ![widmann](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@widmann](https://psychtoolbox.discourse.group/u/widmann)\
**Post date:** [September 21, 2022, 10:18am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/7 "2022-09-21T10:18:34Z")

</div>

> we tried to use ‘IOPort’ for the parallel port (at the address ‘c000’ or 49152) with the intention of sending an 8-bit trigger (we set the 8-bit trigger for 0.004 seconds and then reset the pins to 0, I guess it is a simple TTL?), but we could not figure out how to use this function in this context.

IOPort currently only supports serial ports.

> One of the functions that we were not able to use with new versions of MatLab was ‘digitalio’. Following code uses this:

This is from 2008. If I remember correctly digitalio function never was supported in 64 bit MATLAB and discontinued around 2014 and was unsuitable (slow/inaccurate) for EEG triggering. Not sure whether it ever worked on Linux.

Have you tried method 1 from FAQ as already suggested?

> **[FAQ](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ#ttl-triggers)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

Best,  
Andreas

---

<div class="post-metadata">

**Author:** ![widmann](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@widmann](https://psychtoolbox.discourse.group/u/widmann)\
**Post date:** [September 22, 2022, 3:24pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/8 "2022-09-22T15:24:58Z")

</div>

> Possibly not recently tested on MATLAB though.

Just checked, method 1 still works for sending TTL triggers from parallel port to EEG on both most recent available MATLAB R2022a and Octave 6.4.0 on Ubuntu 22.04.

> **[FAQ](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ#ttl-triggers)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

Best,  
Andreas

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://psychtoolbox.discourse.group/u/Andreas)\
**Post date:** [September 27, 2022, 8:21am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/9 "2022-09-27T08:21:45Z")

</div>

Hi,  
lptwrite works great on Linux, IOport on Windows using parallel port (onboard or PCI card). Furthermore we have good experiences with USB-Devices (e.g. NI USB-6008/9, NeuroSpec MMBT Box [[MMBT-S Trigger Interface Box | NEUROSPEC AG Research Neurosciences](https://www.neurospec.com/Products/Details/1067/mmbt-s-trigger-interface-box)], IO-Warrior [[I/O Interface | IO-Warrior](https://www.codemercs.com/de/io), less expensive]).

The initial question was: are there alternative approaches to send triggers to the Brainproducts EEG System? Brainproducts offers the Remote Control Server (for free, [Download BrainVision Recorder | Brain Products GmbH](https://www.brainproducts.com/downloads/recorder/)) which allows you to drive the Recorder from Matlab on your stimulus computer via TCP/IP. Within the recording you may send annotations to the Recorder which are stored in the .mrk files with a time stamp. At a first glance this seems to be wonderful but testing the timings the annotations appear before a simultaneously sent digital IO trigger via parallel port. The reason behind this: the amplifier stores EEG data and digital signals in real time. The recorded collects buffered data every once in a while but annotations are stored immediately in the .mrk files. As a consequence digital signals appear in the .mrk files 20-30 ms later.  
So you have to stay on your digital markers - using parallel port, USB devices or whatever. We wrote a toolbox on using the Remote Control Server in Matlab and we will publish it soon.  
Cheers  
Andreas

---

<div class="post-metadata">

**Author:** ![Leila](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@Leila](https://psychtoolbox.discourse.group/u/Leila)\
**Post date:** [January 13, 2023, 4:09pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/10 "2023-01-13T16:09:41Z")

</div>

Hi,  
I need to send the TTL via parallel port.  
I have installed the newest version of Matlb and PTB3, under unix. Before I used this line under windows

```auto
config_io;
ioObj = io64;
status = io64(ioObj);
port1 = 888;
outp(port1,i)

```

In recent version of PTB3, there is no config\_io. What is the solution?  
I tried lptwrite also but it seems there is no more this function. Should I downgrade PTB3?

```auto
>> lptwrite
Unrecognized function or variable 'lptwrite'.

```

Best

---

<div class="post-metadata">

**Author:** ![widmann](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@widmann](https://psychtoolbox.discourse.group/u/widmann)\
**Post date:** [January 13, 2023, 4:43pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/11 "2023-01-13T16:43:27Z")

</div>

> I have installed the newest version of Matlb and PTB3, under unix.

What flavor of “unix”? Linux? Distribution?

Have you tested method 1 described in the FAQ as suggested previously in this thread?

> **[FAQ](https://github.com/Psychtoolbox-3/Psychtoolbox-3/wiki/FAQ#ttl-triggers)**
>
> Psychophysics Toolbox Version 3 (PTB-3) is a free set of Matlab and GNU Octave functions for vision and neuroscience research. - Psychtoolbox-3/Psychtoolbox-3

---

<div class="post-metadata">

**Author:** ![Leila](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@Leila](https://psychtoolbox.discourse.group/u/Leila)\
**Post date:** [January 16, 2023, 8:47am UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/12 "2023-01-16T08:47:52Z")

</div>

My linux version :

```auto

ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"

```

I downloaded ppdev-mex-master.zip and put in my Matlab path. But When I run in Matlab

```auto
>> ppdev_mex('Open', 1);
>> lptwrite(1, 255)
>> WaitSecs(1)

```

Nothing happend, in python I can send the TTL by port : `PORT1 = '/dev/parport1'`  
Best

---

<div class="post-metadata">

**Author:** ![widmann](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@widmann](https://psychtoolbox.discourse.group/u/widmann)\
**Post date:** [January 16, 2023, 12:10pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/13 "2023-01-16T12:10:16Z")

</div>

/dev/parport1 is port number 2 in ppdev\_mex.

Try:

```auto
ppdev_mex('Open', 2);
lptwrite(2, 255)
ppdev_mex('Close', 2);

```

The numbering has historical reasons. I kept it for backward compatibility when inheriting the code. Users coming from Windows typically try 1 (LPT1) first. Trying 0 would result in a “Port number out of range.” error message.

---

<div class="post-metadata">

**Author:** ![Long](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@Long](https://psychtoolbox.discourse.group/u/Long)\
**Post date:** [September 1, 2024, 1:31pm UTC](https://psychtoolbox.discourse.group/t/sending-trigger-via-parallel-port/4595/14 "2024-09-01T13:31:58Z")

</div>

Hi Leila,

Have you tried to change port number 1 to 2 as suggested by widmann? I wonder if it works fine. I am intent to use PTB under linux as well and send a trigger through a DSUB25 LPT port.  
Your answer would be very helpful to me.

Best
