Stepper motor DIR conundrum [Solved]

Hi community!

I am currently setting up a large stepper motor (M2-3437-S) using a IM1007 driver.

The driver only has a single DIR pin which if I send a HIGH signal to the motor rotates CW.
If I send a LOW signal the motor moves randomly.

If I pull the DIR pin and ground it, it turns CCW.

Currently my solution is to use two relays one grounded and one 5v and switch them for a direction change, it's not ideal but I currently can't see what else I can do.

If any of you have a better solution or can see what I'm doing wrong I would appreciate your input

Thank you!

UPDATE** SOLVED
Faulty driver was causing my issues, replaced the unit and all is good.

MADMAN-_-zZ:
If I send a LOW signal the motor moves randomly.

If I pull the DIR pin and ground it, it turns CCW.

I don't understand what is different in those two statements?

...R

I've made progress since yesterday, seems the arduino board i was using was acting up and I switched to another board and the DIR pin works as it should now.

The issue I am having now is the stepper motor skipping steps and going random directions, I think it is an issue with the delayMicroseconds() being too long or short and I am playing around with numbers to get it working right, I do have acceleration acting on this to ramp up the speed.

EDIT**

I am stumped, I have added a keypad to select rotation direction followed buy a full 360 rotation of the stepper but it just goes whatever direction and skips steps. example code below.

void input(){
  char key = keypad.getKey();
  if(key)
  {
    switch (key)
    {
      case '*':
        digitalWrite(iDir, LOW);
        Serial.println(digitalRead(iDir));
        moveMotor();
        break;
      case '#':
        digitalWrite(iDir, HIGH);
        Serial.println(digitalRead(iDir));
        moveMotor();
        break;
      default:
        Serial.println(key);
    }
  }

void moveMotor() {
  //temp
  iStepCount = 400;
  
  for (int i = 0; i < iStepCount; ++i) {    
    //motorAcceleration();
    digitalWrite(iStep, HIGH);
    delayMicroseconds(iPulse);
    digitalWrite(iStep, LOW);
    delayMicroseconds(iStepSpeed);
    //Serial.println(digitalRead(iDir));
  }
}
}

Please post your ENTIRE code and a wiring diagram.

No wiring diagram at the moment

#include <Keypad.h>

//wheel cicumference 180.01325905069513

const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'#','0','*','D'}
};
byte rowPins[rows] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[cols] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

const int iDir = 12;
const int iStep = 13;
int iStepCount = 0;
float fStepTimer = 0;
const int iStepsPerRev = 400;

float fMaxSpeed = 300;//200
float fMinSpeed = 1000000;//25000;//2000
int iPulseMicro = 3;
float fStepSpeed = fMinSpeed;
float fAcceleration = 100;

float fDist = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(iDir, OUTPUT);
  pinMode(iStep, OUTPUT);

  digitalWrite(iDir, HIGH);
  digitalWrite(iStep, LOW);

  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  input();
  
}

void input(){
  char key = keypad.getKey();
  if(key)
  {
    switch (key)
    {
      case '*':
        digitalWrite(iDir, LOW);
        Serial.println(digitalRead(iDir));
        moveMotor(10);
        break;
      case '#':
        digitalWrite(iDir, HIGH);
        Serial.println(digitalRead(iDir));
        moveMotor(10);
        break;
      default:
        Serial.println(key);
    }
  }
}

void moveMotor(float fDistance) {
  //temp
  iStepCount = 400;
  
  for (int i = 0; i < iStepCount; ++i) {    
    //motorAcceleration();
    digitalWrite(iStep, LOW);
    delayMicroseconds(iPulseMicro);
    digitalWrite(iStep, HIGH);
    delayMicroseconds(fStepSpeed);
    //Serial.println(digitalRead(iDir));
  }

  resetSpeed();

  //if (digitalRead(iDir) == HIGH)
    //digitalWrite(iDir, LOW);
  //else
    //digitalWrite(iDir, HIGH);
}

void motorDir(){
  
}

void motorAcceleration() {
  if (fStepSpeed > fMaxSpeed)
    fStepSpeed -= fAcceleration;
  else if (fStepSpeed <= fMaxSpeed)
    fStepSpeed = fMaxSpeed;      
}

void resetSpeed() {
  fStepSpeed = fMinSpeed;
}

The code in Reply #4 does not have any direction stuff. Please post the correct program in your next Reply.

Have you tried writing a simple program that makes the motor do 2 revolutions in one direction followed by 2 in the other direction with a short delay between the direction changes? Try the examples in this Simple Stepper Code

...R
Stepper Motor Basics

switch (key)
{
case '*':
digitalWrite(iDir, LOW);
Serial.println(digitalRead(iDir));
moveMotor(10);
break;

This is where DIR is set and it sets correctly, i did a simple test before all this with had it rotating one way then another which worked fine most of the time, some delay settings caused the random fluctuations (slower or faster speeds then the one I got to work even by 25 microseconds difference cause issues)

MADMAN-_-zZ:
switch (key)
{
case '*':
digitalWrite(iDir, LOW);
Serial.println(digitalRead(iDir));
moveMotor(10);
break;

This is where DIR is set and it sets correctly,

Post a complete program.

...R

Relays? Does it not work with the 5V Arduino directly?

You cannot use a mechanical relay for the step pin. That is much too slow.

Wiring schematics are required. A pencil sketch photographed with a phone is sufficient.

You cannot use a mechanical relay for the step pin. That is much too slow.

I'm no longer using a relay to switch the DIR, was never going to use the relay for stepping.

Post a complete program.

That segment of code I posted was from the whole program I posted before, I didn't want to double post the same block of code twice, I was just highlighting where the direction change was made.

Attached wiring diagram and current setup

Thank you for taking the time to help, I appreciate it.

EDIT**
So I have connected another stepper to see if it was a coil/wiring issue, same problem so far.
I believe the code and wiring is correct, I am starting to think it's an issue with the driver, I slowed the steps right down to almost one per 0.5 seconds and the motor will do a full rotation correctly but only clockwise, then if I apply rotational force counter-clockwise to the motor shaft it will step CCW until I release the shaft.

The diagram doesn't show all the wires that are in the photo. The ground connection going to the option inputs is simple enough but I worry about all those wires going to the stepper. You seem to have 8 wires there. Are you sure that's wired correctly?

I found a manual for that stepper controller here: https://motion.schneider-electric.com/downloads/manuals/discontinued_prod/im1007.pdf I have not done any calculations to confirm if your wiring is correct.

If the motor goes in the direction that you're pushing it then it's being driven incorrectly. Perhaps one of the output stages of the controller is blown and it's not able to drive one output properly. Does it have the same holding torque and power consumption on each of the 4 'full' steps? If one step isn't holding torque then that driver transistor is blown.

MorganS:
The diagram doesn't show all the wires that are in the photo. The ground connection going to the option inputs is simple enough but I worry about all those wires going to the stepper. You seem to have 8 wires there. Are you sure that's wired correctly?

I found a manual for that stepper controller here: https://motion.schneider-electric.com/downloads/manuals/discontinued_prod/im1007.pdf I have not done any calculations to confirm if your wiring is correct.

If the motor goes in the direction that you're pushing it then it's being driven incorrectly. Perhaps one of the output stages of the controller is blown and it's not able to drive one output properly. Does it have the same holding torque and power consumption on each of the 4 'full' steps? If one step isn't holding torque then that driver transistor is blown.

Thanks for the reply.

I have wired the Motor according to the stepper manual and motor paper, I am certain that it is correctly wired in parallel, I had a 4 wire nema 34 that I tried as well with the same issues.

Something weird that happened before, I flicked on the power and tried it again and it was working flawlessly, swapping direction and completing a full rotation on button press, then I held the shaft to put a bit of load on it and it went back to the erratic movement, hasn't worked again since....

MADMAN-_-zZ:
Thanks for the reply.

I have wired the Motor according to the stepper manual and motor paper,

I can only interpret that, alongside the failure to respond to Reply #7, as meaning that you are not prepared to take the trouble to help us to help you.

Remember, we can't see your workbench from here.

...R

Robin2:
I can only interpret that, alongside the failure to respond to Reply #7, as meaning that you are not prepared to take the trouble to help us to help you.

Remember, we can't see your workbench from here.

...R

Sorry Robin, you are asking me to do what I have already done, Reply #4 has the full program including what I highlighted in Reply #6, because you said direction change was non existent in Reply #4, further I replied you again #9 to explain this and also posted a very brief wiring diagram and a picture showing my workbench with all the components.

I am certain wiring and code is correct, as I said it worked for a brief moment before going bad again, the stepper driver is setup for 9amps which is within the stepper motors working range wired in parallel according to the motors wiring manual, the only thing I could think it is at this moment is a faulty driver.
I am in the process of getting another driver to test it with.

MADMAN-_-zZ:
Sorry Robin, you are asking me to do what I have already done, Reply #4 has the full program

No, the apology is all mine. I seem to have become totally confused - old age, maybe.

I am not good at spotting errors in code but I don't see anything wrong with what is in Reply #4. Which points the finger at a hardware problem. An easy way to damage a stepper driver is to disconnect (even briefly, such as a loose connection) a wire between the motor and the driver while the driver is powered.

Have you tried my simple stepper code?

...R

Robin2:
No, the apology is all mine. I seem to have become totally confused - old age, maybe.

I will look at it again.

...R

Thanks Robin, I appreciate your input, I read through other threads where you have posted and your insight is always very helpful.

What is your power supply? If it cannot supply the current that the driver asks for then it might produce those symptoms.

MorganS:
What is your power supply? If it cannot supply the current that the driver asks for then it might produce those symptoms.

It is a very beefy power supply made for stepper driving outputting 70v but I haven't measured the amperage output, the unit is branded Aeronaut but I cannot find information about it on their website. I haven't tried to measure amperage because I don't have any resistors lying around am worried I'll blow my multimeter.

These drivers motors and powersupply were given to me by a friend, I assumed that they were once a single package for some CNC machine, he needs me to program it to work with a guillotine cutter to move a measuring bracket a specific distance inputted via a keypad, I am more then capable of programming it but just working out this setback is my issue.

I have requested he give me one of the other motors and drivers to test so that I can hopefully rule out a hardware issue.

MADMAN-_-zZ:
Thanks Robin, I appreciate your input, I read through other threads where you have posted and your insight is always very helpful.

I updated Reply #14 - not realizing you had seen the original.

...R

Robin2:
I updated Reply #14 - not realizing you had seen the original.

...R

Thanks Robin, Yes I tried a very basic stepper code, which sort of works, the first time I tried it as per my opening this thread it was not doing what I wanted at all, After using different pins and swapping back and forth it started working what seemed to be fine, one full rotation CW 1 second pause then a full CCW rotation, then I expanded on that code and it started being erratic again, I went back to the basic code and still erratic except for as per reply #11 once i turned it on and it worked with the keypad until i put load on the shaft and now it is back to being erratic and broken.

I was careful to never disconnect wires while the stepper was powered, and I did try another brand new stepper I had lying around with the same result, So right now I am thinking the driver is faulty, hopefully I get a replacement soon to test that.