Switec X27.168 inconsistent needle movements

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

You need to have a home point switch to calibrate to, find the zero point. As You tell, pressing reset makes the position lost.

From what I have read, there is no need for the switch as you drive the motor against the stop and that becomes 0. I don’t understand why the motor moves clockwise when the reset button is pressed as the command is still setPosition(-940)

Read where? Please quot it.
Running a stepper into a mechanical stop can be used but usually an end switch is used to avoid the mechanical stress for the mechanics.
What does the reset button reset? The controller? The driver? Both?
What is the logic in the driver set up to do, if it receives a reset?

This is from the Switec X25 library example


 // run both motors against stops to re-zero
  motor1.zero();   // this is a slow, blocking operation
  motor2.zero();  
  motor1.setPosition(427);
  motor2.setPosition(427);

I don’t know what the reset button does, but the script is run again from the start

As the driver has no reset input only the controller board resets.
Then code execution starts from the beginnig.
Note the current situation, press reset and put the fínger into the code and see what takes place.

Hi,

These steppers are air cored, so pushing them against a mechanical stop does not cause damage, they don't have the torque.

All car Switecs do a home sweep each time you turn the ignition switch on.
Some, to look sexy, do a clockwise then anti-clockwise sweep in unison of all dials.

Tom.... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.