1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Arduino Sketch

Discussion in 'Miscellaneous' started by Harry King, Jan 2, 2017.

  1. Harry King

    Harry King Member

    Joined:
    Apr 6, 2016
    Messages:
    43
    Balance:
    224Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Ok, I am to the point of my limitation and can only say what it is I am looking for I wrote my first adapted code to match what I need and it was success in loading it to the board:

    // MultiStepper.pde
    // -*- mode: C++ -*-
    //
    // Shows how to multiple simultaneous steppers
    // Runs one stepper forwards and backwards, accelerating and decelerating
    // at the limits. Runs other steppers at the same time
    //
    // Copyright (C) 2009 Mike McCauley
    // $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

    #include <AccelStepper.h>

    // Define some steppers and the pins they will use
    AccelStepper stepper1(1, 3, 6); // pin 3 = step, pin 6 = direction
    AccelStepper stepper2(1, 4, 7); // pin 4 = step, pin 7 = direction
    AccelStepper stepper3(1, 5, 9); // pin 5 = step, pin 8 = direction

    void setup()
    {
    Serial.begin(9600);
    stepper1.setMaxSpeed(1000);
    stepper1.setSpeed(1000);

    stepper2.setMaxSpeed(1000);
    stepper2.setSpeed(1000);

    stepper3.setMaxSpeed(1000);
    stepper3.setSpeed(1000);
    }

    void loop()
    {
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
    stepper1.moveTo(-stepper1.currentPosition());
    stepper1.run();
    stepper2.run();
    stepper3.run();
    }

    Things I need mainly working with DCS, Cliffs of Dover and FSX P3D :
    1. I am looking the motors to stop and reset on eject or crash.
    2. I am not sure of gear ratio at the moment, but something that can be adjusted by position to match motor turn with 360 X Y Z full rotation.
    3.Not sure about the speed yet needed
    4. correct com3 connection information corrected
    5. feedback based on steppes.

    Again I am not sure of much in what I am trying to tackle but I am willing and very patient with this project.

    Thanks for all your help since I got the games connect to sim tune and virtual axis I know the next step will be the hardest. Thanks for the long talk Historiker it was a great help and I have been reading quite a bit to write the sketch on multiple step motors.
  2. Harry King

    Harry King Member

    Joined:
    Apr 6, 2016
    Messages:
    43
    Balance:
    224Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Updated sketch:
    Code:
    // MultiStepper.pde
    // -*- mode: C++ -*-
    //
    // Shows how to multiple simultaneous steppers
    // Runs one stepper forwards and backwards, accelerating and decelerating
    // at the limits. Runs other steppers at the same time
    //
    // Copyright (C) 2009 Mike McCauley
    // $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
    #include <AccelStepper.h>
    // Define some steppers and the pins they will use
    AccelStepper stepper1(1, 3, 6); // pin 3 = step, pin 6 = direction
    AccelStepper stepper2(1, 4, 7); // pin 4 = step, pin 7 = direction
    AccelStepper stepper3(1, 5, 9); // pin 5 = step, pin 8 = direction
    void setup()
    {
    Serial.begin(9600);
    stepper1.setMaxSpeed(1000);
    stepper2.setMaxSpeed(1000);
    stepper3.setMaxSpeed(1000);
    }
    void loop()
    {
      // Random change to speed, position and acceleration
      // Make sure we dont get 0 speed or accelerations
      stepper1.moveTo(rand() % 200);
      stepper2.moveTo(rand() % 200);
      stepper3.moveTo(rand() % 200);
      stepper1.setMaxSpeed((rand() % 200) + 1);
      stepper2.setMaxSpeed((rand() % 200) + 1);
      stepper3.setMaxSpeed((rand() % 200) + 1);
      stepper1.setAcceleration((rand() % 200) + 1);
      stepper2.setAcceleration((rand() % 200) + 1);
      stepper3.setAcceleration((rand() % 200) + 1);
    }[code]
  3. Harry King

    Harry King Member

    Joined:
    Apr 6, 2016
    Messages:
    43
    Balance:
    224Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    I am not sure if the top code would work better but I tthink I am on the right tract. Any help to make sure that simtools recognizes the sketch. Or if their is another direction I should be going.
    Last edited: Jan 3, 2017
  4. Harry King

    Harry King Member

    Joined:
    Apr 6, 2016
    Messages:
    43
    Balance:
    224Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Anyway to add this code to create a quick stop once the E key for eject is hit:

    void loop()
    {
    stepper.moveTo(500);
    while (stepper.currentPosition() != 300) // Full speed up to 300
    stepper.run();
    stepper.stop(); // Stop as fast as possible: sets new target
    stepper.runToPosition();
    // Now stopped after quickstop

    // Now go backwards
    stepper.moveTo(-500);
    while (stepper.currentPosition() != 0) // Full speed basck to 0
    stepper.run();
    stepper.stop(); // Stop as fast as possible: sets new target
    stepper.runToPosition();
    // Now stopped after quickstop

    }
  5. UAlberta Formula SAE

    UAlberta Formula SAE New Member

    Joined:
    Aug 26, 2018
    Messages:
    28
    Occupation:
    Engineering Student
    Location:
    Edmonton Alberta Canada
    Balance:
    17Coins
    Ratings:
    +7 / 0 / -0
    My Motion Simulator:
    Arduino
    Looks like an awesome project!

    1. How is this code coming? It looks like you have the basics figured out - what happens when you run it?
    2. I'm not really sure about this one.
    3. I would suggest manually tuning this. Kind of like PIDs - there are fancy ways to calculate the speed you will need but a rough calculation and then testing by feel might be the best route to go (I have more experience with PIDs but often even the best calculations don't account for all variables and require manual adjustment/tuning).
    4. Is this something you figured out? Sounds like an Arduino or driver problem?
    5. Is there a library that can help with this one? I won't suggest any as I haven't personally used any and it could be somewhat hardware dependent.

    I'm excited to see you get this running!