Sending triggers to BIOPAC via USB ttl Module (BlackBoxToolkit)

OS : Win 10 64bit
PsychoPy version : 3.2.4
**Standard Standalone?: YES
What are you trying to achieve?:

Send triggers from psychopy to the MP150 BIOPAC using the USB TTL Module from BlackBoxTooklit.

What did you try to make it work?:
I followed the instructions provided for using the USB TTL Module with psychopy, specifically, using a code component I use at beginning of the experiment section
import serial
ser = serial.Serial("COM5",115200, timeout=1)

and under the begin routine, to send a trigger to Hardware I use
ser.write('01')

And for End Routine I use
`ser.write(‘00’)

I double checked the the module is indeed working using their validation software as well.

What specifically went wrong when you tried that?:
I am getting an error suggesting that this is not being sent as a byte
Traceback (most recent call last): File "C:\Users\hc122\Desktop\InteroStudy2019\interostudynov26_iaps_lastrun.py", line 595, in <module> ser.write('01') File "C:\Program Files\PsychoPy3\lib\site-packages\serial\serialwin32.py", line 308, in write data = to_bytes(data) File "C:\Program Files\PsychoPy3\lib\site-packages\serial\serialutil.py", line 63, in to_bytes raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq)) TypeError: unicode strings are not supported, please encode to bytes: '01'

I am not quite sure if there was a change in the way psychopy uses these functionalities, as this is exactly what the manual says and I don’t see where this goes wrong.

I would be very grateful for any pointers!

Thank you
Helio

1 Like

Try ser.write(str.encode(‘01’))

1 Like

Hi, wanted to send triggers to biopac via psychopy as well and had the same error Message.
Your tip helped me a lot, I can see that the port is opening but I dont receive any triggers/markers on biopac. Can anyone help me with that? I would be grateful for any tips!

Hi @Jennyzl can you check if you are receiving the pulses on the serial port (the red light should blink when the pulse is being received).
If you are, then did you check in acqknowledge/BIOPAC end of things to make sure you have a channel to monitor the signal. You could start by opening all the lowe or upper eigh digital channels to check if they are being sent to any of the chanels there?

Perhaps if you add more info I can help.

Hello! Thank you for your quick reply!

So the thing is the port seems to work, at least the red light turns on. It is not blinking, it is on constanly, should it blink?
I am not sure what you mean by having a channel to monitor the signal (this is my first try with Biopac and EMG so I dont know a lot about it). I can open a Template and can set up the data Acquisition, there is a tab named channels (Analog, digital, calculation and the Chanels 1-4 etc.).
Or do you mean the Black box toolkit configuration Utility?

If you need any more Info, I would be glad to tell you :slight_smile: Ps. I will send some of my coding in here later maybe it will help

So this is my Experiment. I want to show a random set of Pictures which people should rate on two scales. At the same time EMG aktivity will be measured.
image

I tried to code the Experiment, that with every picture Psychopy should send a trigger to BIOPAC to
mark the spot where the first picture is seen by people.
Here is my Code:
image


image

But I think I found my mistake: I should put the " ser.write(‘00’)" in the tab End Routine right?
If so, do I have to change something in BIOPAC specifically, that it will receive the trigger?

Thank you in advance for your help!

Hi @Jennyzl,

a couple of things. Seems like you signal is being sent since the red light is on. Usually you want to send a short marker when the stim is sent and then deactivate it.

So, in the past what I have done is under Begin routine send for instance:
ser.write(hex(01).encode())
ser.flush()
ser.write("00".encode())
ser.flush()

So whenever the signal 01 is on the red light should be on and when the 00 is read the red light will be off.

Also, I have had problems with the default timeout that you have in the beginning of the experiment,
but this following worked
ser = serial.Serial("COM5", 115200, write_timeout=0)
ser.write("RR".encode())

The last line simply resets the serial port in case there is anything hangin around from previous sessions.

On the BIOPAC end of things, these triggers are being sent to the digital input channels (one of the 16 channels that can receive digital inputs). You have to configure them first, so I would just check some of the BIOPAC instructions on how to setup the digital channels. You can make them visible by going to the chanel visibility option in acqknowledge (which should be under the view tab I believe, I don’t have the program atm).

Hope this helps

2 Likes

Hi @Helio_Cuve,

thank you a lot for your help! the Code works for me! The red light is blinking as soon as a picture is shown.
I figured out that i dont have Biopac Acqknowledge but student lab. So I will find a way to connect them.
Again thanks a lot and for your time :slight_smile:

Hi @Jennyzl

Did you every figure out how to connect the digital channels in Biopac student lab? I can see that my triggers are sending properly to the TTL Module as the red light is coming on/off, but Biopac doesn’t seem to register any of the triggers being sent!

Hi @Helio_Cuve

There are a couple of problems with using character inputs while sendin port signals (e.g. not able to send markers that are 10 or larger). I suggest you use bits instead of characters while sending these signals, especially if you are going to use markers larger or equal to 10.

We’ve resolved this issue here. I hope this helps.