0% found this document useful (0 votes)
39 views10 pages

Key Paper

StimSync is an open-source hardware device designed for behavioral and MRI experiments, enabling precise stimulus presentation and response measurement. It simulates USB keyboard inputs, measures various signals, and provides digital outputs for controlling external devices, outperforming existing solutions in latency and precision. The device aims to enhance the flexibility and accuracy of neuroscience research by allowing for custom configurations and validation of timing across different experimental setups.

Uploaded by

22bee009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views10 pages

Key Paper

StimSync is an open-source hardware device designed for behavioral and MRI experiments, enabling precise stimulus presentation and response measurement. It simulates USB keyboard inputs, measures various signals, and provides digital outputs for controlling external devices, outperforming existing solutions in latency and precision. The device aims to enhance the flexibility and accuracy of neuroscience research by allowing for custom configurations and validation of timing across different experimental setups.

Uploaded by

22bee009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Journal of Neuroscience Methods 227 (2014) 90–99

Contents lists available at ScienceDirect

Journal of Neuroscience Methods


journal homepage: [Link]/locate/jneumeth

Clinical Neuroscience
Short communication

StimSync: Open-source hardware for behavioral and MRI experiments


Christopher Rorden a,b,∗ , Taylor Hanayik a,b
a
Department of Psychology, University of South Carolina, Columbia, SC 290208, USA
b
McCausland Center for Brain Imaging, University of South Carolina, Columbia, SC 290208, USA

a r t i c l e i n f o a b s t r a c t

Article history: Background: Many neuroscience experiments rely on presenting stimuli and measuring participants’
Received 9 July 2013 responses to these events. Often computer screens, speakers and keyboards are sufficient. However, these
Received in revised form 7 August 2013 devices are not appropriate for some situations. For example, some studies present tactile or olfactory
Accepted 17 November 2013
stimuli or brain stimulation. Likewise, keyboard buttons are not appropriate for use with vocal responses,
small animals or individuals with motor impairments.
Keywords:
New method: We describe StimSync, which simulates USB keyboard inputs, allowing use with most exper-
Human and animal responses
imental software. StimSync can measure button presses, optical signals from magnetic resonance imaging
Motor-evoked potential
Magnetic resonance imaging
systems, changes in ambient light (e.g. synchronizing intracranial electrography), and auditory events
Custom response device (a voice key). In addition to the USB keyboard mode (necessarily millisecond precision), StimSync can
Open source hardware also be set to provide higher precision timing. This feature can be used to validate timing, ensuring event
Stimulus synchronization synchronization (e.g. auditory events, visual events, brain stimulation). In addition to recording inputs,
StimSync provides seven digital outputs for controlling external devices. Finally, StimSync can record
analog inputs; we illustrate how this can be used to evaluate the rise time for computer displays.
Results: We observed outputs with a mean latency of 2.1 ms (sd = 0.17 ms) and USB inputs with a mean
latency of 2 ms (sd = 0.54 ms).
Comparison with existing method(s): StimSync statistically outperforms two professional solutions and
numerically outperforms other devices described in the literature.
Conclusions: StimSync ([Link] provides an open-
source solution for controlling and validating neuroscience experiments. In addition to sharing the design,
we have produced a batch of devices to demonstrate the market for professional implementations.
© 2014 Published by Elsevier B.V.

1. Introduction (leading to image artifacts, James et al., 2005), and second gradi-
ent switching used to generate images could cause heating in the
Commodity desktop computers have become popular tools for wires (Kugel et al., 2003). Therefore, there is a need for a flexible
acquiring behavioral responses. For many experiments, it is suffi- input device – and ideally one that can appear as a simple keyboard
cient to ask participants to observe a computer and make responses to the host computer (so it can be used without modification with
using a keyboard. However, there are situations where specialized many popular stimulus presentation packages). A second, related
input and output devices are required. For example, we may wish problem is to develop hardware that can help validate the precise
to present olfactory or tactile stimuli, or trigger brain stimulation. timing of different events – for example, ensuring that a stimuli that
Likewise, keyboard buttons may not be appropriate for individuals appears on a computer screen always occurs at a consistent time
with poor motor control or for many species of animals. Further, it is relative to an external trigger signal, such as brief brain stimulation
often desirable to acquire latency information for another modality with transcranial magnetic stimulation.
– such as a ‘voice key’ that detects the onset of speech. Finally, these A historical solution to detecting the closure of custom buttons is
electrical buttons are not appropriate for some environments, such to use the parallel (Dalrymple-Alford, 1992) or RS232 serial (Morris,
as functional magnetic resonance imaging for two reasons: first the 1992) ports of a computer. However, these ports are no longer
electrical signals in the wires cause interference in the MRI signal common, with the features supplanted by the universal serial bus
(USB) port. Further, the stimulus presentation software must be
customized to detect these inputs. Likewise, there are many pro-
∗ Corresponding author at: Department of Psychology, University of South Car-
fessional digital input devices that can record responses, but these
olina, Columbia, SC 290208, USA. Tel.: +1 803 404 2573.
generally also require customization of the software. Ideally, one
E-mail address: Rorden@[Link] (C. Rorden). would want a device that provides accurate timing, appears as a

0165-0270/$ – see front matter © 2014 Published by Elsevier B.V.


[Link]
C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99 91

standard keyboard to the host computer, and allows virtually any into modern computers are sufficient for output, some studies
form of button to be connected. require precise control of additional devices. For example, generat-
One elegant solution for recording button inputs is to emulate a ing a tactile stimulation, controlling the onset of brain stimulation
USB Human Interface Device (HID) – this is a standard protocol that or dispensing juice for an animal all require some form of digi-
describes how keyboards, computer mice, joysticks, etc. communi- tal output. There are proprietary solutions to these problems. For
cate with a computer. Therefore, any HID device will be recognized example, Psychtoolbox provides support for the proprietary Mea-
on any popular computer (for example, those running modern surement Computing 1208FS (Norton, MA, USA) that includes 16
versions of the Windows, OSX and Linux operating systems). Poten- digital outputs which we evaluate here (we also created code to
tially driven by the popularity of computer-based kiosks, photo control this device with EPrime). EPrime allows commands to be
booths and other enclosures, there are now a number of profes- sent via a parallel port allowing simple control for digital outputs.
sional HID devices (for example, we evaluate the inexpensive UHID Markham (1993) describes simple hardware for controlling out-
Nano from [Link]). Similarly, Schubert and colleagues puts using the parallel port. Unfortunately, legacy parallel ports are
(2013) describe how the open-source Leonardo Arduino hardware not included on many modern computers. Our StimSync includes
can act as a HID device for mapping an analog input to keystrokes 7 digital outputs, and we provide EPrime and Psychtoolbox exam-
with low variability (∼1 ms), outperforming many commodity key- ples for controlling this device. A limitation of EPrime is that it is
boards (Plant and Turner, 2009). They also describe software that proprietary. While Psychtoolbox itself is free, it is typically run with
allows the Arduino to and act as a high precision timer when used the proprietary Matlab (though it is possible to run it using the free
with E-Prime. A benefit of the Arduino is that both the software Octave language on some operating systems). In contrast, PsychoPy
and hardware are open source, empowering users to customize (Peirce, 2007) and OpenSesame (Mathôt et al., 2012) are based on
the hardware for their own applications. Here we also present an the Python language and completely open source. Therefore, we
Arduino-based solution to this problem. Our solution extends the also developed and evaluated Python code for controlling digital
work of Schubert et al. (2013) by incorporating additional features outputs using the StimSync.
including the optical inputs, digital inputs, digital outputs, a graph- Previous validation studies have suggested that commodity
ical user interface for modifying key mappings without requiring input devices exhibit both latency and variability in logging key
firmware to be recompiled. Further, we remedy minor limitations presses. For example, Segalowitz and Graves (1990) report key-
of the design of Schubert et al. (2013): our design works reliably boards and PS/2 mice have about a 10 ms delay ± 7.5 ms (that they
with timing functions such as the KbCheck function in Psychtool- inferred was due to polling rate, and therefore regardless of man-
box and implements keyboard debouncing independently for each ufacture), while serial connection mice buttons had a delay of
input. 31 ms with an error of ±2 ms. Using more modern USB devices,
In addition to detecting the closure of mechanical switches, the Plant and Turner (2009) found that different keyboards varied in
Arduino inputs can also be used to detect electrical inputs from latency from 18 to 34 ms with a standard deviation of 0.8–3.7 ms,
other devices. Here we describe how these inputs can be adapted whereas mice had latencies of 10–49 ms with standard deviations
for recording button presses made inside a magnetic resonance of 0.7–4.3 ms. However, one limitation of these studies is that they
imaging (MRI) scanner. Conventional electrical switches can be employ proprietary tools in order to establish these values. Con-
problematic as the wires can generate radio interference (James sider the USB HID device we describe here – how accurate are
et al., 2005) and the metal parts could potentially heat up due the response times recorded using this device? This question is
to induction caused by the rapidly switching magnetic gradients particularly challenging as the polling rate could in theory differ
(Kugel et al., 2003). Here we describe an optical fiber button for use between operating systems (e.g. Linux, Windows or OSX), between
in this situation. computers, or even versions of operating systems (e.g. the hard-
While button inputs allow scientists to measure manual ware may not perform well on some future, as yet unreleased
responses, it is often useful to measure the onset of analog events. version of Windows). Therefore, an important goal is to provide
For example, a voice key is a popular tool for measuring the onset a robust method to validate timing across systems. To achieve this,
of speech and numerous such devices have been described. For we added special firmware routines to the StimSync that allow
example, Abrams and Jennings (2004) describe a software solu- users to directly measure the accuracy of these devices on their
tion compatible with the Visual Basic language. The work of Tyler own system.
et al. (2005) and the proprietary Serial Response Box (Psychology Minimal latency and variability are clearly desirable attributes
Software Tools, Sharpsburg PA USA) are examples of hardware solu- for input devices. However, we wish to emphasize that for many
tions, though both were developed for the now legacy RS422/RS232 behavioral studies any commodity device will provide reasonable
serial ports. More comparable to our design, is the proprietary SV- timing. First of all, a delay that is constant across all conditions will
1 USB voice key (Cedrus Corporation, San Pedro, CA, USA). In our have no bearing on the subsequent statistics. Further, variability on
design, we provide a pair of analog inputs. This can be used as a the scale reported for computer input devices will have little effect
voice key – when a microphone is plugged into an analog port on statistical power for detecting relevant behavioral differences
a keystroke is emulated when the volume of a sound exceeds a (Ulrich and Giray, 1989). However, there are situations where
threshold (with thresholds manually adjusted by a knob). Analog precise timing may be important, especially for outputs. For exam-
inputs can be useful for a wide arrange of uses, beyond that of a ple, perceptual stimuli generate time-locked electrophysiological
voice key. For example, one can plug in an ambient light sensor responses with temporal precision ensuring that signal averaging
that will emulate a keystroke when a light exceeds a given thresh- is accurately able to discriminate different components. Specif-
old. An important use for such inputs is detecting when an image ically, Intracranial Electroencephalography (iEEG) can provide
occurs on a computer screen. Below we exploit this to validate the exquisite temporal information, so a device like a StimSync can
accuracy of our stimulus presentation. Further, these analog inputs help timestamp when a stimulus appeared on a computer screen.
can be recorded and plotted. For example, we evaluated the perfor- Likewise, transcranial magnetic stimulation (TMS) pulses can
mance of three different computer screens when switching from a cause very brief behavioral changes, with precise timing allowing
black to a white image. scientists to calculate when a brain region is required. A nice
In addition to recording inputs (e.g. button presses or voice example of these types of effects is a TMS study by Chambers et al.
key responses), it is often useful to control digital outputs. While (2004), where stimulation of parietal cortex impaired perception
many behavioral studies find that the screens and speakers built when the pulses occurred at 90 ms and 225 ms after the stimuli
92 C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99

but not in the intervening period. In these situations, temporal microcontroller for a Bluetooth serial device. This allows inexpen-
precision is a very important feature for output devices. sive Bluetooth modules to be used for wireless digital outputs,
Therefore, our goal was to develop a simple open source hard- microsecond recording and streaming of analog data. For example,
ware device for recording behavioral inputs and outputs. Next, we for our reference design we use JY-MCU modules that can be pur-
evaluated this device to compare its performance to proprietary chased for around $8 and can be programmed (with firmware we
solutions. Specifically, we evaluated the UHID Nano, as an input include) to communicate at 460,800 bps. These wireless modules
device, and Measurement Computing 1208 fs as a digital output emulate a legacy serial port, allowing the StimSync to control dig-
device. We chose these two proprietary solutions based on their ital outputs, work in ‘oscilloscope’ mode to record analog inputs
low price and software support. The Nano is an inexpensive and and work in microsecond timing mode. However, the Bluetooth
tiny device that can mimic a USB keyboard with up to 8 digital modules do not allow normal USB HID keyboard emulation (as the
inputs. For digital outputs, we tested the Measurement Computing connection mimics a standard serial port rather than a USB device).
1208 fs. The 1208 fs is supported by Psychtoolbox and includes 16 A schematic of our design is shown in the left panel of Fig. 1.
digital outputs. We also created software that allows the 1208 fs The schematic can be used to build a StimSync using an electri-
to be controlled by EPrime. Our aim was to demonstrate that the cal breadboard and a Leonardo, Due, Teensy 2 or Teensy 3. We
StimSync performs similarly to these professional solutions. also created and distribute a reference printed circuit board (Fig. 2)
based on the Teensy 3 using Fritzing. The resulting Fritzing and
2. Methods Gerber files can be mass produced, for example using open source
fabricators such as Fritzing ([Link] and Oshpark
2.1. Basic design ([Link] Our design allows eight digital inputs con-
nected to pins 2.9. These pins utilize the microcontroller’s built-in
We developed our code to work with Arduino-compatible pull-up resistors, so they are driven to the microcontrollers’ posi-
microcontrollers that can mimic a USB keyboard. These include tive voltage when open. Connecting any one of these pins to ground
the Arduino Leonardo and PJRC Teensy 2 that use the AVR 5 V 8- (0 V) generates a key press signal, and subsequent disconnection
bit central processing unit (CPU) as well as the Arduino Due and from ground generates a key release signal. One option is to have
PJRC Teensy 3 that use 3.3 V 32-bit ARM CPUs. While our firmware the Arduino communicate with the computer using the Arduino’s
is compatible with all these devices, our reference design uses the “print” or “write” command (Schubert et al., 2013). However, this
PJRC Teensy 3 ([Link] due to its small size, low cost, approach sends a very brief keyboard signal to the computer, which
and high USB bandwidth. We note that the Teensy does use propri- are not detected by some routines such as the “KbWait” command
etary BIOS, and therefore is not as open as other Arduino designs. in Psychtoolbox (requiring the usage of the “KbQueue” command).
Having firmware compatible with all these designs prevents vendor In contrast, we suggest using the Arduino’s “press” and (after a
lock-in. Note that not all of these devices support all of our features, delay) the “release” command, emulating the way an actual key-
specifically the Arduino Due does not include Electrically Erasable board functions. This latter solution works with all software we
Programmable Read-Only Memory (EEPROM), so this device will have evaluated.
revert to the default keyboard mappings when it is unplugged from We provide graphical software that allows each pin to be
a computer. assigned to any number or letter. For example, pin 2 could be
By default, our design communicates and receives power via assigned to generate a ‘2’ character when a button is pressed and a
the USB port. However, our design reserves pins 0 and 1 of the ‘b’ character when the button is released. Our software reprograms

Fig. 1. Schematic for StimSync. The design includes eight digital inputs (i0–i7), here shown connected to momentary switch push buttons though note these could also be
electrical signals from other devices. These switches use 20,000  pull-up resistors built into the Arduino to ensure that they read high when the switch is open. The schematic
shows seven digital outputs (o0–o6), each shown here with a light emitting diode and resistor, though note these could be a variety of components such as transistors, solid
state relays, etc. The design also includes two Analog sensors (A0, A1) that provide voltage from the range of 0–Vdd (where Vdd is 3.3 V for ARM based-microcontrollers
and 5 V for AVR-based microcontrollers), each paired with a threshold knob (A2, A3: 10 K potentiometers that can be dialed to 0–Vdd) and a detection light (A4, A5) that
illuminates whenever the sensor voltage is greater than the threshold voltage. Also shown is an optional Bluetooth module that allows wireless control of digital outputs,
microsecond timing mode and oscilloscope mode (though not USB keyboard inputs). Note that there is also a built in light (pin 13 on most devices) that is used to indicate
status: on continuously during USB keyboard mode, flashing during oscilloscope mode and blinking twice when in microsecond timing mode.
C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99 93

the StimSync then begins streaming binary data for both the ana-
log and digital channels. We demonstrate how this can be used to
observe and record the rise time for a computer screen switching
from a dark to bright screen.
One issue with both digital and analog inputs is de-bouncing. A
mechanical button works by closing an electrical circuit, but during
the initial vibration the circuit often opens and closes rapidly. Like-
wise, with a voice key we typically log the initial vocal response but
not the onsets of the subsequent phonemes. Our software allows
the user to select a desired debounce time. For example, if the
debounce time is set to 100 ms, an input will send an initial sig-
nal when the circuit is closed but disregard changes for the next
tenth of a second. Our debouncing algorithm works independently
for each input, as it is often desirable to detect response times to
multiple keys simultaneously.
The StimSync also includes pins for digital outputs. The Teensy
3 supports 7 outputs (pins 10.12, 20.23), the Teensy 2 supports 5
outputs (pins 10, 12.15), the Arduino Due and Leonardo support 3
outputs (pins 10.12). For ARM CPUs, these provide up to 9.4 mA at
3.3 V, and the AVR CPUs provide up to 20 mA at 5 V. This is sufficient
to power light emitting diodes (LEDs). For devices that require more
current, these outputs can be used to drive optically isolated tran-
sistors (e.g. 4N35) or solid-state relays (e.g. AQZ207). The StimSync
web page includes examples for each of these circuits. Controlling
the StimSync outputs is done by connecting to the device as an
emulated serial port and writing a single byte value to the port.
Fig. 2. A photograph of our reference StimSync design with a light sensor (red) and For example in Matlab one could “fwrite(ser,data)” – where ser is
a fMRI optical pulse sensor. The right panel shows a photograph of our reference the open serial port and data is a value 0–127 that specifies the
design (center) with buttons (top), LED light (left), analog input sensors (bottom, binary values for the outputs. For example, writing the value 21
showing sound, knob, temperature and light sensors) and fMRI pulse trigger (right). would turn on the first (20̂= 1), third (22̂= 4) and fifth (24̂= 16) out-
(For interpretation of the references to color in this figure legend, the reader is
referred to the web version of the article.)
puts while switching the others off. For Matlab we developed and
provide the wrappers SerDeviceIndex.m and SerDOut.m that mimic
Psychtoolboxs’ DaqDeviceIndex.m and DaqDOut.m for the Mea-
the EEPROM firmware in the Arduino and Teensy, so these changes surement Computing 1208 fs. We also developed EPrime examples
will be reflected when the StimSync is connected to any computer. that illustrate the usage of the StimSyc as well as the 1208 fs.
The StimSync has two analog input channels (pins A0 and A1) Arduinos provide an in-built light emitting diode (pin 13 on
each linked to a wheel potentiometer (A2 and A3) and a light emit- most devices, pin 11 on the Teensy 2). We use this to signal the sta-
ting diode (A4 and A5). For example, if the voltage of analog input tus of the microcontroller. When acting as a keyboard this light is on
A0 is greater than the threshold voltage set with the knob con- continuously, when streaming analog data it blinks on and off, and
nected to A2, then the light on A4 will be on, else it will be off. when sending microsecond data it briefly flashes twice followed by
Whenever the voltage dips below the threshold a key press is gen- a longer pause.
erated, and when the voltage rises above the threshold a key release We developed custom software for using the StimSync. Our key-
signal is generated. For example, for a voice key the threshold can board mapping software allows the user to define which input
be adjusted so that a keyboard signal is sent when the participant corresponds to which keyboard press (Fig. 3). This software also
begins speaking, yet the background noise is not sufficient to trig- logs the microsecond onsets of any inputs, creating a tab-delimited
ger a signal. For our reference design, these analog channels use the text file that can be analyzed to measure the onset of any event. We
same connectors as the Seeed Studio Electronic Brick and Phidget have also created simple Psychtoolbox, OpenSesame, PsychoPy and
Analog sensors. These jacks plug into the socket in only one orienta- EPrime scripts that demonstrate how to use the inputs and outputs.
tion, ensuring correct polarity. This design also allows any sensors Finally, we provide software for plotting and recording the ana-
designed for the Electronic Brick and Phidget to plug in to the Stim- log channels written in the Matlab, Processing, Lazarus/FreePascal
Sync (as long as they work at the voltage of the CPU). A voice key and XCode languages. These tools can run on the most popu-
requires a microphone input. We found that commodity computer lar operating systems. We also provide a full online description
microphones with the microphone mounted on a boom work well, of the communication between a computer and the StimSync
but these require a pre-amplifier (e.g. a transistor or operational that include examples of the commands in the Python language
amplifier to boost the signal). Our reference design is based on the ([Link]
Sparkfun Breakout Board for Electret Microphone (BOB-09964). For
measuring screen intensity we used the Sparkfun TEMT6000-based 2.2. MRI compatible extensions
ambient light sensor (BOB-08688). Both inputs use open source
circuit designs. In addition to emulating a binary switch, these ana- Functional Magnetic Resonance Imaging (fMRI) is a popular
log inputs can also be tracked and recorded across time by using method for inferring brain activation. This method uses a powerful
our computer software that puts the StimSync into ‘oscilloscope static magnetic field, rapidly switching field gradients and radio
mode’. In this mode the StimSync streams data to the computer at frequency signals to acquire brain images. This environment is
a regular rate (using interrupts to ensure regular intervals), and is unsuitable for many electrical and metal devices. Potential prob-
displayed graphically using software that we provide in the Lazarus, lems include heating, projectile movement and image artifacts.
XCode, Matlab and Processing languages. The computer can select Therefore, most participant response devices are not compati-
the sampling rate as well as the number of channels desired, and ble for this environment. Several commercial companies have
94 C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99

an optical piano creating a fiber-optic MIDI device. Our own design


is very similar to that of Sommer et al. (2004), Hollinger et al.
(2007) and the commercial alternatives: an optical fiber is illumi-
nated, when the participant presses a button this attenuates light
transmission to a sensor. For our design we use the HFBR1524 light
source and HFBR2524 light sensor which both use the Versatile
Link optical connections. MRI manufacturers commonly use this
optical connector, so the optical cabling and crimping tools are
easy to acquire. Our design is very simple: one end of the fiber is
illuminated, and a button placed half way along the fiber acts as a
guillotine such that the sensor at the other end can detect the but-
ton state. Our implementation uses constant illumination, and sets
the button-press threshold by measuring light transmission when
the system starts up. We note that other methods are possible, such
as using a potentiometer to manually adjust the threshold or puls-
ing the light to both conserve power and to measure the change in
illumination. The electronics of this design are very simple, but the
manufacturing of the button itself requires great care (especially
if one wants a positive tactile response on button closure): in our
implementation we sliced the optical fiber and had the button
break a 1 mm air gap. We created a foot pedal using an Aquiline
Linemaster 971-S plastic enclosure where the internal metal spring
was replaced with a plastic spring. This design is shown in Fig. 4.
Another fMRI specific requirement is synchronizing the onset
of MRI acquisition with the events that occur during an experi-
Fig. 3. Software to support the StimSync. StimSync simulates a keyboard, and can ment. Most manufacturers provide an optical signal that designates
therefore be used with any software that supports a keyboard. We also include a the start of acquisition for each volume. Detecting these pulses
key mapping program that allows the user to configure the actions generated when can help time lock the start of a behavioral experiment with the
a button is pressed or released, this software also generates a text log file for inputs,
start of the MRI acquisition and can also help detect any drift
allowing users to validate onset timing. Further, we include oscilloscope software
written in Matlab, XCode, Processing, and Lazarus that allow the user to display and between the clocks of the computer running the MRI from the
record inputs, for example, screen intensity. computer acquiring behavioral data. Some vendors of MRI scan-
ners provide devices to convert there optical signals to USB inputs.
However, their devices are expensive and therefore are not avail-
developed response boxes especially for fMRI, with most designs able at all centers, particularly sites that are predominantly focused
using optical fiber cabling inside the magnet hall. However, these on clinical work. Some vendors of MRI-compatible response but-
proprietary designs may not be suitable for all situations (e.g. we tons include inputs for these optical triggers, but this feature is not
know of no commercial foot pedal), and tend to be expensive. James universal. In Fig. 5 we illustrate a simple trigger that converts a brief
et al. (2005) demonstrate that a specific commodity USB keyboard optical pulse into a longer electrical signal. This electrical signal can
appears safe and generates little artifact during fMRI scanning on be reliably detected by a StimSync or UHID Nano. The circuit uses a
a 3T MRI system. One concern is that the same device may not 555-series integrated circuit to convert the very brief optical signal
work as well with a different MRI sequence or if the cabling were to a longer (with duration in seconds equal to 1.1*R*C, so in the dia-
routed differently (Nakamura et al., 2001). Sommer et al. (2004) gram the 220,000  resistor and 0.1 ␮F capacitor yields a delay of
use commodity audio optical fiber and adapt a computer mouse for 24 ms) electrical signal. This pulse duration is long enough to allow
recording responses. Unfortunately, the optical components they the user to visually detect a flicker from the included light emitting
use are no longer widely available. Hollinger et al. (2007) describe diode. Further, this pulse length ensures that the Arduino never

Fig. 4. Schematic for an MRI compatible response button. The analog inputs of an Arduino-compatible device can also be used for MRI compatible input buttons. Here a
HFBR1524 is used to illuminate a fiber optic cable. Closure of a momentary switch button reduces the amount of this light reaching a HFBR2524 detector, reducing the voltage
read by the Arduino Analog input (e.g. A0). Note that there are no electronic components or metal inside the magnet hall. On startup, the Arduino assumes that none of the
buttons are closed, and therefore digital keyboard responses are signaled when the voltage drops below this baseline voltage. Note that in this design the HFBR1524 draws
33 mA, so a large number of buttons will require more power than is available on from the Universal Serial Bus (USB) cable, requiring an external power source.
C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99 95

mounted on the same location of the CRT, with the StimSync set to
the same threshold (we tested PsychoPy during a separate session).
One thousand trials of data were acquired, with the data from
the first trial discarded. Note that EPrime’s data logging records
events in integer milliseconds. Therefore, assuming random syn-
chronization between the screen refresh and the timer, even a
perfect device would appear to have a standard deviation of around
0.5 ms. To allow other users to evaluate their own equipment,
we provide a timing validation diagram and scripts for PsychoPy
([Link]
We conducted a similar study to test the performance of the
digital outputs. We sent an electrical signal that was intended to
coincide with the image presentation. We measured these onsets
Fig. 5. Simple schematic for converting a brief optical pulse from a MRI scanner into using a separate StimSync attached to a different computer that
a keyboard input using either a UHID Nano or StimSync. An HFBR-2524 converts the logged both the screen onset time and the electrical signal. We
optical signal to an electrical signal, and a 555 monostable timer converts this very tested EPrime on Windows and PsychToolbox and PsychoPy on
brief pulse into a signal with a longer duration (set by the resistor and capacitor OSX. We tested two output devices: the StimSync as well as the
attached to pins 6 and 7, here 24 ms). The output if the 555 can either be a UHID
Nano (shown) or an Arduino digital input. The diagram also shows a light emitting
Measurement Computing 1208 fs. For all devices, we acquired 1000
diode attached to the output, which dims with each pulse. trials, discarding the first sample (to avoid variability due to the
system loading files, system priority changes, or changing power
states).
fails to detect a pulse (reading each input takes a finite amount of
We also wanted to evaluate the precision of the StimSync in the
time, so even when an Arduino is tasked with continuously polling
‘microsecond’-timing mode. The StimSync sequentially measures
several inputs it may fail to detect a very brief signal).
each of the inputs, with the sampling of each input (particularly
analog inputs) requiring a finite amount of time. In addition, the
2.3. Validation
device may be regularly interrupted from this sampling to do other
tasks such as USB communication that could also impact the samp-
To evaluate the accuracy of digital inputs we examined the
ling rate. Therefore, we measured the variability of measuring the
performance of both the proprietary UHID Nano and StimSync
temporal jitter observed in a periodic square wave sent from a
emulating USB keyboards. We conducted a simple experiment
waveform generator.
where a dark screen switched to a bright image. An ambient light
Finally, we used the oscilloscope mode of the StimSync to eval-
sensor detected the brightness change and sent a keystroke to the
uate the response time of three different computer displays. We
presentation software, emulating an individual performing a sim-
used the ambient light sensor to record the intensity of the screens
ple visual detection task. We used a cathode ray tube monitor that
as they transitioned from a black to white image. Our aim was to
has a very rapid onset (as we demonstrate below). We tested three
demonstrate that the StimSync is an effective alternative to the
presentation software tools on two computers: EPrime 1.2.6 run-
proprietary BlackBoxToolkit (Plant and Turner, 2009) for evaluat-
ning on the Windows XP operating system (using a Sony VAIO
ing devices. We chose a CRT display, a commodity laptop, and a LCD
SZ791N with 2.5 GHz Intel Core 2 CPU, using the NVidia GeForce
display that is marketed as being suitable for flicker shutter glasses.
8400GS video card while running from wall current), and Psych-
Toolbox 3.0.10 revision 3405, as well as PsychoPy 1.77 running on
the OSX 10.8 operating system (using a MacBook Pro 13” with a 3. Results
2.4 Ghz Intel Core 2 Duo CPU, and the NVIDIA GeForce 9400 M video
card, running off wall current). Note that the electron gun of a CRT The analysis revealed that the StimSync had significantly
draws an image over the screen in a finite time, so the placement of lower latency and variability than the commercial UHID Nano
the optical sensor influences the apparent time of a screen change. for digital inputs in both EPrime and Psychtoolbox for the
For both the EPrime and Psychtoolbox testing the light sensor was tested hardware. For Psychtoolbox the mean input latency for the

Fig. 6. Evaluation of digital inputs in Psychtoolbox. A key press was generated when the computer screen flashed, and the latency between these two events is plotted for
both the StimSync and UHID Nano USB devices across one thousand trials. Note that the StimSync exhibits lower latency and less variability.
96 C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99

Fig. 7. Histogram showing typical latencies of StimSync and UHID Nano when used as digital inputs with Psychtoolbox.

StimSync was 1.99 ms vs. 6.95 ms for the UHID Nano (t(1996) = 49.2; the StimSync delivered a mean latency of 1.65 ms with a standard
p < 0.001), and the standard deviation was 0.54 ms vs. 2.46 ms deviation of 0.20 ms (with a range of 1.1–2.14 ms).
(f(998,998) > 11.7; p < 0.001), as shown in Figs. 6 and 7. For EPrime The microsecond timer function was evaluated by using a 20 Hz
the mean input latency for the StimSync was 8.83 ms vs. 12.39 ms signal generated by a DSO Nano Oscilloscope (Seeed Studio, Shen-
for the UHID Nano (t(1996) = 47.06; p < 0.001), and the standard zhen China) as a digital input. Across 1000 trials we measured a
deviation was 0.46 ms vs. 2.34 ms (f(998,998) > 11.7; p < 0.001). For mean duration between pulses of 49.996973 ms and a standard
PsychoPy the StimSync provides a mean of 2.03 ms with a standard deviation of 0.08 ms (80.49 ␮s). The range between the shortest and
deviation of 0.33 ms (with a range of 1.2–2.94 ms). longest duration was 0.2 ms (209 ␮s). Note that these errors can be
Our analysis also revealed that the StimSync had significantly expected to reflect the combined error of the measuring device and
lower latency and variability than the commercial Measurement the signal generator.
Computing 1208 fs for digital outputs in both EPrime and Psy- We recorded the rise and fall time of screen switching between
chtoolbox. The mean latency in Psychtoolbox was 2.06 ms vs. black and white with three computer monitors. The results are
4.56 ms (t(1996) = 127.26; p < 0.001), and the standard deviation shown in Fig. 10. The Cathode Ray Tube exhibited a rapid pulse with
was 0.17 ms vs. 0.59 ms (f(998,998) > 11.7; p < 0.001), as shown each refresh, the commodity laptop liquid crystal display showed
in Figs. 8 and 9. The mean latency in EPrime was 42.72 ms vs. a relatively slow switching speed, and the high performance desk-
44.25 ms (t(1996) = 161.85; p < 0.001), and the standard deviation top liquid crystal display showed more rapid switching. We did
was 0.05 ms vs. 0.3 ms (f(998,998) > 11.7; p < 0.001). For PsychoPy not conduct any statistics, as these properties are likely to vary

Fig. 8. Evaluation of digital outputs in Psychtoolbox. A digital output was generated when the computer screen flashed, and the latency between these two events is plotted
for both the StimSync and Measurement Computing 1208 fs across one thousand trials. Note that the StimSync exhibits lower latency and less variability.
C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99 97

Fig. 9. Histogram showing typical latencies of StimSync and Measurement Computing 1208 fs when used as digital outputs with Psychtoolbox.

between labs. However, the figure illustrates the variability that The StimSync showed statistically less variability than the
can be observed with different devices. UHID Nano, and numerically outperformed the commodity USB
input devices described by Plant and Turner (2009). We note that
Schubert et al. (2013) also examined the performance of an Arduino
4. Discussion Leonardo emulating a USB keyboard device (their study 6) and
found EPrime had a standard deviation of 0.53 ms, very similar to
Our primary aim was to design and validate a simple open source the 0.47 ms we report here. However, we note that in both cases
device for recording responses, presenting stimuli and validating timing was recorded using EPrime where times are recorded only
the performance of behavioral experiments. This is useful for situa- with millisecond precision. The theoretical limit for timing with
tions where commodity components such as computer screens and this resolution is a standard deviation of around 0.5 ms (unless the
keyboards are not sufficient. We found that our StimSync device stimulus and response are phase locked to the timer’s clock). Inter-
performed at least as well as two professional solutions. In addition, estingly, while Psychtoolbox records data with higher resolution
StimSync includes additional features including a microsecond- (storing timing information as number of seconds with double pre-
timing mode, analog inputs (e.g. voice key) and an oscilloscope cision), we still observed a standard deviation of around 0.5 ms. We
providing a useful tool for validating behavioral experiments. speculate that this reflects the polling rate of the USB device. In

Fig. 10. StimSync can record and log analog inputs. For example, here is the performance of three different computer monitors that exhibit very different properties when
switching from a black to a white screen. The Cathode Ray Tube (CRT) pulses with each 60 Hz refresh, the laptop screen showed a very sluggish rise time, and the desktop
liquid crystal display (that is marketed for its fast switching performance) shows a much more rapid rise profile. By simply attaching an ambient light sensor to a StimSync,
scientists are able to accurately measure the performance of their own equipment.
98 C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99

other words, our data suggest that our device was sampled near Our evaluation suggests that the microsecond-timing mode offers
the 1 ms rate requested by the Arduino/Teensy (the fastest rate a precision that is not possible with UHID devices that are limited
allowed by the UHID standard). This suggests that the StimSync to 1 ms polling rates.
is typically performing near the theoretically optimal level for a We also evaluated three computer monitors. This experiment
1 ms polling rate, though careful inspection of Fig. 6 suggests that was designed to emphasize the variability between different
there are occasional outliers that we discuss later. Both Schubert monitors. Our device provides a simple tool for scientists to
et al. (2013) and our own design provide methods for timing with evaluate the screens they have available, regardless of make,
higher precision, but we argue that this precision is probably not model or future technological developments. Further, by send-
required by most studies in our field. Specifically, we emphasize ing a trigger pulse at the time of an intended screen change one
that due to the central limit theorem all of these devices are proba- can observe the delay between the computer sending an image
bly suitable for most psychological experiments (Ulrich and Giray, and the display showing this image. This may be particularly
1989). We feel the main benefit of the StimSync USB inputs over useful for monitors that buffer the input data causing display
commodity devices is the flexibility of choosing different types of latency.
buttons (e.g. much smaller or larger than standard keyboard but- Our Arduino firmware can be programmed onto any Arduino-
tons), and the ability to use thresholded analog inputs to trigger compatible device that supports USB–keyboard emulation, includ-
digital inputs. ing Arduino Leonardo, Arduino Due, Teensy 2, and the Teensy 3.
Likewise, when turning to digital outputs, the StimSync sta- This provides an inexpensive, flexible and easy to use platform for
tistically outperformed the Measurement Computing 1208 fs. We conducting experiments. In addition, we have produced a limited
suspect this is due to the fact that controlling the seven digi- number of custom printed circuit boards that we will sell to inter-
tal outputs of the StimSync requires transmitting only a single ested scientists. These boards include snap-fitting sockets that are
byte of data over the serial port, whereas most devices require compatible with many available analog sensors. Our aim is not to
a sequence of bytes (and calling an external library). Regardless, mass market these, but rather establish the market potential for
both devices probably provide suitable timing for most neuro- larger production runs.
science studies. It should be noted that the 1208 fs does provide
true analog outputs, whereas contemporary Arduino-compatible
Acknowledgments
devices only provide pulse-width modulation (PWM) outputs (with
the exception of the Due that provides true digital to analog sig-
We are selling a limited number of devices. Our goal is to sell
nals). Again, our aim is not to criticize proprietary devices, but
these near our cost. While not our intention, we may make a small
rather to empower scientists with a flexible open source alterna-
profit selling these devices. All our software is distributed under a
tive.
BSD license, and we provide industry standard Gerber files of our
For all input and output devices, we did observe a few outlier
printed circuit board. Any user or vendor is free to clone our design
trials with unusually long latencies. We suspect these effects are
and sell them as they wish. This work was supported by the National
common in real world studies that attempt to present complex
Institutes of Health (R01 DC009571).
stimuli using commodity multitasking operating systems that are
not designed for real time precision. Furthermore, careful inspec-
tion of Figs. 6 and 8 reveals that there is some timing autocorrelation References
between trials. Similar effects can be observed in the data of
Abrams L, Jennings DT. VoiceRelay: voice key operation using visual basic.
Plant and Turner (2009). Again, we suggest that the size and fre-
Behavior Research Methods, Instruments & Computers 2004;36(4):
quency of these errors is not significant for most neuroscience 771–7.
studies. Chambers CD, Payne JM, Stokes MG, Mattingley JB. Fast and slow pari-
For situations where the USB human interface device mode etal pathways mediate spatial attention. Nature Neuroscience 2004;7(3):
217–8.
does not provide sufficient temporal precision, our device also sup- Dalrymple-Alford EC. Response-key input via the IBM PC/XT/AT’s parallel printer
ports a ‘microsecond’ precision mode. By attaching a sensor to port. Behavior Research Methods, Instruments & Computers 1992;24(1):
the output device (ambient light sensor attached to a computer 78–9.
Hollinger A, Steele CJ, Penhune VB, Zatorre RJ, Wanderley M. fMRI-compatible
screen, microphone attached to computer speaker) one can log electronic controllers. In: Proceedings of the 2007 international con-
button response times or send electrical signals on the stimulus ference on New Interfaces for Musical Expression (NIME07); 2007.
and response onsets to another device (e.g. time stamps logged for p. 246–9.
James GA, He G, Liu Y. A full-size MRI-compatible keyboard response system. Neu-
intracranial recording). In addition, in situations where precise tim- roimage 2005;25(1):328–31.
ing is required, it is worth noting that the microcontroller inside Kugel H, Bremer C, Püschel M, Fischbach R, Lenzen H, Tombach B, Van Aken H,
the StimSync can be reprogrammed to actually run the experi- Heindel W. Hazardous situation in the MR bore: induction in ECG leads causes
fire. European Radiology 2003;13(4):690–4.
ment, removing the complexity and variability inherent with the
Markham MR. An interface for controlling external devices via the IBM
use of a multitasking computer. For example, the StimSync could PC/XT/AT parallel port. Behavior Research Methods, Instruments & Computers
switch on and off devices connected to the digital outputs and 1993;25(4):477–8.
Mathôt S, Schreij D, Theeuwes J. OpenSesame: an open-source, graphical experi-
record responses observed on the digital inputs. While this pre-
ment builder for the social sciences. Behavior Research Methods 2012;44(2):
cision is beyond needs of most users, limits the types of output 314–24.
devices, and requires a high level of programming proficiency, it Morris CC. Using the IBM-compatible microcomputer’s serial port as an
does emphasize the flexibility of Arduino-based hardware in the input–output interface. Behavior Research Methods, Instruments & Computers
1992;24(3):456–60.
laboratory. Nakamura T, Fukuda K, Hayakawa K, Aoki I, Matsumoto K, Sekine T, Ueda H, Shimizu
The StimSync provides an open source alternative for measur- Y. Mechanism of burn injury during magnetic resonance imaging (MRI)-simple
ing these errors, complementing the proprietary BlackBoxToolkit. loops can induce heat injury. Frontiers of Medical & Biological Engineering
2001;11:117–29.
As a validation tool, these devices can help evaluate future hard- Peirce JW. PsychoPy – psychophysics software in Python. Journal of Neuroscience
ware and software. The sheer variety of commodity devices means Methods 2007;162(1–2):8–13.
that any study can only evaluate a small number (e.g. Plant and Plant RR, Turner G. Millisecond precision psychological research in a world of com-
modity computers: new hardware, new problems? Behavior Research Methods
Turner, 2009) on a limited set of computers. The StimSync pro- 2009;41:598–614.
vides an affordable method for a scientist to evaluate their own Schubert TW, D’Ausiliob A, Cantob R. Using Arduino microcontroller boards to mea-
equipment and validate the timing of their experimental software. sure response latencies. Behavior Research Methods 2013 [in press].
C. Rorden, T. Hanayik / Journal of Neuroscience Methods 227 (2014) 90–99 99

Segalowitz SJ, Graves RE. Suitability of the IBM XT, AT, and PS/2 keyboard, mouse and Tyler MD, Tyler L, Burnham DK. The delayed trigger voice key: an improved
game port as response devices in reaction time paradigms. Behavior Research analogue voice key for psycholinguistic research. Behavior Research Methods
Methods, Instruments & Computers 1990;22(3):283–9. 2005;37(February (1)):139–47.
Sommer J, Deppe M, Jansen A, Krach S, Knecht S, Ringelstein EB. A cheap Ulrich R, Giray M. Time resolution of clocks: effects on reaction time
to build and easy to use response box for fMRI-experiments. Neuroimage measurement—good news for bad clocks. British Journal of Mathematical and
2004;22(S1):TH337. Statistical Psychology 1989;42(1):1–12.

You might also like