Stepper Degree to Steps

Hi im trying to tell the stepper motor to turn 90 degree. Based on that i wanna calculate the steps needed. I tried the following:

int degreeToStep(long degree, int stepResolution){
  return ( (float)degree / 360) * (float)stepResolution;
}

degree would be 90, 180, etc.. the degrees i want the stepper to rotate.

stepResolution would be the driver setup, like 200, 400, 800. the steps needed to make one turn.

if degree is 90 and stepResolution is 400, its making 45° instead of 90°, so half of the steps i want it to make.

If degree is 90 and stepResolution is 800 it works as expected.

I think the issue is that im missing some small detail.

The degrees will not be exact;

ninetyDegrees = stepsPerRevolution / 4; // 360/90 = 4

Microstepping (configured on your motor driver board) will allow finer control.

have you tried commanding the stepper to move 400 steps to verify that it rotates one full rotation?

if i remember correctly from the past this worked but i can retry. also the driver says "steps/revolution" next to it

what does the motor say?

when i set the driver to 400 and i make 200 steps i make a 180° turn as expected. so idk why its failing

add some prints to the code using degToStep() to verify the # of steps calculated and the # specified to the driver and visually verify the amount of rotation

Please tell a little bit more about your project. Which board, stepper and driver.
Maybe the MobaTools library is a solution. With MobaTools you can define the target position in degree. The calculation of the needed steps is done by the lib

Turns out the formular was correct but i calculated the steps twice on accident messing it up. basically what i did was this:

degreeToSteps(degreeToSteps(90, 400));

i used degreeToSteps in function A that goes to function B and in function B i apparently used degreeToSteps again making it all silly

Im building a 6DOF robot and i already made a lot of custom functions to calculate and set everything up including a pc software interfacing with the arduino etc etc etc and i really dont wanna switch now. also my biggest goal with the project is to do as much myself as possible because i wanna learn things and its fun

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