Can you help me with sending trigger signals to the EEG equipment? (All Code included)

I’m currently using the Psychopy python library on my local machine environment using Vs code.

The EEG device I am using is the DSI-24 from WearableSensing.

I am also using a WearableSensing wireless trigger hub and NeuroSpec’s MMBT-S trigger interface for connectivity.

I’m currently doing this on one computer. This computer does not have a parallel port, so I wired the wireless trigger hub and the MMBT-S trigger interface to the computer.

The DSI-24 device is wired to the computer.

I then connected the Wireless Trigger Hub and the DSI-24 wirelessly.

In Device Manager, the port number for the MMBT-S is COM3 and the DSI-24 is COM4.

In the following code, I want to send a trigger signal while the sentence ‘Speak’ is presented, or in the form of an event when the sentence is presented.

Here is my complete experimental code I’ve removed the part of the code for sending the trigger signal, as I don’t know anything about it and think it might be confusing.

from psychopy import visual, core, event
from psychopy.sound import Sound
import time
from psychopy import prefs

prefs.hardware['audioLib'] = ['ptb']

# window generation
win = visual.Window(size=(2400, 1200), fullscr=False, color="white", winType='pyglet', allowGUI=True)

# Create text stim
def create_text_stim(text, height, wrap_width=1.7):
    return visual.TextStim(win, text=text, color="black", height=height, wrapWidth=wrap_width)

# Create img stim
def create_image_stim(image_path):
    return visual.ImageStim(win, image=image_path)

# Create sound stim
def create_sound_stim(sound_path, sample_rate=44100):
    return Sound(sound_path, sampleRate=sample_rate)

# Countdown
def draw_countdown(current_time):
    count = visual.TextStim(win, text=str(current_time), color="black", height=0.2,
                           pos=(0.8, 0.8))  # right up
    count.draw()
        
# Speaker img and text
def show_speaker_with_text(text, duration):
    speaker = create_image_stim("exp_images/speaker3.png")
    text_stim = create_text_stim(text, height=0.18)
    speaker.pos = (0, -0.3)
    text_stim.pos = (0, 0.2)
    speaker.draw()
    text_stim.draw()
    win.flip()
    core.wait(duration)
    
# Text Stimulus Presentation Function (without countdown and speaker image, with voice)
def present_text_stimulus_no_countdown_with_sound(text, duration, height, sound_path):
    stimulus = create_text_stim(text, height, wrap_width=2.0)
    stimulus.draw()
    win.flip()
    sound = create_sound_stim(sound_path, sample_rate=44100)
    sound.play()
    core.wait(duration)

# Text stimulus presentation function (with countdown and speaker image, with voice)
def present_text_stimulus_with_countdown_with_sound(text, duration, height, speaker_duration=10, sound_path=None):
    stimulus = create_text_stim(text, height, wrap_width=2.0) # width
    if sound_path:
        sound = create_sound_stim(sound_path, sample_rate=44100)
        sound.play()
    
    # Main stimulus display time
    start_time = time.time()
    while time.time() - start_time < duration:
        stimulus.draw()
        win.flip()
    
    # Show stimulus with 3 second countdown
    for i in range(3, 0, -1):
        stimulus.draw()
        draw_countdown(i)
        win.flip()
        core.wait(1)
    
    show_speaker_with_text("Speak", speaker_duration)
    
# Text Stimulus Presentation Function (no countdown, no speaker image, no voice)
def present_text_stimulus_no_countdown(text, duration, height):
    stimulus = create_text_stim(text, height, wrap_width=1.7)
    stimulus.draw()
    win.flip()
    core.wait(duration)


# Image and text presentation function (text on top, with speech)
def present_image_and_text_above(image_path, text, duration, text_height, speaker_duration=10, sound_path=None):
    img = create_image_stim(image_path)
    txt = create_text_stim(text, text_height, wrap_width=1.8)
    img.pos = (0, -0.3)
    txt.pos = (0, 0.55) 
    
    if sound_path:
        sound = create_sound_stim(sound_path, sample_rate=44100)
        sound.play()
    
    # Main stim time
    start_time = time.time()
    while time.time() - start_time < duration:
        txt.draw()
        img.draw()
        win.flip()
    
    # Show stimulus with 3 second countdown
    for i in range(3, 0, -1):
        txt.draw()
        img.draw()
        draw_countdown(i)
        win.flip()
        core.wait(1)
    
    show_speaker_with_text("Speak", speaker_duration)

# Main Experiment
def run_experiment():
    # First part
    welcome_text = "Example 1"
    present_text_stimulus_no_countdown_with_sound(welcome_text, 13, height=0.09, sound_path="audio_44100/welcome.wav")
    

    # New
    instruction_text3 = "Example 2"
    present_text_stimulus_no_countdown_with_sound(instruction_text3, 12, height=0.09, sound_path="audio_44100/instruction3_2.wav")
    
    questions = [
        "Example3",
        "Example4",
        "Example5",
        "Example6",
        "Example7",
        "Example8"
    ]
    
    for i, question in enumerate(questions, 1):
        present_text_stimulus_with_countdown_with_sound(question, 5, height=0.17, sound_path=f"audio_44100/question_{i}.wav", speaker_duration=7)
    
    # Repeat number
    instruction_text4 = "Example9"
    present_text_stimulus_no_countdown_with_sound(instruction_text4, 9, height=0.1, sound_path="audio_44100/instruction4.wav") #
        
    num_sentence_1 = "Example10"
    present_text_stimulus_with_countdown_with_sound(num_sentence_1, 5, height=0.25, sound_path="audio_44100/num_sentence_1.wav", speaker_duration=7)
    
    num_sentence_2 = "Example11"
    present_text_stimulus_with_countdown_with_sound(num_sentence_2, 6, height=0.25, sound_path="audio_44100/num_sentence_2.wav", speaker_duration=8)
    
    # reverse text
    reverse_text = "Example12"

    present_text_stimulus_no_countdown_with_sound(reverse_text, 8, height=0.1, sound_path="audio_44100/reverse_text.wav")
    
    reverse_word_1 = "Example13"
    present_text_stimulus_with_countdown_with_sound(reverse_word_1, 5, height=0.25, sound_path="audio_44100/reverse_word_90.wav", speaker_duration=8)
    
    # 
    instruction_text6 = "Example14"
    present_image_and_text_above("exp_images/cat_dog_2.png", instruction_text6, 8, text_height=0.1, sound_path="audio_44100/instruction6.wav", speaker_duration=14)
    
    present_image_and_text_above("exp_images/berry_grape.png", instruction_text6, 8, text_height=0.1, sound_path="audio_44100/instruction6.wav", speaker_duration=14)
    
    # 
    figure_sequential_instruction = "Example15"

    present_image_and_text_above("exp_images/sequential.png", figure_sequential_instruction, 22, text_height=0.09, sound_path="audio_44100/sequential.wav", speaker_duration=10)

    # 
    rotation_instruction = "Example16"

    present_image_and_text_above("exp_images/rotation_1.png", rotation_instruction, 17, text_height=0.09, sound_path="audio_44100/rotation.wav", speaker_duration=10)

    # 
    image_instruction = "Example17"
    present_image_and_text_above("exp_images/toothpaste.png", image_instruction, 9, text_height=0.1, sound_path="audio_44100/image_instruction.wav", speaker_duration=8)

    image_instruction2 = "Example18"

    present_image_and_text_above("exp_images/eraser2.png", image_instruction2, 9, text_height=0.1, sound_path="audio_44100/image_instruction.wav", speaker_duration=8)

    end_text = "end"
    present_text_stimulus_no_countdown(end_text, 5, height=0.17)
    
    win.close()

run_experiment()

Can you look at this and help me with what I’m asking for?

I want to send a trigger at the beginning and end of a ‘Speak’ sentence, or for the duration of the sentence.

I looked at the Psychopy documentation on how to present trigger signals, but I don’t use Coder or builder, and it doesn’t seem very intuitive to me.

Please help me out!

Thank you so much.