# Usb2ttl8 triggers with IOPort

**URL:** <https://psychtoolbox.discourse.group/t/usb2ttl8-triggers-with-ioport/5136>\
**Category:** Hardware\
**Tags:** io\
**Created:** [October 19, 2023, 10:29pm UTC](https://psychtoolbox.discourse.group/t/usb2ttl8-triggers-with-ioport/5136 "2023-10-19T22:29:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gopie](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gopie](https://psychtoolbox.discourse.group/u/gopie)\
**Post date:** [October 19, 2023, 10:29pm UTC](https://psychtoolbox.discourse.group/t/usb2ttl8-triggers-with-ioport/5136/1 "2023-10-19T22:29:16Z")

</div>

Hi All,

Im using a USB2TTL8 device ([LabHackers Research Equipment : USB2TTL8 Adapter](http://labhackers.com/usb2ttl8.html)) to send TTL triggers to our EEG amp. This works fine when using matlabs _serial_ and _serialport_ functions, but _IOPort_ wont generate a trigger. Calling ‘OpenSerialPort’ is successful, but the call to ‘Write’ doesn’t produce a trigger. This is using Matlab 2021b on a windows 10. An example of the PTB code I’ve used is below. For context, the text string sent to the ttl device has format of ‘WRITE value [duration] [next\_value]\n’

Any help would be greatly appreciated.

Cheers

```auto
params = 'BaudRate=128000 DTR=1 Terminator=10'

[com err] = IOPort('OpenSerialPort', 'COM5', params)

IOPort('Write', com, 'WRITE 10 200 0\n')  

IOPort('Close', com)

```

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [October 20, 2023, 2:05am UTC](https://psychtoolbox.discourse.group/t/usb2ttl8-triggers-with-ioport/5136/2 "2023-10-20T02:05:58Z")

</div>

Probably, because `\n` only has meaning in a sprintf or fprintf statement etc.,  
whereas here \n would just mean the character \ followed by the letter n. Try

```auto
IOPort('Write', com, ['WRITE 10 200 0' char(10)])

```

To encode the \n newline explicitly as ASCII code 10.

-mario

---

<div class="post-metadata">

**Author:** ![gopie](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gopie](https://psychtoolbox.discourse.group/u/gopie)\
**Post date:** [October 20, 2023, 2:35am UTC](https://psychtoolbox.discourse.group/t/usb2ttl8-triggers-with-ioport/5136/3 "2023-10-20T02:35:49Z")

</div>

That did the trick, thanks Mario!

cheers,

George
