1. 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 Download Package Now!
  2. 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
  3. 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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Arduino haptic/force feedback Assetto Corsa

Discussion in 'DIY Motion Simulator Projects' started by sikjar, Sep 25, 2015.

  1. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi all - Just a short introduction to something I've been working on with my Arduino.

    I have a wheel with no force feedback, and wanted to see if I can add some sort of feedback to it.

    So I made the below script for an Arduino and hooked it up to four small vibrators. It works OK with Assetto Corsa and X-sim, and lets me feel if the wheels are slipping during braking and acceleration, and when the car is oversteering or understeering.

    Now I'd like to try and use XSimulator to make it work with iRacing, just need to save up coins for the plugin...

    Here's the Arduino script for Assetto Corsa

    Code:
    // In part based on X-sim3dashboard v1  (using TM1638 display and Arduino Nano v3)by TronicGr (Thanos) 4-26-2012
    // Shared as Public Domain
    
    
    void setup() {
    
    // Declare pin 3,5,6 and 11 to be an output
          pinMode(3, OUTPUT);
          pinMode(5, OUTPUT);
          pinMode(6, OUTPUT);  
          pinMode(11, OUTPUT);
    //Create Serial Object
        Serial.begin(9600);
    
    }
    
    byte SteeringxSpeed;
    byte SteeringxSpeed1;
    byte SteeringxSpeed2;
    byte SteeringxSpeed3;
    byte SteeringxSpeed4;
    byte SteeringxSpeed5;
    byte SteeringxSpeed6;
    
    void loop() {
    
    char bufferArray[20];              // holds all serial data into a array
    
    int i;
    byte FrontSlip; 
    int FrontSlipOut;
    byte RearSlip;
    int RearSlipOut;
    
    byte SideslipValue; 
    int SideSlipMinusSxS;
    int Understeer;
    int UndersteerOut;
    int  Oversteer;
    int OversteerOut;
    
    
    
    
    
    if (Serial.available() >= 12)  {    //if 12 bytes available in the Serial buffer...
          for (i=0; i<12; i++) {         // for each byte
          bufferArray[i] = Serial.read();        // put into array
    
      
         }
      }
    if (bufferArray[0] == 'A' ){      // if new bytes have been recieved
    
       FrontSlip = bufferArray[1];  
        if (FrontSlip > 100) {
            FrontSlip = 100;
             }
       FrontSlipOut = map(FrontSlip, 0, 100, 40, 255);  
        analogWrite(3, FrontSlipOut);
    }
    
     
    if (bufferArray[2] == 'B' ){      // if new bytes have been recieved
    
       RearSlip = bufferArray[3]; 
       if (RearSlip > 100) {
            RearSlip = 100;
             }
       RearSlipOut = map(RearSlip, 0, 100, 40, 255);     
        analogWrite(5, RearSlipOut);
     
    }
    
     
    if (bufferArray[4] == 'C' ) {      // if new bytes have been recieved
    SteeringxSpeed5 =   bufferArray[5]; 
    
    SteeringxSpeed  = SteeringxSpeed1;
    SteeringxSpeed1 = SteeringxSpeed2;
    SteeringxSpeed2 = SteeringxSpeed3;
    SteeringxSpeed3 = SteeringxSpeed4;
    SteeringxSpeed4 = SteeringxSpeed5;
    // There is a delay from steering input is made until the car reacts. The above routine cancels out this delay.
    
     
    }
    
    if (bufferArray[6] == 'D' ){      // if new bytes have been recieved
    SideslipValue = bufferArray[7];
    
    SideslipValue = SideslipValue /2;
    SteeringxSpeed= SteeringxSpeed /2;
    SideSlipMinusSxS = SideslipValue + SteeringxSpeed;
    
    
    
      // If sideslip is less than a certain value compared to steering input, the car is understeering. Vibrator connected to PIN 6 will be activated.
    if (SideSlipMinusSxS > 131) {
          Understeer = SideSlipMinusSxS - 131;
         if (Understeer > 10) {
                Understeer = 10;
                }
         UndersteerOut = map(Understeer, 0, 10, 40, 255); 
    
         
        }
        if (SideSlipMinusSxS < 132) {
            UndersteerOut = 0;}
              
       analogWrite(6, UndersteerOut);
    
    
       // If sideslip is over a certain value compared to steering input, the car is oversteering. Vibrator connected to PIN 11 will be activated.
    
             if (SideSlipMinusSxS < 126) {
          Oversteer = SideSlipMinusSxS * -1 + 126;
           if (Oversteer > 10) {
            Oversteer = 10;
             }
         OversteerOut = map(Oversteer, 0, 10, 40, 255);
        }
    
    
        if (SideSlipMinusSxS > 125) {
            OversteerOut = 0;
             }  
              
       analogWrite(11, OversteerOut);
      }
    }
    
    
    Connecting the vibration motors
    Don't connect the motors directly to the pins on the Arduino, they draw too much current!
    Here's a tutorial on how to connect vibration motors to the Arduino:
    http://www.learningaboutelectronics.com/Articles/Vibration-motor-circuit.php

    If anybody is interested in doing something similar, I can post more information.
    • Like Like x 4
    • Agree Agree x 1
    • Creative Creative x 1
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. tombo

    tombo Active Member

    Joined:
    Oct 5, 2013
    Messages:
    269
    Location:
    Germany
    Balance:
    2,343Coins
    Ratings:
    +244 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino
    Hello,
    sounds like an interesting project.
    I have send you some coins to purchase the weeks access.
    Maybe some pictrues of your work woul be nice.
    • Friendly Friendly x 4
  4. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks a lot, I will get started with the project and post updates about the progress...
    • Like Like x 2
  5. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
  6. mirxtrem

    mirxtrem mirxtrem.apps

    Joined:
    Apr 22, 2016
    Messages:
    17
    Occupation:
    Electrical engineering student
    Location:
    Colombia
    Balance:
    273Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino
    Hello, i have trying to upgrade my steering wheel because it does not have FFB system, that code works with Arduino UNO?
    I'm gonna change to 900º spin wheel too, mine only have 270º or 300º, maybe we can share information.
  7. ferslash

    ferslash Active Member

    Joined:
    Feb 8, 2011
    Messages:
    488
    Balance:
    4,690Coins
    Ratings:
    +176 / 2 / -0
    post some pics of your sterring wheel i really would like to see how you attached the motors to the wheel

    best regards
    :popcorn
  8. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
    Yes, the above script works with Arduino UNO, but not with X-simulator, it's for X-sim. And it doesn't actually give you force feedback, it only activates a set of vibrators when there is traction loss.

    If you want to make diy force feedback, I suggest you google 'MMOs force feedback'.
    Some guy already used it to make force feedback with a DC motor:
    • Like Like x 1
    • Informative Informative x 1
    • Useful Useful x 1
  9. mirxtrem

    mirxtrem mirxtrem.apps

    Joined:
    Apr 22, 2016
    Messages:
    17
    Occupation:
    Electrical engineering student
    Location:
    Colombia
    Balance:
    273Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino
    I think that it can get with a medium dc motor, and some gears. i have been testing some codes.
  10. Dini200

    Dini200

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    hi @sikjar , can you show the settings for x - sim ?
    to build what should I buy? I have arduino uno