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

Resolved Help with Interface settings for Arduino control please

Discussion in 'SimTools DIY Version' started by pab61, Mar 12, 2017.

  1. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    ###################################################

    Simulator

    1. Commercial or DIY: DIY
    2. DOF (Number of axles ): 1
    3. Actuators (DIY, SCN5 etc.): Stepper Motor
    4. Interface (Arduino, SCN, Mega, DIY etc. ): Arduino

    SimTools

    1. Version Number: 2.1 (current version, where can you find the version number in the software?)
    2. Game Plugin where the error is happening: Default
    3. Settings (Relevant settings): Screenshots below
    ###################################################

    Hi everyone, I'm wondering if anyone can provide me with some guidance on setting up Game Engine for an Arduino?

    I've started with the RCModel code by EAOROBBIE from here which I've modified to work with only 1 axis (P for pitch) and to drive a stepper motor (code below if it helps).

    Code:
    //********************************************************************************************
    // Simtools Stepper 1 Axis code
    // Based on code By EAOROBBIE (Robert Lindsay)
    // By Peter Brennan
    
    //********************************************************************************************
    
    #include <AccelStepper.h>
    
    #define DEBUG 1                                    // comment out this line to remove debuggin Serial.print lines
    
    // Define a stepper and the pins it will use
    AccelStepper stepper(1, 9, 8);
    
    const char kEOL = '~';                              // End of Line - the delimiter for our acutator values
    const int kMaxCharCount = 3;                        // some insurance...
    int valueCharCount = 0;                             // how many value characters have we read (must be less than kMaxCharCount!!
    int actuatorPosition = 0;                           // current Actuator position, initialised to 0
    int newActuatorPosition = 0;                        // initialise variable to collect new motor position
    
    // set up some states for our state machine
    // psReadActuator = 0
    // psReadValue = 1
    int currentState = 0;
    
    void setup()
    { 
      // Set base values for stepper speed and acceleration as well as setting current pos to 0
      stepper.setMaxSpeed(2000);
      stepper.setAcceleration(1000);
      stepper.moveTo(0);
    
       Serial.begin(9600); // opens serial port at a baud rate of 9600
    }
    
    
    
    // this code only runs when we have serial data available. ie (Serial.available() > 0).
    void serialEvent() {
        char tmpChar;
        int tmpValue;
    
        while (Serial.available()) {
            // if we're waiting for a Actuator name, grab it here
           if (currentState == 0) {
                tmpChar = Serial.read();
    
    #ifdef DEBUG 
    Serial.print("read in ");           
    Serial.println(tmpChar);
    #endif
    
    if (tmpChar == 'P') {
    
    #ifdef DEBUG 
    Serial.print("which is actuator ");           
    Serial.println('P');
    #endif
    
    currentState = 1;                 // start looking for the Actuator position
    valueCharCount = 0;                         // initialise number of value chars read in
                        break;
    }
           }
      
    
    // if we're ready to read in the current Actuator's position data
            if (currentState == 1) {       
             
                while ((valueCharCount < kMaxCharCount) && Serial.available()) {
                 
                    tmpValue = Serial.read();
                   
                    if (tmpValue != kEOL) {
                    
                        tmpValue = tmpValue - 48;
           
                        if ((tmpValue < 0) || (tmpValue > 9)) tmpValue = 0;
                        // Determine the new position for the stepper
                        newActuatorPosition = newActuatorPosition * 10 + tmpValue;
                        valueCharCount++;
                    }
                    else break;
                }
               
                // if we've read the value delimiter, update the Actuator and start looking for the next Actuator name
                if (tmpValue == kEOL || valueCharCount == kMaxCharCount) {
    #ifdef DEBUG           
    Serial.print("Move to ");           
    Serial.println(newActuatorPosition); 
    #endif
    // Transfer the new actuator value to the current one, and reset the new position
              actuatorPosition = newActuatorPosition;
              currentState = 0;
              newActuatorPosition = 0;
                }
            } }
        }
       
        void loop()
    {
    // Move the stepper to the desired position if nto already there
         stepper.moveTo(actuatorPosition);
    stepper.run();
    }
    The code seems to be doing what it needs to, using the fomat that EAOROBBIE uses in his code, if I enter PXXX~ in the Arduino Serial Moniotor then the stepper will drive to the position determined by the value of XXX. I had assumed then that all I needed then was to have the interface output setting as P<Axis1a> to get me up and running with testing.

    So then I tried to drive the stepper using the output testing of Game Engine, but I'm not seeing any signs of data being sent between SimTools and the Arduino, so any help in getting my settings right would be greatly appreciated.

    My settings are:
    Default Axis assignments:
    simtools_axis_settings.jpg

    Interface settings:
    simtools_interface_settings.jpg

    What should BitsPerSec be set to (I've seen all sorts of settings used in examples, shouldn't it be 9600, the rate I set in the Arduino code)?

    So then I click on Output testing, turn it on and move the axis, I'm not seeing a response from the Arduino, either in the serial monitor or in the motor.

    simtools_output_testing.jpg

    I'm guessing my problems stem from getting my information of correct setups from a number of sources and guides, most of whaich are for older versions of Simtools (or am I totally off track and have made a fundamental error in how this should all work), can anyone see what I might need to change here to get me up and running? Any help would be much appreciated, thanks!
  2. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    Just a quick update, I hadn't been able to load the interface cfg file that EAOROBBIE posted with his code (I assume cause it was for SimTools 1) but just realised that it'd be a simple text file, so I've now setup the interface settings as for that file:

    Com: COM3 (which is my Arduino)
    BPS: 9600
    Data Bits: 8
    Parity: None
    StopBits:1
    Output Bit Range: 8
    Output Type: Decimal
    Interface Output: P<Axis1a>~

    Still no response in Output Testing, any suggestions on what I'm doing wrong would be apprecaited.
  3. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    OK, some progress, I installed some USB sniffing softwae which reset the usb ports and rebooted the machine, and I'm now seeing some response from the motor.

    The only issue now is that it's a very much delayed response, when I move the testing slider the motor turns about 5 to 8 seconds later, has anyone else seen bahaviour like that before?
  4. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,282
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    49,198Coins
    Ratings:
    +5,093 / 18 / -0
    Hi @pab61,
    Have you tested the outputs from SimTools with any other sketches?
    What is the "Main Level" slider at in the Game Mangers > Profile Editor?
    yobuddy
  5. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks for the reply Yobuddy. no, haven't tested with any others yet (was away second half of last week), but I do have an RC servo lying around somewhere so will try it with the original RCModel sketch and check the main level slider tonight when I get home and then report back.

    Thanks!
  6. speedy

    speedy Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,193
    Location:
    Alexandria , Egypt
    Balance:
    7,931Coins
    Ratings:
    +1,287 / 10 / -0
    My Motion Simulator:
    3DOF, AC motor, Arduino, Motion platform
    SimTools version displayed on the GM startup screen ...

    1.jpg
  7. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks Speedy!
    • Like Like x 1
  8. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,282
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    49,198Coins
    Ratings:
    +5,093 / 18 / -0
    It's on the splash screen of game manager when you startup buddy.
    yobuddy
    • Like Like x 1
    Last edited: Mar 20, 2017
  9. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    Quick update, I had a little time to check a few more things last night, I didn't have time to conclusively answer the questions yobuddy asked, so I won't respond to those until I can answer those accurately, what I was able to quickly test was whether the accelstepper library was slowing things down (I removed the library and replaced the servo movement code with the standard blink with the blink speed determined by the data from simtools). This confirmed that even though I see a response pretty well immediately when the data is sent to the Arduino through the serial monitor, when the data comes from SimTools it's delayed by a number of seconds (the speed of the blinking changed a couple of seconds after I had moved the slider).

    So I'm certain that using accelstepper library is not the cause of the issue (not the primary one at least).

    While on the bus to work this morning I had another thought, it struck me that Simtools Game Engine has always responded quite slowly for me right from when I installed it (when clicking on the buttons down the left hand side, (Axis Assignments, Interface Settings, Output Testing) there's a delay of a couple of seconds before the main panel changes (like the program freezes for a few seconds each time it's asked to do something)). I had just assumed that's normal, but this morning I installed Simtools on my work machine (which is much lower spec than my home racing pc) and I've found that it responds much faster on this machine.

    So I'm now thinking that the solution is more likely to be trying to find out why SimTools is running/responding slowly on my PC rather than trying to find flaws in my Arduino code.

    I plan to uninstall and reinstall tonight to see if that helps, but it anyone has any ideas as to what might be causing that I'd appreciate hearing them.

    Thanks.
    • Informative Informative x 1
  10. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,282
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    49,198Coins
    Ratings:
    +5,093 / 18 / -0
    Have you tried re-installing .net?
    It seems to help sometimes.
    yobuddy
    • Informative Informative x 1
  11. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    OK, thanks for the suggestion, I'll give it a try, do I need to uninstall all versions of .net first?
  12. pab61

    pab61 Member

    Joined:
    Jan 13, 2017
    Messages:
    47
    Location:
    Adelaide
    Balance:
    638Coins
    Ratings:
    +40 / 0 / -0
    My Motion Simulator:
    Arduino
    You sir, win the helpful post of the day, in addition to my eternal gratitude! Uninstalled a couple of older versions of .net, rebooted, and now it's working beautifully! Thanks!

    Will see if I can post some video soon. Now to put the hardware together and get it running so I can try out dirt on iRacing!
    • Winner Winner x 2
    • Like Like x 1
  13. Lodewijk

    Lodewijk Member

    Joined:
    Feb 25, 2012
    Messages:
    32
    Occupation:
    Engineer
    Location:
    South Africa
    Balance:
    597Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    4DOF
    @pab61 I think I'm having the same issue you originally had, with getting information from Simtools to Arduino. I've started a new thread here:
    https://www.xsimulator.net/communit...motion-data-to-arduino-via-serial-port.10827/
    to ask about this.

    Would you mind explaining to me about the cfg file, where it should go, and just basically how I get data from Simtools to Arduino Serial Monitor?

    Are you able to see data from Simtools, coming into your Arduino Serial Monitor?
  14. zhai1987

    zhai1987 Member

    Joined:
    Sep 7, 2021
    Messages:
    96
    Balance:
    320Coins
    Ratings:
    +11 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, AC motor
    <AccelStepper.h>Brother, do you have a library?