# turn on power to physical wire from linux?

How can I put power to some wires [possibly connected via Serial Port?], by using a script? I use Ubuntu. I want to schedule a time [using cron] to automate turning on something, say, an LED, a small motor, anything like that. I just need the power to go on when I run the command, and I can use a transistor or whatever for more power.

How can I do it? My laptop doesn't have a serial port, but I can get a usb-to-serial adapter.

-
Would the Num-Lock LED satisfy "a" LED? :) –  W5VO May 7 '11 at 4:47
@W5V0 no, I meant an "external LED" that I've wired, connected to some port on my laptop –  Matt May 7 '11 at 13:57

What is the something that you want to turn on? You said LED in your question, but then said something in the question. :) I only ask because an LED vs. a solenoid can have very different power requirements. Is there a budget in mind? Do you want something turnkey?

I was going to recommend trying the TI Launchpad, which gives you a micro with a handful of I/O, plus a built-in USB-to-serial adapter, and is Linux-compatible, for a reasonable $5. The price is so good, it's unbelievable. And the tools are free. But if you want to make anything that requires more current than an LED turn on with a serial command sent via cron through Linux, then you'll have to wire up additional components to make it work. If you don't have much of a budget, and want something that looks like it would work out of the box, take a look at this module from Phidgets to see if it's easy enough to get working in Linux. They provide plenty of source code, and have Linux drivers available. There is also the obvious other option, Arduino, which from what I've read works on Linux. I'm just not a fan of the tools, nor the price when compared to the Launchpad. EDIT -- a totally unrelated comment that I just had to share -- today I wanted to get more of the female headers for the Launchpad from Digikey. Well, the two headers cost$1 apiece. I ended up buying another Launchpad, because I would get both headers, as well as a USB cable, the dev board, and an extra MSP430G2 for an extra 3 bucks! Seriously, TI? :)

EDIT (regarding USB-to-serial adapter) -- I am actually having a hard time getting information that this works on the Launchpad. From this post, it sounds like it's possible, but I'm a little confused because some responses talk about the ez430, instead of the Launchpad. I definitely have the MSP430 application UART appear in my Device Manager, but haven't tried to use it in any way. I'll try to play with this next week to see if it really does work.

-
I don't think that I/O on the Launchpad or the Arduino can be controlled via the USB port. –  Leon Heller May 7 '11 at 5:29
the USB port is actually a USB-to-serial adapter, and you can implement your own serial command interpreter on the MSP430. At least, that's what I've read. If for some reason that's really not true, then he would have to use some of the software serial implementations available on the net. But if you plug a Launchpad into the PC, it will come up as both a USB-to-serial adapter, as well as a USB FET for debugging. –  Dave May 7 '11 at 5:53
I'll check for more information, as I don't want to give the OP any bad information here. I hope I didn't recall something incorrectly. –  Dave May 7 '11 at 6:00
Arduino does work on Linux, and I was considering buying one. But this thing you have here is a lot cheaper, does it have lots of the same features? Could I make a Strobe light? A POV clock? or POV display, etc? that would be really awesome –  Matt May 7 '11 at 12:59
Agreed - right now, the TI Launchpad is the ridiculously cheap way to go. –  Toybuilder May 7 '11 at 13:41

If you only want to switch a single LED, programming a microcontroller is overkill. Use a USB->serial adapter, and toggle DTR or RTS pin using the serial API of your scripting language. (I recommend Python + pySerial, but every mainstream language will have some way of addressing serial ports.) This will only supply a few mA, probably enough to dimly light an LED. You can get more current by adding a transistor. The details of that are out of scope for this question.

edit: For ubuntu, first install pyserial:

sudo apt-get install python-serial


Then try something like the following:

#!/usr/bin/python

import serial

s=serial.Serial('/dev/ttyUSB0')
s.setDTR(1)

-
Can you give me an example code? that's kind of what I want! If I can find my serial adapter.. then I could try it –  Matt May 7 '11 at 13:55
@Matt, example code is not normally given on here. We are about designing the electronics, if you just want to know how to make the RTS go high on an RS232 cable then you will get great responses on SO. @markrages may have code available, but he may not even have ubuntu. –  Kortuk May 8 '11 at 1:31
oh.. I see. well I posted the Q here because it was electronic-related. lol –  Matt May 8 '11 at 13:42