Advice on controlling an old stepper motor

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hello. I have got a task to design a control firmware for a stepper motor. It needs to rotate to one direction (close the door) when it receives signal, and rotate to another direction(open the door) when it receives another signal. I have been given some stepper motor and a driver:
I wasnt even able to find any information about this motor.

I am running a driver with 12V and 0.6A current and the motor seems to rotate in both direction using this sketch:

Code:
#define directionPin 3
#define stepPin 2
#define speedDelay 40 // change this to change the speed, the lower it is the faster it will go

void setup() {
  // Initialize the Serial port:
  Serial.begin(9600);

  // set up the driver pins:
  pinMode(stepPin, OUTPUT);
  pinMode(directionPin, OUTPUT);

}

void loop() {
  // Step forward 800 steps:
  Serial.println("Forward");
  digitalWrite(directionPin, HIGH);
  for (int i=0; i<100; i++) {
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);
    delay(speedDelay);
  }
  delay(500);
  // Step backward 800 steps:
  digitalWrite(directionPin, LOW);
  for (int i=0; i<100; i++) {
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);
    delay(speedDelay);
  }
}
Since I require to rotate this stepper motor certain distance , would you recommend me using some library or build my own functions?
I also need to make this stepper rotate in accelerating manner. I have tried using accellstepper library

Code:
// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton, 
// depending on the value of the pot.
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 2, 3);
//direction d3
//pull d2
// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0

void setup()
{  
  stepper.setMaxSpeed(200);
  stepper.setSpeed(1);
}

void loop()
{
  // Read new position
  int analog_in = analogRead(ANALOG_IN);
  stepper.moveTo(analog_in);
  //stepper.setSpeed(1);
  //stepper.set();
  stepper.run();
  //stepper.runSpeedToPosition();

}
I am though confused about how exactly this library works : https://www.airspayce.com/mikem/ard...tepper.html#ace236ede35f87c63d18da25810ec9736

For example, how does moveTo function works? What value do I need to pass. Since the description mentions target position, how does a number that I pass refer to target position? What would happen if I pass 100 or -100?
 

Attachments

dendad

Joined Feb 20, 2016
4,451
I would imagine you run the motor until it hits a limit switch. Then set that position as "home" using the "setCurrentPosition()" command.
Then, if you "moveTo 100", it should step 100 steps. Similarly, "moveTo -100" will go back to home and continue another 100 steps. That is, if your software and the hardware system allows it. Like, you cannot close the dore more that fully closed.
Make up a lever on the stepper and have it operate a microswitch then have your code set the home position.

A multi turn pot read on an analog input can read the position too. But a limit switch is easy.
Play around with it on the bench.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Okay thank you sir. How do I know if my stepper motor has a limit position? Can I rotate it in any direction any amount of times? From what I have heard, stepper motors usually can only rotate 1 or just a few cycles
 

dendad

Joined Feb 20, 2016
4,451
Usually, steppers can go around an unlimited number of turns, just like a "normal" motor.
Limit switches will be operated by a switch, for example, when the door is closed, so the controller will know to stop driving the motor.
Also, another switch at the open position may be a good idea.

My 3D printers all have limit switches at the home position only. The stepper motors drive to home then are stopped. Now the controller knows where the machine is.
So, the controller can now move to a series of known positions to print the work. This assumes the motors do not miss a step. The beauty of a stepper motor is that it moves a known amount for each step, so, if nothing slips or jams, you can work out where it is by the number of steps that have been moved.
EDIT: It looks like 1.8 degrees per step. See this data sheet.
 

Attachments

Last edited:

MaxHeadRoom

Joined Jul 18, 2013
28,617
Okay thank you sir. How do I know if my stepper motor has a limit position? Can I rotate it in any direction any amount of times? From what I have heard, stepper motors usually can only rotate 1 or just a few cycles
There are are many thousands being used presently for motion control, just check out any DIY CNC web site.
The rotational range normally has no electrical limit, just mechanical constraints of the equipment.
They are used in small motion control systems due to the lack of need for feedback positioning, IOW, they move per the programed pulse rate.
Max.
 
Top