English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

Step Motor Module

The Step Motor is a stepper motor module with an integrated LV8548MC driver and five-wire, four-phase wiring. The A, B, C, and D inputs on the board control power to the four magnetic pole coils in the stepper motor through the driver, thereby controlling rotation.

Hardware Connection

Connect control pins PIN2, PIN5, PIN12, and PIN13 to the module's A, B, C, and D inputs, respectively, and turn on the independent power supply.

The coil energization sequence affects the motor's rotation speed, the number of steps per full revolution, the step angle, and operating stability. The following three examples demonstrate stepper motor control using three different step modes.

Example Program

  • Case 1: Single-Phase Four-Step
Coil Step1 Step2 Step3 Step4
MotorA HIGH
MotorB HIGH
MotorC HIGH
MotorD HIGH
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <M5Unified.h>

constexpr uint8_t MOTOR_PINS[4] = {2, 5, 12, 13};
constexpr uint32_t STEP_INTERVAL_MS = 5;

constexpr uint8_t STEP_TABLE[4][4] = {
    {1, 0, 0, 0},
    {0, 1, 0, 0},
    {0, 0, 1, 0},
    {0, 0, 0, 1}
};

constexpr uint8_t STEP_COUNT =
    sizeof(STEP_TABLE) / sizeof(STEP_TABLE[0]);

uint8_t stepIndex = 0;

void setup() {
    M5.begin(M5.config());

    for (uint8_t i = 0; i < 4; ++i) {
        pinMode(MOTOR_PINS[i], OUTPUT);
        digitalWrite(MOTOR_PINS[i], LOW);
    }

    M5.Display.fillScreen(TFT_BLACK);
    M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
    M5.Display.setTextSize(2);
    M5.Display.setCursor(10, 100);
    M5.Display.println("Single-phase 4-step");
}

void loop() {
    M5.update();

    for (uint8_t i = 0; i < 4; ++i) {
        digitalWrite(MOTOR_PINS[i],
                     STEP_TABLE[stepIndex][i] ? HIGH : LOW);
    }

    stepIndex = (stepIndex + 1) % STEP_COUNT;
    delay(STEP_INTERVAL_MS);
}

After uploading the program, you should see the following result.

  • Case 2: Dual-Phase Four-Step
Coil Step1 Step2 Step3 Step4
MotorA HIGH HIGH
MotorB HIGH HIGH
MotorC HIGH HIGH
MotorD HIGH HIGH
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <M5Unified.h>

constexpr uint8_t MOTOR_PINS[4] = {2, 5, 12, 13};
constexpr uint32_t STEP_INTERVAL_MS = 5;

constexpr uint8_t STEP_TABLE[4][4] = {
    {1, 1, 0, 0},
    {0, 1, 1, 0},
    {0, 0, 1, 1},
    {1, 0, 0, 1}
};

constexpr uint8_t STEP_COUNT =
    sizeof(STEP_TABLE) / sizeof(STEP_TABLE[0]);

uint8_t stepIndex = 0;

void setup() {
    M5.begin(M5.config());

    for (uint8_t i = 0; i < 4; ++i) {
        pinMode(MOTOR_PINS[i], OUTPUT);
        digitalWrite(MOTOR_PINS[i], LOW);
    }

    M5.Display.fillScreen(TFT_BLACK);
    M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
    M5.Display.setTextSize(2);
    M5.Display.setCursor(10, 100);
    M5.Display.println("Dual-phase 4-step");
}

void loop() {
    M5.update();

    for (uint8_t i = 0; i < 4; ++i) {
        digitalWrite(MOTOR_PINS[i],
                     STEP_TABLE[stepIndex][i] ? HIGH : LOW);
    }

    stepIndex = (stepIndex + 1) % STEP_COUNT;
    delay(STEP_INTERVAL_MS);
}
  • Case 3: Eight-Step Half-Step
Coil Step1 Step2 Step3 Step4 Step5 Step6 Step7 Step8
MotorA HIGH HIGH HIGH
MotorB HIGH HIGH HIGH
MotorC HIGH HIGH HIGH
MotorD HIGH HIGH HIGH
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <M5Unified.h>

constexpr uint8_t MOTOR_PINS[4] = {2, 5, 12, 13};
constexpr uint32_t STEP_INTERVAL_MS = 5;

constexpr uint8_t STEP_TABLE[8][4] = {
    {1, 1, 0, 0},
    {0, 1, 0, 0},
    {0, 1, 1, 0},
    {0, 0, 1, 0},
    {0, 0, 1, 1},
    {0, 0, 0, 1},
    {1, 0, 0, 1},
    {1, 0, 0, 0}
};

constexpr uint8_t STEP_COUNT =
    sizeof(STEP_TABLE) / sizeof(STEP_TABLE[0]);

uint8_t stepIndex = 0;

void setup() {
    M5.begin(M5.config());

    for (uint8_t i = 0; i < 4; ++i) {
        pinMode(MOTOR_PINS[i], OUTPUT);
        digitalWrite(MOTOR_PINS[i], LOW);
    }

    M5.Display.fillScreen(TFT_BLACK);
    M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
    M5.Display.setTextSize(2);
    M5.Display.setCursor(10, 100);
    M5.Display.println("Half-step 8-step");
}

void loop() {
    M5.update();

    for (uint8_t i = 0; i < 4; ++i) {
        digitalWrite(MOTOR_PINS[i],
                     STEP_TABLE[stepIndex][i] ? HIGH : LOW);
    }

    stepIndex = (stepIndex + 1) % STEP_COUNT;
    delay(STEP_INTERVAL_MS);
}
Page Tools
PDF
On This Page