SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Morrog
#22405
Is there any way to control control the pins on a serial port (9-pin) from software? I'd like to hook up some LEDs to the pins and control each seperately. That would make things really simple, rather than having to hook up a PIC and sending it data to decipher to control the LEDs, I can just use software to control each serial pin and hook LEDs straight up (with resistors of course).
By oPossum
#22406
You can control TxD (3), DTR (4) and RTS (7). Pin 5 is ground, all the others are inputs.

For Windows use the EscapeCommFunction() API call, for Linux/MacOS I think it is IoCtl().
By Morrog
#22413
Hmm yeah only 3 pins. I've decided to use parallel instead, since I'd like about 8 pins. I hooked the port up to my multimeter to do some voltage tests and it seems this will be a tad bit trickier than I'd like. Apparently when the data bit is 0 the voltage is 4.3. When the data bit is 1, the voltage is 4.4. Now this is only on data line 1 (pin 2 and pin 18[gnd]).

Not being too familiar/experienced with electrical engineering: How would I block the current when it isn't over 4.3voltages?
By Morrog
#22416
Actually, the strange voltages only occur when the Control bits are all 1. When they're all 0 the voltage is always 0 (no matter what data is). Something must be wrong somewhere ...
By Kuroi Kenjin
#22428
Pin1 is the strobe signal, AKA data latch. I don't know a heck of a lot about LPT port, since I'd just go with the PIC on the serial port.

I think the LPT port is a standard 0V @ 0, 5V @ 1 I/O. Did you check to make sure you were outputting data (instead of inputting with the port floating high)? 4.4 and 4.3 are essentially the same voltage.

I did a quick google search. These might help:
http://engr.nmsu.edu/~etti/fall96/compu ... inter.html
http://www.lvr.com/parport.htm
By OldCow
#22440
To change the printer (parallel) port output Data (pins 2 to 9),
you have to tell Windows not to mess around with it. Otherwise
it may try to use it periodically and your settings disappear.
I think that is why you read 4.4V when you set it to 0.

The printer (parallel) port of a PC has the following pin out:
(Note that if you use a "printer cable", the connector at the
other end has 36 pins and the pinout is different.)

1: -Strobe (pulse output)
2 to 9: Data Bit 0 to 7 (output)
10: -Acknowledge (input)
11: Busy (input)
12: Out of paper (input)
13: Selected (input)
14: -Auto feed (output)
15: -Error (input)
16: -Initialize (output)
17: -Select (output)
18 to 25: Ground
By Morrog
#22458
I've checked again and again to be sure I'm hooking in to pin2 and pin 18, so I'm not sure why it stays at 0 when it should go up to 5, or why in bi-directional mode it goes from 4.3 to 4.4.
To change the printer (parallel) port output Data (pins 2 to 9),
you have to tell Windows not to mess around with it.
How do I tell Windows not to mess around with it?

I'm using the inpout32.dll method to write directly to address 0x378 (data) and 0x37A (control). Windows XP SP2.
By Kuroi Kenjin
#22459
I think that maybe the issue... starting with win XP (or even ME), microsoft no longer allows direct memory/IO access considering it a security hole. The closest you can get to now, is by using the Win32 API and use CreateFile() opening the file "LPT1" (or whatever number LPT it is). I do know that they put in the SerialPort into the .net framework (2.0 and 3.0), but I don't know if LPT support is in either of those.
By Morrog
#22468
That's why I'm using inpout32.dll. It loads a ring0 driver so it can write and read to memory.

Controlling the port software side obviously works, because I can get that 4.3 to 4.4 voltage change on the port. Something else must be amiss.