I will start programming an experiment where participants must respond with external buttons keys instead of the keyboard. I haven’t done this before and I am looking for suggestions. I have been told about “remapping”. Does anyone have any suggestion or code for external button responses?
The picture shows the yellow and blue buttons, the box which the buttons are attached to, and the two cables that come from the box.
It depends what kind of button box you are using.
From builder view there are already components to support several kinds of external device (e.g. cedrus and iolab) - you can find these under ‘responses’ and see more documentation online under ‘hardware’ https://www.psychopy.org/api/hardware/
If you prefer to hard code your experiment, you can also see several exampled from coder view >demos> hardware and/or > inputs
Hope this helps,
somebody in your lab should know. Does it have a name? Who is its manufacturer?
Anyway, telling from the connectors, it looks as if this a usb-to-serial connection. But this might not help you since psychopy supports only the response boxes @Becca mentioned. You might want to try those (see here). Perhaps your box operates the same way as the cedrus or io labs box? Or try the keyboard-component (see here).
In case you need only two buttons, you might want to try out a gaming mouse which is usually sampled with 1000 Hz (also I am not sure whether python supports this).
the button box has no manufacturer and we have little to no information about it. The button box does work in Presentation software and from there I was able to learn this information about the device:
port type: serial / device: COM1 / Identifier: COM1 / Rate: 19200 / Data Bits: 8 /Stop Bits: 1.
By using the following code I learned that python is recognizing the port (as it prints ‘COM1’) :
ser = serial.Serial()
ser = serial.Serial('COM1', 19200, timeout=0, parity=serial.PARITY_EVEN, rtscts=0)
Now that I know the port is being recognized. I need Psychopy to get the responses from each button that is connected to the serial port and for the program to recognize that responses from the serial port are the ones to be expected (and also record their reaction time and accuracy).
Also note that I have tried to use this button box as an ioLab, cedrus, joy buttons and the buttons do not trigger any response. Any suggestions? @Becca @JensBoelte @mdc @Michael
Thanks for the help,
Sorry, no more suggestions from my side. I don’t have a serial button box for testing. Could you use Presentation to find out what code is send?
Make a loop and print out the result of reading the port, to see what values it sends when you push a button.
while not event.getKeys:
received = str(ser.read(), 'utf-8')
if received != '':