# Trail specific trigger

**URL:** <https://discourse.psychopy.org/t/trail-specific-trigger/4465>\
**Category:** Builder\
**Created:** [May 1, 2018, 10:54am UTC](https://discourse.psychopy.org/t/trail-specific-trigger/4465 "2018-05-01T10:54:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jluedtke](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jluedtke](https://discourse.psychopy.org/u/jluedtke)\
**Post date:** [May 1, 2018, 10:54am UTC](https://discourse.psychopy.org/t/trail-specific-trigger/4465/1 "2018-05-01T10:54:20Z")

</div>

Hi,

I try to implement a code sending a trigger at the end of each trial via a serial port  
(the experiment is build in Psychopy 1.83 , a stand allone version on a windows machine).  
Sending a hard coded trigger is no problem by using the following code:

serial\_port = serial.Serial(‘COM2’, baudrate=115200, bytesize=serial.EIGHTBITS)

serial\_port.write(‘a’) # Send the byte a as a character

serial\_port.close()

The code is implemented in a trial loop, it sends the trigger at the end of each trial, that works very well.  
But I want to send different trigger information depending on the specific condition of each trial. The trial loop is accosiated with an exel table called table1 including a variable trigger\_info. I’m wondering in which way I could refer to this variable so that the code above uses the information from this variable as trigger code. Using $trigger\_info does not work, it seems to be more complicated. Could anybody add an example for the correct reference? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [May 3, 2018, 6:52am UTC](https://discourse.psychopy.org/t/trail-specific-trigger/4465/2 "2018-05-03T06:52:12Z")

</div>

_ **Begin experiment tab:** _

```auto
serial_port = serial.Serial(‘COM2’, baudrate=115200, bytesize=serial.EIGHTBITS)

```

_ **End routine tab:** _

```auto
serial_port.write(trigger_info)

```

_ **End experiment tab:** _

```auto
serial_port.close()

```
