bug with a function

What serial output do you get?

I'd suggest that you print the value (jauge1) immediately after you read it from the scale too.

I did that but when I run the program and go to the monitor it writes until Serial.println("jauge1"); and after that nothing happens

#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);  
  Serial.println("HX711 scale demo");
  scale.begin(3, 2);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  md.init();
  md.calibrateCurrentOffsets();
  Serial.println("Readings:");

  
}


void loop() {
    Serial.println("jauge1");
    float jauge1 = (scale.get_units()); //lecture de la valeur du capteur
    //mesure();
    Serial.print(jauge1);
    Serial.println("jauge1");
    jauge1 = jauge1 / 10; 
    i=(jauge1 *400)/2.5; 
    Serial.print(i);
    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
  
//}

Sounds like reading the scale hangs. Do you have examples that came with the library to try?

I also wonder what pins your motor shield uses. Perhaps there's a conflict.

I tested the examples for the engine and for reading the sensor well and they work perfectly.
for my shield it is a:

I plug it on the arduino pins. and for the sensor I use a card:

I connect my sensor to port D2 on a digital ports

I see very little difference in the code of #14 which "works" and the code of EDIT: #19 [was incorrectly#18] which fails except for the change of a delay() for a Serial.print.

md.calibrateCurrentOffsets();
  delay(10);
md.calibrateCurrentOffsets();
  Serial.println("Readings:");

In the working code of #14, was the motor shield connected?

yes the difference is normal i made express but I tested in both cases and absolutely nothing changes.
and yes everything is well connected to the right port.

yes the difference is normal i made express but I tested in both cases and absolutely nothing changes.

I don’t quite understand what you are saying. Can you please try again with some different words.

Is is true that code #14 prints a value for jauge1 and code EDIT: #19 [incorrectly noted as #18] hangs, and the shield was connected in both cases?

forget the latest version of code and take the 21.when i test this version everything works correctly the print "gauge1" (Serial.println("jauge1"):wink: works but after nothing happens as if the code that was after this line did not exist.
I think that the line after which is the line of reading the sensor poses a problem but I have no idea of why and how I could make my program otherwise to try not to have no problem.that's why I created this post

and I tried the sensor reading program alone and it works very well and when I put the program # 21 nothing works yet the connections are identical.

Drop the motor shield library and try your code again.

Don't spend money on new stuff as long as You have not identified the source of the problem. You might experience the same problem again.

I am wondering if your motor shield is causing a problem. Try the examples for the sensor with it attached - I think you may have already done so. If that's ok, try your existing code but delete the include directive for the library code and comment out anything that needed it. Can you now read the scale?

just BTW.

 i=(jauge1 *400)/2.5;

Probably doesn’t return what you expected, also can you copy & paste the memory stats after successful compilation…
thanks

hello today I tried to see what caused the bug in the motor shield library .so I noticed that the line “md.calibrateCurrentOffsets ();” caused a bug. So I deleted it in the engine program only to start and everything worked normally so I concluded I could remove it from my program.
Another line poses a problem is “md.enableM1Driver();” because when I put it only a value of the sensor is written. But on the other hand this line I cannot suppress it because without it the engine does not start.

when i have the “md.enableM1Driver();” line . after what is written nothing happens while without everything scrolling properly

console :
HX711 scale demo
Readings:
-0.00jauge1
0kgs

new program :

#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);  
  Serial.println("HX711 scale demo");
  scale.begin(3, 2);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  md.init();
  //md.calibrateCurrentOffsets();//bug
  Serial.println("Readings:");
}


void loop() {
    
    float jauge1 = (scale.get_units()); 
    jauge1 = jauge1 / 10; 
    Serial.print(jauge1);
    Serial.println("jauge1");
    i=((jauge1 *400)/2.5); 
    Serial.print(i);
    Serial.println("kgs");
    
    md.enableM1Driver();
    md.setM1Speed(i); 
    
}

and everything worked normally so I concluded I could remove it from my program.

Excellent. Thanks for telling us.
We all have different expectations.

I noticed that the line "md.calibrateCurrentOffsets ();" caused a bug. So I deleted it in the engine program only to start and everything worked normally so I concluded I could remove it from my program.

Very strange.

The code which you claimed to worked properly and which was posted in Reply #14 contains that calibration. Have we all been on a wild goose chase?

#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 
}

you just asked me to post the full code.and sorry if it is misunderstood.anyway yesterday gave the idea of the online tester and I could find the errors so I sent you to find out if you have a solution.