====== Acquiring Digital Codes ======
It is critical that we acquire time-locked digital codes upon presentation of each stimulus. These codes are used to bin the data according to stimulus type during analysis. This is also essential for creating event-related averages of the 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 using the Biopac MP150.
===== Hardware =====
* [[http://labjack.com/u3|LabJack U3 DAQ device]]
* 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 25-pin ribbon cable which connects to a parallel port on the MP150.
* [[http://www.winfordeng.com/products/brk25mf.php|Winford DB25 Dual Connector Breakout Board]]
* 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.
* [[http://www.biopac.com/isolated-digital-interface-printer-port|Biopac I/O]]
{{ :kpnl:biopac:labjack.png?350 |}}
- 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
===== Software =====
==== Sending ====
The LabJack U3 can be controlled via several different programs and languages. We use the [[http://labjack.com/support/labjackpython|LabJack Python module]] to send codes via [[http://www.psychopy.org/|PsychoPy]].
The computer (Mac) should have [[https://developer.apple.com/xcode/|Xcode]] (including the **Command Line Tools**) installed. The libusb package should also be installed (see [[http://labjack.com/support/linux-and-mac-os-x-drivers|here]] for details). Finally, the [[http://labjack.com/support/linux-and-mac-os-x-drivers|LabJack exodriver]] and [[http://labjack.com/support/labjackpython|LabJack Python module]] should be installed.
Below is sample code for sending digital codes. Additional details can be found [[http://labjack.com/support/labjackpython/low-level|here]] and [[http://labjack.com/support/u3/users-guide/5.2.5.10|here]].
# import LabJack module
import u3
#NOTE: if running from PsychoPy you should use "from labjack import u3"
# Initialize some stuff
d = u3.U3()
d.getCalibrationData
d.debug = True
# Set all FIO bits to digital output and set to low (i.e. “0")
# The list in square brackets represent what’s desired for the FIO, EIO, CIO ports. We will only change the FIO port's state.
d.getFeedback(u3.PortStateWrite(State = [0, 0, 0]))
# To send a code, replace the first number in the list with a value between 0-255
# For instance, the following code would send a value of 15 by setting the first 4 bits to “1"
d.getFeedback(u3.PortStateWrite(State = [15, 0, 0]))
==== Acquiring ====
**1.** In the AcqKnowledge acquisition software, select **MP150** => **Set Up Channels**.
**2.** Select **Digital**.
**3.** Check the **Acquire** box next to channels 8-15. The **Plot** and **Value** boxes can remain unchecked.
* Pins 2-9 on the DB25 map to digital inputs 8-15 on the MP150
The MP150 does not read the 8-bit code. Rather, it is simply acquiring 8 separate channels of digital input. We need to create an additional channel that will take the result of an expression (that we define) as input. The expression will convert the 8 binary channels to a single decimal stimulus code.
**4.** Select **Calculation**.
**5.** Check the boxes for **Acquire**, **Plot**, and **Value**.
**6.** From the “preset” dropdown menu select **''Expression''**.
**7.** Select **Setup**
**8.** Enter the following formula: ''(D8*1 + D9*2 + D10*4 +D11*8 + D12*16 + D13*32 + D14*64 + D15*128) / 5''
\\
(note: we divide by 5 because the input is read as 5 volts. So a digital code of ''255'' would be summed to 1275.)