10. Output Devices
Stepper Motor Control with Xiao RP2040 and A4988 Driver. I Know im still doing step motors but they're fun
For this assignment, I used a Seeed Studio Xiao RP2040 microcontroller to control a stepper motor using an A4988 stepper motor driver.
Components Used
- Xiao RP2040
- A4988 Stepper Motor Driver
- NEMA 17 Stepper Motor
- External 12V Power Supply
PCB and diagram


Connections
Xiao RP2040 → A4988 Driver -------------------------- 3.3V → VDD GND → GND D0 → STEP D1 → DIR Direct from PS → A4988 VMOT (via 12V external supply) NEMA17 coils → A4988 OUT1, OUT2, OUT3, OUT4
Code
Below is the Arduino code used to control the stepper motor.
#define STEP_PIN D0
#define DIR_PIN D1
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
}
void moverMotor(int pasos, int velocidad) {
for (int i = 0; i < pasos; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(velocidad);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(velocidad);
}
}
void loop() {
digitalWrite(DIR_PIN, HIGH);
moverMotor(200, 1000);
delay(1000);
digitalWrite(DIR_PIN, LOW);
moverMotor(200, 1000);
delay(1000);
}
Results
The motor successfully rotates in one direction for one full revolution and then changes direction after a short delay.
Conclusion
This project demonstrates how to use our PCB we manufactured with the Xiao RP2040 and A4988 stepper motor driver.