Running a stepper like a servo??

Is it possible to run a stepper motor like a servo? i.e., is it possible to run a stepper motor on two power lines (+12v and GND) and one PWM or analog signal? I am working on a dashboard for American Trucking Simulator, and the code is meant to be used with servo motors to move the needles on the dash. I am at a fork right now...do I look for a solution to run steppers like servos like stated above or do I just change the code to work with steppers and their drivers???? Any suggestions???

I have a topic under "project guidance" too if your interested.

No, a stepper can't be used like a servo, because the output shaft has no memory of the starting position.

You need to "home" the stepper during startup, either by using a limit switch or running into an end stop, or use a shaft encoder to define absolute orientation.

Thank you for the quick response! Is there a driver board that does it or is it just plainly not possible?? Right now I'm trying to use A4988 step sticks and they have 3 wires that correlate to the Arduino, DIRECTION, STEP, and ENABLE.

I edited my response. Does that answer the second question?

Yes thank you. Is there any way you can help me with converting my code? I know the basics, but this is a little advanced for me yet and I would like to get this working. I just need help with the setup, after that I would be fine.

Is there any way you can help me with converting my code?

That would depend on your setup, which you have not described, and on the code, which you haven't posted.

Google "arduino stepper motor" for lots of tutorials and advice. Otherwise, please read the "How to use this forum" post for guidelines on getting informed advice.

#include <Servo.h>

const int SPEEDO_PIN      = A0;
const int RPM_PIN         = A1;
const int FUEL_PIN        = A5;
const int LEFT_INDICATOR  = A2;
const int RIGHT_INDICATOR = A3;
const int PARKING_BREAK   = A4;
const int FUEL_WARNING    = 12;


// defines servo names
Servo speedo;
Servo rpm;
Servo fuel;
Servo cruise;

#define PACKET_SYNC 0xFF
#define PACKET_VER  2

#define SERVO_DIR_NORMAL false
#define SERVO_DIR_INVERT true
int serial_byte;

void setup()
{
  Serial.begin(115200);
  
  speedo.attach(SPEEDO_PIN);
  speedo.write(180);
  rpm.attach(RPM_PIN);
  rpm.write(180);
  fuel.attach(FUEL_PIN);
  fuel.write(40);
  cruise.write(180);
  
  pinMode(LEFT_INDICATOR, OUTPUT);
  pinMode(RIGHT_INDICATOR, OUTPUT);
  pinMode(PARKING_BREAK, OUTPUT);
  pinMode(FUEL_WARNING, OUTPUT);


  //range-splitter LED's
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(26, OUTPUT);
  
  digitalWrite(LEFT_INDICATOR, 0);
  digitalWrite(RIGHT_INDICATOR, 0);
  digitalWrite(PARKING_BREAK, 0);
  digitalWrite(FUEL_WARNING, 0);
 
  
  delay(600);
  
  speedo.write(0);
  rpm.write(0);
  fuel.write(0);
  digitalWrite(LEFT_INDICATOR, 1);
  digitalWrite(RIGHT_INDICATOR, 1);
  digitalWrite(PARKING_BREAK, 1);
  digitalWrite(FUEL_WARNING, 1);

  digitalWrite(22, 1);
  digitalWrite(24, 1);
  digitalWrite(26, 1);
  
  delay(600);
  
  speedo.write(180);
  rpm.write(180);
  fuel.write(85);
  digitalWrite(LEFT_INDICATOR, 0);
  digitalWrite(RIGHT_INDICATOR, 0);
  digitalWrite(PARKING_BREAK, 0);
  digitalWrite(FUEL_WARNING, 0);
  digitalWrite(22, 0);
  digitalWrite(24, 0);
  digitalWrite(26, 0);

  delay(1000);
}

void read_serial_byte_set_servo(Servo& servo, bool invert)
{
  serial_byte = Serial.read();
  serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
  if (invert)
    servo.write(180 - serial_byte);
  else
    servo.write(serial_byte);
}

void read_serial_byte_set_servo_fuel(Servo& servo, bool invert)
{
  serial_byte = Serial.read();
  serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
  if (invert)
    servo.write(85 - serial_byte); //set lower than the tach and speedo to limit movement.
  else
    servo.write(serial_byte);
}


void skip_serial_byte()
{
  (void)Serial.read();
}

void digitalWriteFromBit(int port, int value, int shift)
{
  digitalWrite(port, (value >> shift) & 0x01);
}

void loop()
{
  if (Serial.available() < 16)
    return;
  
  serial_byte = Serial.read();
  if (serial_byte != PACKET_SYNC)
    return;
    
  serial_byte = Serial.read();
  if (serial_byte != PACKET_VER)
  {
//    lcd.clear();
 //   lcd.print("PROTOCOL VERSION ERROR");
    return;
  }
  
  read_serial_byte_set_servo(speedo, SERVO_DIR_INVERT); // Speed  
  read_serial_byte_set_servo(rpm, SERVO_DIR_INVERT); // RPM
  
  skip_serial_byte(); // Brake air pressure
  skip_serial_byte(); // Brake temperature
  read_serial_byte_set_servo_fuel(fuel, SERVO_DIR_INVERT); // Fuel ratio
  skip_serial_byte(); // Oil pressure
  skip_serial_byte(); // Oil temperature
  skip_serial_byte(); // Water temperature
  skip_serial_byte(); // Battery voltage  

  if (cruise.read() < 180)
  {

      }
  if (cruise.read() > 179)
      {
      }
  
  // Truck lights byte
  serial_byte = Serial.read();
  digitalWriteFromBit(LEFT_INDICATOR,  serial_byte, 5);  
  digitalWriteFromBit(RIGHT_INDICATOR, serial_byte, 4);

  
 // Warning lights bytes

  serial_byte = Serial.read();  
  digitalWriteFromBit(PARKING_BREAK, serial_byte, 7);
  digitalWriteFromBit(FUEL_WARNING, serial_byte, 3);  
 
  // Enabled flags
  serial_byte = Serial.read();
  
  // Text length
  int text_len = Serial.read();
  
// Followed by text
  if (0 < text_len && text_len < 127)
  {
    for (int i = 0; i < text_len; ++i)
    {
      
      while (Serial.available() == 0) // Wait for data if slow
      {
        delay(2);
      }
    }
  }
}

so here is what i have going on... i have a ford expedition dashboard that i picked up from a flea market. It has 6 I-believe-to-be air core stepper motors. I bought 6 Polulu A4988 step sticks to control them. The code that I have is meant to be used for servo motors to drive the needles of the dash, but instead of using servos, i would like to use the steppers that are already on the dash. I just need help with the coding now that i know it is not easily possible to control the stepper motors like a servo. This is my first time using stepper motors and stepper motor drivers, so I don't really know what I'm doing other than a little bit of research. I don't know how to change the code so that i can use the steppers in place of the servos without screwing everything up. I could attach some pictures if you would like. :slight_smile:

It has 6 I-believe-to-be air core stepper motors.

Unfortunately, a lot more information is required than that.

How many wires does each indicator have? What is the resistance between all wire pairs? Can you find a model number and a data sheet for the indicator?

I STRONGLY recommend that you start with a simpler project and learn how a stepper motor works, before jumping in to this. Adafruit has the materials and a tutorial for a simple automobile gauge step motor. Please study that carefully.

The resistance between motor pairs is 180 ohms. I read somewhere that I can just run them straight off the board, but I dont think that i have enough pins on the uno to support 6 motors with 4 wires each. I was already reading adafruit's automotive gauges page and while it had some good info, i still dont know what im doing with these.

If they are four wire (bipolar) steppers, any Arduino tutorial on driving bipolar step motors will serve as a rough guide.

Specifically for gauge type motors, Google finds several other tutorials, for example Retro Gauge - OpenXC

You cannot safely drive those gauges directly from the Arduino, because inductive spikes from the coils will destroy the output pins.

Hi,
Is this related to this?

http://forum.arduino.cc/index.php?topic=519310.msg3539218#msg3539218

Tom.. :slight_smile:

Joseph3502:
I bought 6 Polulu A4988 step sticks to control them. The code that I have is meant to be used for servo motors to drive the needles of the dash, but instead of using servos, i would like to use the steppers that are already on the dash.

AFAIK those tiny stepper motors can only take a very small current. I wonder if you can adjust the current limit on an A4988 to a small enough value.

Also, AFAIK those instrument steppers are designed to be driven slowly to their end-stop to establish the zero position at startup.

...R

TomGeorge:
Hi,
Is this related to this?

Car dashboard for ATS - Project Guidance - Arduino Forum

Tom.. :slight_smile:

Yes sir it is. I figured that instead of changing the code, I could just change the hardware...i.e., using a different motor driver or something. :slight_smile:

Robin2:
AFAIK those tiny stepper motors can only take a very small current. I wonder if you can adjust the current limit on an A4988 to a small enough value.

You would need to change the sense resistor to a higher value.

The onboard SMD resistor or just add a resistor?

Robin2:
AFAIK those tiny stepper motors can only take a very small current. I wonder if you can adjust the current limit on an A4988 to a small enough value.

Also, AFAIK those instrument steppers are designed to be driven slowly to their end-stop to establish the zero position at startup.

...R

So really all i have to do is set the current limiting high enough for the motor to function but low enough to not make it go crazy?

Joseph3502:
So really all i have to do is set the current limiting high enough for the motor to function but low enough to not make it go crazy?

The way it will "go crazy" is that it will overheat and the smoke will escape.

IIRC some of those instrument stepper motors only need coil currents of 20 or 40 milliamps. What is the resistance of the coil?

...R

180 ohms between each coil pair, which means at 12 volts each coil will draw 60 milliamps.

180 ohms between each coil pair, which means at 12 volts each coil will draw 60 milliamps.

Yes, and the power dissipation will be V^2/R = 12*12/180 = 0.8 Watts/coil, or 1.6 Watts per gauge.

Are those gauges designed to safely dissipate this much power as heat?

The commonly available SwiTec gauges are specified as 9V maximum[/b] and they have much higher coil resistance.
[u]http://www.jukenswisstech.com/JSTFiles/downloads/2011/06/X27_Flyer_v1.3.pdf[/u]

my motors don't look like that. i believe that mine are air core steppers. ive attached a picture of what they look like. :slight_smile: