5. Basic electrical information
Connecting switches PC keyboards
Connecting relays to keyboards
Connecting Opto-couplers (photo-couplers) to keyboards
Circuit to convert toggle switch action to momentary switch action using relays
Toggle switch action to momentary switch action using Opto couplers
Making your own joystick connections to PC game port
Connecting multiple joysticks to your PC
Connecting external potmeters to a USB joystick (joystick hacking)
Connecting switches PC keyboards
When building a flight simulator cockpit, many switches at various positions replace the keyboard strokes. If you still want to use the keyboard as interface to PC, the cockpit switches need to be wired back to the keyboard.
Mechanically wise, there are two kinds of keyboards: The older types (from the 286 386 era) still have a PCB (printed circuit board) on which real switches and electronics are mounted. The later keyboards use layers of plastic foil with copper patterns and carbon-in-rubber press switches. The foils connect to a small PCB with the controller IC.
If you want to connect many external switches to a keyboard, by all means try to find one of the older keyboards with PCB. Old keyboards can be found at your local junkyard / recycling place. (You may need an adapter from the old DIN type plug to the newer PS2 type plug)
Most keyboards have about 100 switches, which are wired in a matrix to a keyboard controller IC. This means that the keys are floating, i.e. they dont have any common ground point. If you want to keep your setup flexible, the easiest way is to solder a little connector across each keyboard switch and connect your external switches parallel over the keyboard switch. Youll need two wires for each switch, and the external switches must be isolated from each other. The circuit and picture below shows the idea.
Note: These switches must be normally open. A continuously closed contact will produce a key-repeat.
Connecting relays to keyboards
If you use electronic circuits to drive switches, the drive circuits will normally have a common ground. In this case you can use relays or Opto-couplers to make the isolation between drive circuit and keyboard.
Connection of a relay is pretty straight forward: The driver circuit connects to the relay coil which does not have any polarity. The only thing to take care or is that the driver circuit applies voltage across the coil which matches the relay coil spec. This coil voltage is normally printed on the relay housing. The relay contacts connect to the keyboard and dont have polarity either. In case the relay has Make/Break contacts, make sure you connect the Normally Open contacts to the keyboard.
Take note that when you drive the relay coil directly with a switch (either mechanical or electrical) you get a voltage spike over the coil when switching OFF the coil current. To suppress this spike, add a diode over the coil as shown below.
Relay
connection and spike protection
For various types of relay and specs, check: http://www.oeg.com.cn/grlist.htm Many types are suitable, from 1Amp to 10Amp types. The PCG series is fine. Check the coil driving power. 500mW or less is OK, which is about 260 Ohms coil resistance for 12V coil type.
Picture of relay and opto-coupler
test connections
Connecting Opto-couplers (photo-couplers) to keyboards
In case of an opto-coupler connections need some more care:
An Opto-Coupler is contains a light emitting diode and a light sensitive transistor close together in one package. When you drive a current Id through the diode, the diodes light will turn-on the transistor.
Both Opto-coupler input and output have polarity. The driver circuit needs some form of current limiting (resistor) to avoid damaging the Opto-coupler diode. Diode current around 30mA is a good value. Most opto-coupler diodes have about 1V drop when conducting 30mA current. When driving from 12V, the current limit resistor needs to be:
à choose 330 Ohm standard value
When connecting the output circuit to the keyboard, the easiest way of finding the correct polarity connection, is by trial and error: Apply drive to the Opto-coupler input and connect the output to one of the keys; check with Notepad to see whether the key is activated or not. If not, reverse the Opto-couplers connection to the keyboard.
Opto
coupler connection to keyboard
Opto-couplers are often found in switch-mode power supplies. They usually look like an IC, but have only 6 or 4 pins. Most of these couplers have a diode current rating of max 60mA DC.
In the test circuit I used 330 Ohms, which gives 33mA drive current at 12V supply.
The below picture and schematic show the test circuits and setup for relay and Opto-coupler.
(Opto-coupler package top view)
Opto-coupler: Vishay, http://www.vishay.com/products do a search on: TCET1103 or SFH620
Toshiba, http://toshiba.com/taec/index.shtml search for TLP620 or TLP421
Circuit to convert toggle switch action to momentary switch action using relays
Many sim cockpit controls are activated by a key-stroke. This means that the keyboard switch is closed momentary, for about 0.1 .0.2 seconds. If you connect a real toggle (tumbler) switch across the key-board switch, the constant ON of the toggle switch will result in a constant repeat of the key function due to the auto repeat feature of all PC keyboards.
To convert the toggle switch constant ON action into a momentary ON action you need some extra circuit in between the toggle switch and the key-board switch input.
The below circuit shows a simple way to achieve this. It makes use of a relay and an electrolitic capacitor.
In the switch position shown, the electrolitic capacitor is discharged. The relay is not active.
When the switch is flipped to the +12V position, the electrolitic capacitor is charged to +12V via the relay winding resistance. The pulse charge current through the capacitor and the relay will close the relay switch momentarily. When the switch is flipped back to ground, the capacitor will discharge, again activating the relay switch momentarily. Thus the toggle switch action can be transferred to the keyboard as if a key was pressed momentarily. A 330uF (micro-Farad) capacitor and 12V relay (260 Ohm resistance) will give about 0.2 seconds ON-time. The time is not really critical. You can also use a 5V relay and supply, but you may need to experiment with the capacitor value. (100uF .470uF). Remember that electrolitic capacitors have polarity. The positive side should be connected to the switch side.
Note that you dont need the diode across the relay for blocking the inductive spike, as the current through the relay has a slow decaying current (via the capacitor) in both directions.
The above circuit is for cockpit functions that use the same key for activating / disabling, like Parking brake, Gear Up / Down, etc.
If you want to control a function that uses different keys for activate / disable with one toggle switch, you can use the below circuit where charge and discharge currents are directed to different relays via two diodes, see circuit below. (Used in FUIII engine on/off via car key-switch)
Toggle switch action to momentary switch action using Opto couplers
The same idea can also be build with Opto-couplers, but requires some more components.
The Opto-coupler diode cannot be used as time-constant parameter, so some external resistors need to be added for the current limiting and time constant setting.
For toggle to momentary with one opto-coupler, the charge / discharge current needs to flow through the same opto-coupler. If you use a DC opto coupler, you can add a diode bridge, but this is component wise rather wasteful. Its simpler to use an AC type Opto-coupler, that has two diodes anti-parallel inside. (These types are often found in telephone equipment).
Toggle to momentary with single AC type Opto-coupler: This circuit gives an Opto-coupler ON time of about 60msec.
Toggle to momentary with two Opto-couplers for controlling different switches.
There are many cockpit functions in flightsim programs that use the CTR / ALT / SHIFT keys in combination with another key. In this way the number of functions accessible from keyboard can be increased.
Making the combination keystroke with one external switch is however not as simple as the circuits described above; I tried the above circuits with a dual pole relay (one pole for SHIFT and the other for a normal letter key. The result was not satisfactory. The keyboard needs to detect the SHIFT key being pressed 10 or more of milliseconds before a letter key is pressed, otherwise the SHIFT will be ignored. See illustration below.
To make this would require a one-shot IC like HEF4538 per combination key function. If you use a lot of combi keys, the amount of circuitry can get large. Thus far Ive re-mapped the key configuration in such a way to avoid combination key-strokes.
(See my joykeys.cfg for re-mapping the various function keys to single key action)
Making your own joystick connections to PC game port
If you ever opened a normal PC game port joystick, youll see that the X and Y axis movements are coupled to two potentiometers (variable resistors, often called potmeters).
If you have a joystick with throttle, that movement will go to a third potmeter. Youll find that the potmeters have three terminals, but normally only the middle and one of the outer terminals are connected to the wiring.
The switches of the joystick are normally small Tact switches, that are ON when you press them.
All the wiring then goes via shielded cable to the 15 pin D-shell PC game port which is normally located on the sound card. The circuit connection is pretty much standard.
The labove diagram shows the wiring diagram as many audio card makers provide it. The idea was to be able to connect two joysticks, each with X and Y axis and two buttons.(The pin numbers are normally printed on the connector plastic)
In case you were wondering how to connect MIDI in and out to your General Midi keyboard, I added these connections drawings too. (At least it works with my CASIO WK1500)
For flight simulation, you can use the four available axis to control aileron, elevator, throttle and rudder. (See above diagram)
I added the directions of each control w.r.t. to potmeter value. (These are the directions that were used in early DOS games, and may be different for some newer games) For Flight Unlimited I, II and III, these directions are still valid.
If you want to build your own flight controls, you can use the above diagram to connect the potmeters.
If you first want to test whether your game port and software indeed work as described, it is handy to make a small circuit according the diagram, (shown at the left), plug it into your PC, and check the functions.(It consists of 4 adjustable 100k potmeters and 4 switches, wired to a gameport connector
After plugging in the test board, you have to select the right kind of joystick configuration and calibrate the axis to the potmeter values. If you dont calibrate, youll find that your potmeters dont control the functions over the whole range.
Note: These are Win 98 screen shots. (Im using DirectX 8.0 on a P233MMX). In the control panel select gaming options. Either remove you old joystick, or add an new one.Select 4 button flight yoke with throttle.Make sure you check the Rudder/pedals box.
If you have wired your test board correctly, the game port status should show OK. If you used too large potmeter values (> 200k), the game card may not be able to detect your board.
Now you have to calibrate your test board. (See window above) Select properties, then the settings tab, and click calibrate. This window should appear. Just follow the instructions on the screen. Basically youll let the joystick software know you center settings and min/max range of the potmeters used. The software can compensate for quite some variation in resistance. It is however recommended to stay close to the 0 100k resistor range, which normally gives the best results for linearity, jitter, and drift.
The final result should be like the window above. Turning the potmeters from min to max should give the complete range in the square box and bars. I found that sometimes one calibration cycle is not sufficient to get good results, and has to be repeated two or three times. Re-calibration may be necessary every couple of days, or when temporarily unplugging the controls from the PC.
You will sometimes find that the "+" cursor in the lower right of the box will be unstable, (jitter).
Also the low end of the bars may show some jittery behavior. This is due to noise pickup of the potmeter wires. When the potmeter is turned for maximum (100kW ) resistance, the noise can easily be picked up from the wires to the game port. This will give unstable axis movement, and often gives different range after each calibration, as the PC sees variable range at the high resistance setting. As you can see from the wiring diagram, high potmeter resistance corresponds to right aileron, up elevator, right rudder, and idle throttle.
To minimize jitter, use shielded cable for each axis, from potmeter to gameport. Try to keep cables as short as possible, and keep them away from noise sources like switching power supplies.
Sometimes, poor contact of the potmeter wiper to the carbon resistance trace can cause jitter. There are special contact sprays for electronics that can help.
Connecting the unused outer contact of the potmeter to the middle contact can also help, as it avoids the "open contact" condition.
This diagram illustrates how to make your controls less sensitive for noise. Keep the unshielded ends as short as possible.
The joystick game port has only 4 switches. Most joysticks have a POV HAT, which is used to quickly switch between different views (front/left/right/rear) In flight simulation with single monitor setup, I find 4 views insufficient, as the 45o views are often used when flying a traffic pattern. This requires 8-POV HAT capability.
In principle it is possible to use the 4 joystick switches to make 8 views, by using combinations with multiple switches simultaneously ON.
CH flight stick Pro uses this trick to have both joy switches and POV HAT. Their HAT works as following: 12 oclock: 1,2,3,4 ON 3 oclock: 1,2,4 ON 6 oclock: 1,2,3 ON 9 oclock: 1,2 ON.
For each direction, you can use diodes to the corresponding switches, and in this way create a 4 POV HAT using 4 extra switches and 12 diodes. This is described in http://user.fundy.net/jdyarrow/controls/controls_index.html another great info site.
Up to now, I havent been able to figure out a way to have 4 joy key switches and a 8-POV HAT via the game port. Therefore, my HAT still makes use of the keyboard view keys in Flight Unlimited III. Here, the numerical key pad keys 8, 9, 6, 3, 2, 1, 4, 7 give a full view circle around the cockpit. My HAT drives those keys. (I found such a HAT switch at a electronics dump store)
HAT build from
8-position joy-switch.
It consists of a miniature joystick with 8 contacts around and one center contract. The little pivot can be moved in all directions, and the center contact will touch the outer contacts at 45 degree positions. To make this 8 direction switch drive the keyboard switches, isolation must be provided. I used 8 opto-couplers for this. Since the switch can only have one active contact at the time, one common resistor can be used for all opto-couplers.
I put the HAT on the left handle of the yoke: This is more convenient for switching views when flying the traffic pattern, as your right hand will be busy with the throttle. (I mostly fly Base and Final with left hand on the yoke, and right hand on the throttle).
The left yoke handle with HAT, and the 8-position joy-switch that I used for the purpose.
Connecting multiple joysticks to your PC
Light aircraft cockpit controls require more than 4 proportional axis: For example, when you want to add Prop-pitch and Mixture, youll need two more axis. Since the standard game port has only 4 axis, you need to add extra devices. There seem to be multiple game-port cards on the market, but I have never seen them in Taiwan. Adding USB devices is a good alternative. There are USB to Game-port converter boxes, that plug into USB but show a game port D-shell connector at the other end. You can use these devices to add 4 more axis to your sim. I have not bought such a device, but I guess the wiring diagram to the joystick is identical to the one I gave earlier.
For my axis extension, I bought an extra USB joystick. I used a Taiwanese brand Rockfire QF605U. When you plug it in, the (Win 98) system detects the stick and puts it under the gameport joystick that was added earlier. The calibration procedure is similar to the one described earlier. This is the window that should show up when connecting two joysticks to the PC. The Controller ID tab can be used to assign the correct ID to each joystick.
In my original setup, I had the gameport flight yoke assigned as #1 and the USB stick as #2. However, Flight Unlimited III mistook the USB stick as device 1 and gameport as device 2. (?) Since I wanted the gameport for primary controls, I had to swap the IDs as shown on the above window.
Flight Unlimited III has support for multiple joysticks, but you have to tell it via flt3.cfg file what stick axis is supposed to do what. For the gameport flight controls, everything worked as intended (aileron/elevator/throttle/rudder) without adding special commands.
For the USB stick, I assigned Prop Pitch to axis 1 and Mixture to axis 2 by putting the following lines in flt3.cfg:
prop_pitch_device 2 1
mixture_device 2 2
After that, both prop pitch and mixture were controllable via the USB stick. (See attachment for joykeys.cfg and flt3.cfg text)
Connecting external potmeters to a USB joystick (joystick hacking)
The USB joystick internals are different from normal gameport joysticks. In most sticks, the stick movements are still transferred to potmeter movements.
Note: some modern sticks like Microsoft joysticks do not use potmeters, but instead optical encoders. (good for reliability, but unsuitable for hacking).
The joystick potmeters are wired to a small PCB with some electronics on it. Normally one IC (a custom ASIC microcontroller) which deals with the transfer from potmeter resistance to USB to PC game device software.
Still, a potmeter is a potmeter and can easily be replaced by an external potmeter. (The earlier recommendations about jitter still apply)
As you dont need the joystick case, its most convenient to remove the USB PCB from the stick case, together with the USB cable (which provides power and signal).
You should end up with something like the picture above.The connectors at the middle and left are for the potmeters and switches.
With some patience, you can trace the complete circuit connections. It should look something like above.
Note the values on the potmeters (or measure them) In my case they were all 100k, so my external 100k potmeters worked fine with the USB PCB.
I only used axis 1 and 2, so I disconnected the rest, and externally connected the prop pitch and mixture potmeters to the corresponding connector pins. Basically you could also make use of the switches, but for some reason, Flight Unlimited III does not recognize the switches of the second joystick device.
Keep in mind that you need at least one switch to calibrate your joystick, so connecting one external switch is required.
(I would suggest not to solder to the PCB directly. Try to find fitting connectors, and solder the external potmeter (shielded) wires to the wires of the connectors)
Use your Flightsim program for verification of the various potmeter controlled cockpit functions.
If you find that one of the control functions works reversed, the potmeter wiring needs to be changed: leave the middle wire unchanged, but the outer wire needs to be swapped to the other outer connection
Reversing
control direction
Joystick potmeters are different from normal potmeters: Due to the limited movement of the joystick, the potmeters only have variable resistance specifically for that movement. The rest of the slider range will not give resistance any change
When using normal potmeters, try to build the mechanics such that about 270o is used.
Different kind of potmeters.
Dual potmeter, 1W potmeter, standard potmeter and shift potmeter. As long as you choose 100k with linear taper ("B"-type), all work equally well. The closed type potmeters will be better for rudder pedal, as they stay cleaner over time. Shift potmeters are sometimes easier to link to mechanical constructions. Shafts with teeth are easier to fix gear wheels, etc.
I used dual type potmeters, one section for the flight controls, and one section reserved for connection to a simple motion platform (a future project)
Connecting all the cockpit controls can be a tedious work. Try the functionality by checking one function at the time. For the keyboard driving functions, I use Notepad to check the correct key action.
Ribbon cable
connector components
For making connections, the flat ribbon cable with matching connectors is very handy. (The types that are used for connecting Floppy-drives, Hard-drives and CD ROM to your PC main board) The connectors are available in various pin count size, from 10 to 40 pins. You can also get the fitting male pins (2.54mm pitch, they will fit perfectly on experiment board. You can use pre-assembled cable with connectors, but the loose parts can easily be assembled by yourself: The connectors have a top and bottom half, that need to be pressed together in a vise with the ribbon cable in between. Ribbon cable can be bought by the meter.
Building electronic circuits:
Since all circuits are basically one-piece projects, I normally dont bother making real circuit layouts. I use standard experiment board with 2.54mm pitch copper islands, and place the components in a logic fashion. Adjacent connections are done with solder, longer connections with 0.3mm f enamelled copper wire. (You can remove the isolation at the wire ends by heating them with your soldering iron for a few seconds). This method works quick, and the transformer wire isolation is good enough to avoid shorts over crossing wires.
I normally try to build with some ease for disassembly in mind. Modular building blocks help keep things organized and will make trouble shooting easier.
Using labels for various connections with polarities (i.e. supplies) will help avoiding wrong connections and possible damage. For the keyboard wiring connections you cannot do without clear labels.
The key to good electronics soldering:
Not too hot solder iron (40W or so), wipe the tip of the iron clean on a damp sponge after every solder point, solder quick, not more than 4sec (after that, the solder degrades). For soldering wires to connectors: First put a coat of tin on each end of the leads, then solder together.