-
-
Notifications
You must be signed in to change notification settings - Fork 106
Example Encoder with SimConnect Events
A digital rotary encoder or simply "encoder" is used quite often in building simulator panels. For example, encoders are very often used in autopilot panels for the knobs to control the settings for altitude, heading, speed and vertical speed. They can be used in substitution of potentiometers in controlling the cabin and panel light dimmers and also in radio panels to tune the COM and NAV frequencies.
Photo of commonly used EC11 encoders
An encoder typically has three pins marked in the picture below as A, B and G for the encoding function, plus two more pins, marked P1 and P2, for the push button function.
Pins A and B are connected to any two digital pins in your arduino, while pin G is connected to the common ground. For the encoder push button function, one of the pins either P1 or P2 is connected to one arduino digital pin, while the other is connected to common ground, the same as pin G. Make note of which arduino pins you have used, you will need this information later.
We assume you already uploaded the Mobiflight firmware to your arduino board. Open Mobiflight Connector and go to Mobiflight Modules
Your Mobiflight module should appear in the list of boards detected. If not, you need to verify your steps and confirm your board is recognized by Mobiflight before continuing. If your board appears on the list, select this board and press the "Add Device" button at the bottom of the dialog and select "Encoder" from the dropdown list.
You should now see a new device on the list of devices for your board with the name "Encoder" with this configuration window
Enter the pin numbers where you connected the encoder to your arduino board. Pin A for the Left Pin and Pin B for the Right Pin. Don't worry too much about this assignment. For the EC11 encoders, the setting "1 detent (00)" has worked best for me. You may need to select a different setting depending on the encoder you have. If your Mobiflight later reports that your encoder is rotating to the reverse direction that you actually turn it, you just need to reverse the pin assignments in this configuration.
Create another device configuration for the encoder pushbutton. This is just a regular button and you can follow the tutorial for setting up buttons. Make sure to assign the same pin number, where you connected the P1 encoder pin, to your board.
Save your configuration in the board mfmc file and also upload the new configuration to your board by pressing the upload config button. Mobiflight will report when your board has received the new configuration successfully.
Congratulations, you now have a new encoder connected and configured in your Mobiflight board. Next, we will bind this new device to a simulator function using a SimConnect event and the Mobiflight WASM module.
We will use as example how to setup the COM Standby frequency with your encoder, using the pushbutton function of the encoder to switch the encoder configuration from controlling the whole megahertz part of the frequency to controlling the fractional part of the frequency (Khz). For this we need to setup two input configurations for the same encoder, one for the whole Mhz and one for the fractional part. We will use preconditions to activate only one of them at any given time.
First, create an input config (Inputs tab) and name it "COM frequency MHZ" for the whole megahertz part of the frequency. Select the Input tab of the config wizard. In this dialog, you select the module where you installed the encoder, select the device "Encoder" or the name you gave it. Once the encoder is selected, the encoder input settings will appear.
In the "On Left" tab, Select for Action Type, "MSFS2020 - Events". Select the group of presets you wish to use. In this case, "Microsoft/Generic/Radio" and for the Event, select "COM_RADIO_WHOLE_DEC". The DEC indicates the event decreases the frequency by one Mhz.
Now press the "On Right" tab. Select the same Action Type "MSFS2020 - Events", the same group "Microsoft/Generic/Radio" and now select from the dropdown list the companion event to the one used above: "COM_RADIO_WHOLE_INC". The INC indicates the event increases the frequency by one Mhz. Press OK and you are done with this step. Ok, you now have an encoder that can set the whole part of the frequency.
We now need to setup the fractional part by creating another config in a similar way. Name this new config "COM frequency Khz". The procedure is the same, so I won't repeat it here. The events to use are named also in a similar way: "COM_RADIO_FRACT_DEC" and "COM_RADIO_FRACT_INC".
You now have two input configurations that use the same device connected to your arduino, but are bound to two different functions in the simulator. They cannot work both at the same time, so we will control which one is active with the encoder pushbutton. This is done by setting up a Mobiflight Variable that changes value from 0 to 1 and back with each button press. We will use this variable in preconditions to activate only one encoder config at a time.
Create a new input config for the encoder pushbutton and let's name it "COM Mhz Khz Swap". In the Input tab, select the device you created for the encoder button. In the On Press tab, select Action Type "Mobiflight - Variable". Name the variable "Mhz Khz Swap". In the value field, put the code
($+1)%2
This will alternate the value between 0 and 1 with each button press. Press OK. You now have a button that assigns an alternating value to the variable.
In order to use the Mobiflight Variable, we need to create an output configuration that reads this variable. Let's name it "Mhz Khz Swap" the same as the variable used. Make sure to select the Variable Type as "Mobiflight Variable". The name of the variable has to match the name used in the input config, i.e. "Mhz KHz Swap". Press OK to exit.
Now let's go back to the encoder input configurations. First, open the whole Mhz config and press the "Precondition" tab. Put a checkmark on the first (only) item of the Precondition list and change the "Use type of" dropdown to "Config Item". Now choose the precondition settings we want this configuration to be active on. Select in Choose config "Mhz Khz Swap". Note this dropdown contains all of the outputs currently defined. Put in "If current value is" equal to "0". Press the "Apply" button, and OK to exit.
We repeat the same procedure for the fractional frequency configuration, but setting the precondition for the value of "1". Press "Apply" and OK to exit.
The last step we need to complete is to configure an output so that we can see the frequency in our panel. This output configuration can be used in an LCD display or 7 segment LED display. Create an output configuration for the COM standby frequency and put this standard variable in it:
(A:COM_STANDBY_FREQUENCY:1, Khz)
Mobiflight will read and display the frequency as the simulator changes its value in response to you rotating the encoder.
Cheers!
- MobiFlight Connector Installation
- Mobiflight Connector BETA version installation
- Modules
- MobiFlight Connector Files Structure
- MobiFlight Connector Uninstall
- Modules Reset to factory default
- Verifying the WASM module installation and locating the MSFS2020 community folder
- Verifying the WASM module installation and locating the MSFS2024 community folder
- Using a Winwing FCU with MobiFlight
- Providing logs from MobiFlight
- MobiFlight Connector How does it work
- Mobiflight Connector Main Window
- Flash module with MobiFlight firmware
- Input and Output devices
- Joysticks
- Midi Boards
- Sim Variables (for Output)
- Input Actions
- Merging configuration files
- Disabling specific COM ports
- Examples Output LEDs
- Examples Input Switch
- Example 7 segment display
- Example Servo motor
- Controlling LEDs with an output shift register
- Adding lots of buttons with an input shift register
- Beginner's guide to input multiplexers
- Key Matrix with standard MobiFlight and Multiplexers
- Tutorial Easy Driver and x.27 or x.40 Stepper Motor
- Tutorial for Airbus VS display via 7-Segment LED Module
- Example Analog Input Potentiometer
- Baron G58 Tutorial Gear, Flaps, Mags, ELT Input Output Programming
- Using Mobiflight to control arduino-based 3rd party panels (RealSimGear GNS530)
- How to use a VNH2SP30 DC motor shield with MobiFlight
- Using 3D printer mainboards
- Playing sounds by sending keystrokes to AutoHotKey
- Using the selector knob on a Honeycomb Bravo
- Using an adjustable 12 position switch as a GA starter
- Brightness of LCD displays with I2C
- Using three-position switches
- Transponder with one Rotary
- MSFS2020 RPN Tips and Tricks
- MSFS2020 Using the Custom Input Code Box
- MSFS2020 Install WASM module and Event List
- MSFS2020 How to Create and Use User Defined Lvars
- MSFS2020 How to Create a Blinking LED configuration
- MSFS2020 User Defined WASM Module Events Best Practices
- MSFS2020 Developer Mode, Model Behavior dialog and Console window
- MSFS2020 PMDG 737‐700 List of Events that require use of FSUIPC7
- MSFS2020 PMDG 737‐700 Calibrate throttle idle and reverse thrust using interpolation (Valkyrie)
- MSFS2020 PMDG 737-700 Chrono unit functions implemented in Mobiflight
- Configuring PMDG 737 Parking Brake Lever Auto-Release with a Servo in Mobiflight
- Using encoder to drive a value back and forth within a given range
- Adding a custom board to MobiFlight
- User guide - Community Board and Custom Devices
- Developing your own custom devices/boards