Yes this is exactly what i'm trying to do. I will be going at it again today and will be using this info hopefully getting better results. I'll be getting back to you and let you know how i'm doing.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:
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.
- 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)
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:
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.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
Note that this code is very rudimentary. You may want to add lots of features like for example:
Here is an example of a tutorial how to drive a stepper motor by a Raspberry Pi.
- 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.
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.
Thanks again for all your help