LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-20-2008, 09:42 PM   #1
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Rep: Reputation: 15
Linux box to control electrical devices?


I would like to use a linux box and cron to control a series of electrical devices for a project. The only thing I can find is an old paper on how to wire the pins of the parallel port to a set of relays but the paper is not the greatest and it is old so I am looking for the newest techniques for turning a cheap pc running linux into a control box for a number of electrical devices.

Any help is appreciated.
 
Old 07-20-2008, 10:03 PM   #2
johnson_steve
Senior Member
 
Registered: Apr 2005
Location: BrewCity, USA (Milwaukee, WI)
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152

Rep: Reputation: 46
Well you need the relays they are the only way to electricly switch alternating current. traditionaly the parallel port because this makes the control circuit very simple. alternitivly you could make a circuit with a microcontroller that attaches to the serial or USB port to control the relays but USB -> parallel adapters are cheap enough that I would just hack one of those up.
 
Old 07-20-2008, 10:09 PM   #3
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
How are you able to control multiple relays via the parallel port? Can you write the controlling program in Perl or PHP? Are there any tutorials on how to control the parallel port or do you need to have experience in writing device drivers?
 
Old 07-20-2008, 10:30 PM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by vbsaltydog View Post
How are you able to control multiple relays via the parallel port? Can you write the controlling program in Perl or PHP? Are there any tutorials on how to control the parallel port or do you need to have experience in writing device drivers?
You simply send values directly to the /dev/lp0 device:

echo -e -n "\x48" > /dev/lp0

Well ... not quite like that - as soon as the device is 'closed' the driver resets it. So you need to open the device in your controller program; you can control the data lines by writing a byte and you can control the signal lines via IOCTL messages.

Since you will be using 'cron', you will need to:
a. save the state of all relays in a file somewhere
b. design your relay board to 'latch' the state of relays - easily done by toggling one of the signal lines; if you don't do this, all relays will switch off when your program exits.

You might have to have a peek at the kernel's parallel port driver to see what IOCTLs you can use.

Alternatively you can search the internet for commercial relay boards which can be controlled either by the serial port or the parallel port. If you look at the Advantech web site for example, you can get RS485 modules which have multiple contact closures - all you need in addition is an RS232-RS485 converter (which Advantech also sell) - about $400 all up. But unless you can do your own electronic design (or find a kit in an electronics hobby shop), $400 is about what it will cost.
 
Old 07-20-2008, 10:37 PM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Oh, I forgot to say - if you're playing with the mains lines, and especially where inductive loads like motors are involved, you'd better know what you're doing or you can really hurt yourself (and even destroy your computer). For example, double-pole double-throw relays have a special class which guarantee "break-before-make" - a feature which is extremely important in some situations (otherwise the relay shorts through your power supply - a spectacular sight).
 
Old 07-20-2008, 11:09 PM   #6
johnson_steve
Senior Member
 
Registered: Apr 2005
Location: BrewCity, USA (Milwaukee, WI)
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152

Rep: Reputation: 46
$400! I did this years ago (in dos) for a couple of bucks with a chopped up printer cable and 8 relays from the local surplus shop. of course I am the cheapest bastard you will ever meet and have been doing circuit design for over 15 years so YMMV. you might want to use opto-isolators on your parallel port. flyback diodes on any inductive loads couldn't hurt either. if you use a USB -> parallel adapter worst case you fry that. I highly doubt anything would make it back to your computer. I never had any trouble with the one I built and it didn't have any protection not even a fuse. I only used it for simple stuff like lamps and fans.

Here is an example of a very simple one like what I had:

http://www.instructables.com/id/Peri...-screen-saver/

Edit:
110v probably wont kill you but just to be safe; take off your wedding ring, wear rubber soled shoes and always keep one hand in your pocket. or you could just not touch it while it's plugged in.

Last edited by johnson_steve; 07-20-2008 at 11:20 PM.
 
Old 07-21-2008, 05:16 AM   #7
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Well, I really wouldn't encourage people to mix low and high voltages in proximity unless they really know what they're doing. Otherwise I can see any number of violations of the National Electrical Code and that's just a start. I've seen some absolutely dopey wiring and wondered that more people don't fry themselves. 110V will still kill if you grabbed the live and neutral, so I never tell people "110V probably won't kill you" - that just seems to be encouraging them to do silly things.
 
Old 07-21-2008, 07:07 AM   #8
johnson_steve
Senior Member
 
Registered: Apr 2005
Location: BrewCity, USA (Milwaukee, WI)
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152

Rep: Reputation: 46
Quote:
Originally Posted by pinniped View Post
110V will still kill if you grabbed the live and neutral, so I never tell people "110V probably won't kill you" - that just seems to be encouraging them to do silly things.
It ain't the voltage it's the current and the path it takes through your body. a stun gun will send 10,000 volts through your body but it only travels about 2.5"

110v (or less) can kill you if it goes through your heart, hence me telling him to keep 1 hand in his pocket and wear rubber soled shoes. I think you're a bit more cautious (wise) then I. Maybe I'm just silly because I've been zapped to many times. or spend to much time playing with tube amplifiers that run at 140v - 400v DC.

Quote:
Originally Posted by pinniped View Post
Well, I really wouldn't encourage people to mix low and high voltages in proximity unless they really know what they're doing.
I don't understand this comment. isn't this what relays were designed for? how is that any more dangerous then futzing with a lamp, fan or vacuum cleaner? it's true that maybe he could fry the computer if something went wrong and the relay is wired right to the mother board, but he said; "I would like to use a linux box and cron to control a series of electrical devices for a project." to me 'old linux box' reads "some crap I have in the basement or can get of craigslist for $50" far less then the $400 you suggest spending. then again I drive a $900 ford taurus. Now I'm not encouraging any silly behavior. you should always disconnect the power before you work on anything (not that professional electricians do.) but I'm not going to try to scare someone either. I'm not an electrician by trade, but I did go to school for it. the advice I gave him about his ring, pocket and shoes is exactly what my teachers told me.

Last edited by johnson_steve; 07-21-2008 at 07:14 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-Linux (electrical) query about TRIACS re: why their MINIMUM current requirement? GrapefruiTgirl General 6 06-10-2008 04:48 AM
How to control several devices through one parallel port? Vagant Linux - Hardware 3 06-06-2007 08:08 AM
Remote control of Linux box via Windows Pc at work Azalar Linux - Networking 1 09-13-2006 06:07 AM
Using WinXP to remotely control Linux box RDP? VNC? Fisslefink Linux - Networking 4 03-14-2005 12:38 AM
remotely control linux box thevariegator Linux - Newbie 23 03-21-2003 10:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration