Mulit Panel for Flight Simulators Based on Arduino and MobiFlight

by a_peter in Workshop > Tools

3125 Views, 9 Favorites, 0 Comments

Mulit Panel for Flight Simulators Based on Arduino and MobiFlight

panel_outer_1.jpg

Inspired by some hardware of a popular flight simulator vendor i decided to built up something similar on my own. The first version was implemented using simple rotary encoders, a LCD display, an Arduino Leonardo and a case. The result was not bad, but in aviation double stacked rotary encoders are quite common.

After using the first version for some time i stumbled upon the project MobiFlight. A software which supports some Arduino hardware with a special firmware and a bridge software connecting the Arduino to a flight simulator.

You could ask: "Why not buy a ready hardware?". Because you are able to adopt a self built hardware exactly to your needs.

This project needs you to download the freeware MobiFlight to work. Some images were made using the free CAD software Fritzing.

I won't explain every step in depth. A basic knowledge of working with an Arduino and MobiFlight is expected.

You can download the necessary MobiFlight files from https://1drv.ms/u/s!Aue0VAF9b-QrmFNRQrIcOIs334Yu?e=4PEADg

Supplies

First of all: Even though the Arduino has a number of standard plugs you'll have to solder some parts for this project. Nothing complicated, just some pin rows have to be soldered to PCBs (printed circuit boards). If you does not own a soldering iron have a look if there is a maker space nearby. They might have something for you.

The material i used for this project is:

  • 1 Single rotary encoder (to select a "menu")
  • 2 Stacked double rotary encoders, like ELMA E37 (to adjust values)
  • 20x4 character LCD display (to display values)
  • Arduino Mega 2560 R3 or compatible board (to operate the whole thing)
  • Neutrik NAUSB-W USB-adapter (type A and B) (to connect the thing to a PC)
  • Plastic case (not to have cable clutter on your desk)
  • Jumper cables in some variants (to connect everything together)
  • Two USB type A to type B cables, one short for internal, one longer to connect to PC
  • Screws and nuts to mount parts to the case

The single rotary encoders are quite common. Have a look to find a variant soldered to a PCB ready for use with an Arduino and a knob. They can be easily connected to the Arduion with a jumper cable.

The stacked rotary encoders are industrial grade and a litte expensive. Some dealers provide a PCB for connection with an Arduino, but you have to solder the encoder and a row of PIN headers to the PCB on your own. If you think these are to expensive you can of course replace one double encoder by two cheaper single rotary encoders.

To connect the 20x4 character LCD display to the Arduino take care to buy one with an I²C interface. Other displays are not supported by MobiFlight. The I²C interface is a standard to easily control the display from an Arduino. This interface is supported for a number of different display sizes by the MobiFlight software. In most cases you have to solder the I²C interface to the display on your own.

The direction of the type A/B USB-adapter is changebale. It's great for a self-made casing. You can simply unplug your self made panel from you computer.

A "matter of the Heart"

I will mention some open source software. Even though this software is "free", this does not mean it's free in the sense of "free coffee", it's free in the sense of "free speech". Everybody can take this software and modify it, adopt it to own needs and much more.

Nevertheless, the people behind this software are having cost. Mostly for webservers. With this step i want to encourage you to make donations to these Open Source software projects. I don't want to urge you to spend a big amount of money. Instead think about a cup of coffee. In Germany a simple coffee is available for about 1.50 €. If you spend this amount on a monthly base this probably won't ruin you. But if 20 people are donating 1.50 € a month, the maker of an Open Source software are getting 30 € to host a webpage.

When you're living in a country where the coffe is only about 0.20 €: donate this amount monthly. Every cent/pence/whatever helps the makers of the software.

And don't forget: These people typically are full time workers and support their software in their leisure time. In my opinion it's a great idea to assist them with a small amount of money.

If i was able to convince you: Great and thank you. If not: never mind, just continue reading and build up your own multi panel for your flight simulator.

Connecting Rotary Encoders to the Arduino

sRotary_01.jpg
dRotary_01.jpg
dRotary_02.jpg

The PCBs for the single rotary encoders typically include a so called "pull up" resistors. In case they don't: the Arduino (in detail: the used ATmega chips) can optionally provide such a resistor. And finally: The MobiFlight software automatically configures all input PINs to use this pull up logic.

The PCB for the double rotary encoders does not provide a pull up resistor. But as mentioned, the MobiFlight software will configure the Arduino accordingly.

The pins for the single rotary encoder are connected as (PIN on rotary - wire color - pin on Arduino):

  • GND - blue wire - GND
  • + - not needed to connect
  • SW - grey wire (button) - 32
  • DT - white - 34
  • CLK - black - 36

The pins for the two double rotary encoders are connected as (PIN on rotary - wire color - pin on Arduino):

  • COMM - blue - GND
  • Inner B - green - 22/23
  • Inner A - yellow - 24/25
  • Outer B - orange - 26/27
  • Outer A - red - 28/29
  • Button - brown - 30/31

Connecting the Display to the Arduino

I2C_01.jpg

The display uses a so called I²C interface. This interface needs to be connected to power, ground and two dedicated pins by the Arduino. For the Arduino Mega 2560 R3 these are the pins D21/SCL and D20/SDA. These pins are labled accordingly. On most I²C interfaces, these pins are labled too.

Use 4 wires to connect the I²C interface to the Arduino. In the images they are colored like:

  • GND - green - Power GND
  • VCC - yellow - 5V
  • SDA - orange - D20/SDA
  • SCL - red - D21/SCL

Wiring All Together

MultiPanel_01_Steckplatine.png

Now you have to use the jumper cables to connect all necessary pins of the rotary encoders and the I²C interface of the display.

Fit Into Housing

F9MRU4HL5MH2IPV.jpg

Now it's time to take something to make the necessary holes into the housing. You have to measure the diameter of the axis of the different rotary encoders. Take a drill and a saw to make the rectangular hole for the display ... And so on.

My result look like the image above.

Setup the Device

Download the MobiFlight software MobiFlight-Installer.exe. Move the software to a separate folder. This is important because the installer will download the real software to the same folder as the Installer.

Connect the device to your PC. Afterwards start the just downloaded MFConnector.exe. When starting the software will scan for compatible Arduino devices. When asked if you want to install the special software accept it. This will change the default Arudino firmware by the special MobiFlight firmware. This step can be reversed with the connector software.

Configuring the Attached Input and Outupt

mf-module-01.jpg
mf-module-02.jpg
mf-module-03-display.jpg
mf-module-04-double-rotary.jpg

The first part is to enter which hardware is attached to the Arduino. In our case this are more than you might expect.

First of all the rotary encoders do have a pushbutton as well. Next the double rotaries are set up as two individual devices. I named the single rotary as Encoder-Menu and its button as Encoder-Menu-Bt. An encoder is using two pins to determine if the knob was turned left or right. According to the wiring diagram some steps above i used the pins 36 for left and 34 for right. If you encounter that this does not fit for your encoder just swap the pins. Same applies to the type. For my encoders the type 1 detent per cycle (00) was correct.

Next i added the Display as LcdDisplay. The I²C devices all have an assigned address. Refer to the documentation of your display which address is preselected. In many cases this is the address 0x27. The number of columns is 20, the number of rows 4.

The outer and inner rings of the upper double rotary were added as two encoders and the included button as well. Same for the lower double rotary encoder and its button. For the ELMA E37 the left pin always have the higher pin number than the right pin. Refer to the wiring diagram for details.

Implementing the Menu

settings-01-menu-01.jpg
settings-01-menu-03.jpg
settings-01-menu-02.jpg
settings-01-menu-04.jpg
settings-01-menu-05.jpg
settings-01-menu-06.jpg

As the first task we will activate the single encoder to work as a menu selector. This way we will be able to have configurable number of menus (or tell them screens) to use the double encoders for different tasks.

We will start on the Ouput tab of the MFConnector main window. Add a new line by double clicking the name and assigning a name. I chose menu as the name. This step has created a globally accessible variable with the name menu which we will use quite often.

Next we want to be able to change this variable using the single encoder. Change to the Input tab of the main window and add a new item. After giving a name like menu or menu input open the configuration of this new item. Choose the correct Arduino (here Multipanel (COM5)) and the device Encoder-Menu.

Now we want to tell MobiFlight what to do when the encoder is used. We will begin with the On Right event because this is a little bit easyer to understand.

Choose the Action Type value MobiFlight - Variable. In the next line you have to select the variable menu which was created on the input tab. In the line Value we tell what to do. The formula is ($+1)%7. The $ will contain the value of the variable menu. We add 1 to this value. Next we do a modulo operation. This will give the remainder of a whole number division. Samples:

  • Value was 0 -> (0 + 1) is 1, dividing 1 by 7 is zero with a remainder of 1. 1 is assigned to menu.
  • Value was 6 -> (6 + 1) is 7, dividing 7 by 7 is one with a remainder of 0. 0 is assigned to menu.

With this code when turning the encoder to the right it will change: 0 - 1 - 2 - 3 - 4 - 5 - 6 - 0 - 1 and so on.

The left direction is a little bit more complicated. The formula is ($-1+7)%7. When starting from 0 the new value will be -1. We add 7 to -1 which results in 6. 6 divided by 7 is 0 with a remainder (% operator) of 6. When turning the encoder to the left this code will change the variable menu: 0 - 6 - 5 - 4 - 3 - 2 - 1 - 0 - 6 and so on.

If you want to have more or less menu pages, just change the digit 7 in both formulas (left and right) by the new number of menu pages. Sample: changing to ($+1)%3 and ($-1+3)%3 would result in a menu changing 0 - 1 - 2 or 0 - 2 - 1.

Change back to the Output tab of the main window. When turning the knob to the left or to the right you should see the value in the table accordingly.

Now we want to display this menu value to the attached display. Add a new line by double clicking and assigning a name like display. Open the settings for this new line. Select the menu variable in the Sim Variable settings. Change to the Display tab and enter data like in the screenshot above. Again the $ sign is a placeholder for the value of the variable menu.

When anything worked like expected you'll see the screenshot above on the display. When using the menu encoder the appropriate value should be shown.

Using the Menu Variable

condition_01.jpg
condition_02.jpg

Now we added a variable which tells us, which page the user is on. We will use this variable on the inputs as well as on the outputs.

The screenshots are showing samples for Output and Input. In both cases you see, that only some are used to be displayed or used to change values. By using the Precondition we are able to control what happens in which menu. The standard case is that you have quite a lot of red exclamation marks that indicate that the Output/Input is inactive for the moment. When changing the menu with the topmost rotary, the exlamation marks should move.

Using the Fast Option

fast_01.jpg

One very interesting setting for rotary encoders are the On Left (Fast) and On Right (Fast) tabs on the input settings. By using them you can accelerate settings.

As a sample I took the setting of the heading bug. Select the normal event on the typical way: Microsoft/Generic/Flight Instrument and select HEADING_BUG_DEC. When done you tick the box in front of the Show Preset Code. You see code like (>K:HEADING_BUG_DEC). By copying and pasting this more than once into the text box, the event will be executed more than once when the encoder is in fast mode. This way the heading bug will change more quickly when used rapidly. The same setting can be made for the other direction.

Every MSFS event of this style can be used to accelerate the setting of the desired value.

Multiple Event on the Same Input

multiple-setting-01.jpg

Using the Show Preset Code can be used to map multiple input on the same rotary. For zooming the GNS530 as well as zooming the MFD map of the G1000 you can add the events (>H:AS530_RNG_Zoom) and (>H:AS1000_MFD_RANGE_DEC,number). When turning the rotary, both events will be sent to the simulator. No matter if your'e sitting in a GNS530 equipped aircraft or inside a glass cockpit with a G1000, the map will zoom for both of them.

Selecting Digit to Change

digits_01.jpg
digits_02.jpg
digits_03.jpg
digits_04.jpg
digits_05.jpg
digits_06.jpg
panel_04d.jpg

A very interesting use case is to select the digit to change with one rotary and change the digit with another. This might be used for the ADF frequencies (ADF_100_DEC, ADF_10_DEC and ADF_1_DEC) or the transponder (XPNDR_1000_DEC and so on).

First we add a new MobiFlight Variable on the Output tab as shown in the first image. Its named adf1Digit. This provides a new variable which we will control on the Inputs tab.

Change to the Input tab and map one of the rotaries to this variable as shown in the second image. The change of this variable is done the same way as for the menu variable. In the case of the ADF we need three values (0, 1, 2) which will be resposible for the 100, 10 and 1 increment/decrement of the frequency. The code for On Left will be ($-1+3)%3 and the code for On Right will be ($+1)%3. When done you will see the new variable changing on the Output tab changing 0 - 1 - 2 - 0 or 0 - 2 -1 - 0.

Now we want to give a hint on the display, which digit we are setting when using the other rotary switch. We introduce one more internal variable I called adf1DigitDisplay. Important is to add a Config Reference to the above mentioined variable adf1Digit. Remeber the sign this variable is assinged to, in the screenshot it is the # sign. We will need this for the next tab.

We change over to the Compare tab of this new variable and use a special feature of MobiFlight. We will enter a condition which is always true. In this case we know, that the variable will always be greater or equal to 0. By doing so, the line set it to will always be executed.

In this field we enter the formula

if(#=0,'^^--',if(#=1,'--^-','---^'))

This tests if the referenced variable adf1Digit is 0, and change the value of adf1DigitDisplay to the string ^^--. If the value is not 0, it will test the same variable for "1" and change the output to the string --^-, if not it changes the output to ---^. With that done we have a marker on this screen which will point to the digits that will be changed when using the rotary encododer.

Within the display for this menu we reference the variable adf1DigitDisplay (in the screenshot as @) and put this below the display of the ADF1 frequency. This will result in a display like in the last screenshot.