Header Fly Engravity
Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    May 2012
    Location
    Colombia
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    programing and reading PDE for Link2fs:inOuts

    Hi, I am writing from Colombia. first congratulate you for this wonderful program (Link2fs_inOut_v2) has been a great help to complete my small cabin.
    in truth I write because I have a question and maybe you can help me check myprogram to see where I'm failing.
    basically the program that I write for variables LED light ("L", "M", "R", "> o") but only managed to turn "M" flap position (in 3 different LEDs and works great), the other variables not get light them.



    //here is my program ...

    int xx;
    int pinNo;
    int doutpin;
    String flaps, flapsold;
    String stallold, stall;
    String fuell, fuellold;
    String parking, parkingold;

    void setup() {
    for (int doutPin = 2; doutPin <= 7; doutPin++)
    {
    pinMode(doutPin, OUTPUT);
    }
    Serial.begin(115200);
    }

    void loop(){

    if (Serial.available() > 0) {
    xx = Serial.read();
    if (xx == 'M'){
    delay (11);
    flaps = char(Serial.read());
    flaps += char(Serial.read());
    flaps += char(Serial.read());
    if (flaps != flapsold){
    if (flaps == "000") {digitalWrite(2, HIGH);} else {digitalWrite(2, LOW);}
    if (flaps >"000" && flaps< "014")
    {
    digitalWrite(3, HIGH);
    delay(30);
    digitalWrite(3, LOW);
    delay(30);
    }

    if (flaps == "014"){digitalWrite(3, HIGH);} else {digitalWrite(3, LOW);}
    if (flaps >"014" && flaps< "057")
    {
    digitalWrite(4, HIGH);
    delay(30);
    digitalWrite(4, LOW);
    delay(30);
    }

    if (flaps == "057") {digitalWrite(4, HIGH);} else {digitalWrite(4, LOW);}
    flapsold = flaps;
    }
    }



    xx = Serial.read();
    if (xx == 'L'){
    delay (11);
    stall = char(Serial.read());
    if (stall != stallold){
    if (stall == "0") {digitalWrite(5, LOW);} else {digitalWrite(5, HIGH);}
    stallold = stall;
    }
    }


    xx = Serial.read();
    if (xx == 'R'){
    delay (11);
    fuell = char(Serial.read());
    fuell += char(Serial.read());
    fuell += char(Serial.read());
    if (fuell != fuellold){
    if (fuell < "009") {digitalWrite(6,HIGH);} else {digitalWrite(6, LOW);}
    fuellold = fuell;
    }
    }

    xx = Serial.read();
    if (xx == ">o"){
    delay (11);
    parking = char(Serial.read());
    if (parking != parkingold){
    if (parking == 0) {digitalWrite(7, LOW);} else {digitalWrite(7, HIGH);}
    parkingold=parking;
    }

    }
    }
    }


    I think the problem is when reading data from several digits, the FLAPS "M" read 3 digits "000". but as you would to read a variable as a single digit: example STALL "L" or PARKING BRAKES ">o" that would only "0" or "1" values. I can see that the program reads correctly in the text box but this does not make any effect on my board.

    The program compiles good

    could you tell me which way I'm doing wrong?

    I would appreciate your help.


    Greetings from Colombia

    Gabriel

  2. #2
    25+ Posting Member
    Join Date
    May 2012
    Location
    Great white north
    Posts
    32
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    here's what I do to extract numeric variables from link2fs


    Code:
    if(j1 == 'R')
    {
        delay(11);
        i=0;
        while(i < len)
        {
          Sbuffer[i] = Serial.read();
          i++;
        }
        temp = atoi(Sbuffer);
        if(temp != fuel)
        {
          fuel = temp;
        }
    }
    sBuffer is a character buffer defined elsewhere that is bigger than the max variable length you'll be using this with.
    fuel is an int. So now you can perform operations using the fuel value.

    your if statement for the parking break is incorrect since the Serial.read function only extracts a single character. so you would need a nested statement

    Code:
    if (xx == ">"){
     xx = Serial.Read(); 
     if(xx == "o")
     {
       etc
    Hope this helps you along

  3. #3
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    May 2012
    Location
    Colombia
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    Quote Originally Posted by Steve5006 View Post
    here's what I do to extract numeric variables from link2fs


    Code:
    if(j1 == 'R')
    {
        delay(11);
        i=0;
        while(i < len)
        {
          Sbuffer[i] = Serial.read();
          i++;
        }
        temp = atoi(Sbuffer);
        if(temp != fuel)
        {
          fuel = temp;
        }
    }
    sBuffer is a character buffer defined elsewhere that is bigger than the max variable length you'll be using this with.
    fuel is an int. So now you can perform operations using the fuel value.

    your if statement for the parking break is incorrect since the Serial.read function only extracts a single character. so you would need a nested statement

    Code:
    if (xx == ">"){
     xx = Serial.Read(); 
     if(xx == "o")
     {
       etc
    Hope this helps you along



    Steve5006, thanks for your answer.
    The theme of the buffer for the truth FUELL not understand because I'm just taking my first steps in programming. But after much testing, and successfully achieve that lit my LED indicators for "FLAPS", "FUELL", "STALL", the solution was placed in the program variables in alphabetical order, ie in the previous program the order was: "M", "L", "R", "> o" under flaps, stall, fuell and parking, I've done is rearrange the program so it begins "L", "M", "R" "> o" for Stall, Flaps, Fuell and parking, this has worked for me and now my LED works very well, remember that in the previous program could only turn on the LEDs of the flaps.
    Now the only thing I still can not get the parking LED ">o", I'll try with the nested statement you say, I believe that this will solve.

    I will tell you how it works

    Greetings.

  4. #4
    25+ Posting Member
    Join Date
    May 2012
    Location
    Great white north
    Posts
    32
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    your comment about it needing to be in alphabetical order drew my attention to another error that may be tripping you up. the line

    xx = Serial.read(); should only appear once within your if(serial.available() > 0)

    otherwise as you noticed if data is delivered out of order everything after that point is lost. you want to extract one number on each pass. it may seem slow and possibly inefficient but your arduino is fast enough and the reliability difference will help a lot

  5. #5
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    May 2012
    Location
    Colombia
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    effectively write once (xx = Serial.read ()) the program runs much faster, thanks for the tip.

    but still can not read any function that is composed of more than one character.
    example:
    '> o' Parking B.
    '> q' Fuell Pmp
    '> K' Lights
    etc ...

    While the functions of a single character is read very well.
    example:
    'L' Stall
    'M' Flaps
    'R' Fuell
    etc ...


    Read more of a character with the nested statement:
    if (xx == ">") {
    xx = Serial.read ();
    if (xx == "o")
    {
    etc.

    does not work.


    have any other ideas of how to read more than one character?

    regards

  6. #6
    25+ Posting Member
    Join Date
    May 2012
    Location
    Great white north
    Posts
    32
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    Quote Originally Posted by gisaza View Post


    Read more of a character with the nested statement:
    if (xx == ">") {
    xx = Serial.read ();
    if (xx == "o")
    {
    etc.

    does not work.
    from a bit of testing I found out that this was what Jim was talking about when he included the delay(11); it is absolutely critical it seems to leave a slight delay between reading the '>' and the next character
    so:

    Code:
    if (xx == ">") {
      delay(11)
      xx = Serial.read ();
      if (xx == "o")
      {
        etc.
    seems to remedy the issue

  7. #7
    150+ Forum Groupie WJH308's Avatar
    Join Date
    Aug 2008
    Location
    San Francisco, CA
    Posts
    159
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    Couldn't you just read the serial input as a string, then parse the string to extract the required data?

  8. #8
    25+ Posting Member
    Join Date
    May 2012
    Location
    Great white north
    Posts
    32
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    Quote Originally Posted by WJH308 View Post
    Couldn't you just read the serial input as a string, then parse the string to extract the required data?
    for the ">o" etc cases not without reading the serial in some other way. Serial.Read reads a single byte from the serial buffer. since we are passing it chracters encoded in ascii this means each read takes a single character. Presumably you could take both at the same time similar to how we buffer the integer reads if you were writing a program that only took variables of the ">*" variety otherwise we'd lose the leading digit on everything else.

    In terms of the buffer this is essentially what we are doing except that the string version is not saved permanently

  9. #9
    300+ Forum Addict
    Join Date
    Apr 2008
    Location
    Graham, WA
    Posts
    311
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    You might be better off collecting a whole buffer of data and only processing it after getting an "end of command" byte like a carriage return.

    Example:

    Code:
    void loop() {
      int inByte = 0;
      int test = 0;
      if (Serial.available() > 0) {
        /* append the byte to the buffer */
        inByte = Serial.read();
        buffer[bufIndex] = inByte;
        bufIndex++;
        if ((inByte == '*') || (inByte == '\n')) {
          processBuffer();
          clearBuffer();
          bufIndex = 0;
        }
      }
    }
    This particular example triggers the buffer processing function if the input is 'terminated' with an asterisk or a carriage return.

    g.

  10. #10
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    May 2012
    Location
    Colombia
    Posts
    5
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: programing and reading PDE for Link2fs:inOuts

    Steve5006, your contribution of delay (11) actually helped me solve the problem of reading more than one character, eg (> o) thanks for this.
    Now I have a new concern, I want more realism to my cabin and I want the script to read and act on all variables swiche as long as the battery is turned on (as in reality), otherwise I do not want no LED lights, but that's where the problem because the variable in the program that reads the battery is "X" and as I said before the program reads in alphabetical order, this alone makes me a problem.
    I wait to play Jim can help us.

    Greetings and thank you very much for your help.

Page 1 of 2 12 LastLast