I have a stepper motor attached to a gearbox so getting the stepper up to full speed is important. The system is working almost like a clamp. I am in need of a way to move the stepper motor fast. The problem I’m having is I need the stepper to stop at a certain pre-load (5 lbs). In order to do this I have also included the hx711 library that reads the load cell. Currently the stepper is going very slow and just clicking maybe one step a second. At the moment I’m using accelstepper and hx711 libraries.
Current code:
#include "AccelStepper.h"
#include "HX711.h"
AccelStepper stepperY(1, 2, 3); // 1 = Dedicated Driver Board, 2 = pinStep, 3 = pinDirection
#define slot_sensor 9
long TravelY; // Used to store the Y value entered in the Serial Monitor
int move_finished=1; // Used to check if move is completed
long initial_homing=-1; // Used to Home Stepper at startup
long val = 0;
float count = 0;
void setup() {
Serial.begin(9600); // Serial monitor with speed of 9600 Bauds
pinMode(slot_sensor, INPUT_PULLUP);
delay(10); // 10ms Delay
}
void loop() {
HX711 cell(5,4);
Serial.println("Preloading");
delay(1000);
// stepperY.setCurrentPosition(0); // Set the current position as zero for now
stepperY.setMaxSpeed(3000.0); //
stepperY.setAcceleration(1000.0); //
while (cell.read()<-25000) { // load cell reads -25000 at 5 lbs
stepperY.moveTo(initial_homing);
initial_homing--;
stepperY.run();
}
Serial.println(cell.read());
}
Now if I don’t read the cell reading it works at the perfect speed, but then I have no way to stop the stepper at the desired preload.
example:
#include "AccelStepper.h"
#include "HX711.h"
AccelStepper stepperY(1, 2, 3); // 1 = Dedicated Driver Board, 2 = pinStep, 3 = pinDirection
#define slot_sensor 9
long TravelY; // Used to store the Y value entered in the Serial Monitor
int move_finished=1; // Used to check if move is completed
long initial_homing=-1; // Used to Home Stepper at startup
long val = 0;
float count = 0;
void setup() {
Serial.begin(9600); // Serial monitor with speed of 9600 Bauds
pinMode(slot_sensor, INPUT_PULLUP);
delay(10); // 10ms Delay
}
void loop() {
HX711 cell(5,4);
Serial.println("Preloading");
delay(1000);
// stepperY.setCurrentPosition(0); // Set the current position as zero for now
stepperY.setMaxSpeed(3000.0); //
stepperY.setAcceleration(1000.0); //
while (-26000<-25000) { // load cell reads -25000 at 5 lbs
stepperY.moveTo(initial_homing);
initial_homing--;
stepperY.run();
}
Serial.println(cell.read());
}
Open to any and all suggestion on how I can accomplish my goal of getting the stepper to spin faster and stop when the load cell reads the correct preload. Any help is appreciated.