Results 1 to 4 of 4
  1. #1
    New Member
    Join Date
    Jun 2016
    Location
    canada
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Link2FS Fuel Flow Problem

    Hello,

    I'm building gauges for the FSX Cessna 172 and am currently working on the EGT/Fuel Flow Gauge. My problem is that when I check both extractions (Extractions 2: ?M, ?V) for EGT and for Fuel Flow, the Fuel Flow Gauge does not move smoothly, or sometimes, not at all. If I extract only the Fuel Flow (?V) the gauge works perfectly. Below is the Code I wrote, the Monitor results for both ?M and ?V, and the Monitor results for just ?V

    Code:
    #include 
    Servo FuelLeft_Gauge;
    Servo FuelRight_Gauge;
    Servo EGT_Gauge;
    Servo FuelFlow_Gauge;
    
    
    int CodeIn;// used on all serial reads
    //int KpinNo; 
    //int Koutpin;
    //String flaps;
    String Fuel_Left;
    int Fuel_LeftI;
    String Fuel_Right;
    int Fuel_RightI;
    String EGT;
    int EGT_I;
    String FuelFlow;
    int FuelFlow_I;
    String MasterBATT;
    int MasterBATT_I;
    
    
    //String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
    
    
    void setup() 
    {
     Serial.begin(115200); 
     pinMode(14, OUTPUT);// For the Left Fuel Gauge.
     pinMode(15, OUTPUT);// For the Right Fuel Gauge.
     pinMode(16, OUTPUT);// EGT
     pinMode(17, OUTPUT);// FuelFlow
     FuelLeft_Gauge.attach(14);
     FuelRight_Gauge.attach(15);
     EGT_Gauge.attach(16);
     FuelFlow_Gauge.attach(17);
    }
    
    
    void loop() {
      {KEYS();} //Check the "keys" section
    
    
      if (MasterBATT_I == 0) 
          {
          FuelLeft_Gauge.write(10);
          FuelRight_Gauge.write(130);
          EGT_Gauge.write(10);
          FuelFlow_Gauge.write(130);
          }
      
      
      if (Serial.available()) {
        CodeIn = getChar();
        if (CodeIn == '=') {EQUALS();} // The first identifier is "="
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
        if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
        if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
      }
    
    
      
    
    
    }
    
    
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }
    
    
    void EQUALS(){      // The first identifier was "="
     CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'A'://Found the second identifier
           //Do something
        break;
         
        case 'B':
           //Do something
        break;
         
        case 'C':
           //Do something
        break;
         }
    }
    
    
    void LESSTHAN(){    // The first identifier was "<"
    CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'A'://Found the second identifier
           //Do something
        break;
         
        case 'B':
           //Do something
        break;
         
         case 'X': //Left Fuel Gauge
           Fuel_Left = "";
           Fuel_Left += getChar();
           Fuel_Left += getChar();
           Fuel_Left += getChar();
           Fuel_LeftI = Fuel_Left.toInt(); //conver to an integer (Thanks Phill)
           Fuel_LeftI = map (Fuel_LeftI, 0, 100, 20, 125);
           FuelLeft_Gauge.write(Fuel_LeftI);
         
        break;
    
    
          case 'Z'://Right Fuel Gauge
                
            Fuel_Right = "";
            Fuel_Right += getChar();
            Fuel_Right += getChar();
            Fuel_Right += getChar();
            Fuel_RightI = Fuel_Right.toInt(); //convert to an integer 
            Fuel_RightI = map (Fuel_RightI, 0, 100, 118, 15);
            FuelRight_Gauge.write(Fuel_RightI); 
         
          break;
       }
    }
    
    
    void QUESTION(){    // The first identifier was "?"
    CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'A'://Found the second identifier
           //Do something
        break;
         
        case 'B':
           //Do something
        break;
         
        case 'F':
        MasterBATT = "";
        MasterBATT += getChar();
        MasterBATT_I = MasterBATT.toInt(); //convert to integer
          
        break;
    
    
        case 'M':
           EGT = "";
           EGT += getChar();
           EGT += getChar();
           EGT += getChar();
           EGT += getChar();
           EGT_I = EGT.toInt();
           EGT_I = map (EGT_I, 0, 1200, 20, 125);
           EGT_Gauge.write(EGT_I);
        break;
    
    
        case 'V':
           FuelFlow = "";
           FuelFlow += getChar();
           FuelFlow += getChar();
           FuelFlow += getChar();
           FuelFlow += getChar();
           FuelFlow += getChar();
           FuelFlow += getChar();
           FuelFlow_I = FuelFlow.toInt();
           Serial.println(FuelFlow_I);  //FOR TESTING ONLY
           FuelFlow_I = map (FuelFlow_I, 0, 45, 118, 15);
           FuelFlow_Gauge.write(FuelFlow_I);
        break;
        
      }
    }
    void SLASH(){    // The first identifier was "/" (Annunciator)
      //Do something
    }
    void KEYS() 
    {
    /*  Kstringnewstate = "";
      for (int KpinNo = 2; KpinNo < 70; KpinNo++){
        KpinStateSTR = String(digitalRead(KpinNo)); 
        KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 2));
        if (KpinStateSTR != KoldpinStateSTR)
        {
          if (KpinNo != 13){
          Serial.print ("D"); 
          if (KpinNo < 10) Serial.print ("0");
          Serial.print (KpinNo);
          Serial.println (KpinStateSTR);
          }
        }
        Kstringnewstate += KpinStateSTR;
      }
      Kstringoldstate = Kstringnewstate;*/
    }
    Results from Monitor for ?M and ?V

    To Card
    Code:
    ?F1?M155
    ?V0000.3
    ?F1?M155
    ?V0000.3
    ?M157?V0000.4
    ?M158?V0000.5
    ?M161?V0000.7
    ?M164?V0000.8
    ?M169?V0001.1
    ?M173?V0001.2
    ?M181?V0001.5
    ?M186?V0001.7
    ?M202?V0002.7
    ?M211?V0003.1
    ?M232?V0003.8
    ?M255?V0004.4
    ?M269?V0004.7
    ?M280?V0005.0
    ?M314?V0005.5
    ?M327?V0005.8
    ?M352?V0006.2
    ?M370?V0006.4
    ?M383
    ?M394?V0006.5
    ?M411
    ?M418?V0006.3
    ?M427?V0005.9
    ?M429?V0005.6
    ?V0005.0
    ?M426?V0004.7
    ?M418?V0003.9
    ?M410?V0003.5
    ?M390?V0002.5
    ?M379?V0002.1
    ?M358?V0001.7
    ?M349?V0001.8
    ?M340?V0002.8
    ?V0003.3
    ?M346?V0004.2
    ?M360?V0005.5
    ?M382?V0006.7
    ?M394?V0007.3
    ?M412?V0007.8
    ?M439?V0008.8
    ?M450?V0009.1
    ?M461?V0009.4
    ?M482?V0010.0
    ?M492?V0010.2
    ?M509?V0010.6
    ?M515?V0010.9
    ?M527?V0011.3
    ?M537?V0011.6
    ?M542?V0011.7
    ?M546?V0011.9
    ?M554?V0012.2
    ?M560?V0012.3
    ?M566?V0012.5
    ?M569?V0012.6
    ?M575?V0012.7
    ?M579?V0012.8
    ?M580?V0012.9
    ?M584?V0013.0
    ?M587?V0013.1
    ?M588
    ?M591?V0013.2
    ?M592?V0013.3
    ?M594?V0013.1
    ?M595?V0012.9
    ?M596?V0012.8
    ?M597?V0012.7
    ?M598?V0012.4
    ?V0011.8
    ?V0011.3
    ?M597?V0010.8
    ?M596?V0010.1
    ?M594?V0009.4
    ?M593?V0009.1
    ?M589?V0008.3
    ?M582?V0007.4
    ?M577?V0007.0
    ?M565?V0006.1
    ?M543?V0005.0
    ?M531?V0004.4
    ?M500?V0003.4
    ?M487?V0003.1
    ?M457?V0002.6
    ?M442?V0002.3
    ?M410?V0001.6
    ?M394?V0001.2
    ?M362?V0000.7
    ?M349?V0000.5
    ?M322?V0000.4
    ?M298?V0000.3
    ?M288
    ?M266
    ?M257
    ?M241
    ?M235
    ?M223
    ?M218
    ?M214
    ?M205
    ?M201
    ?M195?V0000.4
    ?M192
    ?M188
    ?M186
    ?M183
    ?M182
    ?M179
    ?M178
    ?M177
    ?M175
    ?M174
    ?V0000.5
    ?M173
    ?M172
    ?M173
    ?M174
    ?M173
    From Card
    Code:
    6
    6
    5
    3
    13
    11
    11
    0
    So you can see that there are many more lines for the ?V than what the Arduino sent to the servo (6,6,5,3,13,11,11,0). Here the servo only moved 8 times.

    When I turn off the ?M below is the result

    Code:
    To Card
    ?F1
    ?V0000.3
    ?V0000.5
    ?V0001.0
    ?V0001.6
    ?V0001.9
    ?V0002.4
    ?V0002.7
    ?V0002.9
    ?V0003.4
    ?V0003.6
    ?V0004.0
    ?V0004.1
    ?V0004.4
    ?V0004.3
    ?V0004.0
    ?V0002.9
    ?V0002.1
    ?V0001.0
    ?V0000.7
    ?V0000.5
    ?V0000.3
    ?V0000.7
    ?V0001.2
    ?V0002.2
    ?V0002.8
    ?V0003.2
    ?V0003.5
    ?V0003.9
    ?V0004.4
    ?V0005.0
    ?V0005.3
    ?V0005.8
    ?V0006.0
    ?V0006.2
    ?V0005.9
    ?V0005.7
    ?V0004.9
    ?V0004.5
    ?V0004.1
    ?V0003.4
    ?V0002.4
    ?V0002.0
    ?V0001.1
    ?V0000.7
    ?V0000.3
    From Card
    Code:
    0
    0
    1
    1
    1
    2
    2
    2
    3
    3
    4
    4
    4
    4
    4
    2
    2
    1
    0
    0
    0
    0
    1
    2
    2
    3
    3
    3
    4
    5
    5
    5
    6
    6
    5
    5
    4
    4
    4
    3
    2
    2
    1
    0
    0
    In this result there are as many servo movements as there are ?V reports.

    My cycle time is set to 50M/s and my refresh time is 10.

    Is this something that I have coded wrong? Has anyone else experienced this?

    Any insight is greatly appreciated.

    Space.....

  2. #2
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Link2FS Fuel Flow Problem

    ?M egt downloads three data characters. You are stripping four. Remove one "EGT += getChar();"

    Did you try leaving the declaration of global variables intact and strip the code down to essential void loop(),
    char getChar() and void QUESTION()'s case:'M' and case: 'V'?

    Hugh
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  3. #3
    New Member
    Join Date
    Jun 2016
    Location
    canada
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Link2FS Fuel Flow Problem

    I removed one EGT += getChar(); as you suggested with no change.
    I stipped down the code as well with no change.

    However, I did get it to work. During one of the tests, I a
    ccidentally added the extraction for Manifold Pressure ?Q and the ?V began to respond properly. When I went back to Link2FS to see what was different, I noticed that the ?Q was clicked. I tried several times turning it on and off, and each time it was ON, the Fuel Flow servo behaved as expected. I re-instated my complete code, and the Fuel Flow servo continues to respond properly. I don't know why this happens and I guess that would be a question for Jim. As I recently discovered that he is no longer here, I will just keep the ?Q extraction active and hope nothing changes.

    Thanks for the suggestions Hugh, I'm always open to them!

    Space....

  4. #4
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Link2FS Fuel Flow Problem

    Hi,
    Just a reflection...
    And if you removed the point character in your string variable
    FuelFlow += getChar();
    FuelFlow += getChar();
    FuelFlow += getChar();
    FuelFlow += getChar();
    getChar(); //read character but not include it
    FuelFlow += getChar();
    because with the decimal point character, your string looks like a float ie : FuelFlow="0001.5" and after you convert it to int... (maybe the trouble)
    if string looks like FuelFlow="00015" -> FuelFlow_I=15
    after divide by 10 in a float variable or modify your code to take care of your variable*10