Results 1 to 10 of 10
  1. #1
    150+ Forum Groupie
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    227
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Arduino Mega flap code and SwitecX25.168 stepper

    Hi all,

    I've wrote some code to get the flap gauge working with the Arduino Mega and Link2FS and the small SwitecX25.128 stepper.
    The problem is that the stepper won't move. The basic movement to the zero position is working, but the stepper doesn't react on the FSX gauge values

    Is there anybody who has an idea what's wrong in my code? See below.

    Regards

    Jan




    int CodeIn;
    #include "SwitecX25.h"
    SwitecX25 flap(315*3, 4,5,6,7);




    void setup() {
    Serial.begin(115200);
    flap.zero();

    }
    void loop(){
    if (Serial.available() > 0) {
    Serial.flush();
    if (CodeIn == '#') {EXPERTS();}
    }
    flap.update();
    }


    char getChar()
    {
    while(Serial.available() == 0);
    return((char)Serial.read());
    }




    void EXPERTS(){




    CodeIn = getChar();
    switch(CodeIn) {
    case 'b': {

    String flapdata;
    int flapPosition;
    flapdata += getChar(); //Get three characters for flap data from Link2fs
    flapdata += getChar();
    flapdata += getChar();


    flapPosition = flapdata.toInt();
    flap.setPosition(map (flapPosition,0,100,0,945)); // Calculation is made in FS2Link *100/16384 at the FSUIPC tab
    flap.update();


    }
    }
    }

  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: Arduino Mega flap code and SwitecX25.168 stepper

    Remove the flap.update in your case 'b'. You only nead the update in the void loop.
    End your switchcase with "
    break;"
    See sketch:
    http://www.mycockpit.org/forums/showthread.php?t=29336&page=5&highlight=SwitecX25
    Every switchcase is ended with "break;"
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    150+ Forum Groupie
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    227
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Mega flap code and SwitecX25.168 stepper

    Quote Originally Posted by BuzziBi View Post
    Remove the flap.update in your case 'b'. You only nead the update in the void loop.
    End your switchcase with "
    break;"
    See sketch:
    http://www.mycockpit.org/forums/showthread.php?t=29336&page=5&highlight=SwitecX25
    Every switchcase is ended with "break;"

    Thanks BuzziBi

    Did what you have suggested but with no result yet.

    Any other ideas?

    Regards

    Jan

  4. #4
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Mega flap code and SwitecX25.168 stepper

    Hi Jan,I'll put the serial.flush() part (see loop()) in the setup() fonction right after serial.begin()
    the serial.flush() fonction aims to remove any residual character in the buffer
    You've forgotten CodeIn = getChar(); in the loop() fonction so no '#' (or other character) detected if you don't read serial buffer

    void setup()
    {
    Serial.begin(115200);
    if (Serial.available() > 0) Serial.flush();
    flap.zero();
    }

    void loop()
    {
    CodeIn = getChar();
    if (CodeIn == '#') {EXPERTS();}
    }

  5. #5
    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: Arduino Mega flap code and SwitecX25.168 stepper

    Did you test the wiring to the stepper, using the example that was included in the Switec library?
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  6. #6
    10+ Posting Member
    Join Date
    Apr 2015
    Location
    France
    Posts
    14
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Mega flap code and SwitecX25.168 stepper

    Hi Jan,

    Is your SwitecX25 able to move from Start to END and come back to Start ?

    I did not look your code, but i had the same problem... I had to send an "opposite value" to mak it working fine ...

    Eg : if my value was 197, i had to send -197 ... And everything went OK ...

    Hope it will help.

    Regards.

  7. #7
    150+ Forum Groupie
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    227
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Mega flap code and SwitecX25.168 stepper

    Did some testing and found that in general this code is working for my 737 flap gauge.
    Only problem is that the flap gauge has a non lineair scale.
    Any thoughts how to solve that in the Arduino code?

    regards

    Jan




    int CodeIn;
    #include "SwitecX25.h"
    SwitecX25 Flap(315*3, 4,5,6,7);

    void setup() {
    Serial.begin(115200);
    Flap.zero();

    }

    void loop() {

    if (Serial.available() > 0) {
    Serial.flush();
    CodeIn = getChar();
    if (CodeIn == '<') {EXPERTS();}
    }
    Flap.update();

    }

    char getChar()
    {
    while (Serial.available() == 0);
    return ((char)Serial.read());
    }

    void EXPERTS() {
    CodeIn = getChar();
    switch (CodeIn) {

    case 'G':{
    String Flapdata;
    int FlapPosition;
    Flapdata += getChar();
    Flapdata += getChar();
    Flapdata += getChar();
    FlapPosition = Flapdata.toInt();
    Flap.setPosition(map (FlapPosition, 0, 100, 0, 810));
    break;}

  8. #8
    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: Arduino Mega flap code and SwitecX25.168 stepper

    The
    SwitecX25 Flap(315*3, 4,5,6,7); (315'3 = minimum 0-maximum 945)
    so
    0, 100, 0, 810 should be 0, 100, 0, 945
    and if you ie are using stock 737, the max valu on flaps from Link2fs is 057,
    and should be
    0, 057, 0, 945
    use Link2fs Monitor to see the min/max value on FlapPosition.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  9. #9
    150+ Forum Groupie
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    227
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Arduino Mega flap code and SwitecX25.168 stepper

    Hi,
    The output( The value 810 is also ok, because the the travel range of the flap needle is aprox. 270 degree and not 360.
    The problem is that the scale between the flap settings isn't lineair. So the question is how to solve that?
    regards
    Jan

  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: Arduino Mega flap code and SwitecX25.168 stepper

    OK. I wired up a Switec stepper and could see what you meen.
    Can you try with
    if(FlapPosition == 003) {Flap.setPosition( 150);} // position 1 and so on
    or
    if(FlapPosition > 002 && FlapPosition <004 ) {Flap.setPosition( 150);} // position 1 and so on
    or
    if(FlapPosition > 002 | | FlapPosition <004 ) {Flap.setPosition( 150);} // position 1 and so on
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------