Stepper Motor

Description

Stepper motor drivers are available on the following module:

The OI-Stepper board is designed to drive bipolar stepper motors up to NEMA 24 size, with a supply voltage range from 9V to 30V. Each output, powering a motor phase, supports a nominal current of up to 4.2A RMS (6A peak).

The board uses the PowerSTEP01 driver from STMicroelectronics, a high-performance, fully integrated stepper motor driver. The PowerSTEP01 provides advanced motion control, high microstepping resolution, and robust protection features.

Characteristics

Stepper Motor Driver Characteristics

Parameter

Value

Note

Supported motor size

Up to NEMA 24

Supply voltage

9V – 30V

Board limit (PowerSTEP01 supports up to 85V)

Max current per phase

4.2A RMS (6A peak)

Microstepping

Up to 1/128

Programmable

Driver IC

PowerSTEP01

STMicroelectronics

Protections

  • Overcurrent protection (programmable threshold)

  • Overtemperature protection (thermal shutdown)

  • Undervoltage lockout (UVLO) on all power supplies

  • Short-circuit protection (load and ground)

  • Cross-conduction protection (prevents shoot-through)

  • Open-load detection (running and standby)

  • ESD protection on all pins

Software Features

  • Rich API for motion and parameter control

  • Homing process with limit switch support

  • VSCode extension for parameter configuration and testing

Operation

Homing

The homing command allows you to zero the motor position using a limit switch. The switch (mechanical or inductive, PNP type) must be configured before calling homing.

The motor moves toward the limit switch at the desired speed. Once triggered, it moves slowly in the opposite direction until the switch is released. This position is set as zero, ensuring repeatable and accurate homing regardless of the initial position or speed.

Speed Control

Speed is managed by three parameters: acceleration, maximum speed, and deceleration. These parameters finely tune the motor’s motion profile and are used by the moveRelative and moveAbsolute functions.

The run function spins the motor at a constant speed set by the user, not exceeding the configured maxSpeed.

Stop Modes

Several stop modes are available:

  • Soft Stop: Decelerates to a stop and holds position

  • Hard Stop: Stops immediately and holds position

  • Soft HiZ: Decelerates to a stop and enters high-impedance (HiZ) mode

  • Hard HiZ: Stops immediately and enters HiZ mode

Warning

In hold mode, the motor consumes current and may heat up depending on the holding torque. Avoid prolonged holding to prevent overheating.

In HiZ mode, the motor is unpowered and free to move. Ensure your mechanism is safe if the motor is unpowered.

Power Control

Motor torque is set by several parameters:

PowerSTEP01 Torque Parameters

Parameter

Description

Default

KVAL_ACC

Acceleration torque

16%

KVAL_DEC

Deceleration torque

16%

KVAL_RUN

Running torque

16%

KVAL_HOLD

Holding torque

16%

Back-EMF compensation

Coef. for compensating back-EMF; increase to boost torque

6%

Warning

Do not increase torque or current parameters too quickly. Excessive values can overheat and damage the motor or driver.

Configuration

Parameters can be set in two ways:
  • Via the VSCode extension: parameters are stored in the module and can be exported/imported as JSON

  • In code: functions allow setting speeds and other parameters during initialization

Code examples

The example code below demonstrates how to control a stepper motor with the OI-Stepper module:

#include "OpenIndus.h"
#include "Arduino.h"

OIStepper stepper;

void printTask(void*)
{
    while (1) {    
        Serial.printf("position: %ld | speed: %f\n", 
            stepper.getPosition(MOTOR_1), stepper.getSpeed(MOTOR_1));
        delay(100);
    }
}

void setup(void) 
{
    Serial.begin(115200);

    /* Print task */
    xTaskCreatePinnedToCore(printTask, "Task to print parameters", 10000, NULL, 1, NULL, 0);

    /* Settings */
    stepper.setMaxSpeed(MOTOR_1, 1000);
    stepper.resetHomePosition(MOTOR_1);

    delay(1000);

    /* Homing */
    Serial.printf("Homing\n");
    stepper.attachLimitSwitch(MOTOR_1, DIN_1, ACTIVE_HIGH);
    stepper.homing(MOTOR_1, 800);
    stepper.wait(MOTOR_1);
    Serial.printf("position: %ld\n", stepper.getPosition(MOTOR_1));

    /* Move relative */
    Serial.printf("moveRelative\n");
    stepper.moveRelative(MOTOR_1, 100);
    stepper.wait(MOTOR_1);
    Serial.printf("position: %ld\n", stepper.getPosition(MOTOR_1));

    /* Move relative */
    Serial.printf("moveRelative\n");
    stepper.moveRelative(MOTOR_1, -200);
    stepper.wait(MOTOR_1);
    Serial.printf("position: %ld\n", stepper.getPosition(MOTOR_1));

    /* Move absolute */
    Serial.printf("moveAbsolute\n");
    stepper.moveAbsolute(MOTOR_1, 200);
    stepper.wait(MOTOR_1);
    Serial.printf("position: %ld\n", stepper.getPosition(MOTOR_1));
}

void loop(void) 
{
    delay(1000);
}

Software API

class MotorStepper : public Motor

Public Static Functions

static void attachLimitSwitch(MotorNum_t motor, DIn_Num_t din, Logic_t logic = ACTIVE_HIGH)

Attach a limit switch to the specified motor The first limit switch attached will be used for homing. Limit switches will be used for stopping motor when they will be reached.

Parameters:
  • motor

  • din

  • logic

static void detachLimitSwitch(MotorNum_t motor, DIn_Num_t din)

Detach a limit switch to the specified motor.

Parameters:
  • motor

  • din

static void setStepResolution(MotorNum_t motor, MotorStepResolution_t res)

Set the Step Resolution. Default resolution is 1/16 step.

Parameters:
  • motor

  • res

static void setAcceleration(MotorNum_t motor, float acc)

Set acceleration.

Parameters:
  • motor

  • acc – step/s2

static void setDeceleration(MotorNum_t motor, float dec)

Set deceleration.

Parameters:
  • motor

  • dec – step/s2

static void setMaxSpeed(MotorNum_t motor, float speed)

Set max speed.

Parameters:
  • motor

  • speed – step/s

static void setMinSpeed(MotorNum_t motor, float speed)

Set min speed.

Parameters:
  • motor

  • speed – step/s

static void setFullStepSpeed(MotorNum_t motor, float speed)

Set full step speed. Above this speed, the motor will run in full step.

Parameters:
  • motor

  • speed – step/s

static int32_t getPosition(MotorNum_t motor)

Get the current position.

Parameters:

motor – Motor num

Returns:

int32_t position in step

static float getSpeed(MotorNum_t motor)

Get the current speed.

Parameters:

motor – Motor num

Returns:

float speed in step/s

static MotorStepperStatus_t getStatus(MotorNum_t motor)

Get the motor status without clearing it.

Parameters:

motor – Motor num

Returns:

MotorStepperStatus_t Structure containing parsed motor status information

static void clearStatus(MotorNum_t motor)

Clear the motor status and reset errors.

Parameters:

motor – Motor num

static void resetHomePosition(MotorNum_t motor)

Reset home position without perform homing.

Parameters:

motor

static void setPosition(MotorNum_t motor, int32_t position)

Set the absolute position.

Parameters:
  • motor

  • position – position in step

static void stop(MotorNum_t motor, MotorStopMode_t mode = SOFT_HIZ)

Stop the motor.

Parameters:
  • motor – Motor num

  • mode – Mode [SOFT_STOP, HARD_STOP, SOFT_HIZ, HARD_HIZ]

static void moveAbsolute(MotorNum_t motor, uint32_t position, bool microStep = false)

Go to position.

Parameters:
  • motor

  • position – Absolute position

  • microStep – Default to false. If true, position will be read as microstep position

static void moveRelative(MotorNum_t motor, int32_t position, bool microStep = false)

Move.

Parameters:
  • motor

  • position – Absolute position, can be positive or negative

  • microStep – Default to false. If true, position will be read as microstep position

static void run(MotorNum_t motor, MotorDirection_t direction, float speed)

Stepper Run command.

Parameters:
  • motor[in] Motor num

  • direction[in] Movement direction (FORWARD, REVERSE)

  • speed[in] in step/s

Returns:

None

static void wait(MotorNum_t motor)

Await end of motor movement. If motor is moving with a ‘run’ command, wait will return as soon as the required speed is reach.

Parameters:

motor

static void homing(MotorNum_t motor, float speed)

Run task to perform homing. Please set a limit switch before performing a homing. The motor will run in reverse until it reach the limit switch. Then it will move at min speed until it move out of the sensor. The position will be set at the home position.

Parameters:
  • motor

  • speed

static float getSupplyVoltage(void)

Get the supply voltage.

Returns:

float Supply voltage in volts

static void attachFlagInterrupt(void (*callback)(MotorNum_t, MotoStepperFlag_t))

Attach a flag interrupt for the given motor.

Parameters:

callback – Callback function

static void detachFlagInterrupt(void)

Detach flag interrupt callback for the given motor.

static void triggerLimitSwitch(MotorNum_t motor)

Trigger the limit switch.

Parameters:

motor