# Need help figuring out why stepper motor losses steps/accuracy.

Hello everyone, I am having an issue and can’t seem to get a solution or possible lead in obtaining a solution to my problem from web searches.

My issue that I need help with is, I have 2 nema 17 motor attached to the adafruit motorshield v2 which is connected to an arduino uno. I am using matlab to control the stepper to move in a grid like pattern. A 20 by 20 grid, where 0,0 is its origin. The setup that I have does what I want it to do, raster scanning using a carriage with a sensor attached, where one stepper controls the x axis and the other the y axis.

I am using the function move(obj, value) in matlab.

The stepper motors are defined as;
x=stepper(shield, 1,200,‘rpm’,1000,‘stepType’,‘Interleave’)
y=stepper(shield, 1,200,‘rpm’,1000,‘stepType’,‘Interleave’)
I am able to successfully move the steppers through the grid in both x and y direction,

At the end of the grid, the position of the stepper should be at 0,20, however i an having an issue where throughout the scan each row going upwards the x axis is some how being displaced. So instead of the final position being 0,20, it is at something like 4,20 on the grid.

What is the step rate (steps per second)? If microstepping, what value?

the usual stuff:

• voltage to low
• acceleleration/develeration too fast
• speed too high
• pulselength wrong
• driver not up to the task

The motorshield is a poor choice for controlling stepper motors - it is really for DC motors. You really should be using specialised stepper motor drivers such as the DRV8825.

Steps can be missed because the load on the motor is too high, because the motor is being expected to move too fast, or because the motor is not being accelerated (and decelerated) when higher speeds are required.

Hey everyone, thank you for replying.

JCA34F:
What is the step rate (steps per second)? If microstepping, what value?

Hello, i am unsure about the steps per second. I am using Interleave, with the motor configured with 200 steps per revolution, and RPM of 1000. In the code i used move(x, steps). My steps are usually between 100-1500 from previous runs, i eventually settled on 1250.

zwieblum:
the usual stuff:

• voltage to low
• acceleleration/develeration too fast
• speed too high
• pulselength wrong
• driver not up to the task

Hello, the device i am working on was constructed by another group before me and the voltage for the motorshield and the required nema17 motors are satisfactory based on their datasheet. As for acceleration/deceleration i am moving the steppers with the matlab move functions, defined as: move(sm,steps) rotates the stepper motor for the specified number of steps. The move command blocks MATLAB® while the stepper motor is rotating.
with my current step at 1250, previously i used a different values ranging between 100-1500. THe drivers that i am using are supplied by the arduino ide and matlab addon for the arduino and motorshield. I am unsure if there are other drivers avalible to be used.

Robin2:
The motorshield is a poor choice for controlling stepper motors - it is really for DC motors. You really should be using specialised stepper motor drivers such as the DRV8825.

Steps can be missed because the load on the motor is too high, because the motor is being expected to move too fast, or because the motor is not being accelerated (and decelerated) when higher speeds are required.

Hello, unfortunately the motorshield and the construction of the device that i am working on was previously created by peers that came before me and it is an on going project. Do you have an recommendations of how i could tweak the configuration that i have and steps number i could used to move the stepper?

I should also mention that i choose (would like) the steps value thatmoves the stepper to equal 10mm per cycle.

The first thing I would do if a stepper motor is missing steps is reduce the speed by a factor 10. If it does not miss steps at that slower speed then I would gradually increase the speed to the point where it starts missing and then back off 10% or 15%

If it is still missing steps at the slower speed then I would start to think that the stepper motor does not have enough torque for the project.

I would also experiment with some simple Arduino code that does not need Matlab to see if the problem is caused by the Matlab - Arduino link up. I have never used Matlab myself.

...R

Well, then you have 3 options:
a) use what you have and live with the limitations
b) get to your peers and tell them to build the hardware the propper way.
c) go on complaining ...

The image above illustrates the issue that i am attempting to fix. The green circle is my origin, the beginning of my scan and the red is the end position of the scan. I am trying to understand why the end position is not at the yellow circle but instead at the red circle.

zwieblum:
Well, then you have 3 options:
a) use what you have and live with the limitations
b) get to your peers and tell them to build the hardware the propper way.
c) go on complaining ...

Hello, i am more than ready to accept that there is no solution to my issue, in regards to hardware limitations, if that is the case than that is my solution and I can move on.

I am unable to go to my peers about the issue due to them not being present and have moved on from the project as a whole. I am not advocating that the project was constructed in an incorrect manner or correct manner, all i am focusing is trying to ascertain a fix or probably cause for the issue that i am facing.

And lastly I feel like i am not complaining (this is a last resort for me after many many searches and posts on matlabs community forum), i am posting here in hopes of someone can offer me advice or point me in the right direction or ultimately has encountered this issue that can offer some meaningful advice or recommendations, rather than reply to the thread with nothing constructive or relating to the issue at hand.

Side note: Because of posts such as this, it is why i was reluctant on posting on here, but i have no other choice in trying to understanding the problem. If this is what this community has to offer me in terms of broadening my understanding of something, i will gladly refrain from using this community or recommend it.

"not constructive" is in the eye of the viewer.I would not say "stack a inappropriate motor driver shield on top of an arduino" to be a great constructing efford. If you used the search funtion you'd already know that are cnc shield for driving steppers. Constrution efford to use thes is not that big - remove old shied, stach cnc shield on top of it, be done. And you'd know there's also a thing called GRBL, but I'll leve that up to you to find out.

Indeed, not constructive is in the eyes of the viewer, I am not here to argue with you or anyone else for that matter. I am here because I am confined to a hardware setup that I cannot change in the immediate future, if I could, I would have already done that a never posted on here. I have a setup that is static, and I am working with what I have and trying to understand why the issue that I am having. I appreciate your reply in its limited capacity, but if you have nothing more to offer with the understanding of the constraints that I have to work with, than I suggest you be on your way and refrain offering your opinion and insights that are not conducive to my original post.

You write a lot of text with minimal information. Have you checked the list in #2? Especially “acceleration” ? If you did, where’s the code where you set the acceleration? If you have no acceleration to set, how should that work out?

This is the code that i use in Matlab to control the stepper motor. I confined to using Matlab for this project. The option to use Arduino directly is not possible. Matlab has an addon that communicates with the Arduino and the shield to move the stepper.

So no acceleration. You are lucky that it works as it does.

This is the link to the information that i am using within Matlab for controlling the motors.

Yes, that's where the motorshield came from, too. Anyway, this won't help you. You need a defined acceleration/deceleration or you loose steps. Now you have infinite acceleration/deceleration - that will never work. You can decrease speed to a crawl, that might look as if it works for a while, but that's an illusion.
Oh, before you try to implement acceleration/deceleration in Matlab: that won't work, either. You need realtime control of the stepper driver.

zwieblum:
Yes, that's where the motorshield came from, too. Anyway, this won't help you. You need a defined acceleration/deceleration or you loose steps. Now you have infinite acceleration/deceleration - that will never work. You can decrease speed to a crawl, that might look as if it works for a while, but that's an illusion.
Oh, before you try to implement acceleration/deceleration in Matlab: that won't work, either. You need realtime control of the stepper driver.

Thanks for the reply. Ugh so it looks like im pretty much stuck when it comes to using Matlab for controlling the steppers. I guess this is the limitations of using their addons?

Update: I've looked through the MATLAB files for the functions used and no mention of acceleration or deceleration. Also looked into the .h file for the Arduino motor shield that is programmed to the Arduino and there is also no mention of acceleration or deceleration.

Also, to sum this up, based on the image that I uploaded previously, the reason I am having the issue that i am having is due to not being able to define a set value for acc/deceleration? Would this assumption be correct to explain the problem in the picture?

Kind of. But why can’t you just send out gcode to /dev/ttyACM0 (or what ever is your serial port)? just your “move(12,130)” would send send “g1 x12 y130” ?

zwieblum:
Kind of. But why can't you just send out gcode to /dev/ttyACM0 (or what ever is your serial port)? just your "move(12,130)" would send send "g1 x12 y130" ?

Actually that is what i am working on now, i already have a piece of code that sends information over the serial connection to get data from the arduino itself. So right now i am attempting to do that same and just have the 2nd arduino with the motorshield do the movement of the steppers based on serial communication data.

motorshield won't work with grbl, so you'll need to write your own. AccelStepper?

zwieblum:
motorshield won't work with grbl, so you'll need to write your own. AccelStepper?

I've seen other users post that, i have yet to look into it though. I was thinking something more primitive lol, using the supplied StepperTest example in Arduino and modifying it to use Serial.readString to receive either a word or a combination of word and value to indicate FORWARD/BACK/UP/DOWN and RPM to choose movement lenght.