Maker Pro
Maker Pro

Connect external switch to PC

M

Mickel

I had a need to connect a double footswitch (2 momentary switchs) to a PC. I
came up with the idea of using the circuit board from a USB keyboard. This
was the perfect solution as it was cheap, small and didn't require any
drivers to be written. When I pulled apart the keyboard and hooked up the 2
switches to page up and page down keys it didn't work. So I measured the
resistance of the flexible circuit and concluded I needed to put a 50ohm
resister in series with the switches. When I bridged the resistor across the
pins (without using the footswitch) it fired the page up or page down key as
expected. I thought the problem was solved but when I hooked up the 2
switches it stopped working. The really interesting this was though, if I
hooked up only 1 of the switches then it worked ok. This was really odd
because by disconnecting a switch that was open anyway, all I was doing was
removing a 3 metre long wire that wasn't connected to anything. So I got the
idea of hooking up a diode to this wire and that worked. So my problem is
solved but can anyone explain to me why putting a diode on a piece of wire
connected to nothing solved the problem?

Also, one I had the diodes in place i worked fine without the resistor.

I'm not much good with ascii circuits but here it is:

------
| |
| |--~~------------------
| | | |
| KB | \ \
| | | |
| |-->-------------- |
| |-->-------------------
------
|
|
|
|
USB

~~ = 50 ohm resistor
-> = diode

Thanks heaps,
Michael
 
M

Mickel

kreed said:
These invariably have diodes inserted to prevent "phantom key presses"
from 2 keys on the same row or column being pressed together and
simulating a 3rd key being pressed.

That makes sense but I can't see any components. The keyboard just consists
of a hard and soft circuit board. The flexible board doesn't have any
components unless a diode is built into the track? I would have thought if
they were going to use diodes then they would put them on the hard circuit
board.

Perhaps they are using a different method of sending out different pulses in
different lines and then look for the resulting waveform?
The couple of times I tried this, I used an optocoupler to trigger the
key, for safety reasons (optical isolation), and this would have its
own internal diode (the phototransistor).

having said this, I have found keyboard hacking to prove unreliable.

I've had some in service for over 5 years. Although that was in the day when
a USB keyboard was over $20. Today's $8 keyboards might not be so reliable.
Interestingly the last time I made these I had none of these troubles.
In these situations I would consider using those "MAME" - video arcade
keyboard emulator modules.
They just plug in to a USB or PS2 socket and appear to windows as a
keyboard, but they have screw terminals that you simply take to ground
using any kind of switch you want to use to "press a key".

Thanks for that, that is an option. It is more expensive than what I sell my
module for now ($60) but it's one of those situations where cost isn't a
huge issue.

Michael
 
D

Don McKenzie

Mickel said:
Thanks for that, that is an option. It is more expensive than what I sell my
module for now ($60) but it's one of those situations where cost isn't a
huge issue.

Michael

This may well be too expensive for your module also Michael, but here is
an OZ designed and produced alternative:
http://www.dontronics-shop.com/top16-usb-io-module.html

Cheers Don...


--
Don McKenzie

Site Map: http://www.dontronics.com/sitemap
E-Mail Contact Page: http://www.dontronics.com/email
Web Camera Page: http://www.dontronics.com/webcam
No More Damn Spam: http://www.dontronics.com/spam

Breakout, Prototype, Development, & Robotics Boards:
http://www.dontronics-shop.com/sparkfun-electronics.html
 
P

petrus bitbyter

Mickel said:
I had a need to connect a double footswitch (2 momentary switchs) to a PC.
I came up with the idea of using the circuit board from a USB keyboard.
This was the perfect solution as it was cheap, small and didn't require any
drivers to be written. When I pulled apart the keyboard and hooked up the 2
switches to page up and page down keys it didn't work. So I measured the
resistance of the flexible circuit and concluded I needed to put a 50ohm
resister in series with the switches. When I bridged the resistor across
the pins (without using the footswitch) it fired the page up or page down
key as expected. I thought the problem was solved but when I hooked up the
2 switches it stopped working. The really interesting this was though, if I
hooked up only 1 of the switches then it worked ok. This was really odd
because by disconnecting a switch that was open anyway, all I was doing was
removing a 3 metre long wire that wasn't connected to anything. So I got
the idea of hooking up a diode to this wire and that worked. So my problem
is solved but can anyone explain to me why putting a diode on a piece of
wire connected to nothing solved the problem?

Also, one I had the diodes in place i worked fine without the resistor.

I'm not much good with ascii circuits but here it is:

------
| |
| |--~~------------------
| | | |
| KB | \ \
| | | |
| |-->-------------- |
| |-->-------------------
------
|
|
|
|
USB

~~ = 50 ohm resistor
-> = diode

Thanks heaps,
Michael

Those keyboard switches are in a matrix and you don't know the matrix
layout. Guess wenn you connect both switches separately (so no common wire)
your problem may be solved.

petrus bitbyter
 
M

Mickel

petrus bitbyter said:
Those keyboard switches are in a matrix and you don't know the matrix
layout. Guess wenn you connect both switches separately (so no common
wire) your problem may be solved.

I do know that matrix layout because I followed the tracks on the flexible
board. AFAIK, I had the wiring hooked up correctly. I checked multiple times
for extra circuits that I might have missed but could find nothing. I
thought there might be a complete loop on the flexible board all the way
back to a different pin on the solid board but there was nothing I could
see.

Michael
 
M

Mickel

Bruce Varley said:
Would it be less messy to use the handshake lines on a COM port, assuming
that one will be available? A small amount of software may be required,
but the hardware side would be a heap neater.

We used to use serial but the whole idea behind using a USB keyboard was to
eliminate the serial port. The serial port had the problem of some false
triggering with clients who had some noisy equipment. I could have possibly
solved that but some modern PCs don't have serial ports. I could use a USB
to serial converter but it might just be easier to make it USB. We also gain
the advantage that users don't need to specify which port they are using.
Selecting COM1: vs COM2: seems a little old fashioned to me. :_)

Michael
 
M

Mickel

kreed said:
Didnt see the point in hacking up a good quality KB as at the time,
they were not much cheaper than some of those "MAME" modules were
(about $30) and after all - "we only needed the PC board and the
IC" ;)

I think I agree with you there. I get a brand new keyboard and throw 95% of
the mass of it straight in the bin.
Might have discovered that even the good KB used the same technology
as the cheapies and also not be easy to interface ?

Quite possibly.
I also remember that earlier on, a friend of mine made up a MAME video
game system into a home made arcade cabinet for his kids and hacked up
a PS2 keyboard to connect up the joystick and buttons. It worked
fine, the only problems he had was having to bring 2 wires up to each
button, instead of the usual method of every button having a common
ground. Was a mess of wires, but he was happy with it.

That would be an issue for me as I have a lot of double footswitches in the
field with only 3 wires. :)
One option would be to go to rubbish dump sales or charity shops and
buy some old keyboards ?

Bugger that!! :))
The only other theory I can think of with your situation is that from
memory of working on these cheap keyboards, the "key contacts" are 2
white translucent plastic sheets that are pushed together when a key
is pressed.

That is true.
These may not be a simple switch that closes and shows close to zero
ohms, they might have a substantial contact resistance, hence working
when you add the resistor.

This is correct except it is the tracks that have the resistance. From 70ohm
to about 30 from a quick test I did (some keys obviously have longer
tracks).
For all I know It may also work by measuring inductance, or
capacitance. If this is the case, then
having a length of wire hanging off the key matrix may act to increase
capacitance, or pick up mains hum or other interference causing the
problem you have with it not working when the wire is attached.

Maybe the diode happens to block interference or limit it to one side
of the matrix.

When I measured the voltage across the switch (when open) I get -2.5V. When
I switched the contacts over I still got -2.5V so something odd is going on
there. I thought maybe they send down different frequency pulses so they can
detect multiple keypresses.
Remembering too, some of those MAME things can be in the $30-40 range
if you dont need a lot of inputs like the one shown. The one shown
was the only one found on Ebay at the time I searched, just to give a
pic of one for you.

I will have a look into this and most likely switch to one of these
controllers in the future. This is actually what I was looking for but
didn't realise existed. Just from a wastage point of view I prefer not to
throw out brand new keyboards. Thanks for the tip!

Cheers,
Michael
 
G

GeoffC

I had a need to connect a double footswitch (2 momentary
switchs) to a PC. I came up with the idea of using the
circuit board from a USB keyboard. This was the perfect
solution as it was cheap, small and didn't require any
drivers to be written. When I pulled apart the keyboard and
hooked up the 2 switches to page up and page down keys it
didn't work. So I measured the resistance of the flexible
circuit and concluded I needed to put a 50ohm resister in
series with the switches. When I bridged the resistor
across the pins (without using the footswitch) it fired the
page up or page down key as expected. I thought the problem
was solved but when I hooked up the 2 switches it stopped
working. The really interesting this was though, if I
hooked up only 1 of the switches then it worked ok. This
was really odd because by disconnecting a switch that was
open anyway, all I was doing was removing a 3 metre long
wire that wasn't connected to anything. So I got the idea
of hooking up a diode to this wire and that worked. So my
problem is solved but can anyone explain to me why putting
a diode on a piece of wire connected to nothing solved the
problem?

Also, one I had the diodes in place i worked fine without
the resistor.

I'm not much good with ascii circuits but here it is:

------
| |
| |--~~------------------
| | | |
| KB | \ \
| | | |
| |-->-------------- |
| |-->-------------------
------
|
|
|
|
USB

~~ = 50 ohm resistor
-> = diode

Thanks heaps,
Michael

You could check out devices called 'keyboard wedges'. Such as
made by Unique Micro Design in Melb.
 
M

Mickel

Mickel said:
I will have a look into this and most likely switch to one of these
controllers in the future. This is actually what I was looking for but
didn't realise existed. Just from a wastage point of view I prefer not to
throw out brand new keyboards. Thanks for the tip!

I just realised it's not quite what I'm after. I really need 3 wires for my
2 switches, it looks like I would have to use 4 wires. Also I don't want to
install any software on the PC and I definately can't use PS2 as this is
usually already in use. Bugger, looks like i'm back to hacking appart
keyboards.

Michael
 
M

Mickel

kreed said:
The MAME boards that I have seen will work with 3 wires as you
require. (All will IIRC)

Each of the switch positions you just take to ground to activate the
switch, so you on need one wire for common and one wire for each
needed switch.

Ok, my misunderstanding again :) When it said "no matrix, every switch wire
independently" I presumed both wires. Of course it wouldn't make much sense
for them to have 40 pins for 20 keys. To have a common ground is actually a
better solution for me because when I pull appart a keyboard I'm just lucky
that page up and page down keys share a common wire on the matrix, it's
quite possible I could find a keyboard that this is not the case.
The other alternative - if you are happy to use a microcontroller, is
to make up one of the many PS2 keyboard emulator circuits that are
published on the internet (usually using PIC). If you are going to be
making a lot of these, this is probably the cheapest and most hassle
free way to go.

IF you can't use PS2 into your computer, then you can include a PS2 -
USB adaptor, even though it is yet another expense.

Finally, IIRC, some (not all) of the MAME PS2 boards will go in line
with an existing PS2 device
allowing both to be used.

I'm really keen on a USB solution. From a quick search I just did there are
USB options available. I'm in 2 minds, pulling apart a keyboard does work,
it's cheap, simple and the board is very small. On the other hand there
could be issues for example if someone extends the length of cable to the
footswitch. I'll do some research and see if I can find a good USB mame
board.

Thanks for all the information.

Cheers,
Michaek
 
Top