Load Cell pedals slow response

Hello,

I'm actualy going to finish my project for sim racing pedals using load cell.

On the web I found some ispiration and I tried a lot of sketchs, but nothing working correctly for my porpose.

What I need is the the values from load cell will be sended to the pc in the faster way possible.

I already tried HX711multi library that is working but I found issue on spike when more then one load cell are connected.

So I used HX711 bogde using this code that is working (without spikes) but with low reactivity.

This is my code:

#include <HX711.h>
#define calibration_factor1 -640.0 // Do your calibration first.
#define calibration_factor2 -140.0 // Do your calibration first. 
#define DOUT1  3
#define CLK1  2
#define DOUT2  4
#define CLK2  2
#include <Joystick.h>

HX711 scale1;
HX711 scale2;
/*


For the true false flags, use this list. Its all in  Joystick.h 
    bool includeXAxis = true,
    bool includeYAxis = true,
    bool includeZAxis = true,
    bool includeRxAxis = true,
    bool includeRyAxis = true,
    bool includeRzAxis = true,
    bool includeRudder = true,
    bool includeThrottle = true,
    bool includeAccelerator = true,
    bool includeBrake = true,
    bool includeSteering = true);
  */

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


  
    
// Variable
//int throttle = A0;
// int brake = 2; / no need for this as we read directly from scale
//int clutch = A2;


// init joystick libary
void setup() {

  // Ranges are 1023 by default
  // Joystick.setBrakeRange(0, 1023); 
  //Joystick.setThrottleRange(0, 1023); 
  //Joystick.setZAxisRange(0, 255);
  
  Joystick.begin();
  Serial.begin(115200);
//  Serial.flush();

  

  scale1.begin(DOUT1, CLK1);
  scale1.set_scale(calibration_factor1); 
  scale1.tare();
  scale2.begin(DOUT2, CLK2);
  scale2.set_scale(calibration_factor2); 
  scale2.tare();
  
}

void loop() {

  Joystick.setThrottle(- scale2.get_units());
  delay(1);

  Joystick.setBrake(scale1.get_units());
  delay(1);
  
Serial.println ( scale1.get_units());
Serial.println (- scale2.get_units());

 
//  Joystick.setZAxis(analogRead(clutch));
 // delay(1);
}

Ah actually I'm using for the Brake 2 load cells connected to HX711 and one for Throttle load cell connected to other HX711 both are connected to arduino promicro pin 2 (CLK) pin 3 (brake) pin 4 (Throttle)

Waiting for some suggestion.

First suggestion: Learn to use the code tags! Some experts here won't even try to help you if you dont use them because it makes reading the code a royal pain in the...

If you are having responsiveness issues, why do you have delays in there in the first place? I would try taking them out and see if that helps.

Also, why are you calling .getunits so much? Why not call it once per scale, save it in a variable, and use the value of the variable instead of making repeating calls which may return different values anyway.

Hi

Tags done :stuck_out_tongue_winking_eye:.
Effective removing the delays the situation is better now. Thanks

Regarding get unit calls is due to the load cell is connected to throttle and brake pedal so I need to know every little values change.

Yesterday night after delays modification I noticed that both values, sometimes (couple times in 2 minute circa) I saw 0 or 100% of the value :man_shrugging:.
Should be caused by sharing of the clocks wiring?

Today I try to separate it..

If you have any suggestions will be appreciated :wink:

Hello again,

problem of spikes is solved by separeting the CLK, now each HX711 clock is connected to a different pin.

I also tried @JaBa modification putting .getunits outside the loop and putting in a variable, but this was not good , infact the reactivity was low then before.

Any other suggestion to speed up?

Thanks

Set your HX711 so it is taking 80 samples/second, not 10?

You misunderstood my suggestion. You can put the variable either outside of the loop (it is then global) or inside the loop as a static (the scope of the variable is only within the loop, but any assigned value is always available). However, getting the value from the sensor and assigning it to the variable is still done within the loop.

void loop() {
  int units1 = scale1.get_units();
  int units2 = - scale2.get_units();
  Joystick.setThrottle(units2);

  Joystick.setBrake(units1);
  
Serial.println (units1);
Serial.println (units2);
}

Looking at your code again, I'm not sure why I suggested it need be global or static. I may have confused that with the user I tried to help prior to you.

Yeah ! This is the way… I found on the web the possibilities to put hx711 to 80 sample per second..

Find out the solution thanks :+1:t2:

OK I tried and working well.

How can I measure the actual speed?

Thanks

Actual speed of what? If you want the HX711 samples per unit time, then write a program that records the time it takes to get some relatively large number of samples, say 10000 or so. Then divide the number of samples by that time. That will get you in the ballpark.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.