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.
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.
| Coil | Step1 | Step2 | Step3 | Step4 |
|---|---|---|---|---|
| MotorA | HIGH | |||
| MotorB | HIGH | |||
| MotorC | HIGH | |||
| MotorD | HIGH |
#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.
| Coil | Step1 | Step2 | Step3 | Step4 |
|---|---|---|---|---|
| MotorA | HIGH | HIGH | ||
| MotorB | HIGH | HIGH | ||
| MotorC | HIGH | HIGH | ||
| MotorD | HIGH | HIGH |
#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);
}| 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 |
#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);
}