Results 1 to 5 of 5
  1. #1
    10+ Posting Member ialong's Avatar
    Join Date
    Jan 2015
    Location
    UK
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    No Airspeed to LCD

    Hi, i`m still trying to get my switch panel going. I have solved some problems, connections and program errors, still on airspeed display,
    I have altitude and heading ok, no airspeed, went back to the original program and can`t get that to work ether, the original program
    is Jims Alt_Airspeed.ino.
    My program now is,

    Code:
    /* 
        
        Tonys_Full_Panel2.ino 22/9/15
        
        For use with "Link2fs_Multi" (FSX)
        Based on parts of Jims multi starter 2, Lights demo, Alt_Airspeed demo and Thomas Flummer - 4 lcd on 1 arduino.
        
        
        This sets the Arduino Mega card to indicate gear position and flaps, using simconnect codes with 
        the remainder for inputs except pin 13.
        LED for nose gear down onto pin 2 (Thru a resistor)
        LED for left gear down onto pin 3 (Thru a resistor)
        LED for right gear down onto pin 4 (Thru a resistor)
        LED for nose gear in transition onto pin 5 (Thru a resistor)
        LED for left gear in transition onto pin 6 (Thru a resistor)
        LED for right gear in transition onto pin 7 (Thru a resistor)
        LED for Flaps not fully up onto pin 8 (Thru a resistor)
        LED for Flaps 1st down onto pin 9 (Thru a resistor)
        LED for Flaps 2nd down onto pin 10 (Thru a resistor)
        
        For the gear control, attach 2 buttons (or a double throw toggle switch) to pins 23 and 24
        A button on pin 26 will raise the flaps 1 notch
        A button on pin 25 will lower the flaps 1 notch
        
        You need to tick "?Y" in "Link2fs_Multi" down the bottom of "systems2". (Extractions2 tab).
        Also you need to tick "
    #include 
     
     
    // initialize the library with the numbers of the interface pins,thanks Tom.
    LiquidCrystal lcd1(15,16,19,20,21,22);
    LiquidCrystal lcd2(15,17,19,20,21,22);
    LiquidCrystal lcd3(15,18,19,20,21,22);
    
    
    int CodeIn;// used on all serial reads
    int KpinState;
    int KpinNo; 
    int Koutpin;
    
    String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate, headi, headiold, airsp, airspold, altit, altitold;
    String gearSimple, flaps, flapsOld; 
    
    
    void setup(){
    
    //the line below is for the mega card. 
     Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111"; 
     
     
    lcd1.begin(16, 2);
    lcd2.begin(16, 2);
    lcd3.begin(16, 2);
     // Print a message to the LCD.
    lcd1.setCursor(4, 0);
     lcd1.print("ALTITUDE");
      // lcd1.setCursor(0, 1);
       //  lcd1.print("Waiting_for_data");
    
    lcd2.setCursor(4, 0);
     lcd2.print("AIRSPEED");
      // lcd2.setCursor(0, 1);
       //  lcd2.print("Waiting_for_data");
         
    lcd3.setCursor(4, 0);     
     lcd3.print("HEADING");
      // lcd3.setCursor(0, 1);
       //  lcd3.print("Waiting_for_data");
         
         
     // Lets set the output pin modes (longhand)     
      pinMode(2, OUTPUT); // gear nose LED
      pinMode(3, OUTPUT); // gear left LED
      pinMode(4, OUTPUT); // gear right LED
      pinMode(5, OUTPUT); // gear nose in transition LED
      pinMode(6, OUTPUT); // gear left in transition LED
      pinMode(7, OUTPUT); // gear right in transition LED
      pinMode(8, OUTPUT); // Flaps not fully Up LED
      pinMode(9, OUTPUT); // Flaps down 1st position LED
      pinMode(10, OUTPUT); // Flaps down 2nd position LED   
         
     Serial.begin(115200);    
         
        // now we will do all the inputs in a routine ,,,
      for (int KoutPin = 23; KoutPin <= 69; KoutPin++)// Get all the pins ready for simconnect codes and "Keys"(all inputs)  
      {
        pinMode(KoutPin, INPUT);
        digitalWrite(KoutPin, HIGH); 
      }  
      Serial.flush();
      }
    
    void loop() {        
                              
      {INPUTS();} //Check the Simconnect and "keys" section for any input pins
      if (Serial.available()) {
        CodeIn = getChar();  
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
        if (CodeIn == '?') {QUESTION();}// The first identifier is "?"  
      }
    } // end of void loop (The main one)
     
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }// end of getchar void. 
    
    void LESSTHAN(){    // The first identifier was "<"
       // set the cursor to column 4 line 1:
      // note: line 1 is the second row, since counting begins with 0:
      // read the oldest byte in the serial buffer:
              CodeIn = getChar(); // Get the second identifier
               switch(CodeIn) {// Now lets find what to do with it
                case 'D': // Found the reading "altitude"
                  delay (11);// It seems to need a delay here
                  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){ // checks to see if its different to the "old" reading
                       delay (11);
                       lcd1.setCursor(4, 1);//sets the cursor position for the first letter
                       delay (11);
                       lcd1.print(altit);//Prints the data to the LCD
                       altitold = altit;// Writes the current reading to the "old" string.
                       break;
                      }            
                 }
               CodeIn = getChar(); // Get the second identifier
                switch(CodeIn) {// Now lets find what to do with it  
                 case 'P': // Found the reading "airspeed indicated"
                  delay (11); // It seems to need a delay here
                  airsp = "";
                  airsp += char(Serial.read());
                  airsp += char(Serial.read());
                  airsp += char(Serial.read()); 
                  airsp += ("  "); //pads it up to 5 caracters          
                  airsp += ("  ");  //pads it up to 8 caracters            
                  if (airsp != airspold){  // checks to see if its different to the "old" reading
                       delay (11);
                       lcd2.setCursor(4, 1); //sets the cursor position for the first letter
                       delay (11);
                       lcd2.print(airsp); //Prints the data to the LCD
                       airspold = airsp; // Writes the current reading to the "old" string.
                       break;       
                      }
                }
               CodeIn = getChar(); // Get the second identifier
                switch(CodeIn) {// Now lets find what to do with it  
                 case 'J': //  Found the reading "heading"
                   delay (11);// It seems to need a delay here
                   headi = "";
                   headi += char(Serial.read());
                   headi += char(Serial.read());
                   headi += char(Serial.read());
                   headi += ("  "); //pads it up to 5 caracters             
                   headi += ("  "); //pads it up to 8 caracters
                   if (headi != headiold){  // checks to see if its different to the "old" reading
                       delay (11);
                       lcd3.setCursor(4, 1); //sets the cursor position for the first letter
                       delay (11);
                       lcd3.print(headi);//Prints the data to the LCD
                       headiold = headi;// Writes the current reading to the "old" string.
                       break; 
                      }
               }   
             CodeIn = getChar(); // Get the second identifier
              switch(CodeIn) {// Now lets find what to do with it
               case 'G'://Found the second identifier ("G" Flaps position)
                   flaps = "";
                   flaps += getChar();
                   flaps += getChar();
                   flaps += getChar();
             int flapsINT = flaps.toInt(); // convert it to an integer (Thanks Phill)
              if (flapsINT > 0){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);}//action the LED
               if (flapsINT > 5){digitalWrite(9, HIGH);}else{digitalWrite(9, LOW);}//action the LED (was > 20)
                if (flapsINT > 40){digitalWrite(10, HIGH);}else{digitalWrite(10, LOW);}//action the LED
               break;                
               }// end of switch
          }// end of lessthan void
       
    void QUESTION(){    // The first identifier was "?"
    CodeIn = getChar(); // Get the second identifier
      switch(CodeIn) {// Now lets find what to do with it
        case 'Y': // found the second identifier (the "Gear simple")
           gearSimple = "";
          gearSimple += getChar();// get first charactor (Nose gear)
          if (gearSimple == "2"){digitalWrite(2, HIGH);}else{digitalWrite(2, LOW);}
          if (gearSimple == "1"){digitalWrite(5, HIGH);}else{digitalWrite(5, LOW);}
          gearSimple += getChar(); // get the second charactor (gear left)
          if (gearSimple.endsWith("2")){digitalWrite(3, HIGH);}else{digitalWrite(3, LOW);}
          if (gearSimple.endsWith("1")){digitalWrite(6, HIGH);}else{digitalWrite(6, LOW);}
          gearSimple += getChar(); // get the third charactor  (gear right)
          if (gearSimple.endsWith("2")){digitalWrite(4, HIGH);}else{digitalWrite(4, LOW);}
          if (gearSimple.endsWith("1")){digitalWrite(7, HIGH);}else{digitalWrite(7, LOW);}
        break;
         }
    }// end of question void
    
    
    void INPUTS(){ // Simconnect codes and "Keys" section
      Kstringnewstate = "";
      for (int KpinNo = 23; KpinNo <=69; KpinNo++){ //set this to the input pins. (pins 23 to 69)
        KpinStateSTR = String(digitalRead(KpinNo)); //read the state of the pin
        KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 23));// gets the 'old' state of the pin from string
        if (KpinStateSTR != KoldpinStateSTR){// checks if it's different to the last reading of that pinNo
          if (KpinNo != 13){ // avoid using pin 13 as an input unless you know the tricks.
            if (KpinNo == 23 && KpinStateSTR == "0"){Serial.println ("C01");} //sets gear handle up
            if (KpinNo == 24 && KpinStateSTR == "0"){Serial.println ("C02");} //sets gear handle down
            if (KpinNo == 25 && KpinStateSTR == "0"){Serial.println ("C15");} //Decrements flap handle position
            if (KpinNo == 26 && KpinStateSTR == "0"){Serial.println ("C14");} //Increments flap handle position     
            if (KpinNo == 27){if (KpinStateSTR == "1" ){Serial.println ("C410");}else {Serial.println ("C411");}}//Nav lights
            if (KpinNo == 28){if (KpinStateSTR == "1" ){Serial.println ("C420");}else {Serial.println ("C421");}}//Beacon lights
            if (KpinNo == 29){if (KpinStateSTR == "1" ){Serial.println ("C430");}else {Serial.println ("C431");}}//Landing lights
            if (KpinNo == 30){if (KpinStateSTR == "1" ){Serial.println ("C440");}else {Serial.println ("C441");}}//Taxi lights
            if (KpinNo == 31){if (KpinStateSTR == "1" ){Serial.println ("C450");}else {Serial.println ("C451");}}//Strobe lights
            if (KpinNo == 32){if (KpinStateSTR == "1" ){Serial.println ("C460");}else {Serial.println ("C461");}}//Panel lights
            if (KpinNo == 33){if (KpinStateSTR == "1" ){Serial.println ("C480");}else {Serial.println ("C481");}}//Wing lights
            if (KpinNo == 34){if (KpinStateSTR == "1" ){Serial.println ("C500");}else {Serial.println ("C501");}}//Cabin lights
            if (KpinNo == 35){if (KpinStateSTR == "1" ){Serial.println ("E01");}else {Serial.println ("E04");}}//Mags
           // if (KpinNo == 36){if (KpinStateSTR == "1" ){Serial.println ("E42");}else {Serial.println ("E43");}}//Start
            if (KpinNo == 36 && KpinStateSTR == "0"){Serial.println ("E35");}//Start
            if (KpinNo == 37){if (KpinStateSTR == "1" ){Serial.println ("A430");}else {Serial.println ("A431");}}//Master
            if (KpinNo == 38){if (KpinStateSTR == "1" ){Serial.println ("E17");}else {Serial.println ("E18");}}//Battery
            //  Add more here but remember to also change the figure in the next line down. 
            // now the "Keys" bit ,,,
            if (KpinNo > 38){ //Change pinNo number to same as the highest one used for simconnect codes.
            Serial.print ("D"); 
          if (KpinNo < 10) Serial.print ("0");
          Serial.print (KpinNo);
          Serial.println (KpinStateSTR);
            }//end of 'its pinNo is greater than 14' 
          }//end of 'its not pin 13'
        }//end of 'its different'       
        Kstringnewstate += KpinStateSTR;
      }//end of 'for' loop (read the pins)
      Kstringoldstate = Kstringnewstate;
     
      delay (11);
    
      }//end of INPUTS void
    Still don`t know how to put progs in a box, any help would be appreciated.
    I.A.Long.

  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: No Airspeed to LCD

    I think that your multiple uses of the lines in void LESSTHAN()

    CodeIn = getChar(); // Get the second identifier
    switch(CodeIn) {// Now lets find what to do with it

    is eating up the data before it can be processed. Only one switch is needed for one or more cases.

    Cut or copy and paste will get you every time.
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  3. #3
    10+ Posting Member ialong's Avatar
    Join Date
    Jan 2015
    Location
    UK
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Airspeed to LCD

    Quote Originally Posted by BushPilotWannabe View Post
    I think that your multiple uses of the lines in void LESSTHAN()

    CodeIn = getChar(); // Get the second identifier
    switch(CodeIn) {// Now lets find what to do with it

    is eating up the data before it can be processed. Only one switch is needed for one or more cases.

    Cut or copy and paste will get you every time.
    Hi BushPilotWannabe, thanks for the help, took a bit of work to get it to compile, now all LCDs, LEDs and switchs, are running.
    At last! been working on this project since last January.
    As you said, Cut or copy and paste will get you every time, if you don`t know what your doing.
    Thanks again for your help and the time you put in.
    All the best, I.A.Long.

  4. #4
    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: No Airspeed to LCD

    Terrific! What's next?

  5. #5
    10+ Posting Member ialong's Avatar
    Join Date
    Jan 2015
    Location
    UK
    Posts
    19
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Airspeed to LCD

    Hi, this panel used parallel LCDs so I`ll try to make one using I2cs to loose some cabling, possibly dedicated to the A2A Cessna 172 for flight training.
    I have not really thought of any thing after that, as I like flying old light aircraft ie: Aulster, Pipers and the like, may be a panel using an Uno with a 20-4 LCD.
    Again thanks for the help, All the best, I.A.Long.