views:

206

answers:

6

I've got a potential client who wants a database driven app, either in Java or Python driving MySQL or PostgreSQL, but we need to get input from an external machine, such that every time this external machine closes a microswitch, a value in the database gets decremented and it shows up on the app.

Also, when that value in the database reaches zero, we want to turn on a light on the external machine until the operator does something in the GUI, and then we want to turn off the light.

My client's proposed solution is to wire the microswitch into one of the keys on the keyboard and just avoid using that key for anything else (he suggested the F12 button), and to control the light by playing a sound file through the left channel to start it, and the right channel to stop it.

That seems a little cheesy to me, especially the wires going into the keyboard - and not just cheesy, but also a potential source of hardware problems if the operator accidentally pulls out a wire. I'd much rather something that either went into the USB port or possibly an internal card, just to keep the wiring around the back and away from the operator. But since the client hopes to sell a lot of these, he wants to keep the price down.

I realize this isn't strictly "programming", but it's to solve a problem in a program I'm writing. So I'm asking you: is there a cheap hardware device that would do what I want?

+2  A: 

Hmmm... Computers still come with serial (RS-232 UART) and parallel ports right? I believe these are pretty easy to wire things up to, the "protocols" (especially for the PP) are too simple to even be called that, and the components are cheap.

It's very easy to find info on the net from hobbyists who connect up their robots etc. using these ports. E.g.: http://www.interfacebus.com/Design_Connector_Parallel_PC_Port.html

But I don't know, perhaps USB is just as simple.

j_random_hacker
Actually, I mentioned USB because it seems to me that computer makers have largely dropped RS-232 and parallel, haven't they?
Paul Tomblin
OK, I must be living in the past :) Marcelo's USB-UART bridge could be the way to go then.
j_random_hacker
yes, unfortunately.
Jason S
+3  A: 

I'd use one of those USB<->UART bridges. Those chips translate between USB and serial port (RS232 - the voltage levels) signals. They are seen as a COM port on windows or a tty on linux

They have all 8 signals from the serial port standard. You could use one of the input pins to get your microswitch and an output pin to drive a buzzer.

Yes, that would add to the cost, but they are very cheap in large quantities. Also, the project is so simple that, if there isn't already done on the 'net a student could do it in a couple of days.

Marcelo MD
+3  A: 

Cheap hardware device: Arduino

It's small, cheap, programmable, and very easy to learn how to program for (pretty much C++). It can interface with either USB or Serial depending on the board you get. It's the hardware hacker's wet dream when it comes to tinkering around with wierd projects that need to interface with a computer somehow. You could even wire up an LED for notifying the technician directly to the arduino.

Pros: Very little hardware knowledge needed to complete your project. All the wiring for reading a switch and lighting an LED are on the arduino project's site.

Cons: Learning how to interface your software with the Arduino Library might take a little bit of time.

Josh W.
Looks cool! +1.
j_random_hacker
OP just wants to read a *switch*, for goodness sake.
Jason S
He asked for a small cheap hardware device, that's what I linked. And reading a switch like what he's asking for is one of the example tutorials on the Arduino site (Learning -> Digital IO - Debounce, for anyone else reading)
Josh W.
ok, fair enough, +1. (a quick look around reveals very little that is less expensive except for USB <-> serial converters.)
Jason S
@Josh, "Debounce" is an example of reading a switch on the Arduino and turn on an LED on the Arduino, but not of how to read that information on the PC. I can't find any examples of interacting with the PC, which is the only thing I need.
Paul Tomblin
Oh wait, I just found the "Serial" documentation. This board looks like overkill for what I want, but on the other hand these boards are dirt cheap.
Paul Tomblin
+3  A: 

To expand on Marcelo's answer, in case you want to prototype this quickly, FTDI does make a standalone board, the UB232R, which is about US$20 in single quantities. You could use the CTS pin as an input (with an appropriate pullup, e.g. 10K) from your device to the PC.

All you need besides one of these is a USB cable and a way to connect the board to your microswitch. (not sure whether a solderless breadboard would be appropriate / robust enough, but it's a quick & dirty solution since the UB232R has a DIP8 footprint) No external power supplies, no need to make a custom PC board, no need to program anything other than your PC, no need to learn any hardware drivers beyond the basic communication port services, assuming your PC's communication libraries include features to read the CTS pin status.

edit: for an output, you can use the RTS pin. If you have more inputs and outputs than this, you'll want to think a little more carefully....

Jason S
Since I'm the sort of software guy who is dangerous with screw drivers, do you know where I could find somebody to design and build a device?
Paul Tomblin
build what device? buy a UB232R, read its datasheet, buy a solderless breadboard (the holes on each row are tied together), buy a USB cable, put the UB232 into the solderless breadboard, get hold of a 10K resistor, connect the 10K between Vcc and CTS, connect the microswitch between CTS and GND, program your PC.
Jason S
oops, forgot to say "connect USB cable between UB232 and PC" ;-)
Jason S
...and you may need some 22 gauge solid hookup wire to connect the microswitch to the breadboard. somewhere around you at work there must be someone with electrical skills....
Jason S
This will give you a cheap *prototype*, but costs of moving this to quantity production will be a lot more significant.
Roddy
agreed. Sometimes the largest development cost is software development, so if you can prototype something quickly to get a software platform going, then later come up with low-cost compatible hardware, you'll get a good head-start to a good long-term solution. I suspect the lowest cost system would probably be a custom board based around an FTDI chip or a microcontroller capable of USB interfacing. Still, when you or the OP refers to quantities, what kind of quantities? 100? 1K? 10K? 100K? $10000 in hardware development cost (not much!) amortized over 1000 units is still an extra $10/unit.
Jason S
A: 

Your best bet is to go for one of the simple GPIO dongles like the Advantech ADAM range.

For example, the ADAM 6050 has a bunch of inputs and outputs and is explicitly designed for connecting to random external equipment. It can be connected via TCP/IP using the common modbus protocol (a hand-coded driver is usually no more than a few dozen lines).

For the RS-485 model, one-off cost is $110 - you should be able to get significant volume discounts as a reseller/OEM. You'll need a cheap wall-wart PSU as well.

While there may be cheaper "per unit" solutions out there, this is a professional works-out-of-the-box approach that doesn't involve cracking the case on the PC or building/modifying something from chip/module level in any way.

Don't forget the to factor in the costs of designing, manufacturing, stocking and supporting whatever solution you finally opt for.

Roddy
"a couple of hundred $$"? I think you and I have a very different idea of "cheap hardware".
Paul Tomblin
@paul : Sounds like we do! Can you update the question to be more explicit? I've updated my answer with 'real' pricing for one of the Adam modules.
Roddy
+1  A: 

http://www.awce.com/gp3.htm - Nice support for VB, C++, Java, Linux, etc. etc. Plenty of examples.

JimDiGris