Tutorial Setting up 7 segment LED modules with SimConnect Events - MobiFlight/MobiFlight-Connector GitHub Wiki

Setting up 7-Segment LED modules with Mobiflight and SimConnect Events

The type of 7-segment LED modules supported in Mobiflight is the MAX7219 chip. MAX7219 is an integrated serial input/output common-cathode display driver that is very popular for arduino projects with each chip capable of driving up to eight digits. A commonly found package in all the online stores is the one using this chip with eight numeric display blocks. These complete modules are used often to display numeric information in simulator panels such as speed, or heading settings in an autopilot or the barometric pressure setting for the altimeter.

Here is a picture of these modules and a typical schematic diagram of how they are connected.

MAX7219 LED MODULE2

In addition to the power and ground wires, only three additional connections (DIN, CS and CLK) are needed to the Mobiflight board digital pins. If needed, several modules data lines can be connected in daisy chain. Because these modules contain a diode to protect the components from erroneously applying the power, the voltage drop introduced by these diodes makes daisy chaining the power connections beyond two or three boards difficult. Individual 5v wiring to each module is the recommended solution. Desoldering the diodes to eliminate the voltage drop is also an option, but more complicated. The data lines do not have this limitation.

Mobiflight can handle up to 8 modules in a daisy chain and up to 4 individual chains for a total capacity of 256 digits per Mega board. Electrically, each module may consume up to 120mA which means only up to about 4 modules can be powered from an Arduino Mega. Any number beyond will require an external 5v power supply.

The MAX7219 modules are connected to the Arduino Mega with only five wires as shown in the diagram below. The three digital pins in the board can be any pins. There is no special requirement for these pins. Make a note of which pins are connected to DIN, CS, and CLK in your LED module, as you will need this information later.

7 segment arduino connection

Create the LED module device configuration

In the previous section, you completed the wiring of your 7-segment display to the Arduino Mega board. Now we will create the device configuration for the display in the board configuration. We assume that you have already uploaded the Mobiflight firmware to your board. If not, you need to complete this step before proceeding. If you don't know how to do this, please refer to the tutorial on how to upload the firmware.

Open Mobiflight Connector and go to the "Mobiflight Modules" window by pressing the button located in the main toolbar.

image

Mobiflight will display all Arduino boards connected to your PC (if more than one). Your board should be recognized by the application and included in the list of available boards with the blue Mobiflight logo icon. If the board is shown as unknown, you will probably need to upload the firmware and try again.

Select the correct board from the list by clicking on its icon. Press the "Add device" button at the bottom of the window. A drop down list will appear with all the device types. Select "LED 7-Segment".

image

A new device named "LedModule" will be added to the list of devices connected to your board and the device configuration window for the 7-Segment display will be shown on the right side of the window. Here you will enter the Arduino pin numbers where you connected the DIN, CS and CLK pins of your display module. The "Num" parameter is the number of LED modules connected in daisy chain to these pins. As mentioned earlier, you can daisy chain up to 8 modules and can have up to 8 separate chains. You can also change the device name if desired.

image

That's it for the device configuration. You should now upload the configuration to your board by pressing the upload button. This will take a few seconds and Mobiflight will confirm when the action is complete. It is a good idea to also save the configuration in a mfmc file by pressing the save button, in case something may happen to your Arduino board.

Setting up the 7-Segment Module to Display Heading and Indicated Air Speed

In this tutorial, we will use the 7-segment module to display the airplane heading and speed. For this, we need to create two output configurations, one for heading and one for speed.

First the heading configuration. Open a new configuration and name it "7-Segment Heading" and press the three dots at the right side of the row to open the config wizard. Click on the Simvariable tab at the top of the window and select "SimConnect (MSFS2020)" as the Variable type. Now select from the Group drop down list "Microsoft/Generic/Flight Instrumentation" and from the Preset drop down list the variable "HEADING INDICATOR". The Variable field will be filled with your selection.

image

Setting the display position. Click on the Display tab and select the board where the module is connected and in Use Type of put "Display Module". In Addr / Connector select the specific module "LedModule" we created earlier. The module has 8 digits so we set Number to 8 and we put check marks on positions 6, 7 and 8, where the heading value will be displayed. Because the heading is normally displayed with left "0" padding, we put a check mark in Use Left Padding and "0" as the padding character. Press OK to finish this configuration.

image

Second, the Speed configuration. Create the output config for the speed variable in the same way described for heading. Name this configuration "7-Segment Speed". In this case the Group is the same: "Microsoft/Generic/Flight Instrumentation" and the preset for speed is "AIRSPEED INDICATED". The variable field will show the selected variable.

image

Setting the display position. The procedure to set the position of the speed value is the same as for the heading shown above. The only difference is that the digit positions are 1, 2, and 3. We will also set the "0" left padding option as we did for heading. Press OK.

image

CONGRATULATIONS. You now have setup your 8 digit display module to show the heading on the right side and the indicated air speed on the left side of the display.

How to Turn the Display Off

Your display is working great and displays the airplane current heading and speed, but you noticed that when starting the airplane from cold and dark, your display is on, even though there is no power in the virtual cockpit. Here is a way to make the display turn off if there is no power in the cockpit. The trick is to change the display to show only spaces (so it seems to be off) through the use of a Transform formula and the Compare function.

In this example, we will need to create output configurations for two additional standard variables that indicate the state of the power in the cockpit. These are "AVIONICS MASTER SWITCH" and "ELECTRICAL MAIN BUS VOLTAGE". We want to set our display such that it will be ON only when there is power in the main bus AND the avionics master switch is set to ON. If any of these two conditions is not met, we want the display to be OFF.

AVIONICS MASTER SWITCH. Create a new output configuration in the same way as previously and name it "AVIONICS MASTER ON". Select SimConnect (MSFS2020), the Group is "Microsoft/Generic/Avionics" and the Preset is AVIONICS MASTER SWITCH. Note this is a boolean variable that only takes values of 0 or 1.

image

ELECTRICAL MAIN BUS. Create a new output configuration following the same procedure as before and name it "MAIN BUS ON". In this case we want to select the Group "Microsoft/Generic/Miscellaneous and the Preset is "ELECTRICAL MAIN BUS VOLTAGE". Here the setup is a little different as this variable is in Volts. We put a check mark in Transform and put the formula

if($>5,1,0)

This expression will have a value of 1 if the voltage is higher than 5 volts, i.e. the main bus is powered.

image

We now have two output configurations for the two variables we need to use. We will go back to the heading and speed output configurations we created earlier to modify their behavior using a Transform formula and Compare that brings these two new configurations together.

Modified Heading display configuration. Please open the "7 Segment Heading" output configuration created previously. Go to the bottom section of the window "Config References", put a check mark on the first line and open the drop down menu next to the check box. This is a list of all the defined outputs in Mobiflight. Select "AVIONICS MASTER ON" and put "#" in the box marked "As". Next, go to the second check box and put a check mark there, select the output "MAIN BUS ON", and put "?" in the "As" box. Please note that both config references only take values of True or False (1 or 0).

You have now added the AVIONICS MASTER ON and the MAIN BUS ON variables as values that can be used in the Transform field. The "#" and "?" are placeholders that are used in the formula to represent these two values.

In the Transform field enter this formula.

if(#*?=0,999,$)

By multiplying both config references which only have values of 1 or 0, the result is 0 if either of the references have a value of 0 (False). In other words, if MAIN BUS ON or AVIONICS MASTER ON is False, the display should be OFF. To achieve the OFF condition, we set a special value of 999 that will be picked up by the Compare function. For the case when both references are true, the display is ON with the heading value ($).

image

The work is not over yet. We have one more step to complete the Heading config. In order to turn off the display when the special value of 999 is present we use the Compare tab. Open the Compare tab of the heading display configuration. Check the "Apply comparison" check box and set the condition to "if current value is =" the special value "999". The "Set it to" field should be filled with three spaces in single quotes. Press OK.

image

Modified Airspeed display configuration. If you followed the above procedure, this is a repeat of the same that needs to be done to the "7-Segment Speed" output configuration created earlier. Use the same config references, the same transform formula and the same compare settings.

image

The Compare window is identical to the heading configuration.

You have completed the tutorial. Your 8 digit LED display will show the heading and air speed, but it will be "OFF" when either there is no power on the main bus or if the avionics master switch is off.

Using the Brightness Reference Parameter

The 7 segment display output config wizard has a parameter that allows the user to control the brightness of the display. You can set the brightness from 0 (off) to 15 (brightest) by specifying an output config that will serve as the reference value for this brightness.

image

Notes on this parameter:

  • The brightness is set for all the digits controlled by this particular LED module or Max7219 chip.
  • Setting the brightness with this method will override the brightness setting in the Module device configuration.
  • The output config to be used as Brightness Reference should have a value between 0 and 15.
  • You can vary the brightness by changing the value of the Brightness Reference output config.
  • An alternate method for blanking the displays is by setting the Brightness Reference to zero.