Maker Pro
Maker Pro

stepper motors

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
Hello. I'm a newbee here and looking for some help. I'm also a newbee on the raspberry pi and g code.
At present I can run each motor seperately but I need to have them interact with each other.
What i'm trying to do is write a program to run 2 stepper motors at different times to complete a procedure.
I have a power source, 2 seperate stepper motor drives, 1 for the x axis the other for the y axis, 2 stepper motors (Nema 23 for x axis, Nema 17 for the y axis)
I need to have #1 stepper motor ( x axis ) to complete a round, which is cw & ccw (# to be determined) and have #2 stepper motor to move the ( y axis ) amount of movement to be determined, cw & ccw.
Help would be greatly appreciated.
Thanks Driver72
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
What is meant by "Interact with each other"??
So far it sounds like two independent moves?
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
Yes they will be. That is reason for 2 stepper motor drivers. Can one motor move and pause while the other moves and come back to the first one and move. That would complete the loop and then i would repeat it however many times needed.
 

Delta Prime

Jul 29, 2020
1,966
Joined
Jul 29, 2020
Messages
1,966
Can one motor move and pause while the other moves and come back to the first one and move.
Curious?
Building a differential transmission?
You need a feedback system to count the number and pulses of the stepper motor, this is usually done with, opto-encoders, hall-effect sensors, torque sensors.
Such as found in a CNC machine.
I don't believe you are a hobbyist.
What is your end application? Details are necessary for a more in depth explanation.
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
I have a surface grinder in my shop that i'm trying automate so I don't have to crank the wheels to make all this happen.
I saw this on youtube but only half of the program was given which i have working. Now I'm trying to get the second motor to be a player.
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
. I'm also a newbee on the raspberry pi and g code.
Do you mean G-Code as in CNC?
I don't use Raspberry Pi but I assume it can keep track of the number of pulses it issues?
No feedback device needed with steppers!
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
Curious?
Building a differential transmission?
You need a feedback system to count the number and pulses of the stepper motor, this is usually done with, opto-encoders, hall-effect sensors, torque sensors.
Such as found in a CNC machine.
I don't believe you are a hobbyist.
What is your end application? Details are necessary for a more in depth explanation.

Do you mean G-Code as in CNC?
I don't use Raspberry Pi but I assume it can keep track of the number of pulses it issues?
No feedback device needed with steppers!
I believe so. I have the stepper drivers wired to the Rpi gpio's and labeled pulse pins & direction pins but can't get them to work together when I need them to . I can get them to work when programmed alone but not together.
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
Curious?
Building a differential transmission?
You need a feedback system to count the number and pulses of the stepper motor, this is usually done with, opto-encoders, hall-effect sensors, torque sensors.
Such as found in a CNC machine.
I don't believe you are a hobbyist.
What is your end application? Details are necessary for a more in depth explanation.
In this setup you tell the rasp pi how many pulses you want the motor to move
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
Do you mean G-Code as in CNC?
I don't use Raspberry Pi but I assume it can keep track of the number of pulses it issues?
No feedback device needed with steppers!
Yes. I apologize, I need 1 motor to run a half of a round, (cw ) pause while the other moves in whatever amount of pulses it is set up for ( cw ) , then have the other motor complete its other half of the round ( ccw ). This will be set up to run for however many times I need it to complete the task I need it to do.
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
What i'm trying to do is write a program to run 2 stepper motors at different times to complete a procedure.
I need to have #1 stepper motor ( x axis ) to complete a round, which is cw & ccw (# to be determined) and have #2 stepper motor to move the ( y axis ) amount of movement to be determined, cw & ccw.
So the way I interpret that, only one stepper positioning at a time?
If so, I would not have thought that a problem ?
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
You only to set the direction pulse once and then issue steps as required?
What stepper drive(s) are you using
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
You only to set the direction pulse once and then issue steps as required?
What stepper drive(s) are you using
digital stepper driver DM542T.
Okay so if I'm useing gpio20 for motor A & gpio12 For motor B as direction pins,
is that written as
direction_pin = 20, 12
and gpio21 for motor A & gpio16 for motor B as pulse_pins, written as
pulse_pin = 21, 16
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
I have never used those products, but typically you do not require to issue a pulse stream for the DIR, only the step pulse rate.
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
I have never used those products, but typically you do not require to issue a pulse stream for the DIR, only the step pulse rate.
Ok I appreciate you trying to help. I'll keep at it and we'll get it I'm sure.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,720
Joined
Nov 17, 2011
Messages
13,720
Let me preface that I'm not an expert on stepper motors, but here's my 2 cents from what I can deduce from the manual and from your description:

The DM542T seems to be controlled by these signals:
  • pulse - stepper pulses from the controller (Raspbery Pi) to the Stepper driver
  • dir - direction signal from teh controller to the driver. Note that the dir signal needs to lead the pulse signal by 5 µs (table on page 3) which means that after changing dir you need to wait 5 µs before issuing the next pulse by the controller.
  • ena - enable 5 V inputs instead of 24 V inputs. This signal can be fixed to active (my understanding of the manual)
These are differential signals, meaning that you apply a positive voltage to the "+" pin and GND to the '-' pin. This alow easy control of the driver bei either high-active outputs or low-active outputs, see manual, figure 4 and 5, respectively.

That said let's assume the pins are wired correctly.

Next step would be to set the cintrol signal voltage to 5 V as the factory setting is 24 V (see table on page 3 and figure 2 and read slo chapter 4 of the manual). The Raspberry can't handle 24 V signals, only 5 V signals.
Let's assume this has been done.

Now to the code. I will use pseudo code as I don't know how you are programming this (probably Python?), but pseudo code should be good enough to get you on track:
Code:
# Declaration of pins

mot1_dir = pin??
mot1_step = pin??
mot2_dir = pin??
mot2_step = pin??

# Declaration of constants for better readability.
# Needs to be matched to your actual setup

LEFT = 1
RIGHT = 0

# Subroutine to move either motor by numsteps in the given direction
def move_motor(motor, direction, numsteps):
    if (motor==1):
        mot1_dir = direction
        wait(5µs)
        for i in range(numsteps): #create pulses
            mot1_step=1
            wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
            mot1_step=0
            wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
    if (motor==2):
        mot2_dir = direction
        wait(5µs)
        for i in range(numsteps): #create pulses
            mot2_step=1
            wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
            mot2_step=0
            wait(5µs) #for max. speed of 200 kHz pulse frequency. Increase the value for slower speed.
          
# Here comes your main routine to control the movement of the motors with a sample sequence.
# This sequence needs to be matched to your requirements.
# You also may want to incorporate some kind of control like e.g. reading a button to initiate or stop the sequence etc.
move_motor(1,LEFT, 100) # This will move motor 1 only, motor 2 is at rest.
move_motor(2, RIGHT, 200) # This in turn moves motor 2 whiel motor 1 is at rest
move_motor(1,RIGHT, 100)
move_motor(2, LEFT, 200) # after this step all motors should be in the initial position
Actually moving only one motor a a time, as you requestwed, is the easy part. Moving 2 motors synchronously will be more challenging as you have to output pulses to both motors simultaneously.

Note that this code is very rudimentary. You may want to add lots of features like for example:
  • moving the motors to a defined position when you turn on the machine. This may require additional sensors (end switches) to detect the end position of the motors/mechanics)
  • adding an emergency button to immediately stop the motors
  • adding code to evaluate the alarm signals from the DM542T
  • etc.
Here is an example of a tutorial how to drive a stepper motor by a Raspberry Pi.

By the way: If this is the only job for the Raspberry Pi, this computer is pure overkill. A comaparatively cheap Arduino (clone) can do this for way less money.
 

kellys_eye

Jun 25, 2010
6,514
Joined
Jun 25, 2010
Messages
6,514
ena - enable 5 V inputs instead of 24 V inputs. This signal can be fixed to active (my understanding of the manual)
For testing I would agree however when a system is fully operational it is wise to use this facility to remove the power from the windings else the stepper can overheat - not withstanding any need to keep a 'hold' on the stepper position that is.
 

Driver72

Jan 10, 2024
13
Joined
Jan 10, 2024
Messages
13
For testing I would agree however when a system is fully operational it is wise to use this facility to remove the power from the windings else the stepper can overheat - not withstanding any need to keep a 'hold' on the stepper position that is.
Yes when not in use I will kill the power.
 
Top