Stepper Motor Wiring "Best Practice"
mindrobots
Posts: 6,506
I've been playing with the "Cheap Chinese Steppers" on my Cheap Robot and have a question about the best way to wire the motors to make directional control and software the easiest.
For example, if you wire your RIGHT motor, with connections IN1 to PIN1, IN2 to PIN2, IN3 to PIN3 an IN4 to PIN4 and then sequence the 8 patterns through them as PIN1, PIN2, PIN3, PIN4, your motor runs clockwise, which for the RIGHT side is seen as FORWARD. If you wire your LEFT motor with connections IN1 to PIN1, IN2 to PIN2, IN3 to PIN3 and IN4 to PIN4 and then sequence the 8 patterns through them as PIN1, PIN2, PIN3 and PIN4, this motor also runs clockwise BUT on the LEFT side, that is seen as REVERSE.
To change the direction on the left side, you can either:
1) wire the motor differently (IN1 to PIN4, IN2 to PIN3, IN3 to PIN2 and IN4 to PIN1) and keep all the software the same and not have to keep track of which motor you are working with or whether forward is backward or if you need to invert directions or pin orders or any of that.
2) wire both motors the same and invert the pin assignments someplace in the software definitions for the left motor pins or the initialization
3) wire both motors the same, keep the pin assignments in the same order and then when you send out the pulses either send out the pulses, invert them for the left motor (you need to keep track of left and right somehow).
The lazy person in me screams #1 for ease of writing software and just make a BIG NOTE that the left and right motors get wired in opposite ways. This keeps all your software the same, forward is forward in relation to the robot. With other stepper applications, you are more than likely talking clockwise and counterclockwise so it's not a big deal keeping track of direction.
Yes? No? Maybe? Don't really care?
Any of the Robot Masters have any words of wisdom to steer me away from #1?
Servos are another matter and direction control has to be done in software with LEFT/RIGHT motor flags and adjusting accordingly but the steppers give you the very easy rewire option.
For example, if you wire your RIGHT motor, with connections IN1 to PIN1, IN2 to PIN2, IN3 to PIN3 an IN4 to PIN4 and then sequence the 8 patterns through them as PIN1, PIN2, PIN3, PIN4, your motor runs clockwise, which for the RIGHT side is seen as FORWARD. If you wire your LEFT motor with connections IN1 to PIN1, IN2 to PIN2, IN3 to PIN3 and IN4 to PIN4 and then sequence the 8 patterns through them as PIN1, PIN2, PIN3 and PIN4, this motor also runs clockwise BUT on the LEFT side, that is seen as REVERSE.
To change the direction on the left side, you can either:
1) wire the motor differently (IN1 to PIN4, IN2 to PIN3, IN3 to PIN2 and IN4 to PIN1) and keep all the software the same and not have to keep track of which motor you are working with or whether forward is backward or if you need to invert directions or pin orders or any of that.
2) wire both motors the same and invert the pin assignments someplace in the software definitions for the left motor pins or the initialization
3) wire both motors the same, keep the pin assignments in the same order and then when you send out the pulses either send out the pulses, invert them for the left motor (you need to keep track of left and right somehow).
The lazy person in me screams #1 for ease of writing software and just make a BIG NOTE that the left and right motors get wired in opposite ways. This keeps all your software the same, forward is forward in relation to the robot. With other stepper applications, you are more than likely talking clockwise and counterclockwise so it's not a big deal keeping track of direction.
Yes? No? Maybe? Don't really care?
Any of the Robot Masters have any words of wisdom to steer me away from #1?
Servos are another matter and direction control has to be done in software with LEFT/RIGHT motor flags and adjusting accordingly but the steppers give you the very easy rewire option.
Comments
I don't know what the Robot Masters might say, but I would advise WIRE EVERYTHING THE SAME and KEEP THE SOFTWARE THE SAME until the absolute last minute at the highest level.
That is, define for example FOWARD = Left CCW and RIGHT CW, at the level just below the final application. It makes debug and test easier.