Skip to content
Jorg Neves Bliesener edited this page Jan 13, 2019 · 3 revisions

Welcome, Cockpit Builders

Anyone who already tried to build a Flight Simulator Cockpit with X-Plane probably went through some kind of trouble when handling physical switches that should trigger actions in X-Plane.

In terms of hardware, the Teensy microcontroller is a high performance substitute for Arduino systems. Furthermore, it comes with a native programming interface for X-Plane]. The Teensy interface is very easy to use, please check the original documentation at https://www.pjrc.com/teensy/td_flightsim.html.

However, even with the intuitive Teensy programming model, correctly handling cockpit switches in X-Plane is not as easy as it seems. Having built some cockpits, and helped to build on others, I've learned a number of things that should be observed:

  • Hardware switches must be debounced to work correctly. See https://www.allaboutcircuits.com/technical-articles/switch-bounce-how-to-deal-with-it/
  • X-Plane can be controlled through commands or through datarefs. The most common error made is trying to write to a dataref, when X-Plane actually requires commands to control a certain feature. See the specific section for additional explanations.
  • Repeated, high frequency dataref write operations or commands not only consume bandwidth on the USB bus, but also can overload and consequently crash X-Plane or plugins like Lua or Python. Only set datarefs or send commands when a switch actually changes.
  • No rule without an exception: You must set all switch values right after a plane is loaded in order to synchronize the plane with your real hardware.
  • Some switches in X-Plane are actually controlled through "up" and "down" commands, that require a dataref for tracking. That's when things really start to get complicated. See here
  • When you have LOTS of switches (more than 20 or so), you may not have enough pins on your Teensy to connect them all. A switch matrix is a common and proven technique to connect and query many switches to a microcontroller. However, it requires additional software to be used.

The FlightSimSwitches library addresses all the issues mentioned above, plus some more. It is licensed under LGPL3 and can be used in commercial projects, according to LGPL3 terms.

The various pages in this Wiki explain how to use this library and respond some Frequently Asked Questions