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

Read Extra1 (Traction Loss) via Arduino (USB)

Discussion in 'DIY Motion Simulator Building Q&A / FAQ' started by JayMonkey, Feb 11, 2017.

  1. JayMonkey

    JayMonkey New Member

    Joined:
    Jul 20, 2016
    Messages:
    19
    Location:
    UK
    Balance:
    40Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi All,

    Am trying to do a bit of experimentation with Traction Loss (Extra 1 Channel) With Assetto Crosa.

    Right now i'm just trying to get the raw data values for Extra 1 into my processing code on Arduino Nano.

    I have Sim Tools 1.3 with AC Plug-in. I've mapped Axis 1 to Extra 1 in Axis Assignments.

    ST_Axis.JPG

    With AC Running I can See Extra 1 in the SimTools Tuning Center is generating a value of approximately between -20 to +20 however it has 13 decimal places !!!!

    SR_TC.JPG
    eg: 20.2188758850098 to -20.2188758850098

    Is there a way within Sim Tools to format the data to an 0 decimal places ?
    i don't need the decimal places ?

    I've got my Interface setup as follows ....

    ST_Interfcae.JPG

    My Arduino code is working .. i have a second serial (software) port set up on the Arduino with a debug console running on a small linux PC .... if i open the serial (USB) monitor in the IDE and manually send data to it it processes the string correctly.

    Some examples of manually sent data ....

    TL5Z = a value of 5
    TL-11Z = a value of -11
    TL19Z = a value of 19

    However if I close the serial (USB) monitor and allow the Arduino to receive data from Sim Tools all it ever sends is a value of 127

    Sent string = TL127Z

    No matter what i do it seems that the Axis 1 value never equals the Extra 1 value .. its always 127 ????

    I will post my full Arduino code as a separate post following this one since no one respomded to my last ple for help with this issue ....

    This is my first experience with Game Engine .... so be gentle with me if I've missed something obvious.

    Cheers
    Jay
    Last edited: Feb 14, 2017
  2. JayMonkey

    JayMonkey New Member

    Joined:
    Jul 20, 2016
    Messages:
    19
    Location:
    UK
    Balance:
    40Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    Arduino
    This is my Arduino code for processing AC Extra 1 sent as Axis 1 ... right now i'm just trying to get meaningful data ...
    TL position code will go in the commented area's

    Code:
    
      #include <SoftwareSerial.h>
       #define DEBUG 1
     
      SoftwareSerial mySerial(8, 7);
    
      String inputString = "";         
      String LastInputString = "";
      boolean stringComplete = false;
      boolean ActiveTL = false;
      String TL_Raw = "" ;
      int TL_Value = 0;
      int Last_TL_Value = 0;
    
    void setup() {
    
       Serial.begin(38400);
       Serial.flush();
    
       mySerial.begin(38400);
      
       #ifdef DEBUG
          mySerial.println("Traction Loss Test System Ready ....");
          mySerial.println("");
       #endif
    
       inputString.reserve(50);
    }
    
    void loop(){
    
      if (stringComplete) {
        ProcessData();
      }
    
      if (TL_Value != Last_TL_Value) {
        TL_Output();
      }
     
    }
    
    void serialEvent() {
      if ( ActiveTL == false){
        while (Serial.available()) {
          char inChar = (char)Serial.read();
        inputString += inChar;
          if (inChar == 'Z') {
            stringComplete = true;
          }
         }
      }
    }
    
    void ProcessData(){
    
         if (inputString.substring(0,2) == "TL") {
          TL_Raw = inputString.substring(2,inputString.length()-1);
    
          LastInputString = inputString;
        
         if (TL_Raw.substring(0,1) == "-") {
            TL_Value = TL_Raw.substring(1,2).toInt();
            TL_Value = - TL_Value;
         }
         else {
            TL_Value = TL_Raw.substring(0,2).toInt();
         }
         
          if(TL_Value > 20) {
            TL_Value = 20;
          }
    
          if(TL_Value < -20) {
            TL_Value = -20;
          }
         }
        stringComplete = false;
        inputString = "";
    }
    
    void TL_Output() {
    
        Last_TL_Value = TL_Value;
       
          #ifdef DEBUG
            mySerial.println("");
            mySerial.print("Traction Loss String = ");
            mySerial.println(LastInputString);
          #endif
         
          if (TL_Value == 0) {
            #ifdef DEBUG
              mySerial.println("No Traction Loss ... ");
            #endif
    
          // Code to move Traction Loss to 0 Position here *****
    
          }
         
          if (TL_Value > 0) {
            #ifdef DEBUG
             mySerial.print("Right side Traction Loss = ");
             mySerial.println(TL_Value);
            #endif
    
          // Code to move Traction Loss to + (right) Position
    
          }
    
          if (TL_Value < 0) {
            #ifdef DEBUG
              mySerial.print("Left side Traction Loss = ");
              mySerial.println(TL_Value);
            #endif
           }
    
          // Code to move Traction Loss to - (left) Position
    
    }