Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    New Member
    Join Date
    Sep 2012
    Location
    Queensland
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    new servo code for arduino 1.0.1 & Link2FS

    Firstly, big thank you to Jim for creating the awesome Link2FS program!

    After recently getting involved with home cockpit building and the Arduino, I ran into a snag with the servo VSI code posted on this forum. My limited knowledge but alot of searching around told me that the latest build of the Arduino language makes said example inoperative.

    After much hair pulling this is what works for me to drive a servo indicating airspeed:

    if (j1 == 'W'){ // 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());

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

    int value = airsp.toInt(); //turns the value from Link2FS to an integer with name 'value'
    delay (50); //experiment with this number

    value = map(value, 0, 350, 10, 17; // maps 'value' to the servo ( 0 - 350 kias = 10 - 178 servo degrees)
    myservo.write(value); //sends 'value' to the servo
    airspold = airsp; // Writes the current reading to the "old" string.
    }
    }

    Basically the new language (1.0.1) allows a much easier way to change the strings from Jim's program to integers that can be sent to your servos.
    Now the only bit required is:

    int value = airsp.toInt();

    Change 'value' to whatever name you want and 'airsp' to the string name you are converting.
    This may seem straight forward to some but I thought others with my limited experience level may benefit.

  2. Thanks WJH308, Jim NZ, AK Mongo thanked for this post
  3. #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: new servo code for arduino 1.0.1 & Link2FS

    That,s good news Phil ,, Its certainly a lot easier than the other method.

    Some Guys are going to be happy with that one ..

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

  4. #3
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Nov 2012
    Location
    Sydney
    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: new servo code for arduino 1.0.1 & Link2FS

    PhillTTD.
    Had the same problem and thanks to you the sketch now compiles and loads. Unfortunately it still does not communicate with Link2FS. I am trying to extract Roll and Pitch info to drive two servo's for a small prototype platform.

    Being new to this I do not understand your last Paragraph "change value to whatever name you want and airsp to the string you are converting". I have less than limited experience and I am old as well.

    Can you help please.

    Sam

  5. #4
    New Member
    Join Date
    Sep 2012
    Location
    Queensland
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: new servo code for arduino 1.0.1 & Link2FS

    Sam

    I think basically your code would look like this:

    #include
    Servo pitchservo;
    Servo rollservo;

    String pitch,pitchold,roll,rollold;

    void setup()
    {
    pitch.attach(; //change this to the pin number your servo is attached to
    roll.attach(9); //change this to the pin number your servo is attached to

    Then in here put all the rest of the code from the examples on Jims site
    When you get to the bit that looks like

    if (j1 == 'c'){ // Found the reading "whatever", I cant remember the exact letter its looking for here to get pitch or roll
    but anyway, right after this you will put:

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

    if (pitch !=pitchold){ // checks to see if its different to the "old" reading
    delay (11);

    int valuepitch =pitch.toInt();
    delay (5);

    valuepitch = map(valuepitch, 0, 90, 5, 170); //the first 2 numbers here are aircraft pitch, 0 degrees and 90 degrees,
    //I dont know if a negative number would work here - try it.

    servopitch.write(valuepitch); //sends the info to move the servo
    pitchold = pitch; // Writes the current reading to the "old" string.
    }
    }



    For the roll channel, do the exact same thing but change the word pitch above to roll.

    I'm not very good at explaining things but this may have triggered some of your neurons.
    Hope it works.

    Phill

  6. #5
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Nov 2012
    Location
    Sydney
    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: new servo code for arduino 1.0.1 & Link2FS

    PhilTTD.

    How's that for a quick response.
    Will try over the weekend.
    Very much appreciated.

    Thanks

    Sam111

  7. #6
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Nov 2012
    Location
    Sydney
    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: new servo code for arduino 1.0.1 & Link2FS

    Phil

    Tried late last night and combined with the latest version of Link2fs InOut FSX is now talking to the two servo's. The response is jittery but I am sure that with some adjustment I acn smooth it out.

    Thanks again for sharing your expertise - very much appreciated.

    Next step is to build a model platform. Will advise.

    Sam

  8. #7
    500+ This must be a daytime job



    Join Date
    Oct 2009
    Location
    Juneau, AK
    Posts
    619
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: new servo code for arduino 1.0.1 & Link2FS

    Make sure your servos are powered by a separate source not off the arduino and you may get rid of the jitters. At least it worked for me.

    Reid
    http://juneaucessnasim.blogspot.com
    N58243 (virtual)- Low and Slow...

  9. #8
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: new servo code for arduino 1.0.1 & Link2FS

    Hi guys, just been playing with this myself.
    if you make sure you capture all the string first so the +/_ xxx.x you should get a nice smooth movement.
    Also to get over the negative value thing from -90 to +90 , just add 90 to the value and output that value direct to the servo this will give you 0 at -90 , 90 at 0 and 180 at +90.
    that should also work for any of the other gauges that have negative add the negative value and then map it.
    just been flying on my pc and i was very smooth.
    hope this helps.
    mark

  10. #9
    Our new friend needs to reach 10 posts to get to the next flight level
    Join Date
    Nov 2012
    Location
    Sydney
    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: new servo code for arduino 1.0.1 & Link2FS

    Mark.

    Thanks will try. So Map (0,90,0,180) instead of Map(_50,50,0,180)

    Note: My current setup places the platform in a level position on startup with the aircraft on ground.

    Maybe I am missing something.

    Sam111

  11. #10
    75+ Posting Member vikingsraven's Avatar
    Join Date
    Dec 2012
    Location
    UK
    Posts
    89
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: new servo code for arduino 1.0.1 & Link2FS

    Sam111
    Sorry what I meant was ignore map for this onjust add 90 to your intial
    Value this will then change the value from -90 to 0 and +90 to 180 , your origninal zero.
    will be 90.
    Value = value + 90 // map(value, -90,90,0,180).

Page 1 of 2 12 LastLast