Jump to content

Use Serial/RS232 Port to control LEDs?


Ano Ano

Recommended Posts

Can Labview control the LED's via the PC parallel port (old printer port)?

Much better than serial (8 bit bi-directional, i.e digital inputs OR outputs :) ). My favourite low cost digital IO. Fantastic for foot-switches and system monitoring and essentially free. Unfortunately, not many PCs come with them nowadays.

http://digital.ni.com/public.nsf/allkb/B937AC4D8664E37886257206000551CB

There are also a couple of examples in the "Example" finder.

You have to check whether your motherboard already has pull-up resistors (most do, some don't). Then you can connect 5V LEDs directly or just short them to ground (if using as digital in). Note that logic is reversed since you sink to ground THROUGH the IO line to light an LED. I always stick a transistor in there too to be on the safe-side, since if you get it wrong...you blow the port. It also inverts the logic so I don't get confused (happens regularly).

http://www.beyondlogic.org/spp/parallel.htm

  • Like 2
Link to comment

Then you can connect 5V LEDs directly or just short them to ground (if using as digital in).

This would actually need to be checked. If a computer comes with a parallel port it's likely to be 3.3V, not 5V. I know the old Dells we still have in the lab are 3.3V parallel ports.

In the end, it's probably better to go with an off-the-shelf cheap USB-based digital I/O module. There's tons of these on the market.

Edited by Saverio
Link to comment

This would actually need to be checked. If a computer comes with a parallel port it's likely to be 3.3V, not 5V. I know the old Dells we still have in the lab are 3.3V parallel ports.

Why is 3,3v a problem?

In the end, it's probably better to go with an off-the-shelf cheap USB-based digital I/O module. There's tons of these on the market.

Chicken :lol: Seriously though. This is kindergarten stuff. But if you've never used a screwdriver as a chisel, then maybe it's better to just throw money at it. :D

melman.jpg

Not one of mine by the way :P

Edited by ShaunR
Link to comment

Why is 3,3v a problem?

I didn't say it was a problem. I said it needed to be checked. You would need a different resistor value and what's considered "high" would be different.

Chicken :lol: Seriously though. This is kindergarten stuff. But if you've never used a screwdriver as a chisel, then maybe it's better to just throw money at it. :D

And when your motherboard gets damaged because you connected something improperly, or did not properly ground, or did not properly account for potential overvoltages or voltage spikes, then we'll see what's cheaper: buying a new computer or buying a cheap digital I/O module. :P

P.S. I always use a screwdriver as a hammer. :D

Link to comment

I didn't say it was a problem. I said it needed to be checked. You would need a different resistor value and what's considered "high" would be different.

Parallel ports are TTL compliant. So that means anything between 2.7v and 5v is considered "high" (conversely 0-0.5v is low). A diode only needs a forward voltage of about 2v so it's not a problem. The resistor isn't there as a potential divider. It's there to limit the current so you don't fry the port and/or the LED. For this purpose, the lower the voltage, the less current->good thing! A 4k7 resistor (470 with pull-ups if you want to be ultra safe) will give you about 1ma@5v with no pull-ups, or, if you like 0.7ma@3.3. If you find its not bright enough then a 1K will give you 5/3ma but I wouldn't go any lower without buffering.

But it's not hard. You can forget the maths. A 10k pot and an ammeter will give you the perfect values for your port. Just twiddle it (the technical term) until you get the brightness you want whilst keeping an eye on the current. You can then measure it and find a preferred value for when you "productionise" it

You'll be wanting to drive LCD displays in no time ;)

3.5 Using the Parallel Port of the Computer (click on "more" to expand the article)

And when your motherboard gets damaged because you connected something improperly, or did not properly ground, or did not properly account for potential overvoltages or voltage spikes, then we'll see what's cheaper: buying a new computer or buying a cheap digital I/O module. :P

P.S. I always use a screwdriver as a hammer. :D

You'll only blow the port. If you never use it, you won't miss it :P

Edited by ShaunR
Link to comment

Much better than serial

Indeed it is! I got the parallel port working (for the serial port I could only control one LED). I had to go to bios to tell it to use only the EPP for the parallel port (LPT1)

http://imageshack.us/photo/my-images/267/parallelport.jpg/

The problem though is that when I boot/start the PC, the port automatically turns on all LEDs. How can I "tell" the PC to keep the LEDs "off" until I use them in Labview??

Link to comment

The problem though is that when I boot/start the PC, the port automatically turns on all LEDs. How can I "tell" the PC to keep the LEDs "off" until I use them in Labview??

That's a classic problem; [low cost] DIO cards have a tendency to set their outputs high when initialized by software. I've solved it previously by having one of the outputs go to a on after delay relay which turned on control power to the rest of the outputs. Not a great solution (relying on the problem to solve the problem), but we needed something cheap and immediate.

EDIT: Hit post and realized you can have a switch that turns on "control power", which is power to anything that can move. The outputs of the parallel port can't drive much, so you'll need a transistor, relay or the like if you're driving something more than a LED.

Edited by Tim_S
Link to comment

The problem is that when the computer starts, it turns on by default the LED without me running the Labview software.

How can I change this?

You don't; the pull-up resistors keep the level high until told otherwise. You invert the output instead.

  • Like 1
Link to comment

Hello,

I built an application that turns off the LED and then auto-closes. I edited the registry so that it runs this application during startup.

The problem is that the PC starts, the application opens and closes, but it does not switch off the LEDs. I think its because the drivers (NI? Win7?) may not load in time.

Any advice/idea on how to tweek this and make it work?

Link to comment

Do you have error handling to diagnose what's happening? If a program needs drivers, the OS should load them automatically, preventing the application from executing before they're ready.

I am using as base code the "Out Port8.vi" (see http://imageshack.us/photo/my-images/708/lptoff.jpg/). Top part works when the driver is found. Bottom part is vice versa. I placed a small delay to give the OS some time to seek drivers and varied the time from 500 to 5000 and it did not matter much as it cannot located the drivers. as a .vi the program works perfect. as an .exe it does not.

Why does it have hard time locating the drivers?

Link to comment

Hello,

It seems that the error that Labview produces is "−4850" which states that:

"LabVIEW does not support this device driver on Windows Vista or later."

This is strange though as the program works as a .vi but does not work as an .exe

I am running LV2010.1 & Win 7

Is there a solution for this driver issue?

Link to comment

A warning about those VIs: Vista and Windows 7 impose more strict security on direct access to hardware. If you want to manipulate the parallel port, use VISA. There's an example that ships with LabVIEW.

That said, the likely reason is that the required DLL is not being copied to you application's data folder. This is not surprising, given that those VIs shouldn't be used in the first place. See here: http://digital.ni.com/public.nsf/allkb/496CD7613F331EA4862571E200633507

  • Like 2
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.