I had a couple of Arduino Mega-1280 in my collection, and after some tests with the board I found that it's perfect to create an interface. Using Arduino (with an "Ethernet Shield" for connection to LAN) and only the built-in UDP networking features of the X-Plane it is possible to build a quite complex system for the cockpit interface (for more complex, we can use multiple cards with their own IP-addresses).
All that was needed - is to learn the quite simple format of data transfer in X-Plane by UDP (see Data/Info) and write a program for Arduino, which would receive and process the data sent by X-Plane, use it for the cockpit gauges, and send back the data from all the buttons, switches, encoders and analog axes.
The Arduino Mega was choosen to be used in the project, as this version of the Arduino family has the maximum number of analog inputs (16), a large number of digital outputs/inputs and the memory size is 128 kb.(or 256 for Mega 2560)(See specification on the Arduino site).
Arduino board has an USB interface, that emulates a serial protocol, using an object "Serial" and it useful when debugging a program to output the results to the terminal, but not suitable for fast data exchanging communication. It is implemented for using in the development environment (IDE) to download the code in the controller, for quickly code debugging and checking it out in the same time.
X-Plane, lucky, has built-in capabilities for exchange data with other computers on the network, using an UDP protocol. The data format is quite simple, it is described, in particular, in the file "Sending Data to X-Plane.html", located in the /Instructions/ folder of the simulator.
For connecting Arduino to the local network we need an additional board called "Ethernet Shield". This board is mounted on top of the Arduino board as the other shields that extend the functionality of Arduino. A part of the IDE includes an Ethernet library with the UDP class which needed exactly for our purposes.
First, it was need to figure out how to get the necessary data from the simulator (and then how to send data back) using the Arduino. With a few test programs with visual output (Serial.print) problem of data transfer was quickly solved and the rest of the time it took to debug the main program.
The simplest way of I/O interface building is to use only the Arduino board for X-Plane Interfacing, not using any other schematics or even key-matrix. With this approach we can get about 50 digital inputs for buttons/toggles or up to 20-30 encoder controlled data.
This way is described on the "Arduino Cockpit Simulator" pages.
For this Baron-58 project, though, in addition to Arduino I've made the data BUS circuit board ( extention for 128 inputs) and a board with the registers for LED indicators (serial output from Arduino).
See more in detail - Electronics
The main program for Arduino consists of the following parts:- module of data input from all switches, buttons, encoders and transfer them to the X-Plane (more than 130 of digital inputs)
Data transfers to X-Plane by Ethernet UDP using DREF, CMND, or DATA packets (Described in "Arduino code").
Total used 128 digital inputs (including ones from 19 encoders) organized in 8-bit data bus (16 ports x 8 bit), i.e. used only 8 digital inputs of Arduino, plus 4 outputs to address these 16 ports. For some additional switches will be used another 10-12 digital inputs.
For output to the LED indicators used only two digital outputs - one for data, plus one for strobe, ie output is organized in the form of three in serial external shift/latch registers.
Seven Arduino PWM outputs are used for servo gauges:
- Fuel left
- Fuel right
- Bus Volts (bus voltage)
- Alt load left (load on the left alternator, in amperes)
- Alt load right (load on the right alternator, in amperes)
- Prop Amps (Current in the heating system of propeller blades)
- De-Icing Pressure (Pressure in the de-icing system)
(Prop Amps and De-icing pressure show only two values - 0 when corresponding switches in the off position and nominal values when they are turned on.)
For the axes are used 16 analog inputs of Arduino:
Variables for the first five axes are transferred to X-Plane continuously (highest priority), the rest ones - on a change in state.
See more in detail - Arduino code
Although this system was developed for Baron 58, it can be adapted for any other aircraft!