I have an X27 168 wired directly to the Arduino pins 8,9,10 and 11. I tried various sample programs on this site but was getting strange behavior, so I have cut the program down to try and understand the interaction between the stepper library and the X27.
This is my code:
#include <Stepper.h>
#define STEPS 315
Stepper myStepper(STEPS, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
delay(1000);
Serial.write("Start\n");
delay(1000);
Serial.write("Set speed\n");
delay(1000);
myStepper.setSpeed(100);
delay(1000);
Serial.write("Step -600 first\n");
delay(1000);
myStepper.step(-600);
delay(1000);
Serial.write("Step -600 second\n");
delay(1000);
myStepper.step(-600);
}
void loop() {
delay(1000);
Serial.write("Step -600 loop\n");
myStepper.step(-600);
}
As I understand it, to zero the motor, it should be instructed to step with a value greater than the number of available steps so that it will hit the stop. My first attempt at this told the motor to step -600 but had unpredictable results with a different movement each time I pressed reset or uploaded the program, so I added the second step(-600) and it still behaved erratically, so I added the step(-600) in the loop and this video shows the behavior.
I am trying to create a gauge that fits in a 50mm housing with the pivot near the top, so I cant have the needle swinging so far round