Home Publications Certifications LinkedIn GitHub Email

Binary, Parallel Ports and EEG

EEG machines sometimes use parallel cables to send event markers. These are useful to figure out when certain situations occur, e.g. when a stimulus is shown. When were doing building our EEG experiment, we needed to know how to interface between Python and the EEG hardware.

parallel port
Image from Wikipedia. The female end of a parallel port.

Not knowing anything about how the cables work, we sought to splice an unused cable, only to find a bunch of cables in it. Images like these proved useful:

parallel pins
Image from http://d4web.net. Note the 8 data pinouts (D0 - D7).

With one end of the cable connected to a PC running python, we could use the parallel module (which in this case was already included in the Psychopy library, which we use to draw gratings). This enabled us to activate/deactivate the pins. E.g.:


	from psychopy import parallel
	parallel.setPortAddress(address='/dev/parport0')
	x = 1
	parallel.setData(x)

But what was that actually doing? To the other end of the cable (the one that we spliced), we connected a multimeter. Turns out, when 'x' was set to '1', there was voltage across D0 and ground. When x was set to '2', D1 was active. But when x was set to 3, D0 and D1 were active, but D2 was not!

But the parallel.setData() function and the EEG event markers both support integer inputs from 0 to 255. If each of the eight data pins could only be on or off, there are 2^8 possible pin states, for a total of 256. Hey, it's just binary! If that's true then we can control each pin by having 'x' be a 8-bit binary string, and just converting that to a base 2 integer. So to have only D7 and D1 active:


	x = '10000010' # activate only 2 of the 8 pins
	parallel.setData(int(x,2)) # use the parallel function on the base 2 integer of x

And that worked! And the numbers matched the EEG markers!

Sure, this seemed like an unnecessary exercise to splice the cable, given that we could have just read the to read about what the function does. But a bit of hands-on knowledge is a good thing, and the concept here is practically the same for using GPIO found on things like the Raspberry Pi. Maybe it's possible to run an EEG study/ interface with the machine from a single Raspberry Pi? (assuming it is good enough to display stimuli correctly). Maybe patch the GPIO back to a parallel cable?

GPIO pins
Image from https://learn.sparkfun.com.