SimVimCockpit InterfaceSimVim Instrument PanelsAboutBlog

Arduino Interface

Arduino code

When starting this Baron 58 project we wrote lots of test code for Arduino, to clarify all aspects of data exchange between Arduino and X-Plane, initially using only inbuilt Ethernet UDP protocol of X-Plane, without plugin or any other software and library.

You can take o look at some of these early programs in the "Code Archive", where you will see the evolution of Arduino I/O interface for our Baron project.
Also, there you can find the "B58-final" code that was successfully used in our Baron as main program before we made another "library-plugin-based" version.

For this Baron-58 project Arduino "Mega-1280" board coupled with Ethernet shield was chosen. To extend the number of inputs we made a DIY extention board for 128 inputs, as well as the board with output registers for LED indicators (serial output from Arduino):

Note: The input extension method described here was designed specifically for our Baron 58 project and shouldn't be considered as the only possible or recommended option for your own cockpit project!

Library and plugin

Later, since summer 2014 all this work and test sketches were revised and organized in a single Arduino library that includes functions for network interaction between Arduino and X-Plane, functions for receiving and decoding any of X-Plane incoming data, and functions for transmitting data to X-Plane. It makes Arduino programming for users as simple as possible - you only need to define the pin number and its function (button, switch, encoder, axis, etc.).

The Arduino program monitors all inputs in each cycle, but if no changes were detected, it does not transmit anything to X-Plane. if the program detects that the position of any of the controls was changed, it immediately sends the specific packet via Ethernet. In general, the whole process of data sending (in the newest B58 code editions) takes 1-5 milliseconds in one cycle.

In the last versions of the Baron code the XPData library is used and data from X-Plane is received via ArdSim plugin (without the need to define data groups for output in the "Data Input/Output" X-Plane menu).

Currently our Baron 58 is in a process of migrating to SimVim interface..

You may apply other options using our newest ArdSimX interface: use several Arduino boards, or key-matrix connection method, without the need to make additional extension board and program Arduino.

All information about Arduino programming is here Arduino cockpit Interface. There you can find descriptions of input and output, the libraries, plugins and code samples.


I/O Extension boards

DIY 128 inputs extension for Arduino

To extend I/O capability of microcontroller, common "key matrix" technique can be used. But for the Baron-58 project I decided to use a parallel input bus interface, because this is convenient and easy way that I have used in my electronics practice.

Using just 8 Arduino pins as inputs plus 4 as outputs we have 128 inputs (this technique could be used for outputs too).

The diagram below shows how to use 8-bit bus transceivers (x16) and one demultiplexer for inputs extension.

The extension board needs to be powered from a separate supply! (not from Arduino). Good choice is to use some old PC Power supply (AT) for +5v bus.


This system consists of an 8-bit bus and 16 8-bit ports connected to it. Only one of the 16 ports is connected to the bus at any given moment. The program code for reading all 128 inputs is running in each cycle (about 1.5 ms) and the status of all inputs is firstly stored in the 16-byte array. Then the stored data is checked for changes and processed for further transmitting to X-Plane.

Schematic for 128 inputs:

Diagram: using 16 8-bit bus transceivers with multiplexer for inputs extension

Instead of 8283A (8282A) any functionally similar ICs could be used such as: PB 8287, 74LS245, etc. 8283A (8282A) is a register with LATCH. An STB signal (on pin #11) latches data when it falls from high to low level and is not needed in this circuit (it always is in high level).

We need only the -OE signal to set inactive ICs outputs to high-impedance level (only one is chosen at any moment). As we don't need the LATCH function here, you can use any of the common octal bus transceivers, such as 74LS245 and 8287: (the 8287 is very similar to 8283 IC with the same pinouts, but it is a bi-directional bus transceiver and instead of STB it has T (dir) , which has to be in high level too to work as 8283)

The 245 is identical to 8287, but DIR (T) is on pin #1 (vs 11) and -OE on pin #19 (vs 9), on the opposite side of IC, also data pins are shifted. As for inversion, the function (in the XPData library) "BusScan (pin1, pin2, inv)" has a 3rd argument "inv" that defines what ICs will be used (0 = inverted, 1 = not inverted).

The code for processing this is included in the XPData Library since version 2.0. All you need to do is define which pins are to be used with input from extension board (8+4 pins) in the "setup" section of your code:

Bus128 ( 38, 46, 1 ); // Initialize Data bus inputs - 8 pins starting with #38 (38-45) and 4 pins for address (46-49). ICs have non-inverting outputs (1)

This part of code determines exactly what a single input (port) has to do. Just use all the same library functions that are described on the library page, but instead of pin nimbers, use numbers for inputs starting from 100 (i.e. 128 inputs from #100 to #227):
example for library version 3.2 !
//=============== Data processing ===========  

//-------- Port #1 (100-107) ------- switches

Toggle (100, "systems/avionics_on", "systems/avionics_off");                 // Master Avionics switch     
Toggle (101, "lights/nav_lights_on", "lights/nav_lights_off");             // NAV light  switch 
Toggle (102, "lights/beacon_lights_on", "lights/beacon_lights_off");       // Beacon Light switch   
Toggle (103, "lights/strobe_lights_on", "lights/strobe_lights_off");       // Strobe Light switch    
Toggle (104, "lights/taxi_lights_on", "lights/taxi_lights_off");           // Taxi  light switch  
Toggle (105, "electrical/battery_1_on", "electrical/battery_1_off");       // BATTERY switch    
Toggle (106, "electrical/generator_2_on", "electrical/generator_2_off");   // R Alt switch     
Toggle (107, "electrical/generator_1_on", "electrical/generator_1_off");   // L Alt  switch  

//-------- Port #2 (108-115) ------- switches

Toggle (108, "ice/inlet_heat0_on", "ice/inlet_heat0_off"); // Fuel Vent De-Icing   
Toggle (109, "ice/prop_heat0_on", "ice/prop_heat0_off");  // Prop Heat switch               
Toggle (110, "ice/window_heat_on", "ice/window_heat_off"); // WSHLD  switch   
Toggle (111, "ice/pitot_heat0_on", "ice/pitot_heat0_off"); // Pitot Heat switch
Toggle (112, "ice/AOA_heat0_on", "ice/AOA_heat0_off");     // Stall Wrn Heating  
Toggle (113, "ice/wing_heat0_on", "ice/wing_heat0_off");  // AUTO Surface De-Icing sw  
Toggle (114, "fuel/fuel_pump_1_on", "fuel/fuel_pump_1_off");   break;// FUEL Pump L  
Toggle (115, "fuel/fuel_pump_2_on", "fuel/fuel_pump_2_off");   break;// FUEL PUMP R   

//-------- Port #10 (172-179) ------- buttons

Button(172, "audio_panel/monitor_audio_com1");     // Audio Com1   
Button(173, "audio_panel/monitor_audio_com2");     // Audio Com2   
Button(175, "audio_panel/monitor_audio_dme");      //  A_DME 
Button(176, "audio_panel/monitor_audio_nav1");     //  Audio Nav1 
Button(177, "audio_panel/monitor_audio_adf1");     //  A_Adf  
Button(178, "audio_panel/monitor_audio_nav2");     //  Audio_Nav2    
Button(179, "audio_panel/monitor_audio_mkr");      //  A_Mkr    
You don't have to connect all 16 ICs (bus transmitters) if you don't need 128 extended pins.

The sample Arduino code for 128-I/O extentsion board is included in the package with XPData Library

Using bidirectional 74LS245 ICs

The 74LS245 is a bi-directional bus transceiver, and it has DIR input which determines the direction of data flow.
When DIR input is in low level (0), the data is transmitted from Bn to An:

Diagram: using 8-bit bus transceivers for input extension

If you have to connect "B" inputs to Arduino (if it is more suitable for your needs) the "DIR" input should be in high level:
When DIR input is in high level (1), the data is transmitted from An to Bn:

Diagram: 8-bit bus transceivers for input extension

Using bidirectional 74LS245 ICs for output and input extension

As we can choose the direction of data flow anytime with Arduino code putting the 74LS245 DIR input to "0" or "1" or latch data for register 8282A/8283A setting STB input to "0", so we can use mixed ICs and assign some ports for outputs using the 8282A (or 8283A LATCH register).

Here the DIR input is in low level "0", when IC #1 is chosen for data reading and in high level when IC #2 is chosen for data output (the data is transmitted from Arduino to LEDs). When DIR/STB is "0" the 8282A IC will store data:

Diagram: using 8-bit bus transceivers and registers with latch for input/output extension

© Copyright 2012 - Vlad