Generation of diagonal line using 2 stepper motor linear axes

Hi guys,
I have made a two axis linear slides using stepper motor. I'm using a4988 driver.
My question is:
If I move from (0, 0) to (400, 400), both stepper motors move at a constant speed, and reaches (400, 400). Great.

If I move from (0, 0) to (400, 100), then I need to increase the speed of one of the stepper motors by 4 times fine.
But if I move from (0,0) to say (431,89), then I need to increase the speed of one of the motor by 4.84 times. But stepper.serSpeed() won't take values in integer.
Thank you!!

The Bresenham algorithm is used to draw lines stepwise. Then you don't need to worry about setting fractional speeds.

3 Likes

Thanks @jremington!!
But would the bresenham algorithm generate exact diagonal line?

Yes, subject to motor and linkage slop. Read the linked page to learn the details.

1 Like

Another approach would be to use GRBL to generate the pulses. GRBL is free to download and runs on Uno, can drive 3 independent steppers for XYZ axes. It incorporates interpolation (probably Bresenham). Takes g-code input, so you would send it

G01 X431 Y89 F100

to move from current position to (431,89).

GRBL widely used in DIY CNC machinery, nice program.

1 Like

Thanks @jhaine but is the software easy to use??

In my experience yes, running on a Uno. See

GRBL Software Guide for Beginners [2023] - MellowPine(.&text=After%20installing%20Arduino%20IDE%2C%20select,a%20folder%20named%20'grbl'.&text=Open%20the%20'grbl%2Dmaster',a%20subfolder%20named%20'grbl'.

for instructions on downloading and installing. Once installed you can send it g-code commands from the serial monitor command line or a number of g-code senders.

GRBL installation can on occasion be a little tricky but most people get it to work.

This is the link you should always use for UNO's

GRBL acts simply as an interface between the shield and the UNO.

Almost all of us use a SENDER type program such as UGS or LaserGRBL

There are many more sender programs so you might find one that is easier for you to get to grips with.

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