# Sending multiple triggers in one routine using parallel port

**URL:** <https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696>\
**Category:** Coding\
**Created:** [February 16, 2024, 9:05pm UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696 "2024-02-16T21:05:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![the\_plague.doctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/the_plague.doctor/32/40933_2.png) [@the\_plague.doctor](https://discourse.psychopy.org/u/the_plague.doctor)\
**Post date:** [February 16, 2024, 9:05pm UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696/1 "2024-02-16T21:05:36Z")

</div>

Hello,

I am trying to send triggers to BrainVision through a parallel port. My experiment consists of many different images flashing briefly onscreen one after another. I am hoping to send triggers whenever a new image flashes on screen. It would be most convenient if I were able to send a different trigger for each different image category (faces, pareidolia, object). Below is the experiment in builder mode:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/b/fbfd05e8dc452376d35fb6d8bab366401ae17596.png)

I’m not sure if this is necessary to mention here, but I am using a condition file for the experiment. I am including a snippet below:

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/e/0e6b78c8af119594c6d5afb88994061558cdd85d.png)

I am also including my code below:

```auto
#Begin Experiment
from psychopy import parallel
p_port = parallel.ParallelPort(address=0x7F88)

```

```auto
#Begin Routine
pulse_sent = False  

p_port.setData(0) 
pulse_terminated = True

```

```auto
#Each Frame
if Images.status == STARTED:
    if Images == 'pareidolia' or Images == 'face' or Images == 'object': #write your condition here - I didn't include any code for the status of the p_port component, only the keyboard response
          p_port.setData(1) 
          logging.log(level=logging.EXP, msg = 1) #print this in the logfile, you check the psychopy logfile timing compared to your output from the EEG marker file
          pulse_start_time = t
          pulse_sent = True
          pulse_terminated = False

# terminate the trigger at least 0.0167 ms (1 frames) later:
if pulse_sent and not pulse_terminated:
    if t - pulse_start_time >= 0.0167:
        p_port.setData(0)
        pulse_terminated = True

```

The experiment runs perfectly, but there are no triggers being sent.

1. How do I fix the code so that triggers are sent?
2. Is it possible to send triggers through a parallel port using a conditions file? I’ve seen posts on using a serial port to do this, but not parallel ports.

Thank you!

```auto

```

---

<div class="post-metadata">

**Author:** ![the\_plague.doctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/the_plague.doctor/32/40933_2.png) [@the\_plague.doctor](https://discourse.psychopy.org/u/the_plague.doctor)\
**Post date:** [February 20, 2024, 11:43pm UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696/2 "2024-02-20T23:43:51Z")

</div>

Hello!

I am still struggling with this, so any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [February 21, 2024, 9:07pm UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696/3 "2024-02-21T21:07:11Z")

</div>

I can’t help except by posting what might be relevant threads.

> [@Parallel port code no longer working since update to Psychopy 2022.1.1](https://discourse.psychopy.org/t/parallel-port-code-no-longer-working-since-update-to-psychopy-2022-1-1/28571):
>
> Hello all, We recently updated the psychopy version in our EEG lab to version 2022.1.1 from a much older version (I’m not sure which but at least 3 years old). Everything mostly works fine but all of my code interacting with parallel ports no longer works. For example, if I use: parallel.setPortAddress(address = 0xCEF8) then try to use the parallel port I get the error message: ‘RuntimeError: Port address must be set using setPortAddres’. If I check the parallel port via print(parallel.PORT) th…

> [@Sending triggers via parallel port to eego software](https://discourse.psychopy.org/t/sending-triggers-via-parallel-port-to-eego-software/27171):
>
> OS (e.g. Win10): Win 7 PsychoPy version (e.g. 1.84.x): PsychoPy2 \*\*Standard Standalone? y \*\*What are you trying to achieve?: First of all, thanks in advance and apologies for bringing up a common issue again but I’ve been searching for answers all day and not been able to solve this issue. I’m trying to get PsychoPy to send triggers to the eego EEG software to see when certain images are displayed. I’ve followed threads such as this: [Cannot send a signal via ParallelPort using PsychoPy on…](https://discourse.psychopy.org/t/cannot-send-a-signal-via-parallelport-using-psychopy-on-windows7-64bit/969)

> [@Parallel module and class](https://discourse.psychopy.org/t/parallel-module-and-class/37640):
>
> Hello, I have written a script using Psychopy’s coder and now I need to send triggers through a parallel port to our data collection equipment. I found [this article](https://psychopy.org/hardware/parallelPortInstr.html#parallel) that explains how to use Psychopy’s Builder to communicate via a parallel port. I also found the documentation to the psychopy.parallel module described in [this article](https://psychopy.org/api/parallel.html#psychopy.parallel.ParallelPort). Unfortunately, the article does not provide access to the source code of the module and there is no documentation about the class methods and attributes besides th…

> [@Parallell Port component doesn't send triggers to EEG recording device](https://discourse.psychopy.org/t/parallell-port-component-doesnt-send-triggers-to-eeg-recording-device/37680):
>
> Hello everyone, I’m trying to send markers to an EEG recording device (I’m using BrainVision Recorder) with the help of the Parallel Port component of the builder. I tried to make sure that I follow the instructions for the component ([Communicating via a Parallel Port — PsychoPy v2023.2.3](https://www.psychopy.org/hardware/parallelPortInstr.html)). I’ve attached screenshots of my try of rebuilding the test experiment suggested in the Parallel Port component instructions and of the folder with my experiment file and the driver files needed in case I ma…

> [@Differentiating Parallel Port Signals for Each Video in a Loop](https://discourse.psychopy.org/t/differentiating-parallel-port-signals-for-each-video-in-a-loop/35462):
>
> Hello, I am currently working on an experiment where I have a routine with a loop that displays three different video clips. Each time the routine resumes, it cycles through these videos. Alongside this, I am using a parallel port that sends out a signal with the value “9”. However, for my data analysis, I need each video clip to be associated with a unique signal. (10, 11 …) I am having trouble figuring out how to modify the parallel port signal so that it sends a different value each time a…

---

<div class="post-metadata">

**Author:** ![the\_plague.doctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/the_plague.doctor/32/40933_2.png) [@the\_plague.doctor](https://discourse.psychopy.org/u/the_plague.doctor)\
**Post date:** [April 24, 2024, 10:52pm UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696/4 "2024-04-24T22:52:49Z")

</div>

After a long time of attempting to figure out this issue, I finally have resolved it, so I am posting it here for anyone who is having a similar problem! For reference, my stimuli consist of face, pareidolia, and object images. To align your triggers with your stimuli, I inserted the following code into the “Each Frame” code component.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/0/9047e266880f6de329f075d7799da106889fece8.png)

And that worked for me! Turns out I was severely overcomplicating things.

---

<div class="post-metadata">

**Author:** ![Vyoma](https://avatars.discourse-cdn.com/v4/letter/v/dbc845/32.png) [@Vyoma](https://discourse.psychopy.org/u/Vyoma)\
**Post date:** [January 8, 2025, 11:17am UTC](https://discourse.psychopy.org/t/sending-multiple-triggers-in-one-routine-using-parallel-port/38696/5 "2025-01-08T11:17:30Z")

</div>

Thank you for this. What changes have you made in the parameters of parallel port to accommodate this? Using this structure, i am not able to get triggers for all the stimuli!
