Controlling two steppers simultaneously for a high precision movement path. Ideas for which method to use?

Hey everyone,

For a project I would like to control two stepper motors simultaneously.
I need to use the X and Y paths as an input (probably x,t and y,t table).
I want to have my motors precisely follow this path, but I am not sure what software to use.
As an example ;
I want to move: X=0 to X=45 (mm) during t=0 to t=3
I want to move: Y=30 to Y=0 (mm) during t=2 to t=3

Tolerances: maximum deviation is 0.1 mm. I will use steppers with screws, I think this should can me this accuracy.

I am considering using either Grbl (g code), MATLAB or the plain Arduino IDE to control stabdard stepper motors. If you have any recommendations, please let me know. I think it might be tricky to generate / convert an X,T trajectory to GRBL , however I think GRBL is the easiest way of controlling the motors.

Main question: how would you go about implementing this software-wise?

  1. It is important that the stepper motors can function at the same time, and that they can follow a precise and defined trajectory (preferably with an adjustable velocity).

  2. I want to use an endstop as my 'home position', and calibrate the machines starting location from here (every time it is used). I am not sure how good Grbl can be adapted to this, because I found that the motors shut down if an endstop is reached. The endstop that I am using is the Opto Endstop from reprap.

If you have any advice, please tell me. Thanks!

You need to better define what you want, you state for example: "precisely follow". Define the tolerances involved, the hardware you are using, and additional sensors. Post a tentative schematic, not a frizzy thing with links to all the hardware devices showing technical information.

Have a look at the Arduino code for the MakeBlock plotter. Search in you favorite search engine for "Makeblock XY-Plotter Robot". It controls two steppers (movement) and a servo (pen up/down)

1 Like

Thanks. I looked at the code and it is quite useful.

For anyone wanting to look at it : GitHub - Makeblock-official/XY-Plotter-2.0: Instruction for xy-plotter, learn more from Makeblock official website


From the description you have given of your project, it has many similarities to a CNC mill / router, with just two axes controlled instead of three. For that reason, an Arduino Uno with CNC Shield and two stepper carrier boards (either A4988 or DRV8825 based) will definitely meet your hardware requirements, as the CNC Shield also has the end stop inputs that you require.

For control software, I would look at Grbl - as you have stated your project has time critical movements and Grbl is already geared up for this as you can define X / Y positions and have the adjustable velocity (by setting feed rates). From a software / electronics point of view this set-up is definitely capable of meeting your maximum deviation of 0.1mm.

I think that the more difficult part of your project in terms of meeting the 0.1mm tolerance requirement will be the mechanical design, especially the rigidity of your machine. This of course depends on the loads involved and is beyond the discussion here, but is something you will need to think about carefully.

For your end stop requirements, you are partially correct in that Grbl does shut down the motors if an end stop is reached as this is usual behavior if a machine travels to it's limits. However, if you enable the homing cycle as described in the documentation at Grbl Homing Cycle, then this will achieve exactly what you seem to be looking for - at start up the machine will move to a known location based on your end stops.

If you go down the Grbl route, the main problem you will have is streaming the Gcode commands that define your X / Y paths to your Arduino controller. This implies have a second device to do this; often a laptop / desktop computer running the streaming software. A raspberry pi is an excellent alternative if you don't want to have a laptop or desktop running. Depending on the complexity of the path and whether or not it needs to be changed regularly, you could also use a second Arduino to stream the Gcode commands to the Grbl controller.

I have written two articles that may be of use to you in your project, the first describing building a CNC controller around an Arduino Uno and CNC Shield and overcoming some of the common problems that may be encountered. This is at Arduino / CNC Shield Machine Controller. The second article describes problems you may encounter when using end stops, including possible electromagnetic interference - Fitting End Stop Limit Switches to a CNC Machine

Hope this helps and good luck with your project!


1 Like

Hi capellanc,

Thanks for you reply. I looked at your articles!

I have a quick question for the GRBL movement control. Most software that I have found online concerns inserting a drawing of some sort, and letting the software turn it into a GRBL path. What I would like to use as an input is the following: A table of time, Xposition and Yposition.

Horizontally, it could look like this :

T = [ 0, 1.2, 2 ]
X = [ 0, 10, 30]
Y = [ 10, 0 , 10]

I am looking for software that takes the table above as an input, and converts it into motion by itself. I tried doing this with matlab and uploading all of the pulses onto the arduino, but this would take too much memory. I have also looked into various open source GRBL programmes, but they all seem to take an image as an input, not a table or something. The trajectory is important to me.

Do you happen to know if such software exists?

Thanks again!


Hi poenwnl,

What you appear to have is a set of XY co-ordinates that could be almost directly converted into Gcode commands with a simple script, I don't think you need any software to do it as such. Gcode does not have time as a parameter, but it does have feedrate (i.e. speed).

I'm going to assume units of mm and seconds for the following:
If I use your table as an example, you start at t = 0 with (x, y) = (0, 10). You then move to (x, y) = (10, 0) at time 1.2s. Using pythagoras, this gives a distance travelled of 14.14mm. Speed will therefore be 14.14 / 1.2 = 11.78mm/s. Gcode uses units of mm/minute for feedrate, so this will become 11.78 x 60 = 707mm/min. Your Gcode is now quite straightforward:

G0 X0 Y10 - this will 'fast travel' to your starting position
G1 X10 Y0 F707 - This will move to your next location at the speed (hence time) that you requested
... repeat!

The above text is what you should be streaming to your Grbl controller - it will then pulse the stepper motors to make the movements required.

Gcode takes XY positions - it is only the feed rates that you need to calculate, together with any unit conversions. If you have all your t, x and y variables calculated you have to create the above as a text file, something that should be straightforward in Matlab or maybe a simple script (Python?). You don't need to calculate the pulses at all - Grbl will pulse the steppers for you. Your only problem is calculating the feed rates for each movement.

A starting point for this might be putting Grbl on to an Arduino Uno, then connecting to the Uno using a terminal emulator (Putty?). You will then find it is as easy as typing "G1 X10 Y0 F707" to get the movement you want.

Hope this makes sense!


1 Like

Oops! Just realised that this will not work in the way I described due to the acceleration and deceleration involved, so the feed rate calculations need to be adjusted to take into account acceleration and deceleration. This shouldn't be too difficult however, so my basic concept still applies.


1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.