Stepper Motor Spec: Steps per Revolution?

Greetings,

I’m experimenting with my Sparki, and I’d like to know a bit more about the stepper motors that are in this little robot. What’s the number of steps for one complete revolution?

Thanks.

Part Number: 28BYJ-48 – 5V
Find datasheet here: http://www.sensors.co.nz/datasheet/28BYJ-48%20Stepper%20Motor.pdf

Perfect. Thank you.

I see 64 steps per revolution of the motor rotor, and I guess the motor has an internal gear ratio of 64:1, so effectively we have 4096 steps per revolution of the motor shaft.

Furthermore, the Sparki library seems to advance the motors by half steps, so effectively Sparki needs 8192 steps for a complete revolution of a wheel.

If that’s wrong, please correct me.

Okay, I’ll correct myself…

I have found that the 4096 already includes the intermediate or half steps, so 8192 is incorrect. Each stepper motor requires 4096 steps for one complete revolution of the motor shaft.

Calling sparki.motorsRotateSteps(…) with 4096 steps will give one complete revolution of the wheels.

Then again, I just lied a little bit for two reasons…

  1. The motorsRotateSteps() function in the 1.0.5.4b library did not work for me. The problem was that the code was not setting up the speedCount and speedCounter variables. Below is my fix, which mirrors the code in motorRotate(). (I don’t like the code I copied from motorRotate; why use expensive float computation?)

[code]void SparkiClass::motorsRotateSteps( int leftDir, int rightDir, int speed, uint32_t steps, bool wait)
{
uint8_t oldSREG = SREG;
cli();
motor_speed[MOTOR_LEFT] = motor_speed[MOTOR_RIGHT] = speed;
step_dir[MOTOR_LEFT] = leftDir;
step_dir[MOTOR_RIGHT] = rightDir;
remainingSteps[MOTOR_LEFT] = remainingSteps[MOTOR_RIGHT] = steps;

// Fix by wolfw: added code to initialize speedCount[] and speedCounter[]
speedCount[MOTOR_LEFT] = speedCount[MOTOR_RIGHT] = int(100.0/float(motor_speed[motor])*5.0);
speedCounter[MOTOR_LEFT] = speedCounter[MOTOR_RIGHT] = speedCount[MOTOR_LEFT];

isRunning[MOTOR_LEFT] = isRunning[MOTOR_RIGHT] = true;

SREG = oldSREG;
sei();
if( wait)
{
while ( areMotorsRunning() ){
delay(10); // remainingSteps is decrimented in the timer callback
}
}

}[/code]

  1. 4096 steps actually yield a little more than one complete turn, and this error seems to accumulate over multiple turns. So far, I don’t understand what’s causing this error.

Hi, It seems that you’re mixing left and right’s in your fix…
Dirk

The motorsRotateSteps function in the current library is declared this way:

so the directions of the left and right wheels can be controlled independently (via the leftDir and rightDir parameters), but the speed is common to both. As a result, the same magic speed number as calculated by

needs to be assigned to the speedCount and speedCounter variables of both wheel motors:

speedCount[MOTOR_LEFT] speedCount[MOTOR_RIGHT] speedCounter[MOTOR_LEFT] speedCounter[MOTOR_RIGHT]

I agree that the code looks confusing, but at least for now, I intentionally matched the style of other, similar code that’s already in the library.

The library really needs some sort of motorsRotateSteps function (or set of functions) that can control the each of the wheels as well as the gripper individually. Today, the motorsRotateSteps function cannot control the gripper motor, although the “while ( areMotorsRunning() )” in that function actually tests for whether any of the motors, including the gripper, is running, so there’s another subtle (but possibly benign) bug there.