Using the STSPIN220 breakout with Arduino involves wiring up the breakout with a stepper motor to your Arduino-compatible microcontroller and running the provided example code.


Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VDD.
Here is an Adafruit Metro wired up to the breakout with a stepper motor. You'll need to connect the stepper motor power supply to the DC jack on the Metro.
- Stepper motor power supply to Metro DC Jack
- Breakout + terminal block to Metro VIN (red wire)
- Breakout VDD to Metro 5V (red wire)
- Breakout GND to Metro GND (black wire)
- Breakout DIR to Metro pin 2 (blue wire)
- Breakout STEP to Metro pin 3 (orange wire)
- Breakout MS1 to Metro pin 4 (green wire)
- Breakout MS2 to Metro pin 5 (grey wire)
- Breakout EN to Metro pin 6 (pink wire)
- Breakout RST to Metro pin 7 (cyan wire)
- Breakout 1A to stepper motor coil 1 positive (green wire)
- Breakout 2A to stepper motor coil 1 negative (yellow wire)
- Breakout 1B to stepper motor coil 2 positive (red wire)
- Breakout 2B to stepper motor coil 2 negative (black wire)
Check your stepper motor wiring - your motor may have different wire colors or wire order.
Library Installation
You can install the Adafruit_STSPIN library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_STSPIN, and select the Adafruit STSPIN library:
There are no additional dependencies required for this library.
/*! * @file STSPIN220_Basic.ino * * Basic example for the Adafruit STSPIN220 stepper motor driver library. * This example demonstrates how to use the STSPIN220 with Arduino Stepper * library compatible interface. * * Connect: * - STEP pin to Arduino digital pin 2 * - DIR pin to Arduino digital pin 3 * - MODE1 pin to Arduino digital pin 4 (optional) * - MODE2 pin to Arduino digital pin 5 (optional) * - EN/FAULT pin to Arduino digital pin 6 (optional) * - STBY/RESET pin to Arduino digital pin 7 (optional) * * Make sure to connect proper power supply (1.8V-10V) to VS pin * and connect stepper motor to OUTA1, OUTA2, OUTB1, OUTB2 outputs. * * Written by Limor Fried/Ladyada for Adafruit Industries. */ #include <Adafruit_STSPIN220.h> // Define the number of steps per revolution for your stepper motor // Most steppers are 200 steps per revolution (1.8 degrees per step) const int stepsPerRevolution = 200; // Pin connections (adjust according to your wiring) const int DIR_PIN = 2; // Direction pin const int STEP_PIN = 3; // Step clock pin const int MODE1_PIN = 4; // Mode 1 pin (optional, but will let you set microstep mode) const int MODE2_PIN = 5; // Mode 2 pin (optional, but will let you set microstep mode) const int EN_FAULT_PIN = 6; // Enable/Fault pin (optional) const int STBY_RESET_PIN = 7; // Standby/Reset pin (optional, but will let you set microstep mode) // Create stepper object with full pin configuration Adafruit_STSPIN220 myStepper(stepsPerRevolution, STEP_PIN, DIR_PIN, MODE1_PIN, MODE2_PIN, EN_FAULT_PIN, STBY_RESET_PIN); // Alternative: Create stepper object with minimal pin configuration, but we default to 1/16 microsteps! // Adafruit_STSPIN220 myStepper(stepsPerRevolution, STEP_PIN, DIR_PIN); void setup() { Serial.begin(115200); while (!Serial) { delay(10); // Wait for serial port to connect } Serial.println("Adafruit STSPIN220 Stepper Motor Test");delay(100); // Set the speed to 60 RPM myStepper.setSpeed(60); Serial.println("Set speed"); delay(100); // Set microstepping mode to 1/16 steps, this is also // the 'default' if we dont connect the mode/reset pins myStepper.setStepMode(STSPIN220_STEP_1_16); Serial.println("Setup complete. Starting motor test...");delay(100); } void loop() { // Calculate total microsteps for one full revolution int totalMicrosteps = stepsPerRevolution * myStepper.microstepsPerStep(); Serial.print("Stepping forward one revolution ("); Serial.print(totalMicrosteps); Serial.println(" microsteps)..."); myStepper.step(totalMicrosteps); delay(1000); Serial.print("Stepping backward one revolution ("); Serial.print(totalMicrosteps); Serial.println(" microsteps)..."); myStepper.step(-totalMicrosteps); delay(1000); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. The default 1/16 microstepping mode is set. Then, in the loop, the stepper motor is rotated clockwise and counter clockwise.
/*! * @file STSPIN220_MicrostepDemo.ino * * Microstepping demonstration for the Adafruit STSPIN220 stepper motor driver library. * This example steps through each available microstepping mode, performing one full * rotation forward and backward for each setting so you can compare the smoothness. * * Connect: * - DIR pin to Arduino digital pin 2 * - STEP pin to Arduino digital pin 3 * - MODE1 pin to Arduino digital pin 4 (required for mode switching) * - MODE2 pin to Arduino digital pin 5 (required for mode switching) * - EN/FAULT pin to Arduino digital pin 6 (optional) * - STBY/RESET pin to Arduino digital pin 7 (required for mode switching) * * Make sure to connect proper power supply (1.8V-10V) to VS pin * and connect stepper motor to OUTA1, OUTA2, OUTB1, OUTB2 outputs. * * Written by Limor Fried/Ladyada for Adafruit Industries. */ #include <Adafruit_STSPIN220.h> // Define the number of steps per revolution for your stepper motor // Most steppers are 200 steps per revolution (1.8 degrees per step) const int stepsPerRevolution = 200; // Pin connections (all pins required for this demo) const int DIR_PIN = 2; // Direction pin const int STEP_PIN = 3; // Step clock pin const int MODE1_PIN = 4; // Mode 1 pin (required) const int MODE2_PIN = 5; // Mode 2 pin (required) const int EN_FAULT_PIN = 6; // Enable/Fault pin (optional) const int STBY_RESET_PIN = 7; // Standby/Reset pin (required) // Create stepper object with full pin configuration Adafruit_STSPIN220 myStepper(stepsPerRevolution, STEP_PIN, DIR_PIN, MODE1_PIN, MODE2_PIN, EN_FAULT_PIN, STBY_RESET_PIN); // Array of all available step modes stspin220_step_mode_t stepModes[] = { STSPIN220_STEP_FULL, STSPIN220_STEP_1_2, STSPIN220_STEP_1_4, STSPIN220_STEP_1_8, STSPIN220_STEP_1_16, STSPIN220_STEP_1_32, STSPIN220_STEP_1_64, STSPIN220_STEP_1_128, STSPIN220_STEP_1_256 }; // Human-readable names for each mode const char* modeNames[] = { "Full step", "1/2 step", "1/4 step", "1/8 step", "1/16 step", "1/32 step", "1/64 step", "1/128 step", "1/256 step" }; const int numModes = sizeof(stepModes) / sizeof(stepModes[0]); void setup() { Serial.begin(115200); while (!Serial) { delay(10); // Wait for serial port to connect } Serial.println("Adafruit STSPIN220 Microstepping Demo"); Serial.println("====================================="); Serial.println(); Serial.println("This demo will cycle through all microstepping modes,"); Serial.println("performing one rotation forward and backward for each mode."); Serial.println("Watch and listen to compare the smoothness!"); Serial.println(); } void loop() { for (int i = 0; i < numModes; i++) { Serial.print("Mode "); Serial.print(i + 1); Serial.print("/"); Serial.print(numModes); Serial.print(": "); Serial.print(modeNames[i]); Serial.print(" ("); // Set the new step mode if (!myStepper.setStepMode(stepModes[i])) { Serial.println(" - FAILED to set mode!"); continue; } // Reset speed after changing microstepping mode to maintain consistent RPM myStepper.setSpeed(30); int microsteps = myStepper.microstepsPerStep(); Serial.print(microsteps); Serial.println(" microsteps per full step)"); // Calculate total microsteps for one full revolution int32_t totalMicrosteps = (int32_t)stepsPerRevolution * (int32_t)microsteps; Serial.print(" → Forward rotation ("); Serial.print(totalMicrosteps); Serial.print(" microsteps)..."); myStepper.step(totalMicrosteps); Serial.println(" done!"); delay(1000); // Pause between directions Serial.print(" ← Backward rotation ("); Serial.print(totalMicrosteps); Serial.print(" microsteps)..."); myStepper.step(-totalMicrosteps); Serial.println(" done!"); Serial.println(); delay(500); // Pause between modes } Serial.println("Demo complete! Starting over in 2 seconds..."); Serial.println("=============================================="); Serial.println(); delay(2000); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. In the loop, the different microstep modes are cycled. When a new mode is initiated, the stepper motor makes a full rotation clockwise and then counter clockwise. In the Serial Monitor, you'll see output from this process printed out for each microstep mode.
Page last edited June 16, 2025
Text editor powered by tinymce.