Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Link2FS confusion, second attempt.

    I am trying again, cause I did not get any response. I reckon that what I wrote, was confusing!
    I have tried to clean up the code and removed what I dont nead.
    The strange thing is that I get Link2FS to work against the code if, I only use the encoder section.
    And if I only use the LCD section of the code, it works as well.
    But when I combine both of the codes in a sketch as shown below, then the mess starts.
    It looks as if the encoders works until I click on the "CLIK HERE TO ENTER PROGRAMMING MODE.",
    then the signal from the two encoders shows up as just numbers and dots!
    Before I clik the "CLIK HERE TO ENTER PROGRAMMING MODE.", the traffic from comport shows as expected: D740, D750, D760, and D770!

    Code:
    /*
      
     ======================================================
     
                            This sketch prints the  altitude and the heading to the LCD.
                            It will also have two encoders to adjust course and altitude
                                         It is set up to use with the Uno card
     =======================================================
    
    
    
    
    // include the library code:
    #include "math.h" //added (Note,, This must be before Quadrature.h)
    #include "Quadrature.h" //added
    Quadrature quad1(8, 9);
    Quadrature quad2(11, 12);
    
    
    long Xold1;// the first encoder "old" reading
    long Xold2;// the second encoder "old" reading
    
    
    #include 
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
    int j1;
    int j2;
    int pinNo; 
    int doutpin;
    String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate, altit, altitold, apHeading,apHeadingold;
    /*
     ======================================================
    */
    void setup() 
    {
      // set up the LCD's number of columns and rows: 
      lcd.begin(16, 2);
      // Print a message to the LCD.
      delay (11);
      lcd.print("");
      delay (11);
      lcd.setCursor(0, 1);
      delay (11);
      lcd.print("HEADING ALTITUDE");
      delay (11);
      // the line below is for the Uno card
      stringoldstate = "11111111111111111111";
      //the line below is for the mega card 
      //stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
      
      Serial.begin(115200);  
      for (int doutPin = 10; doutPin <= 19; doutPin++)  //added.. changed the 8 to a 10,, no need to set it up for "keys" but we still need pin 10 setup as a digital pin.
        {  
       pinMode(doutPin, INPUT);
       digitalWrite(doutPin, HIGH);  
        }  
    Serial.flush(); 
    }
    
    
    void loop() {
    /*
     ======================================================
    */
      //the RE section.
      long X1 =(quad1.position())/2;  // divide by 2 for half cycle encoders
        if (X1 != Xold1){  
          if (X1 > Xold1) {Serial.print("D740");} 
          if (X1 < Xold1) {Serial.print("D750");}
          Xold1 = X1;     // overwrites the old reading with the new one.
          }//end of quad1 read
        
      long X2 =(quad2.position())/2;  // divide by 2 for half cycle encoders
        if (X2 != Xold2) {
          if (X2 > Xold2) {Serial.print("D760");} 
          if (X2 < Xold2) {Serial.print("D770");}
          Xold2 = X2;     // overwrites the old reading with the new one.
          }//end of quad2 read
      // end of RE section.
      
     /*
     ======================================================
    */ 
      
      // read the oldest byte in the serial buffer:
       if (Serial.available() > 0) {
        j1 = Serial.read();
    
    
       
        if (j1 == 'r') {    // Found the reading "autopilot AP. Heading"
                  delay(11);  // It seems to need a delay here
                  apHeading = "";
                  apHeading += char(Serial.read());
                  apHeading += char(Serial.read());
                  apHeading += char(Serial.read());
                  Serial.print("apHeading - ");
                  Serial.println(apHeading);
                  apHeading += ("  "); //pads it up to 5 caracters
                  apHeading += ("   ");  //pads it up to 8 caracters
                  if (apHeading != apHeadingold){  // checks to see if its different to the "old" reading
                      // delay (11);
                       lcd.setCursor(0, 0); //sets the cursor position for the first letter
                       delay (11);
                       lcd.print(apHeading); //Prints the data to the LCD
                       apHeading = apHeading; // Writes the current reading to the "old" string.
                        }        
                  }              
        
       if (j1 == 'C'){     // Found the reading "altitude"
                  delay (11);
                  altit = "";
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += ("   "); //pads it up to 8 caracters
                  if (altit != altitold){
                       //delay (11);
                       lcd.setCursor(8, 0);
                       delay (11);
                       lcd.print(altit);
                       altitold = altit;
                        }        
                  } 
            
                  }
          
       }
     
    
    
      
    
    
      
    
    
      
    }

  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    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 confusion, second attempt

    I am trying again, cause I did not get any response. I reckon that what I wrote, was confusing!
    I have tried to clean up the code and removed what I dont nead.
    The strange thing is that I get Link2FS to work against the code if, I only use the encoder section.
    And if I only use the LCD section of the code, it works as well.
    But when I combine both of the codes in a sketch as shown below, then the mess starts.
    It looks as if the encoders works until I click on the "CLIK HERE TO ENTER PROGRAMMING MODE.",
    then the signal from the two encoders shows up as just numbers and dots!
    Before I clik the "CLIK HERE TO ENTER PROGRAMMING MODE.", the traffic from comport shows as expected: D740, D750, D760, and D770!

    Code:
    /*
      
     ======================================================
     
                            This sketch prints the  altitude and the heading to the LCD.
                            It will also have two encoders to adjust course and altitude
                                         It is set up to use with the Uno card
     =======================================================
    
    
    
    
    // include the library code:
    #include "math.h" //added (Note,, This must be before Quadrature.h)
    #include "Quadrature.h" //added
    Quadrature quad1(8, 9);
    Quadrature quad2(11, 12);
    
    
    long Xold1;// the first encoder "old" reading
    long Xold2;// the second encoder "old" reading
    
    
    #include 
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
    int j1;
    int j2;
    int pinNo; 
    int doutpin;
    String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate, altit, altitold, apHeading,apHeadingold;
    /*
     ======================================================
    */
    void setup() 
    {
      // set up the LCD's number of columns and rows: 
      lcd.begin(16, 2);
      // Print a message to the LCD.
      delay (11);
      lcd.print("");
      delay (11);
      lcd.setCursor(0, 1);
      delay (11);
      lcd.print("HEADING ALTITUDE");
      delay (11);
      // the line below is for the Uno card
      stringoldstate = "11111111111111111111";
      //the line below is for the mega card 
      //stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
      
      Serial.begin(115200);  
      for (int doutPin = 10; doutPin <= 19; doutPin++)  //added.. changed the 8 to a 10,, no need to set it up for "keys" but we still need pin 10 setup as a digital pin.
        {  
       pinMode(doutPin, INPUT);
       digitalWrite(doutPin, HIGH);  
        }  
    Serial.flush(); 
    }
    
    
    void loop() {
    /*
     ======================================================
    */
      //the RE section.
      long X1 =(quad1.position())/2;  // divide by 2 for half cycle encoders
        if (X1 != Xold1){  
          if (X1 > Xold1) {Serial.print("D740");} 
          if (X1 < Xold1) {Serial.print("D750");}
          Xold1 = X1;     // overwrites the old reading with the new one.
          }//end of quad1 read
        
      long X2 =(quad2.position())/2;  // divide by 2 for half cycle encoders
        if (X2 != Xold2) {
          if (X2 > Xold2) {Serial.print("D760");} 
          if (X2 < Xold2) {Serial.print("D770");}
          Xold2 = X2;     // overwrites the old reading with the new one.
          }//end of quad2 read
      // end of RE section.
      
     /*
     ======================================================
    */ 
      
      // read the oldest byte in the serial buffer:
       if (Serial.available() > 0) {
        j1 = Serial.read();
    
    
       
        if (j1 == 'r') {    // Found the reading "autopilot AP. Heading"
                  delay(11);  // It seems to need a delay here
                  apHeading = "";
                  apHeading += char(Serial.read());
                  apHeading += char(Serial.read());
                  apHeading += char(Serial.read());
                  Serial.print("apHeading - ");
                  Serial.println(apHeading);
                  apHeading += ("  "); //pads it up to 5 caracters
                  apHeading += ("   ");  //pads it up to 8 caracters
                  if (apHeading != apHeadingold){  // checks to see if its different to the "old" reading
                      // delay (11);
                       lcd.setCursor(0, 0); //sets the cursor position for the first letter
                       delay (11);
                       lcd.print(apHeading); //Prints the data to the LCD
                       apHeading = apHeading; // Writes the current reading to the "old" string.
                        }        
                  }              
        
       if (j1 == 'C'){     // Found the reading "altitude"
                  delay (11);
                  altit = "";
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += char(Serial.read());
                  altit += ("   "); //pads it up to 8 caracters
                  if (altit != altitold){
                       //delay (11);
                       lcd.setCursor(8, 0);
                       delay (11);
                       lcd.print(altit);
                       altitold = altit;
                        }        
                  } 
            
                  }
          
       }
     
    
    
      
    
    
      
    
    
      
    }

  3. #3
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    232
    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 confusion

    Hello BuzziBi. I read the first response, but I don't have a real solution. I was hoping Jim would answer your question. But, as of late, he has been working a ton of hours. In the meantime, I can only offer basic troubleshooting. There seems to be a discrepancy between keys and the arduino. In such a case, I would create a simple switch; program the keys portion of Linkfs and go from there.

    Since I haven't played with my grey code encoders yet, that is the best I can offer.
    -James

  4. #4
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    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 confusion

    Thanks for the reply.
    I could not find any solution. Has been sitting for hours, tried different solutions, but going nowhere.
    I wonder if I should run the LCD at a uno cards and the encoders on second Uno card.
    Have not tried it yet. I realize that I can't run two cards at the same comport, but it is possible to run Link2FS x 2 simultaneously, and will it work? Or can I connect the two cards with RX/TX? Do you know?

  5. #5
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    232
    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 confusion

    My guess is that "keys" works w/ Linkfs when the lcd is not used?

    I have used to instances of Linkfs, each with the comport defined for the respective cards, and it worked. Or, you can could tie the two cards together via Rx/Tx; I've never done it, but I believe you only have to write the line "Serial1.print" to do it.
    If you don't have it already, Below is a link for Jim's latest; this will allow both cards and one instance of software running. Note - the Multi is still in testing and Jim is receiving feedback only - no support until official release.
    jimspage Link2fs multi beta FSX arduino mega flight simulator

  6. #6
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    232
    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 confusion

    Also, after further review of the code, I noticed this in your setup loop:

    for (int doutPin = 10; doutPin <= 19; doutPin++) { pinMode(doutPin, INPUT); digitalWrite(doutPin, HIGH);}

    Since it is declaring pins 10 though 19 as inputs and Writing all of them HIGH, does this conflict with your encoder library... or anything else you have connected to pins 10-19?? This may be correct and required- I am ignorant to the encoders and the library. But normally when I declare a pin to be an input, I simply declare it; I've never digitalWrite it as HIGH - I only do that for outputs.

    Also, you may want to remove the delays which are directly in front of you lcd statements; these are unnecessary delays.

    Just a thought.

  7. #7
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    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 confusion

    TX JMeller for reply!

    The only reason why that line:
    "" for (int doutPin = 10; doutPin <= 19; doutPin++) { pinMode(doutPin, INPUT); digitalWrite(doutPin, HIGH);}""
    is there, is that I could not eliminate it from the original code ""pde_inout_v4.ino"" without getting a compiling error. It was originally there to control push button on one of the encoders. The rest of the code for this was at the end of the code. I managed to remove most, but not this
    I've tried to eliminate as much as possible out of the code to see if I got away from the error, but have not succeeded.

    I have now occupied the kitchen table trying to connect two arduino one cards, encoders on one, and LCD on the other. But I am convinced that I have a error in the code, and this is why I fail.
    Within someone finds the problem, I'll try with two cards
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  8. #8
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    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 confusion

    Thanks James ,,, yes ,, I'm only getting about 5 hours sleep a night ,,, the mission a bit bigger than I first thought !!! Same again next week.

    Buzzibi ...
    The code you posted (now) in this thread is such a mess it wouldn't be easy to step you thru a fix.
    Use the code you first posted on this thread as once you get that going it will be easy to modify to do what you want.
    I hope you've still got that code as what is in this thread now is nothing like it.
    Never change code in a forum post ,,, you know whats going on but no-one else does ,, so hence ,, no-one will help.

    You need to plan what pins are being used for what before you start ,, there are inputs and outputs ,, group them together.
    In your (first ,, now gone) code you were so close to it going but the grouping was not organized.

    So using the originally posted (now gone) code ,,,
    LCD is output
    Rotary encoder is input
    Keys is input.

    So,,,
    Make the LCD pins 7,6,5,4,3,2
    Make the Rotary encoders pins 8, 9 and 10, 11
    Now the rest can be used for Keys.(pins 12 to 19)


    In void setup ,,,
    As the keys input is now 12-19 (and not 8-19) you need to change the line ,,
    for (int doutPin = 8; doutPin <= 19; doutPin++)
    to ,,
    for (int doutPin = 12; doutPin <= 19; doutPin++)


    In the keys section you need to also change the 8 to 12 ,,,
    for (int doutPin = 8; doutPin <= 19; doutPin++)
    to ,,
    for (int doutPin = 12; doutPin <= 19; doutPin++)


    Also in the keys section change the line ,,,,
    oldpinStateSTR = String(stringoldstate.charAt(pinNo - 8 ));
    to,,
    oldpinStateSTR = String(stringoldstate.charAt(pinNo - 12));

    Notes ,,,,
    On your (original) posted code you may have to import the LCD library again ?????
    As the forum peels off some things when you post ,, you are better off to zip the code and post it as a attachment.
    James is correct about the "delays" BUT remove them only after you get the code going.
    You obviously need to tick the appropriate things in "inOut" and enter the appropriate "keys" codes.

    I've just done the above ,, line for line ,,, and that originally posted code goes fine.
    From there you should be able to modify the read-outs top suit what you want to do.


    P.S. I've deleted that second thread as it's just a double-up.
    Last edited by Jim NZ; 03-08-2013 at 05:13 PM.
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  9. #9
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    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 confusion

    Thank you Jim. I take you as my teacher anytime!

    I read your response this morning and got the encoders to operate immediately.
    The push buttons took a little longer to sort out.
    The problem was in my head rather than code!
    It took me a long time before I realized that the message I read in the: "Com Port Keys Traffic",
    D120 changing to D121, when button pushed, was in reality a message.
    That the digital (D) pin (12) (0) or (1) was changing from closed to open
    I figured it out after reading the "Readme Instructions.txt" attaches to the "link2fs_keys_v4".
    Tomorrow I will try it on the FSX computer.
    I'll come back with the results.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  10. #10
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    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 confusion

    O JOY, IT WORKS!

    Starting fram the beginning with a clean code, changing one ting at the time, I finaly succeeded.
    The LCD now shows the Heading and Altitude. The 2 Encoders can be used to change both the Heading and Altitude.
    Now the head is full of ideas.
    I wontbuttons for the:AP ON/OFF, ON/OFF Heading and Altitude, the transponder buttons for squawk codes, the button for adjusting the Altimeter barometric pressures, and the radio frequency change.
    I see no end to the possibilities to extend the simulator with buttons and switches
    Thanks you Jim!
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

Page 1 of 3 123 LastLast