Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  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

    Newby needs help with sketches,2nd go

    Hi, seam to have lost my first post, I`ll try again.
    I am trying to make a switch panel, with three LCDs for Altitude,Airspeed and Heading,
    16 switches and 9 LEDs.
    I have patched together parts of other sketches, which work on breadboard but don`t
    when I try to put them together.
    LEDs in simplegear part work, LCDs have lost first line and only display random things on
    second line, first line worked on breadboard.
    I have not tested the switches yet, apart from the gear setup.


    code: don`t know how to display it in a box, I just copy & paste.


    /*

    For use with "Link2fs_Multi" (FSX)
    Based on parts of Jims multi starter 2, Lights demo, Alt_Airspeed demo and Thomas Flummer - 3 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 down onto pin 9 (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 " Attach a button to any pin, 23 upwards and program that pin in "Keys" section or the direct inputs section.
    Everything to do with "Keys" starts with a "K" in this code.


    */
    // include the library code:
    #include

    // initialize the library with the numbers of the interface pins,thanks Tom.31
    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 j1;
    int j2;
    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()
    {
    // set up the LCD's number of rows and columns:
    lcd1.begin(16, 2);
    lcd2.begin(16, 2);
    lcd3.begin(16, 2);
    // Print a message to the LCD.
    delay (11);
    lcd1.setCursor(4, 0);
    delay (11);
    lcd1.print("ALTITUDE");
    delay (11);
    lcd2.setCursor(4, 0);
    delay (11);
    lcd2.print("AIRSPEED");
    delay (11);
    lcd3.setCursor(4, 0);
    delay (11);
    lcd3.print("HEADING");
    delay (11);
    //the line below is for the mega card.
    Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
    // 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 LED
    // 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.begin(115200);
    }

    void loop() {
    {INPUTS();} //Check the Simconnect and "keys" section for any input pins
    {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
    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 OTHER(){
    // 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:
    if (Serial.available() > 0) {
    j1 = Serial.read();
    if (j1 == ' 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.
    }
    }

    if (j1 == ' delay (11); // It seems to need a delay here
    airsp = "";
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    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.
    }
    }

    if (j1 == ' delay (11);// It seems to need a delay here
    headi = "";
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read());
    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.
    }
    }//end of other void

    }
    }
    void LESSTHAN(){ // The first identifier was "<"
    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 > 20){digitalWrite(9, HIGH);}else{digitalWrite(9, 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 10 to 19)
    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 == 2{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 == 37){if (KpinStateSTR == "1" ){Serial.println ("A431");}else {Serial.println ("A430");}}//Master
    if (KpinNo == 3{if (KpinStateSTR == "1" ){Serial.println ("E18");}else {Serial.println ("E17");}}//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


    I have been working on this for weeks, so any input would be wellcome.

    Ivor Anthony Long.




  2. #2
    500+ This must be a daytime job



    Join Date
    Jan 2009
    Location
    Tampa
    Posts
    531
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Newby needs help with sketches,2nd go

    can you describe what you mean about LCD's losing the first line? It sounds like the LCDs may be un-initialized. Can you comment out any 2 lines defining a display and have the others work?
    We will sort this out, no doubt.

  3. #3
    500+ This must be a daytime job



    Join Date
    Jan 2009
    Location
    Tampa
    Posts
    531
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Newby needs help with sketches,2nd go

    Assuming that all wiring is good,

    Try putting a small delay between each of these lines:

    LiquidCrystal lcd1(15,16,19,20,21,22);
    LiquidCrystal lcd2(15,17,19,20,21,22);
    LiquidCrystal lcd3(15,18,19,20,21,22);
    and these lines:
    lcd1.begin(16, 2);
    lcd2.begin(16, 2);
    lcd3.begin(16, 2);
    It may be a matter of having the control and data lines "settled: between initializations

    also, a silly question does the code compile cleanly for you? And which Arduino board are you using?



    I do much the same thing, take code from examples and build upon it. When I have problem, I start commenting code out that might be causing an issue.
    Last edited by Buddym; 01-04-2015 at 07:41 PM. Reason: getting more curious

  4. #4
    500+ This must be a daytime job



    Join Date
    Jan 2009
    Location
    Tampa
    Posts
    531
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Newby needs help with sketches,2nd go

    Also, it is worth note, I have used the I2C LCD libs with great success, and you can save a lot of pins if needed, given which board you might be using. Most of the LCD displays with I2C backpack boards don't allow you to change the I2C address easily, I bought a bunch of I2C adapters on Ebay that work great, and have solder pads you can bridge to set the address. If needed I will duplicate your setup and test it here as well.

  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: Newby needs help with sketches,2nd go

    Quote Originally Posted by Buddym View Post
    can you describe what you mean about LCD's losing the first line? It sounds like the LCDs may be un-initialized. Can you comment out any 2 lines defining a display and have the others work?
    We will sort this out, no doubt.
    hi, what I mean is when I setup on the breadboard, I had line 0 on each LCD displaying Altitude,Airspeed And Heading, from the void setup,
    I have lost this now and don`t now why. The second line 1 has random letter things not readable, some times I have tweaked bits and line 1,
    the second line, seams to change in FSX but at this stage nothing is moving.
    Any ideas, thank for the interest, I see some one says try delays, I`ll give that a try.

    Thanks again Ivor.

  6. #6
    500+ This must be a daytime job



    Join Date
    Jan 2009
    Location
    Tampa
    Posts
    531
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Newby needs help with sketches,2nd go

    ok, great. So "on the breadboard" means you have changed your hardware configuration? If that is the case, and it worked with this code, then it must be wiring. I doubt my previous suggestions regarding inserting delays will help at all. Also, I wanted to be accurate, your displays are in fact 2 lines, 16 chars? Bear with me, I will try and help if I can.

  7. #7
    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: Newby needs help with sketches,2nd go

    hi, it does compile, I`m using a mega with v2 shield, all male pins and I made a strip board up with male pins so I can
    run three lines to 1 on the mega, apart from the potentiometers and initiators, which worked on my first breadborad
    setup.
    I will try the delays and see how it goes.
    Thanks for the interest and help, all the best Ivor.

  8. #8
    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: Newby needs help with sketches,2nd go

    yes 16 x 2, its all still on the breadboard I will recheck the contacts but I think its the sketch.
    I have added the simplegear and the keys. When I say it was working I mean the void setup
    was displaying the line 0 info. I have not been able to display the FSX info to line 1.
    Thanks again, Ivor.

  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

    Smile Re: Newby needs help with sketches,2nd go

    Hi ialong
    You should study the demo INO's in the Link2fs Multi folder, and the extraction tabs in Link2fs Multi!
    There are several errors in your sketch!
    As the first identifier for "Altitude, Airspeed and Heading" indications is (lessthan).
    The Altitude, Airspeed and Heading readouts, should be in this section.
    Code:
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    You have got this in youre sketch:
    if (j1 == ' delay (11); // It seems to need a delay here
    airsp = "";
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    airsp += char(Serial.read());
    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.
    }
    }


    The int j1, is a part of the code from the old Link2fs_inout or Link2fs_Keys, and should not be used in the Link2fs Multi sketches. I assume that you are using the Multi as you are using parts of the simconnect in youre sketch.
    If you study this code, you will see that the airsp will display if there is stored anything in the "int j1". But as youre code never stores anything in j1, there will never be anything to display.


    Second, you have this:
    Code:
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read());
    headi += char(Serial.read()); 
    this is asking for 5 digits from FSX, on your heading. You will only get 3 digits and are therefor making the arduino wait for a digit that never will come!
    Try to see how many digits the FSX is sending by using the Link2fs MONITOR or the arduino ide serial monitor.

    Good luck
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  10. #10
    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: Newby needs help with sketches,2nd go

    Hi, BuzziBi.
    Thanks for the help, I have played with the lessthan void but can`t get the flaps bit to compile, need to work
    on it.
    The errors seem to be copy errors as my sketch should read:

    if (j1 == ' 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

    Note the lessthan symbol

    As I said thanks for your time and help, I`ll play with the lessthan void and look at the number of digits.
    All the best Ivor A Long.

Page 1 of 2 12 LastLast