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 Now a Download Plan!
  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. 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 code for force feedback

Discussion in 'DIY Motion Simulator Building Q&A / FAQ' started by sthevan pinter kairys, Jun 5, 2021.

  1. sthevan pinter kairys

    sthevan pinter kairys New Member

    Joined:
    Jun 5, 2021
    Messages:
    1
    Balance:
    8Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    Arduino
    hello i have the steering wheel: gt force lprc-10000

    The drive found on the logithech website does not start my engine. (Flywheel open and engine test done, it is working) 'It could be some faulty circuit'.

    I bought an arduino uno with the intention of starting the engine on it, to have force feedback.

    Could someone help me with the code.

    I found this one, but it uses 4 engines, my case will take advantage of the single engine on the flywheel.

    https://www.xsimulator.net/community/threads/arduino-haptic-force-feedback-assetto-corsa.7412/
    Code:
    // Em parte baseado no X-sim3dashboard v1 (usando a tela TM1638 e Arduino Nano v3) por TronicGr (Thanos) 4-26-2012
    // Compartilhado como domínio público
    
    
    void setup () {
    
    // Declara os pinos 3,5,6 e 11 como uma saída
          pinMode (3, SAÍDA);
          pinMode (5, SAÍDA);
          pinMode (6, SAÍDA); 
          pinMode (11, SAÍDA);
    // Criar objeto serial
        Serial.begin (9600);
    
    }
    
    byte SteeringxSpeed;
    byte SteeringxSpeed1;
    byte SteeringxSpeed2;
    byte SteeringxSpeed3;
    byte SteeringxSpeed4;
    byte SteeringxSpeed5;
    byte SteeringxSpeed6;
    
    void loop () {
    
    char bufferArray [20]; // mantém todos os dados seriais em um array
    
    int i;
    byte FrontSlip;
    int FrontSlipOut;
    byte RearSlip;
    int RearSlipOut;
    
    byte SideslipValue;
    int SideSlipMinusSxS;
    int Subviragem;
    int UndersteerOut;
    int Oversteer;
    int OversteerOut;
    
    
    
    
    
    if (Serial.available ()> = 12) {// se 12 bytes disponíveis no buffer Serial ...
          para (i = 0; i <12; i ++) {// para cada byte
          bufferArray [i] = Serial.read (); // colocar na matriz
    
     
         }
      }
    if (bufferArray [0] == 'A') {// se novos bytes foram recebidos
    
       FrontSlip = bufferArray [1]; 
        if (FrontSlip> 100) {
            FrontSlip = 100;
             }
       FrontSlipOut = map (FrontSlip, 0, 100, 40, 255); 
        analogWrite (3, FrontSlipOut);
    }
    
     
    if (bufferArray [2] == 'B') {// se novos bytes foram recebidos
    
       RearSlip = bufferArray [3];
       if (RearSlip> 100) {
            RearSlip = 100;
             }
       RearSlipOut = map (RearSlip, 0, 100, 40, 255);     
        analogWrite (5, RearSlipOut);
     
    }
    
     
    if (bufferArray [4] == 'C') {// se novos bytes foram recebidos
    SteeringxSpeed5 = bufferArray [5];
    
    SteeringxSpeed = SteeringxSpeed1;
    SteeringxSpeed1 = SteeringxSpeed2;
    SteeringxSpeed2 = SteeringxSpeed3;
    SteeringxSpeed3 = SteeringxSpeed4;
    SteeringxSpeed4 = SteeringxSpeed5;
    // Há um atraso entre a entrada da direção e a reação do carro. A rotina acima cancela esse atraso.
    
     
    }
    
    if (bufferArray [6] == 'D') {// se novos bytes foram recebidos
    SideslipValue = bufferArray [7];
    
    SideslipValue = SideslipValue / 2;
    SteeringxSpeed = SteeringxSpeed / 2;
    SideSlipMinusSxS = SideslipValue + SteeringxSpeed;
    
    
    
      // Se a derrapagem for menor que um determinado valor em comparação com a direção da direção, o carro está subvirando. Vibrador conectado ao PIN 6 será ativado.
    if (SideSlipMinusSxS> 131) {
          Subviragem = SideSlipMinusSxS - 131;
         if (Subviragem> 10) {
                Subviragem = 10;
                }
         SubviragemSaída = mapa (Subviragem, 0, 10, 40, 255);
    
        
        }
        if (SideSlipMinusSxS <132) {
            SubviragemSaída = 0;}
              
       analogWrite (6, UndersteerOut);
    
    
       // Se a derrapagem estiver acima de um certo valor em comparação com a direção da direção, o carro está sobrevirando. Vibrador conectado ao PIN 11 será ativado.
    
             if (SideSlipMinusSxS <126) {
          Oversteer = SideSlipMinusSxS * -1 + 126;
           if (Oversteer> 10) {
            Sobrevirar = 10;
             }
         OversteerOut = map (Oversteer, 0, 10, 40, 255);
        }
    
    
        if (SideSlipMinusSxS> 125) {
            OversteerOut = 0;
             } 
              
       analogWrite (11, OversteerOut);
      }
    }
    
    P_20200115_092210.jpg IMG_20210401_180329468.jpg IMG_20210528_143915606.jpg
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0