how to switch the input pin of an lpt port to ground using an optocoupler

Thread Starter

nilsbo

Joined Jan 6, 2017
2
Hi, thank you for your time. I am a newbie.

I am building a operant conditioning box. In this set up I have nose poke port that detect an IR beam interruption. This I have build myself with a set of Kinbright LED and photo-transistor. This switches a 5V power supply on and off. This signal I want to read with the lpt port pins. As far as I understood this cannot be done directly as the pins are always pulled up high by the computer. Therefore I bought some optocouplers (Sharp PC817X2NSZ0F (2420048 at farnell)). These I wanted to use to switch the input pins to ground to make them 0V.

First I wanted to test if it worked. In the first test I used an arduino digital out pin to mimic the signal. Nothing happened. I think it is because the arduino does not supply enough power. In the second test I applied the power directly from the power supply that I want to ultimately use anyway. Again, no effect or change at all on the output side of the optocoupler.

Can any of you please advise me on how to solve this and or read the datasheet of the optocoupler so I can understand what input it needs and what input is too much?

thank you
Nilsphoto 1.JPG photo 1.JPG photo 1.JPG
 

Attachments

MrChips

Joined Oct 2, 2009
30,807
You most likely killed the optocoupler already. Get a new one.

To begin, you need a current limiting resistor in series with the LED side of the optocoupler. A resistor around 330Ω to 470Ω is suitable.

Next, you need a load resistor from +5V to the collector of the photo-transistor. 1kΩ to 4.7kΩ will be suitable.
 

Alec_t

Joined Sep 17, 2013
14,314
the pins are always pulled up high by the computer.
What computer and are the pins configured as inputs?
If they are so configured then the internal pull-ups would normally be very weak, so the pins could safely be shorted to ground.
 

ClassOfZero

Joined Dec 28, 2016
114
The parallel printer port in an IBM PC clone, IEEE1284. This is 3-byte interface, bidirectional data, unidirectional status, and bidirectional control. You can't do bit manipulations through the BIOS, but many compilers give you direct access to the ports.

https://en.wikipedia.org/wiki/Parallel_port

ak
I'm guessing you meant 3 port interface. Whether the data port is bi-directional depends on the mode the port has been set in the bios.

Port access used to be easy under windows pre NT kernel for windows (direct access under win 9X was possible but still left the port open for other processes to gain control of), to correctly access hardware ports directly you will need a device driver, the underlying OS doesn't allow user space to directly access hardware, any other method is a hack and bypasses the "security" of the kernel. Directly modifying the IOPL is not the way to do it, at best it's a hack, at worst it's a security hole, in between it's messy.

The official way is you need to "grab" a port for use. Whether you want to share it is up to you.......Yeah it's consulted way to do things.



Linux is a little easier, but you still need to gain permission from the kernel.

Anyways to the question in hand, the following link shows a way to use opto couplers, input to hardware is 3.3v so change a few values to suit your purpose.
http://www.anderswallin.net/2006/08/optoisolator-cards-for-mesa-5i20-servocard/#more-77
 

Thread Starter

nilsbo

Joined Jan 6, 2017
2
thank you all for your time.

The resistor to protect the LED of the optocoupler was what was lacking. I now have a working circuit.

cheers
Nils
 
Top