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

Need help with load cell brake

Discussion in 'DIY Motion Simulator Building Q&A / FAQ' started by butternutz, Apr 12, 2022.

  1. butternutz

    butternutz New Member

    Joined:
    Dec 19, 2021
    Messages:
    2
    Balance:
    16Coins
    Ratings:
    +2 / 0 / -0
    I'm trying to build a racing sim. I have two pots--one for steering and one for accelerator. I'm using a load cell for the brake. The load cell is using a HX711 and all this is wired to an Arduino Leonardo. Here is the program for the Arduino.


    Code:
    // https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-2.0
    
    #include <Joystick.h>
    #include <Q2HX711.h>
    Q2HX711 hx711(A4, A5);
    
    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 1, 0,
                       false, false, false,  // axis x, y, z
                       false, false, false,  // rotate rx, ry, rx,
                       false, false,         // rudder, throttle,
                       true, true, true);    // accel, brake, steering);
    
    const int button_pin = 2;
    int button_value = 0;
    
    int steeringPin = A1;
    int gasPin = A0;
    int steeringValue = 0;
    int gasValue = 0;
    
    int brakeValue = 0;
    
    
    void setup() {
      Serial.begin(9600);
      Joystick.begin();
    
      pinMode(button_pin, INPUT_PULLUP);
    }
    
    void loop() {
    
      steeringValue = analogRead(steeringPin);
      gasValue = analogRead(gasPin) * -1 + 850;
      brakeValue = hx711.read() / 1000;
    
      Serial.write("Brake is ");
      Serial.println(brakeValue);
    //  Serial.write("Gas is ");
    //  Serial.println(gasValue);
    //  Serial.write("Steering is ");
    //  Serial.println(steeringValue);
    
      //Controller assignments
      Joystick.setBrake(brakeValue);
      Joystick.setSteering(steeringValue);
      Joystick.setAccelerator(gasValue);
    
      button_value = !digitalRead(button_pin);
      Joystick.setButton(0, button_value);
    
      delay(200);
    }
    Now here is what I don't understand. The gas and steering are fine, but I have an issue with the brake. The brakeValue will print to the serial monitor but it will not show up in Windows game controller settings. To be more clear I go to "Devices and printers" and then choose the Arduino. I open 'game controller settings' and try to calibrate it. When I get to the brake callibration part, if I check 'show raw data' there is none. But I can have the Arduino software open at the same time so I can view the monitor or plotter and it will show that brakeValue is changing.

    I'm pretty lost. Any help at all getting this working will be appreciated.
  2. Erik Middeldorp

    Erik Middeldorp Member

    Joined:
    Sep 15, 2018
    Messages:
    50
    Occupation:
    sheet metal worker
    Location:
    Auckland, New Zealand
    Balance:
    609Coins
    Ratings:
    +45 / 0 / -0
    • Informative Informative x 1
  3. butternutz

    butternutz New Member

    Joined:
    Dec 19, 2021
    Messages:
    2
    Balance:
    16Coins
    Ratings:
    +2 / 0 / -0

    Thanks. I went to look at the return type and stumbled across the problem. There's a setBrakeRange that defaults to a certain min and max. My readings were out of range. So I used that function and set the range to what I needed and BINGO!
    • Like Like x 1
    • Winner Winner x 1