bug with a function

hello i will explain my project to you so that you can understand my bug.the purpose of this program is to read the value of a force sensor.with this value I do a little calculation and send it to my engine.

the problem is that the line in my program that which binds the sensor value did bug and the rest of the program does not work anymore.
if you ever have an idea for a solution i am a taker.thank you very much

my programme

#include "DualG2HighPowerMotorShield.h"
#include "HX711.h"
#define calibration_factor -4630.0
#define DOUT 3
#define CLK 2
DualG2HighPowerMotorShield24v14 md;
HX711 scale(DOUT, CLK);
int i;

void stopIfFault()//fonction securité en cas de problème electrique
{
if (md.getM1Fault())
{
md.disableDrivers();
delay(1);
Serial.println("M1 fault");
while (1);
}
if (md.getM2Fault())
{
md.disableDrivers();
delay(1);
Serial.println("M2 fault");
while (1);
}
}

void setup() {

Serial.begin(115200);
scale.set_scale(calibration_factor);
scale.tare();
md.init();
md.calibrateCurrentOffsets();
delay(10);

}

void loop() {

float jauge1 = (scale.get_units()); //lecture de la valeur du capteur
jauge1 = jauge1 / 10;//calcul
i=(jauge1 *400)/2.5;//calcul puis mise dans une variable pour injecter dans le moteur

md.enableDrivers();
delay(1);
md.setM1Speed(i);//ligne pour faire varier la vitesse du moteur
stopIfFault();// securité

}

What does “did bug” mean?

Please remember to use code tags when posting code

If You attach code according to given advice like "How to use this forum" You will use "code tags", up to the left in this window. That makes it much easier for helpers using tablets, smartphones etc. to read the code and You will get better help.

Having a brief look I don't see any "bug line".

sorry for my mistake.normally if i understood correctly i put the code in the right form.
the problem is if i put the line reading the sensor value nothing works and if I remove this line and enter the value of jaugel by hand it works normally.so i wonder why it doesn't work.
for information I tested the sensor program and everything works normally

#include "DualG2HighPowerMotorShield.h"
#include "HX711.h"
#define calibration_factor -4630.0 
#define DOUT  3
#define CLK  2
DualG2HighPowerMotorShield24v14 md;
HX711 scale(DOUT, CLK);
int i;


void stopIfFault()//fonction securité en cas de problème electrique
{
  if (md.getM1Fault())
  {
    md.disableDrivers();
    delay(1);
    Serial.println("M1 fault");
    while (1);
  }
  if (md.getM2Fault())
  {
    md.disableDrivers();
  delay(1);
    Serial.println("M2 fault");
    while (1);
  }
}


void setup() {

  Serial.begin(9600);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  md.init();
  md.calibrateCurrentOffsets();
  delay(10);
  
}


void loop() {
  
    float jauge1 = (scale.get_units()); //lecture de la valeur du capteur
    jauge1 = jauge1 / 10; //calcul
    i=(jauge1 *400)/2.5; //calcul puis mise dans une variable pour injecter dans le moteur 

  
    md.enableDrivers();
    delay(1);  
    md.setM1Speed(i); //ligne pour faire varier la vitesse du moteur 
    stopIfFault(); // securité 
     
   
}

You could drop the use of "DualG2HighPowerMotorShield" code parts and make sure that the reading of the HX711 works well.
It's a too usual mistake to put all ingreidients into the pot and try running. Verify each subsystem/part alone and make sure You're comfortable with it. Then add the pieces together.

the HX711 code works well.I tested the two programs separately and it works properly .so the problem does not come from the two separate programs but of the assembly of the programs yet I did put all the pieces of code

I take my hat off. Well done testing the parts one by one. I'm not familiar with all parts but I know that sometimes different libraries collides with each other, using the same pin, or timer in different ways. Hopefully a more wide knowing helper steps in.

OK thank you anyway for the time you took for me.

Wait a little. Some parts of the globe is at midnight now and those helpers hopefully are at sleep.

Please answer the question in reply #1. We don't understand the problem.

Explain what you expect to happen, and what happens instead.

Hint: put in Serial.print() statements to see if variables have values that make sense.

See this code from the library example.

#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

HX711 scale;

void setup() {
  Serial.begin(57600);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() {

  if (scale.is_ready()) {
    long reading = scale.read();
    Serial.print("HX711 reading: ");
    Serial.println(reading);
  } else {
    Serial.println("HX711 not found.");
  }

  delay(1000);
  
}

I do not see the scale.begin( ) in your code.

the problem is that the value read by the sensor is not transmitted after the program to do the calculations.

float jauge1 = (scale.get_units());

the goal of the program is to continuously read the value of the sensor and use this value to calculate and vary the speed of my motor.but when I run my program nothing happens because in my opinion reading the value prevents any other action.

Do you call “scale.begin()” in setup()?

the HX711 code works well

Please post the complete code which successfully uses

float jauge1 = (scale.get_units());

cattledog:
Please post the complete code which successfully uses

float jauge1 = (scale.get_units());
#include "DualG2HighPowerMotorShield.h"
#include "HX711.h"
#define calibration_factor -4630.0 
#define DOUT  3
#define CLK  2
DualG2HighPowerMotorShield24v14 md;
HX711 scale(DOUT, CLK);
int i;
float jauge1;



void setup() {

  Serial.begin(115200);  
  scale.begin(3, 2);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  md.init();
  md.calibrateCurrentOffsets();
  delay(10);
  
}


void loop() {

    float jauge1 = (scale.get_units()); //lecture de la valeur du capteur

    jauge1 = jauge1 / 10; //calcul
    Serial.println("jauge1");
    i=(jauge1 *400)/2.5; //calcul puis mise dans une variable pour injecter dans le moteur 
    Serial.print(i);
    Serial.print(" Kgs"); 
    Serial.println();
  
    md.enableDrivers();
    delay(1);  
    md.setM1Speed(i); //ligne pour faire varier la vitesse du moteur  
}
scale.begin(3, 2);

The need for this code was pointed out in replys #10 and #12. It does not appear in the code which does not run properly.

TheMemberFormerlyKnownAsAWOL:
Do you call "scale.begin()" in setup()?

I added what you told me but it doesn't change anything I always have the same problem

Post the new code, using code tags, in which you added scale.begin(), and use Serial.print() to report the output of scale.get_units().

:)My problem is that I sometimes write functions that contain a bug, but your question title suggests that you work the other way around... ?!

#include "DualG2HighPowerMotorShield.h"
#include "HX711.h"
#define calibration_factor -4630.0 
#define DOUT  3
#define CLK  2
DualG2HighPowerMotorShield24v14 md;
HX711 scale(DOUT, CLK);
int i;
float jauge1;



void setup() {

  Serial.begin(115200);  
  scale.begin(3, 2);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  md.init();
  md.calibrateCurrentOffsets();
  delay(10);
  
}


void loop() {

    float jauge1 = (scale.get_units()); //lecture de la valeur du capteur
    //mesure();
    jauge1 = jauge1 / 10; //calcul
    Serial.println("jauge1");
    i=(jauge1 *400)/2.5; //calcul puis mise dans une variable pour injecter dans le moteur 
    Serial.print(i);
    Serial.print(" Kgs"); 
    Serial.println();
  
    md.enableDrivers();
    delay(1);  
    md.setM1Speed(i); //ligne pour faire varier la vitesse du moteur  
}

//void mesure(){
   //float jauge1 = scale.get_units(); //lecture de la valeur du capteur
  
//}