Have response time with own button box

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

OS (e.g. Win10): W10
PsychoPy version (e.g. 1.84.x): 2021.2.3
Standard Standalone? (y/n) ?: yes
**What are you trying to achieve?: I would like to calculate the response time of a subject after the onset of a stimulus, the button box to reply is connected with serial link to psychopy, so i have elaborated a code to insert it in Builder.

**What did you try to make it work?: I try to calculate response time=trialClock.getTime()-stim.tStart when a button is pressed.

**What specifically went wrong when you tried that?: Wrong result for RT and sometimes word stimulus “freeze” and i have to press on the button again to go to the next stimulus.

My stimulus is a standard stroop experiment constructed with an Text component (no problem with that)
and my button box code is inserted with a code component:

bug1210

Here is a description of my code component…
In the tab “before experiment”:

import serial
import time
from psychopy.hardware import keyboard
from psychopy import core

kb = keyboard.Keyboard()

port = serial.Serial("COM3", 19200, timeout=1)
time.sleep(2)
port.flushInput() # Clear buffer serial port
DI = port.read()
print(DI)
inc=0

tps=[]
rep_list=[]
rt_list=[]
t0=0

In the tab " Each frame":

DI = port.read()
kb.clock.reset()  # when you want to start the timer from
keys = kb.getKeys(['q'], waitRelease=True)
    
    
if 'q' in keys:
    port.close()
    print(rt_list)
    core.quit()  
    
elif DI == b'\x04':
    rep_list.append('blue')
    #rt=time.time()-start
    #thisExp.addData('resp.rt',trialClock.getTime()-stim.tStart) 
    continueRoutine = False
    print('blue')
elif  DI == b'\x07':
    rep_list.append('yellow')
    #thisExp.addData('resp.rt', trialClock.getTime()-stim.tStart) 
    continueRoutine = False
    print('yellow')
elif  DI == b'\x08':
    rep_list.append('black')
    #thisExp.addData('resp.rt', trialClock.getTime()-stim.tStart) 
    continueRoutine = False
    print('black')
elif  DI == b'\x12':
    rep_list.append('red')
    #thisExp.addData('resp.rt', trialClock.getTime()-stim.tStart) 
    continueRoutine = False
    print('red')
elif  DI == b'\x13':
    rep_list.append('white')
    #thisExp.addData('resp.rt',trialClock.getTime()-stim.tStart) 
    continueRoutine = False
    print('white')

And in the tab “end experiment”:
port.close()

In the each frame tab you can see that i try to calculate the RT as soon as a button is pressed with:

thisExp.addData('resp.rt', trialClock.getTime()-stim.tStart) 

But no sucess with this method!

Any idea to calculate the response time?

Thanks a lot!!

Hello,

I have the same problem.
Were you able to slove it?

Greetings! :slight_smile: