psychopy.org | Reference | Downloads | Github

Sending triggers to brain vision trigger box

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 2021.1.1.4
Standard Standalone? (y/n) If not then what?:

Hi,

I am trying to send triggers to my EEG system. I am using the brain vision achiChamp amplifier and the goal is to send triggers whenever an auditory stimulus started playing. As I must use the serial port to send triggers to the trigger box I have used this code which I found here in Psychopy forum:

#Python Example
import serial
import time
import threading
Connected = True
PulseWidth = 0.01
def ReadThread(port):
while Connected:
if port.inWaiting() > 0:
print “0x%X”%ord(port.read(1))

Open the Windows device manager, search for the “TriggerBox VirtualSerial Port (COM6)”

in “Ports /COM & LPT)” and enter the COM port number in the constructor.

port = serial.Serial(“COM6”)

Start the read thread

thread = threading.Thread(target=ReadThread, args=(port,))
thread.start()

Set the port to an initial state

port.write([0x00])
time.sleep(PulseWidth)

Set Bit 0, Pin 2 of the Output(to Amp) connector

port.write([0x01])
time.sleep(PulseWidth)

Reset Bit 0, Pin 2 of the Output(to Amp) connector

port.write([0x00])
time.sleep(PulseWidth)

Reset the port to its default state

port.write([0xFF])
time.sleep(PulseWidth)

Terminate the read thread

Connected = False
thread.join(1.0)

Close the serial port

port.close()

However, when I use port.write() command nothing is sent to the EEG system. I tried to just set the port high and low by using port.setDTR(True) and it works. But by using this command, I am not able to send different triggers, and the only way to differentiate triggers for different stimuli is the time interval between setting high and low.
Now I am wondering why in my system the serial port.write() command is not working but port.setDTR() works. I should also mention that the computer which is used for sending triggers is connected through a USB port and a USB to serial converter to the trigger box. I am not sure if that is the problem.
I would be more than happy if anyone can help me.

Hi There,

Could you try encoding a string when you use the port.write() command - something like this?

Hope this helps,
Becca