Sending a 'click' to the parallel port from a device

179 views
Skip to first unread message

Daniel Riggs

unread,
Nov 21, 2015, 3:00:20 PM11/21/15
to psychopy-users
Hello!

I'm to trying to record 'yes' or 'no' clicks in the parallel port from a homemade switch, like the one described here at this great blog by Matt Wall:

https://computingforpsychologists.wordpress.com/2012/04/15/how-to-make-your-own-parallel-port-response-boxes/

It's literally a box with two on/off pushbutton switches. One is running to pin 2, and the other to pin 4, and they're both sharing a ground pin.

I've never worked with hardware at this low of a level, so I hope you'll be gentle. I've been successful in getting psychopy / pyparallel to read and set data (I've been messing around lighting up led's with a breadboard), but I can't influence that data from the switches (or from the breadboard).

For example, if I set pin 2 high from a script (set it to '1'), it doesn't matter if there is a closed electrical circuit or not, readPin() always returns 1. I was under the impression that it would be set to 0 if there was no electricity running to it.

I tried messing with other pins, like the 'autofeed' status pin (14), and again can to turn things on and off via the computer, but don't know how to change any data from outside of the computer.

Lastly, since this is a PCI-E card (it didn't come built into my motherboard), my research lead me to wonder if it has something to do with the mode the port is using. I tried manually changing the port to EPP mode via the pyparallel class, but to the same effect. Hoping someone will have some insight. Thanks for your time!

Dan

Richard Höchenberger

unread,
Nov 21, 2015, 3:27:36 PM11/21/15
to psychop...@googlegroups.com
Hello Dan!

On Sat, Nov 21, 2015 at 9:00 PM, Daniel Riggs <daniel...@gmail.com> wrote:
I've never worked with hardware at this low of a level, so I hope you'll be gentle. I've been successful in getting psychopy / pyparallel to read and set data (I've been messing around lighting up led's with a breadboard), but I can't influence that data from the switches (or from the breadboard).

Just to be sure it's not a problem with your code or the Python interface per se, I would recommend you try out a tool like the Parallel Port Tester and see if the pins are set to their respective high/low states when they should be :)
 
For example, if I set pin 2 high from a script (set it to '1'), it doesn't matter if there is a closed electrical circuit or not, readPin() always returns 1. I was under the impression that it would be set to 0 if there was no electricity running to it.

I cannot follow here. I thought you hooked up that button box to your parallel port, and the box is going to generate voltage. Why would you then want to control pins from within a script? Or do you mean: you connected pin 2 to another pin, set pin 2 to high, but cannot measure a high voltage on that pin?

Cheers,

    Richard
 

Daniel Riggs

unread,
Nov 21, 2015, 3:58:45 PM11/21/15
to psychopy-users
Hello Richard!

Sorry I wasn't clear. I made a button box, but since I was running into problems I hooked up a breadboard with some led lights to to the parallel port just to rule out the port itself as an issue. I had used the Parallel Port tester on Windows, but I mainly use linux, so I breadboarded it and was able to use the pyparallel class (that psychopy uses) to ensure that I could read and set data from the script. The parallel port seems to be working correctly. I actually don't want to control the device from a script, I was just using a script to try to understand what was happening at the parallel port.

The goal is just to register when one of these buttons is pushed. The button box just has two switches that would close the circuit, so they don't generate voltage by themselves. My plan (apparently flawed) for registering a click was to have a pin set high, but since the switch would not initially depressed, I thought a readPin() call would return 0 since the circuit wouldn't be closed. The script would detect a button press by continually calling readPin()  until it returned 1. For example: 

If I initialize pin 2 to high (1), and the circuit is closed (the button is depressed), readPin(2) returns 1. This is what I expected.
Now if I break the circuit (the button is not pressed), readPin(2) still returns 1, when I expected it to return 0.

Hopefully I've made myself a little bit clearer, and maybe you have some suggestions for a different approach? I know other people have gotten this working (their button boxes didn't produce voltage), but they were using different presentation software. Thanks a lot for your patience.

Dan

Richard Höchenberger

unread,
Nov 21, 2015, 4:20:35 PM11/21/15
to psychop...@googlegroups.com
Hi Dan,

thanks for the clarification.

I'm however still a little confused about your setup:

On Sat, Nov 21, 2015 at 9:58 PM, Daniel Riggs <daniel...@gmail.com> wrote:
If I initialize pin 2 to high (1), and the circuit is closed (the button is depressed), readPin(2) returns 1. This is what I expected.

Why would you expect that? As soon as you read from the pin, it does not produce an output voltage anymore, and should effectively have ground potential. Or maybe I'm just confused here :)
 
Now if I break the circuit (the button is not pressed), readPin(2) still returns 1, when I expected it to return 0.

Have you tried connecting e.g. pins 2 and 3 to one another? And only writing to pin 2, while only reading from pin 3?

    Richard

Richard Höchenberger

unread,
Nov 21, 2015, 4:23:18 PM11/21/15
to psychop...@googlegroups.com

On Sat, Nov 21, 2015 at 10:19 PM, Richard Höchenberger <richard.ho...@gmail.com> wrote:
On Sat, Nov 21, 2015 at 9:58 PM, Daniel Riggs <daniel...@gmail.com> wrote:
If I initialize pin 2 to high (1), and the circuit is closed (the button is depressed), readPin(2) returns 1. This is what I expected.

Why would you expect that? As soon as you read from the pin, it does not produce an output voltage anymore, and should effectively have ground potential. Or maybe I'm just confused here :)

Ooooh, do you mean "setting the line connecting my circuit and pin 2 to high (from the circuit), while the pin is set to read mode"? :)

Daniel Riggs

unread,
Nov 21, 2015, 4:30:03 PM11/21/15
to psychop...@googlegroups.com
Yes! That is what I mean: I would like to set the pin high from the circuit.

I'm confused about the 'read mode': is that referring to the different modes available on the parallel port (hence my comment above about trying to use EPP mode, since it allows for data input and output)?

I think I see what you mean about connecting one pin to another: maybe take a signal from a 'high' pin 13 (one of the status pins), and wire it to a data input pin? Then when the button closes the circuit, it hopefully takes the voltage from pin 13 and connects it to the input pin? I'm trying to mess with that now, anything I'm still not understanding? Thanks as always, Richard.

Dan

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/L-vZDiTP7-0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/CAGm-8jP%2BCe%2BYQHweXRFbEmrndjdqLxnRJHroxh-va4tEQqXdVw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Dan Riggs
917-968-6090

Daniel Riggs

unread,
Nov 21, 2015, 4:34:43 PM11/21/15
to psychop...@googlegroups.com
I'm not sure I follow with the pin no longer having voltage after it's been read. At least in my breadboarding, the led remains lit for however long the pin is set to 1. But again, my understanding of this stuff is VERY rudimentary.
--
Dan Riggs
917-968-6090

Richard Höchenberger

unread,
Nov 21, 2015, 5:25:02 PM11/21/15
to psychop...@googlegroups.com
Hi Dan,

On Sat, Nov 21, 2015 at 10:29 PM, Daniel Riggs <daniel...@gmail.com> wrote:
I'm confused about the 'read mode': is that referring to the different modes available on the parallel port (hence my comment above about trying to use EPP mode, since it allows for data input and output)?

actually I haven't worked with parallel ports in some years, so I cannot tell you anything about EPP etc. from the top of my head. What I meant with regard to read and write mode is this:
usually if you have a data generation or acquisition device and set a line to be an output channel, a pulldown mechanism will try to pull down its voltage to ground potential if the channel is set to a LOW state. So if for example you had the following circuit:

pin 2 --> pin 3 <-- pin 4

with pins 2 and 4 set to operate as output, and pin 3 as input, and you were to set pin 2 to HIGH, but pin 4 to LOW, maybe you wouldn't even be able to measure any voltage input on pin 3 because pins 2 and 4 are now also bridged (via pin 3), and the circuit behind pin 4 would pull down the voltage output from pin 2. But I guess this is actually not an issue in your specific case ;)
 
I think I see what you mean about connecting one pin to another: maybe take a signal from a 'high' pin 13 (one of the status pins), and wire it to a data input pin?

 Yes, or install a second parallel port, just to be sure :) Or could you maybe hook up an external voltage source? Usually everything >+3.5V is considered HIGH, so you could try with three AA or AAA batteries or so ;) Generally, I find it extremely useful to have a programmable power supply and a dedicated data acquisition board around the lab somewhere.

All the best,

    Richard

Richard Höchenberger

unread,
Nov 21, 2015, 5:26:58 PM11/21/15
to psychop...@googlegroups.com
On Sat, Nov 21, 2015 at 10:34 PM, Daniel Riggs <daniel...@gmail.com> wrote:
I'm not sure I follow with the pin no longer having voltage after it's been read. At least in my breadboarding, the led remains lit for however long the pin is set to 1. 

Now this is weird, but then again, I am pretty tired and will re-read your messages after a night's sleep. But generally, if a pin is set as input, it should not generate a voltage relative to ground. Are you sure your button box and that pin share ground?

    Richard 

Richard Höchenberger

unread,
Nov 23, 2015, 7:11:41 AM11/23/15
to psychop...@googlegroups.com
Hey Dan,

any news on this one? Did you make any progress? :)

Cheers,

Richard
Message has been deleted

Daniel Riggs

unread,
Nov 23, 2015, 10:42:30 AM11/23/15
to psychopy-users
Hello Richard,

No real news. I contacted the guy who had built a similar box, and he says he's not sure why it's not working for me. He said that "the data pins should have a 5V signal, and if you connect one of them to one of the ground pins, that should drop that signal to 0V and change the pins status", which is what I was hoping for, but no dice. So does this mean that ground is not lowering the voltage enough?

Testing on the breadboard, this would mean that an led between a data pin and a ground pin should not stay lit, right? But in my case it does. It actually only lights when connected to a high data pin and to ground, and remains lit until I set the pin to low from the computer.

I'm kind of at the limit of my understanding, so other than going out there and learning as much as I can about how electronics work (any resources would be appreciated), I'm not too sure what to do.

I suppose my last line of inquiry is determining if my pins are set to input or output, and how to change that. That was my question concerning the different 'modes' of the parallel port, (SPP, ECP, EPP, etc.) which seem to affect whether certain pins can be input or output. Since my parallel port card did not come with the motherboard, it's not something I can change within the BIOS, and my understanding is that the mode is set depending on the device connected to it. The device can send it data telling it what mode to use. Looking at the pyparallel source it had a method to set the mode, but calling it has made no difference yet.

I certainly don't want to waste too much more of your time, and thank you again for your help.

Dan

Daniel Riggs

unread,
Nov 23, 2015, 10:54:19 AM11/23/15
to psychop...@googlegroups.com
I might be an idiot: I had put resistors between the leds and the pins to not burn them out. When I get home later today I'll try connecting it directly to ground and see if the value of the pin changes.

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/L-vZDiTP7-0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

Daniel Riggs

unread,
Nov 23, 2015, 9:01:45 PM11/23/15
to psychopy-users
Figured it out!

Richard, your comments about how a pin is brought low by bring the voltage to ground really helped!

I think the issue is that unless one is able to reliably set the mode on the parallel port, there are only certain pins that will work for this application. I have to use an input pin (in my case, 12 and 13 work). When the switch is depressed and the circuit is closed, the voltage of the pin is brought low to ground and the value is reported as '0' for as long as the button is pressed.

And Richard, your comments and those in an email from Matt Wall lead me to believe that when I was testing with the breadboard, the resistors I was using (due to my general lack of understanding of the process), while keeping the leds from burning out, also kept the voltage from getting low enough to change the value. So in my final setup, I used a 100ohm resistor between each input pin and its switch, following the article cited above. I believe this is to prevent a short circuit.

Long story short, I think only certain pins are available for this in certain parallel port modes.

Also for the rare linux user who is still interested in using the parallel port, the kernel module 'lp' completely takes over the port, and has to be unloaded or pyparallel won't work (it gives an IOError: [Errno 6] No such device or address). You have to run 'sudo rmmod lp' every time you start your computer, or you can blacklist the lp module.

Lastly, there are some methods in the pyparallel code that are commented out, that will allow you to read or set more pins, since some of the pins could not be read from the psychopy class directly. The psychopy class does have a reference to the pyparallel object, so its methods can be accessed from there. For example:

from psychopy import parallel

#get a ParallelPort object
pport = parallel.ParallelPort()

# Try to read status pin 14
# this returns None, with the message:
# Pin 14 cannot be read (by PParallelLinux.readPin() yet)
pport.readPin(14)

# ParallelPort has a reference to its pyparallel object, called port
# note that the 'autoFd()' method has to be uncommented in the
# parallelppdev.py file. This returns True or False
pport.port.autoFd()

So that's it! Very much appreciate the help! Maybe someone else will find this useful at some point. Thank you Richard!


Dan
  


On Monday, November 23, 2015 at 10:54:19 AM UTC-5, Daniel Riggs wrote:
I might be an idiot: I had put resistors between the leds and the pins to not burn them out. When I get home later today I'll try connecting it directly to ground and see if the value of the pin changes.
2015-11-23 10:42 GMT-05:00 Daniel Riggs:
Hello Richard,

No real news. I contacted the guy who had built a similar box, and he says he's not sure why it's not working for me. He said that "the data pins should have a 5V signal, and if you connect one of them to one of the ground pins, that should drop that signal to 0V and change the pins status", which is what I was hoping for, but no dice. So does this mean that ground is not lowering the voltage enough?

Testing on the breadboard, this would mean that an led between a data pin and a ground pin should not stay lit, right? But in my case it does. It actually only lights when connected to a high data pin and to ground, and remains lit until I set the pin to low from the computer.

I'm kind of at the limit of my understanding, so other than going out there and learning as much as I can about how electronics work (any resources would be appreciated), I'm not too sure what to do.

I suppose my last line of inquiry is determining if my pins are set to input or output, and how to change that. That was my question concerning the different 'modes' of the parallel port, (SPP, ECP, EPP, etc.) which seem to affect whether certain pins can be input or output. Since my parallel port card did not come with the motherboard, it's not something I can change within the BIOS, and my understanding is that the mode is set depending on the device connected to it. The device can send it data telling it what mode to use. Looking at the pyparallel source it had a method to set the mode, but calling it has made no difference yet.

I certainly don't want to waste too much more of your time, and thank you again for your help.

Dan

On Monday, November 23, 2015 at 7:11:41 AM UTC-5, Richard Höchenberger wrote:
Hey Dan,

any news on this one? Did you make any progress? :)

Cheers,

    Richard

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/L-vZDiTP7-0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-users+unsubscribe@googlegroups.com.
To post to this group, send email to psychopy-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages