This is an old revision of the document!
Table of Contents
PsychoPy is an open-source application to allow the presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments. It’s a free, powerful alternative to Presentation™ or e-Prime™, written in Python (a free alternative to Matlab™ ).
I have chosen PsychoPy as the primary stimulus presentation software for the lab for a number of reasons:
- It is free
- It is open-source
- Experiments can be developed in two environments
Builder
a nice GUI interface for quick and easy development of experimentsCoder
a programming environment for exploiting the power of Python programming to develop more complex paradigms and/or for greater customization an experiment.
- There is an active and friendly user group for getting help and addressing issues.
Below are notes and tips for building experiments for use in the EEG lab. Many of these tips include using a custom code componet in Builder
. This is a way of inserting short pieces of Python code into your Builder experiment. In other words, you can leverage some of the power of Coder
without leaving the Builder
GUI environment. An alternative would be to start by building your experiment in Builder
and then compiling the code to be further modified in Coder
.
Moving between Builder
and Coder
is a one-way street. You can move from Builder
to Coder
, but not from Coder
to Builder
.
Notes on sending digital event codes
It is critical that we acquire stimulus-locked digital codes so that we can bin the data according to stimulus type during analysis. This is also essential for creating event-related averages of psychophysiological data (e.g. creating ERPs from EEG data) as it gives us the precise onset time of each stimulus. Below is a description of the hardware, software, and steps necessary for sending and acquiring such codes with PsychoPy and the BioSemi ActiveTwo system.
Hardware
-
- The stimulus presentation computer interfaces with this device via USB. The device then outputs the 8-bit digital signal which is relayed to the MP150 via a 37-pin ribbon cable which connects to a parallel port on the ActiveTwo USB receiver.
-
- This breakout board (aka terminal board or terminal block) gives us an easy way of wiring the output from the LabJack U3 to the ribbon cable.
- USB from stimulus presentation computer
- 8-bit digital output from I/O lines FIO0-FIO7.
- A separate wire connects each line to the breakout board.
- Wires are connected to screw terminals on the breakout board. Each terminal is connected to a single pin of the male/female DB-25 connectors.
- FIO0-FIO7 should be wired to terminals 2-9 of the breakout board.
- The ground should be wired to terminal 18 of the breakout board.
- A 25-pin ribbon cable connects the breakout board to the MP150
Setting the default LabJack address
- PsychoPy has a built-in python library to drive the LabJack DAQ device. By default, PsychoPy uses the address for the “EI0” DB15 pins (address = 6008). We use the “FIO” terminal blocks so we need to specify the correct address (
6000
). In order to use the “FIO” terminal we need to add the following custom code component to the beginning our Builder experiment. PsychoPy users thread.
def mySetData(self, byte, endian='big', address=6000): if endian=='big': byteStr = '{0:08b}'.format(byte)[-1::-1] else: byteStr = '{0:08b}'.format(byte) [self.writeRegister(address+pin, int(entry)) for (pin, entry) in enumerate(byteStr)] labjacks.U3.setData = mySetData
Initializing the LabJack
Status attribute
- There seems to be a bug in Builder that results in an attribute of the p_port not being initialized. Running an experiment with LabJack digital codes that was built in Builder will give the following error.
AttributeError:'U3' object has no attribute 'status'
This can be fixed by adding the following code to the start of the script (anywhere after the code that imports the LabJacks module)
p_port.status = NOT_STARTED
Alternatively, you should be able to fix this problem by using the custom code
component, selecting the Begin Routine
tab, and adding the following“
p_port.status = []
- The LabJacks will initialize with all bits set to hight (i.e. sending a
255
code). So you should also add the following code to your script (it can be added right after the code shown above).
win.callOnFlip(p_port.setData, int(1), address=6000)