I am attempting to retrofit a X27.168 stepper motor within an old mechanical speedometer for an engine swap that will now have a VSS.
Currently I am using the AccelStepper Library, and have not been satisfied with what I have been able to accomplish.
First question is there a way around defining the current position ? Any time I upload code it effectively starts from what ever position the motor is in and that is no longer 0 mph.
How do I determine appropriate Speed and Acceleration? The stepper library had the motor running smoother, so I do not believe I have these calibrated accurately.
Once I have these two items addressed, what function would be best for the VSS input ? The moveTo just moves a set number of steps from its current position.
#include <AccelStepper.h>
// Define the stepper motor and the pins that is connected to
AccelStepper stepper1(8, 4, 5, 6, 7); // (Typeof driver: with 2 pins, STEP, DIR)
void setup() {
stepper1.setMaxSpeed(1500); // Set maximum speed value for the stepper
stepper1.setAcceleration(1500); // Set acceleration value for the stepper
stepper1.setCurrentPosition(0); // Set the current position to 0 steps
}
void loop() {
delay(500);
stepper1.moveTo(-100); // Set desired move: 800 steps (in quater-step resolution that's one rotation)
stepper1.runToPosition(); // Moves the motor to target position w/ acceleration/ deceleration and it blocks until is in position
// Move back to position 0, using run() which is non-blocking - both motors will move at the same time
stepper1.moveTo(0);
while (stepper1.currentPosition() != 0 ) {
stepper1.run(); // Move or step the motor implementing accelerations and decelerations to achieve the target position. Non-blocking function
//
//
}
}