MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

icon
Avatar
StickNRudder
From: EHLE, Netherlands
Posts: 5
Hi all,

just joined the MF forum, so here's a little introduction, and my first project.

I am a mechanical engineer (machinery design) by trade, and a PPL pilot by hobby. Of course I also "fly" sims, and I tried to build some parts to resemble the cockpit of my Aquila A210 so I could Sim-practise procedures. I fly FSX, X-Plane, and now also MSFS2020. That's how I got here, because I got my switch box working with FS9, FSX, and X-Plane though FSUIPC and some interface software (link2fs), so my project will be a "moving from link2fs to MobiFlight" type :)

I built a box around a Mega (lucky me) with a couple of rocker switches, and three multi-position switches each connected to their own analog pins. There's a couple of resistors on those to act as voltage dividers, so reading the analog pin will tell the position the rotary switch is in.
And then there's 3 green LEDs as flaps position indicator.

Image:

https://photos.app.goo.gl/GKkDiuK9jdPR6hHcA

Video
https://youtu.be/rFKc2pCc0oQ

So, on the left is the "key" starter switch (5-position). I have to manually return the knob from the "Start" position to the "Both" position. The large rotating knob on the right is the flaps switch (3-position). On the right side is another 3-position rotary switch which I use to select different parameter sets for different airplanes.
The biggest challenge will probably be to have only one Flaps Indicator LED on at any one time, depending on the extension (degrees) of flaps. That has to be based on actual position, not on switch position. Say Flaps 0 = 0 degrees, Flaps 1 = 15 degrees, Flaps 2 = 30 degrees. Then when moving from 0 to 1, LED 0 needs to stay on until 15 degrees is reached. Going back after that, from Flaps 1 to Flaps 0, the LED 1 needs to stay on until 0 degrees is reached. (And the number of degrees for each flap position differs per aircraft type, to make things interesting... hence the parameter selection rotary switch)

So, I will probably get back here to ask for help if (or when) I get overwhelmed :D
I will post updates as responses to this thread to let you know where I am at, and what struggles I face - and hopefully conquer.
[Last edited by StickNRudder, 2022-01-24 17:14]
In theory, practice equals theory...
2022-01-24 17:05
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
Hi

Welcome to Mobiflight !

At first.... In case your request is little complex and we may will awnser a lot of questions here....
I think a DISCORD Contact would be nice..... https://discord.gg/99vHbK7
In a Voice Seasson ( via Headset) we pretty sure can clearup a lot of open questions without write 10 Days here postion via posting!

Whatever i will awnser the basic things now....

1. Compatibility over the Sims.
MF work fine for FSX, P3D ( Via FSUIPC ) and FS2020 (Directly) ... Xplane it also work ( Via XPUIPC) but in a reduced form.
BUT
Not expect to have "one" overall Config that work for all.... Also each single Aircraft can be different within a Sim.
Means.... You will pretty sure at the end need multiple MCC Files.... One for each Situation ( e.g. one for FSX and one for FS2020)
You not need to build them all from scratch.... More logical is to build one and "rework" it multiple times to get finally single files for all your needed Situations !

2. Your Hardware
Good News.... You use a Mega. So you will be already perfect compatible to Mobiflight !
Bad News.... Your Rotary Switches not work!
Mobiflight use Analog Pins only for Potentiometer Inputs OR as "I/0" like Digital ones....
So a MultiPos Rotary ( e.g. with 6 Positions) in Mobiflight is set with 6 Wires to 6 Pins ( normaly DIG but also Analog is posible) .... But we handle them as 6 Buttons finally.
Technical with a complex formula we maybe can set your Switches like a Poti..... And make difficult Configs and Duplications with Preconditions....
But i will say much more profitable is a rework here....
Means If you remove the resitors and simply wire the Switch Pins to individual Input Pins is 100% Our System. I recommend this ( but we can also try if the improvisional solution work for you)

3. Your LED Idea.
MF give a lot of Posibilitys... We can for sure controll a LED in case of the Virtual situation and NOT by the Switch.
Whatever your request sounds a little Difficult !
I need to think if this "both direction" logic is Posible. I think so.... But i have no idea for the code a.t.m.

***********

So Hopefully i give the first input.... Looking forward to talk the next days if you like !
Good Luck !
2022-01-24 21:26
Avatar
StickNRudder
From: EHLE, Netherlands
Posts: 5
Thanks for your quick reply!

yeah, I knew I had a challenge cut out for me :)

So far, I have tested MF to work with all my sims through FSUIPC. That is: FSUIPC7 for MSFS2020. I need to run the sim in conjunction with FSUIPC anyway because I always have a Flight Logger running for my VA that is dependent on it. So far I had MF work with one configuration for all three sims that way. It is only a simple indicator LED, a push button, and yesterday I got a 7 segment LED to work, but it gave me the confidence in MF to move forward with MF :)

But you are right; I will probably end up using SimConnect for MSFS2020 instead of FSUIPC7 (more "native", more possibilities, less limitations).
Is there a command-line to start MF with a specific mcc file? like in a batch file to start the sim with it's own MF instance with the correct mcc file? I like to automate away possible errors if I can ;)

As for the hardware: soldering a little flatcable to the multi-position switches to separate digital pins is no problem; I will go that route. Otherwise maybe it would work by reading the analog value (there are as many discrete values as there are positions per switch, and have an MF variable (BOOLEAN) per position controlled by that value. That way it might be solved through software. But I agree: the hardware wiring to separate pins is easier. And I have a lot of unused pins :)

I have the "both direction logic" worked out in an Arduino sketch that "talks" to Link2FS. For every incoming Flaps Angle value, it compares to three pre-set values. If one of them is met, then the corresponding LED is lit, and the other two are dimmed. That way, only one LED will light up, and stay lit until a different preset position is met. It's as simple as 3 if statements,but I do not see yet how I can get that into MF just yet. I will need to sleep on that a little more. It should be possible with some virtual switches, I think. But not sure.

For if you are interested, here's the logic as I tested it out before connecting to the sim, by entering values into the Arduino IDE serial monitor:
iconcpp:
// These constants won't change.  They're used to give names
// to the pins used:
const int brightness = 10; // Value 0 (black) to 255 (brightest)
const int FlapsUpPin = 5;
const int Flaps15Pin = 6;
const int FlapsDownPin = 7;
boolean stringComplete = false ;
String inputString;
int command[10];
char received;
char message[10];
 
//char inChar = '';
 
 
 
void setup() {
  // set pins as outputs:
    pinMode(FlapsUpPin, OUTPUT);
    pinMode(Flaps15Pin, OUTPUT);
    pinMode(FlapsDownPin, OUTPUT);
    Serial.begin(115000);
}
 
void loop() {
  //int i = 0;
  //int n=0;
  while (Serial.available() > 0)
    {
        char received = Serial.read();
        //i++;
        //message[i] = char(received);
        inputString = inputString + char(received);
        // Process message when new line character is recieved
        if (received == '\n')
        {
            Serial.print("Arduino: ");
            //for (n=1;n=i;n++) {
            //Serial.print(message[n]);
            Serial.print(inputString);
            //}
            // You can put some if and else here to process the message juste like that:
              if (inputString == "<G000\r\n") {
              analogWrite(FlapsUpPin, brightness);
              analogWrite(Flaps15Pin, 0);
              analogWrite(FlapsDownPin, 0);
              }
              if (inputString == "<G019\r\n") {
              analogWrite(FlapsUpPin, 0);
              analogWrite(Flaps15Pin, brightness);
              analogWrite(FlapsDownPin, 0);
              }
              if (inputString == "<G057\r\n") {
              analogWrite(FlapsUpPin,0);
              analogWrite(Flaps15Pin, 0);
              analogWrite(FlapsDownPin, brightness);
              }
              inputString = ""; // Clear recieved buffer
              }  
      //i=0;
      }
 
}
 


How does the Discord Channel work? Are you guys online on specific times? Or on request? Or always?
In theory, practice equals theory...
2022-01-24 22:28
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
1. FSUIPC

You can work with Both... So you still can use FSUIPC in FS2020 ( Whatever with it´s limitation as you already find out) But also a "Combination" is possible.... E.g. make some Stuff that is more comfortable with Simconnect and do other things by FSUIPC.... In case you still NEED it for your other 3rd Party stuff your in the great situation to work with both things !

*******
2. Auto Start.

Yes possible.... We use a EXE-Paramter correct syntax is.... MFConnector.exe /cfg myfile.mcc
In that case the file must located in the same folder like the MFConnector.exe .....
For sure you can also include a Path in the Syntax like MFConnector.exe /cfg c:\folder1\folder2\myfile.mcc

By the way.... If you start a seasson.... thats a good idea. If you just swap a aircraft ask youreself if its more comfortable to Close MF and start it with this Desktop Link OR if you just klick with your mouse in MF on File --> -Recent Documents ----> Yourfile.mcc ...... Less klicks, less work, less time !

**********
3. About the Switch
A "Indicaton" of Position by a Read is possible.... Thats no problem to define a Output Config that say "Switch is currently in Pos 1,2,3,4,5,6 by a clear Value.
So e.g. if you would press a "Button" then we could define by this Output what Command should be done now in relation to the Position ( read by the Fake Poti)
BUT
A Poti is working "on change" .... Means we will send a command in the Moment you "move" the Switch..... And here we just can define where it was.... But we not can indicate to that Output in what direction the switch is going now.

A solution via MF would be more like to define Areas.... Like a Zone around the Target Position.
Means at first we must Disable the Input Config for the current Position in case a moving will also occure in a additional Command of THAT Zone ( The Poti can not know if he moves away from its current Pos or if he arrive.....
And finally we build a Input Action if the Switch "reach" the new Position by entering that area.

As explaned.... I think this is possible.... But i still think a electrical Rework would be more easy and takes less time as create/write the additional Config Code you will need!

***********
4. About LED.
I see in your Code the LED are located to Pin 5,6,7, Thats fine. MF also be able to controll a LED via PWM, but only on the PWM Pins.... On the other Pins a LED is simply Bool.
About the Logic.... I also expect we find a way....
The Light Bright State when Reach is no Problem ( And also Disable the 2 Other in that case is working) .
We also could easy say dimm BOTH involved LED (where i come form and where i go to) while Transit is no big deal. ( And set the 3rd LED to OFF that time)
Finally also Set the "come from" LED to Dimm and the "Go to" LED to Full bright is a easy thing!
The real tricky part is what you expect.... Remain the "Come From" LED in HIGH whatever the Transit is still running. Thats the magic Part !

I still got a idea... But i need to test this myself !
Good Luck !
2022-01-25 09:33
Avatar
StickNRudder
From: EHLE, Netherlands
Posts: 5
Thanks for your enthousiasm! It works inspiring :)

I have just flashed the board that is in my switch box and am now configuring the rocker switches as a button, and that process works as I expected. So that part will be finished before my flight this evening, and I will at least be able to use my rocker switches already. The soldering bit will probably wait until the weekend. I don't know if I can find the time, but I will certainly try.

I usually do a single flight and then call it quits for the day, so the batch environment could work for me.
Also, I manage a VA, so I want to test stuff out across the sims. So starting up the sim always with the correct MF/*.mcc through one duble-click sounds easy and fool-proof ;) That's why I am interested in the batch file approach.

Will update later!
In theory, practice equals theory...
2022-01-25 18:18
Avatar
StickNRudder
From: EHLE, Netherlands
Posts: 5
I did get a bit further already; still a work in progress :)

All the rocker switches do what I want them to do (switch lights, avionics, fuel pump). The challenge mainly was in the flaps position indicator LEDs and starter switch.

I have a rocker switch on my throttle quadrant assigned to operating the flaps, so my focus went not so much to the operation through this analogue input, but to having the correct LED light up. I more or less got that working by having a "Flaps Value" output that gives a number 0-16383 for the actual flaps position. I then created 3 outputs to control the LEDs, and gave them a precondition of "Flaps Value" being within a specific range (the values were not exactly constant; the middle position was off by 1 when going up compared to going down, and sometimes the 0 position would still read 1). So now the LEDs are dimmed when flaps travel and the correct one lights up when that position is actually reached. This is always correct for flaps up and down, but the middle position may vary per aircraft type. I will see how to deal with that later.
I used a multi-position switch to select a parameter set in the previous set-up, so I think I will use that same switch to define middle positions per aircraft type if I need to. But that's at the bottom of the ToDo list :P

The analogue input for the magnetos and starter switch I tackled in the same fashion. One output records the value, and per "key position" a small range acts as the precondition for that situation (Off, L, R, Both, Start). So now I have 5 binary / Boolean outputs that define the position of the starter key. I then tried to make the start position the precondition for starting the engine, but I read in the MSFS documentation that the starter switch state can be called from the som, but not written to the sim... :O
https://docs.flightsimulator.com/html/Programming_Tools/SimVars/Aircraft_SimVars/Aircraft_Engine_Variables.htm#GENERAL_ENG_STARTER
I cannot quickly find an FSUIPC offset to that, so I am stuck there a little. I will look further tomorrow, but I wanted to share my progress and approach already.

As you can see, a multi-switch with a couple of resistors can be used on a single analogue pin. But it sure takes a lot of fiddeling about. It's a good learning experience, but I think I will in the end just rewire the box to have separate wires to individual pins. Much easier to program, and enough pins available ;)

Anyway: I will get back with an update soon!
Cheers,
Eric-Jan
In theory, practice equals theory...
2022-01-28 17:45
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
About Switch.

Your right. As i said... It´s possible. But not verry usefull !
Also your IDea was correct. You will write with switch basically a "Indicator" ( like a Mobiflight Variable ) with @ do be able to define the Position Values.
Then you use multiple Input Configs and use as Precondition the Output Config, that read that MF Var.
As you say... Possible, but much more a bypass like a simple I/O based Switch with a clear Press command!


About Multiple Aircraft Situation.
We talk above already about the Exe Parameter and your Batch File Idea.
For sure.... It will possible e.g. to read out from Sim what Aircraft is currently in use and you could say " If current Aircraft = C172, then use Flaps Middle Pos of Config X else use Config Y ... Or you use as you expect a "fake Button" to toggle between a "Mode" to have multiple Flaps logics....
BUT
Why not simply build a MCC Config individual for each Aircraft ? ... So if you fly a C172 you load the e.g. C172.mcc File, that already have the perfect Configs to handle THAT Flaps Situation !


About LED.
Your Cheating B) :P
Your initial request was " LED must "remain" Full bright also when a Setting is done..... And must get disabled AFTER Flaps reach the next selected Position.
The current logic you tell me ( LED ON if in Position, Dimmed if a Transit is occured, abd OFF if Flaps are in one of the other Positions....
Thats no big deal. Thats build already by multiple People. More interesting is your initial idea. I still think we can figure this out. But till now i´m not at the point that it is working !

At last... About flickering Values.
Basically check if there is a other Value.... Instead of read Flaps Position.... May you could read Flaps Indication Position....
Check the Vars if there is a better one available.
If not.... You could think about "Areas" like with the Switches.
If Mid Pos can be e.g. 7890 or 7891 or 7892 .... Simply make a formula like if($>=7890&&$<=7892,1,0) So its indication all 3 Values same way!
Just a example.... You could write this formula with multiple AND or OR or with nested ElseIfs .... No mater. I just want to show a example !
Good Luck !
2022-01-28 23:22
Avatar
StickNRudder
From: EHLE, Netherlands
Posts: 5
Haha, you are right about the cheating with the Flaps position indicator LEDs.I tried, but I could not get it to work as i wanted it to. I've been at it for a couple of hours, and decided to quit for the day and accept the "off in transit" solution for now.
But I will definitely be trying again! :)

And thanks for the example of the if statement with the Boolean logic within. I will certainly be using that in the future.
And of course for the thinking along :thumbup:

I will get beck here when I have some progress to report.
In theory, practice equals theory...
2022-01-29 22:32
icon