Hello
I am trying to use a Switec X27.160 stepper to drive a car speedo with an Arduino Nano.
I am getting some very strange behaviour, I have read as many posts as I can but can't see why this wont work.
The needle will need to sweep clockwise as the speed increase. I have started with the basic example from the switec library but set the steps to 940 to match the gauge.
The first requirement is to drive the needle anticlockwise until it hits the stop so that I know where 0 is, to achieve this setPosition (-940) is used and this works, however if I press the reset button on the Arduino, the needle swings clockwise to the other end of the scale, if I press it again, it moves back to 0. Very strange.
This is so basic that I must be doing something wrong, but cannot see it.
The code is
#include <SwitecX25.h>
#define STEPS 940
// For motors connected to digital pins 4,5,6,7
SwitecX25 motor1(STEPS,4,5,6,7);
void setup(void) {
Serial.begin(9600);
Serial.println("SwitcX27Test");
delay(500);
motor1.zero();
delay(500);
motor1.zero();
Serial.println("zero");
delay(1000);
// run the motor against the stops
Serial.println("-940");
motor1.setPosition(-940);
}
void loop(void) {
static int nextPos = 0;
motor1.update();
if (Serial.available()) {
char c = Serial.read();
if (c==10 || c==13) {
Serial.print("Set to ");
Serial.println(nextPos);
motor1.setPosition(nextPos);
nextPos = 0;
} else if (c>='0' && c<='9') {
nextPos = 10*nextPos + (c-'0');
}
}
}
When the script runs, there is a buzz for each zero and then the needle moved half way around the guage with setPosition(480), which is what I would expect, however if I now enter