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

Question DIY Pedals arduino leonardo + load cell.

Discussion in 'DIY peripherals' started by Alecont, Mar 17, 2021.

  1. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0
    Hello good afternoon, i from Argentina, first of all apologies for my English.
    I make this post looking for help to carry out my project, I have an Arduino leonardo + HX711 + load cell 50kg board. My intentions to acquire other lower kg load cells for accelerator and clutch. But I am not sure how to perform its operation, programming, etc. I would really appreciate it very much if through this post you can guide me a little, I have all the materials to start its construction.
    Again thank you very much and apologies for my English.
  2. yellofella

    yellofella Member

    Joined:
    Aug 8, 2011
    Messages:
    94
    Occupation:
    builder
    Location:
    UK
    Balance:
    743Coins
    Ratings:
    +84 / 0 / -0
    My Motion Simulator:
    3DOF, SimforceGT
    Hi buddy and welcome to the community.
    If you are looking at building your own pedal set then there are much better ways to do it than use an Arduino Leonardo. The problems you are going to have are resolution at only 8bit and writing the Arduino code. You may find an example in the FAQ's on this site if you really want to go with the Leonardo but i personally think you would do better with this
    BU0836-LC Load Cell Joystick Controller [BU0836-LC] - 30.00GBP : Leo Bodnar, Simulator Electronics
    This board is designed to be used in sim pedal setups. It has a dedicated load cell input for the brake pedal and 7 potentiometer inputs although you only need 2 for the accelerator and clutch pedals as these do NOT use load cells. It is 12bit on all inputs and as a bonus allows you to add 32 buttons or 16 rotary encoders or a mix of each if you like for a button box and no need to write any Arduino code at all.
    It is the same controller that is on my simcraft high end pedals that cost me over £1000.
    Just connect your potentiometers and load cell, plug in the usb cable, open the di view software to setup and your done.
    hope this helps buddy.
    • Agree Agree x 1
  3. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0

    Thank you very much for your response, I went to Arduino because it is very difficult to find in Argentina another like Leo Bodnar, and importing at this time is not viable in my country. Because I'm looking for the best possible alternative to be able to do it with Arduino.
  4. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    "The problems you are going to have are resolution at only 8bit and writing the Arduino code."

    that is incorrect

    a standard arduino / avr board has 10 bit resolution on analogue read (0-1024 steps) the analogue write has 8 bit (255 steps)

    plenty of compatible boards have resolutions of 8195 steps and higher

    there is example code here - https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide/all


    an arduino leonardo or a pro micro can be configured to work as a joystick controller and it makes them very suitable
  5. yellofella

    yellofella Member

    Joined:
    Aug 8, 2011
    Messages:
    94
    Occupation:
    builder
    Location:
    UK
    Balance:
    743Coins
    Ratings:
    +84 / 0 / -0
    My Motion Simulator:
    3DOF, SimforceGT
    Hi guys. @Gadget999 you are correct the Arduino does have a 10bit ADC and not 8bit as i previously mentioned. However the greater point i was trying to make was that there is better hardware available than an Arduino to control pedals for sim racing at a low cost. I included the link to the Bodnar controller as most high end pedals use this interface board. My simcraft pedals that i purchased 5 years ago use it and if you bought the pedals today they still use it. I think they are probably the best pedal set that you can buy for sim racing but at a high cost. Here is a link to them
    www.simcraft.com/sim-racing-pedals-racing-simulator-pedals-tilton-three-pedal-set/
    I was just trying to point a new member to the best hardware for his needs and that you can buy the controller separately without the massive cost. To try to avoid him getting bogged down in code or wasting money on hardware only to find out later that there was a better way. All this is just advice as @Alecont mentioned in his post that he has the hardware and is ready to build so the arduino route it is for now at least.
  6. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0
    @Gadget999 @yellofella Thank you very much for your answers, for the moment I will experiment with Arduino, I will also consider for the future leo Bodnar board.
  7. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0
    @Gadget999 Hi. Get the load cell and potentiometers to work. But in separate sketches, I can't make them work in the same sketch, could you help me ?? I would appreciate it as it is the last thing I need to finish my set of 3 pedals.
  8. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    Here are 2 sketches I put together for Alecont

    it will allow you to use potentiometers and a loadcell brake together

    noorbeast - might be worth saving the code for future reference


    ----------------------------------------------------------




    #include <Joystick.h>
    #include <HX711.h>
    #define calibration_factor 28000 // Change this value to give accurate reading with your known mass.
    #define DOUT 1
    #define CLK 0


    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
    JOYSTICK_TYPE_MULTI_AXIS, 4, 3,
    false, false, true, false, false, false,
    false, true, true, true, false);

    HX711 scale;

    int brake = 0;
    int lastBrakeValue = 0;
    int RotzAxis_ = 0;
    int Throttle_ = 0;

    const bool initAutoSendState = true;


    void setup() {
    // put your setup code here, to run once:
    Joystick.setBrakeRange(0, 1023);


    Joystick.begin();
    Serial.begin(38400);

    scale.begin(DOUT, CLK);
    scale.set_scale(calibration_factor);
    scale.tare();
    }

    void loop() {
    // put your main code here, to run repeatedly:
    Serial.println (brake);
    brake = scale.get_units(); // if the value is inverted put a - sign in front like -scale.get

    if (brake < 0 or brake < 1) {
    brake = 0;
    }

    if (lastBrakeValue != brake) {
    Joystick.setBrake(brake);
    lastBrakeValue = brake;
    }


    RotzAxis_ = analogRead(A1);
    RotzAxis_ = map(RotzAxis_,1023,0,255,0);
    Joystick.setRzAxis(RotzAxis_);

    Throttle_ = analogRead(A0);
    Throttle_ = map(Throttle_,1023,0,255,0);
    Joystick.setThrottle(Throttle_);

    Serial.println(Throttle_);


    }
    • Like Like x 2
  9. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0
    Thank you very much for helping me put my 2 codes together in the same sketch.

    And whoever needs to use Arduino recommend the tutorials GP Race Simulation on youtube, its sketches and so on. It can be used for anyone who can't access Leo Bodnar boards as in my case.
  10. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,520
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,950Coins
    Ratings:
    +10,770 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Thanks for sharing your work, added o the FAQs with credit to yourself: https://www.xsimulator.net/community/faq/potentiomenter-and-load-cell-code.388/
    • Winner Winner x 1
  11. Alecont

    Alecont New Member

    Joined:
    Mar 17, 2021
    Messages:
    17
    Balance:
    139Coins
    Ratings:
    +1 / 0 / -0
    • Agree Agree x 1
  12. hiihoo

    hiihoo New Member

    Joined:
    Apr 4, 2021
    Messages:
    3
    Balance:
    10Coins
    Ratings:
    +2 / 0 / -0
    Sorry to bother, which of millions of joystick-librarys does this use?
    And, I suppose one can add another loadcell also, for handbrake?

    HX711 has two channels, not yet digged deeper, every example just uses one. :)
  13. hiihoo

    hiihoo New Member

    Joined:
    Apr 4, 2021
    Messages:
    3
    Balance:
    10Coins
    Ratings:
    +2 / 0 / -0
    Could not edit my recent post, so just noticed that hx711 librarys are also millions... :)
    Everybody wants to invent wheel again, someday, given enough time, we will have square wheels again...
  14. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    download one and try - if it doesn't compile download another
  15. hiihoo

    hiihoo New Member

    Joined:
    Apr 4, 2021
    Messages:
    3
    Balance:
    10Coins
    Ratings:
    +2 / 0 / -0
    :)

    So I did, now works. If I didn't be so adhd I might be able to tell which one they were, but..
    The first ofcourse don't work, so try another..

    Also, if somebody else is doing this and installing hardware to diffucult to get place, check the 10hz/80hz jumpers first. :)
    • Agree Agree x 2
  16. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    350
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,544Coins
    Ratings:
    +206 / 2 / -0
    My Motion Simulator:
    2DOF
    Guys, I struggle to use this code. It looks like I can't convert the long scale.get_units() to int.
    I got the following values :
    CurrentAcceleratorState is : -32518. RawReadAccelerator is calibrated : 214531. Scale.read() is : 214552
    CurrentAcceleratorState is : -32518. RawReadAccelerator is calibrated : 214542. Scale.read() is : 214563
    CurrentAcceleratorState is : -32518. RawReadAccelerator is calibrated : 214551. Scale.read() is : 214519
    CurrentAcceleratorState is : -32518. RawReadAccelerator is calibrated : 214521. Scale.read() is : 214556
    CurrentAcceleratorState is : -32517. RawReadAccelerator is calibrated : 214582. Scale.read() is : 214684
    CurrentAcceleratorState is : 32513. RawReadAccelerator is calibrated : 250713. Scale.read() is : 468289
    CurrentAcceleratorState is : 32395. RawReadAccelerator is calibrated : 637116. Scale.read() is : 826500
    CurrentAcceleratorState is : 32254. RawReadAccelerator is calibrated : 956615. Scale.read() is : 1021243
    CurrentAcceleratorState is : 32718. RawReadAccelerator is calibrated : 1245666. Scale.read() is : 1740287
    CurrentAcceleratorState is : -32391. RawReadAccelerator is calibrated : 2384590. Scale.read() is : 2976566
    CurrentAcceleratorState is : 32738. RawReadAccelerator is calibrated : 3671695. Scale.read() is : 4551800
    CurrentAcceleratorState is : 32497. RawReadAccelerator is calibrated : 5427189. Scale.read() is : 5980023
    CurrentAcceleratorState is : 32623. RawReadAccelerator is calibrated : 5762228. Scale.read() is : 4279086

    and the code :

    Code:
    #include <HX711.h>//https://github.com/bogde/HX711
    #include "Joystick.h"
    
    #define DEBUG   //allow to tune min and max
    
    #define USE_ACCEL
    
    Joystick_ Joystick(0x04, 0x04, 0, 0, true, true, false,  true, false, false, false, false, true, true, false);
                      
    
    long rawReadAccelerator;
    int lastAcceleratorState ;
    bool sendDebug = false;
    int unsigned long lastDebug = 0;
    int DebugRefreshRate = 250;
    
    const int doutPin = 12;
    const int sckPin = 13;
    
    HX711 scale ;
    
    void setup() {
    
     //Init Serial USB
     delay(2000);
     //pinMode(ledPin,OUTPUT);
     Serial.begin(9600);
    Joystick.setXAxisRange(-32768, 32767);
     scale.begin(doutPin, sckPin);
     }
     
    void loop() {
        #if defined(DEBUG)
      if (millis() - lastDebug > DebugRefreshRate) {
        sendDebug = true;
        lastDebug = millis();
      }
    #endif
    #ifdef USE_ACCEL
    rawReadAccelerator = scale.read();
    int currentAcceleratorState = (int) map(rawReadAccelerator,200000,4000000,-32768,32767);
    
      if (currentAcceleratorState != lastAcceleratorState)
      {
        Joystick.setXAxis(currentAcceleratorState);
        lastAcceleratorState = currentAcceleratorState;
      }
    #ifdef DEBUG
    Serial.print("CurrentAcceleratorState is :  ");
    Serial.print(currentAcceleratorState);
    Serial.print(". RawReadAccelerator is calibrated :  ");
    Serial.print(rawReadAccelerator);
    Serial.print(". Scale.read() is : ");
    Serial.println(scale.get_units());
      }
    #endif
    #endif
  17. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    try it now

    #include <HX711.h>//https://github.com/bogde/HX711
    #include "Joystick.h"

    #define DEBUG //allow to tune min and max

    #define USE_ACCEL

    Joystick_ Joystick(0x04, 0x04, 0, 0, true, true, false, true, false, false, false, false, true, true, false);


    long rawReadAccelerator;
    int lastAcceleratorState ;
    bool sendDebug = false;
    int unsigned long lastDebug = 0;
    int DebugRefreshRate = 250;

    const int doutPin = 12;
    const int sckPin = 13;

    HX711 scale ;

    void setup() {

    //Init Serial USB
    delay(2000);
    //pinMode(ledPin,OUTPUT);
    Serial.begin(9600);
    Joystick.setXAxisRange(-32768, 32767);
    scale.begin(doutPin, sckPin);
    }

    void loop() {
    #if defined(DEBUG)
    if (millis() - lastDebug > DebugRefreshRate) {
    sendDebug = true;
    lastDebug = millis();
    }
    #endif
    #ifdef USE_ACCEL
    rawReadAccelerator = scale.read();
    int currentAcceleratorState = map(rawReadAccelerator,200000,4000000,-32768,32767);

    if (currentAcceleratorState != lastAcceleratorState)
    {
    Joystick.setXAxis(currentAcceleratorState);
    lastAcceleratorState = currentAcceleratorState;
    }
    #ifdef DEBUG
    Serial.print("CurrentAcceleratorState is : ");
    Serial.print(currentAcceleratorState);
    Serial.print(". RawReadAccelerator is calibrated : ");
    Serial.print(rawReadAccelerator);
    Serial.print(". Scale.read() is : ");
    Serial.println(scale.get_units());
    }
    #endif
    #endif
  18. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    350
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,544Coins
    Ratings:
    +206 / 2 / -0
    My Motion Simulator:
    2DOF
    @Gadget999 i just tried your code, but it works the same. What did you changed ?
  19. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    int currentAcceleratorState = (int) map(rawReadAccelerator,200000,4000000,-32768,32767);

    To

    int currentAcceleratorState = map(rawReadAccelerator,200000,4000000,-32768,32767);


    Does currentAcceleratorState need to be an integer ?
  20. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    Change that line to

    int currentAcceleratorState = map(rawReadAccelerator,200000,6000000,-32768,32767);