I've written the following demo code. It compiles for me on an Uno but, of course I can't run it.
The code just tests how long it takes to move the motor 10 steps followed by a single read of the scales. The steps happen at intervals of 10 millisecs. As far as I can see that should give enough time for the scale to be ready so the scale.read() should return a value almost instantly. My plan is to prove (or disprove) this assumption by running the tests with the scale.read() line commented out and then with it active. If my assumption is correct there will be very little difference in the two sets of timings.
If there is a signficant difference in the timings perhaps you would increase the interval to 20 msecs and try again. If that solves the problem find the smallest interval that works.
Note that I added the line #include "HX711.h" because I didn't save the HX711 stuff into my libraries directory. You can delete that line.
I hope this brings you forward a little bit.
...R
// this is just to test the understanding of using the HX711
#include "HX711.h"
#include <HX711.h>
#include <AccelStepper.h>
// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0); // 24 bit load cell amplifier
unsigned long startMillis;
unsigned long endMillis;
unsigned long currMillis;
unsigned long prevMillis;
unsigned long intervalMillis = 10;
byte maxTests = 5;
byte curTest = 1;
byte maxSteps = 10;
byte curStep = 1;
long scaleData = 0;
byte ledPin = 13; // onboard led
void setup() {
Serial.begin(9600);
Serial.println("Starting DemoCode1.ino");
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
prevMillis = millis();
}
void loop() {
if (curTest > maxTests) {
return;
}
startMillis = millis();
curStep = 0;
testTiming();
endMillis = millis();
Serial.print("Test ");
Serial.print(curTest);
Serial.print(" Time ");
Serial.println(endMillis - startMillis);
curTest ++;
}
void testTiming() {
while (curStep < maxSteps) { // will loop through the steps at the speed set by intervalMillis
currMillis = millis();
if (currMillis - prevMillis >= intervalMillis) {
stepMotor();
prevMillis += intervalMillis;
curStep ++;
}
}
// now the Scale should be ready for reading
scaleData = scale.read();
}
void stepMotor() {
// something visible as an alternative to actually doing motor code
digitalWrite(ledPin, ! digitalRead(ledPin));
}
Edited code to correct an error in the placement of currMillis = millis(); ...R