Results 1 to 2 of 2
  1. #1
    75+ Posting Member
    Join Date
    Feb 2010
    Location
    London
    Posts
    87
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    MCP/COM/NA panel

    Hi
    I started to work on my panel with arduino,and examples codes from jim modified mo my needs.
    his is what i got so far
    2013-12-07 03-55-43.327.jpg2013-12-07 03-55-32.260.jpg

    So fro the top left we have AP speed or mach heading altitude vestical speed
    then COM1 NAV1 transponder
    And here is the code for it


    /*

    ======================================================

    This sketch prints the airspeed, altitude,
    com1. frequency and com1. standby frequency to the LCD.

    It is set up to use with the Uno card but it will also run as-is on the Mega using
    the pins up to No. 19.
    If you have a Mega card and want all the pins, then
    there are only 3 things to change,,,
    where it says <= 19 change that to read <= 69 (on 2 lines)
    also,,
    stringoldstate = "1111111111111111 etc" you need to have the appropriate one active.

    =======================================================

    This example code is in the public domain.

    */

    // include the library code:




    #include

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);


    int j1;
    int j2;
    int pinState;
    int pinNo;
    int doutpin;
    String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate, com1, com1old, com1sb, com1sbold, APairsp, APairspold,
    APaltit, APaltitold,APhdg, APhdgold, VS, VSold, nav, navold, navsb,navsbold,trans, transold, mach, machold;

    void setup()
    {
    // set up the LCD's number of columns and rows:
    lcd.begin(20, 4);
    // Print a message to the LCD.
    delay (11);
    lcd.print("Witaj Bartku");
    delay (11);
    lcd.setCursor(0, 1);
    delay (11);
    lcd.print("Czekam na dane z FSX");
    delay (11);
    // the line below is for the Uno card

    //the line below is for the mega card
    stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

    Serial.begin(115200);
    for (int doutPin = 8; doutPin <= 19; doutPin++)
    {
    pinMode(doutPin, INPUT);
    digitalWrite(doutPin, HIGH);
    }
    Serial.flush();
    delay(5000);
    lcd.clear();
    }

    void loop() {
    // read the oldest byte in the serial buffer:
    if (Serial.available() > 0) {
    j1 = Serial.read();

    if (j1 == 'A'){ // Found the reading "mach"
    delay (11);
    mach = "";
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    mach += char(Serial.read());
    //pads it up to 3 caracters
    if (mach != machold){

    lcd.setCursor(0, 0);
    delay (11);
    lcd.print(mach);
    machold = mach;
    }
    }

    if (j1 == 'u' ){ // Found the reading "airspeed indicated"



    delay (11); // It seems to need a delay here
    APairsp = "";
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());
    APairsp += char(Serial.read());

    //pads it up to 3 caracters

    if (APairsp != APairspold){ // checks to see if its different to the "old" reading



    lcd.setCursor(0, 0); //sets the cursor position for the first letter
    delay (11);
    lcd.print(APairsp); //Prints the data to the LCD
    APairspold = APairsp; // Writes the current reading to the "old" string.
    lcd.setCursor(3, 0);
    lcd.print(" ");
    }
    }



    if (j1 == 'r'){ // Found the reading "heading"
    delay (11);
    APhdg = "";
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    APhdg += char(Serial.read());
    //pads it up to 3 caracters
    if (APhdg != APhdgold){

    lcd.setCursor(5, 0);
    delay (11);
    lcd.print(APhdg);
    APhdgold = APhdg;
    }
    }



    if (j1 == 'p'){ // Found the reading "altitude"
    delay (11);
    APaltit = "";
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());
    APaltit += char(Serial.read());

    //pads it up to 5 caracters
    if (APaltit != APaltitold){

    lcd.setCursor(9, 0);
    delay (11);
    lcd.print(APaltit);
    APaltitold = APaltit;
    }
    }

    if (j1 == 'q'){ // Found the reading "VS"
    delay (11);
    VS = "";
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());
    VS += char(Serial.read());

    //pads it up to 5 caracters
    if (VS != VSold){

    lcd.setCursor(15, 0);
    delay (11);
    lcd.print(VS);
    VSold = VS;
    }
    }

    if (j1 == 'd'){ // Found the reading "Com1 frequency"
    delay (11);
    com1 = "";
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    com1 += char(Serial.read());
    //pads it up to 7 caracters
    if (com1 != com1old){

    lcd.setCursor(0, 2);
    delay (11);
    lcd.print(com1);
    com1old = com1;
    }
    }
    if (j1 == 'e'){ // Found the reading "Com1 stand-by"
    delay (11);
    com1sb = "";
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    com1sb += char(Serial.read());
    //pads it up to 7 caracters
    if (com1sb != com1sbold){

    lcd.setCursor(8, 2);
    delay (11);
    lcd.print(com1sb);
    com1sbold = com1sb;
    }
    }
    if (j1 == 'h'){ // Found the reading "nav1 stand-by"
    delay (11);
    nav = "";
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());
    nav += char(Serial.read());

    //pads it up to 6 caracters
    if (nav != navold){

    lcd.setCursor(0, 3);
    delay (11);
    lcd.print(nav);
    navold = nav;
    }
    }
    if (j1 == 'i'){ // Found the reading "nav1 stand-by"
    delay (11);
    navsb = "";
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());
    navsb += char(Serial.read());

    //pads it up to 6 caracters
    if (navsb != navsbold){
    //delay (11);
    lcd.setCursor(8, 3);
    delay (11);
    lcd.print(navsb);
    navsbold = navsb;
    }
    }
    if (j1 == 'm'){ // Found the reading "nav1 stand-by"
    delay (11);
    trans = "";
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());
    trans += char(Serial.read());

    //pads it up to 4 caracters
    if (trans != transold){
    //delay (11);
    lcd.setCursor(16, 3);
    delay (11);
    lcd.print(trans);
    transold = trans;
    }
    }

    }

    // Now the bit for the "keys" input
    stringnewstate = "";
    for (int pinNo = 8; pinNo <= 19; pinNo++){
    pinStateSTR = String(digitalRead(pinNo));

    oldpinStateSTR = String(stringoldstate.charAt(pinNo - );

    if (pinStateSTR != oldpinStateSTR)
    {
    Serial.print ("D");
    if (pinNo < 10) Serial.print ("0");
    Serial.print (pinNo);
    Serial.print (pinStateSTR);
    delay(11);
    }
    stringnewstate += pinStateSTR;
    }

    stringoldstate = stringnewstate;
    delay(11);

    }

    One again great big thanks to jim.

    But I have a small issue as well

    When I switch from mach to knots and starting to rotate the encoder in FSX every 6 or 7 clicks the mach speed comes on o my LCD
    and disappears with next click.

    For some reason mach speed and knot speed data are send together every 6 or 7 click.
    I amuse that part of this is the fact that data are send continuously.

    I would be grateful for ideas how t fix tat problem as I am a newbie and running out of ideas.



  2. #2
    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: MCP/COM/NA panel

    Your doing well Bart ,, I never closely looked at your code but I imagine the problem is caused by this ,,

    In FSX the mach and the Knots are linked together ,, as in when one is altered, the other changes as well.
    That means that your program is seeing both them change as you adjust it.

    The best way to overcome that is to get the extraction >B (APmach active) and within your code, lock out one or the other to suit what you are changing.

    Simply speaking ,, if the Mach is the indicating text ,, then lock out the reading for the knots so it wont go to the text screen and visa-versa with the knots.

    Have fun ,,, Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !