Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
executable file 90 lines (56 sloc) 2.56 KB

Switec X25 library

This is an Arduino library for driving Switec X25 miniature stepper motors. It was written specifically for the Switec X25.168, and compatible steppers from other manufacturers including the VID29 and MCR1108.

For more information including datasheets see the Gaugette blog.

Usage Notes

This library assumes you are driving the X25 directly from the Arduino IO lines, not through an intermediate controller circuit. A motor can be connected to any 4 Arduino digital output lines. The Arduino Uno has 14 I/O lines, limiting you to three motors. The Mega boards have more.

The rate at which these miniature stepper motors can accelerate is dependent upon the inertia of the needle you are using. You may need to tune the acceleration tables in the library for your needle.


If you read nothing more, please read and understand this:

The update() call is non-blocking. It does NOT move the motor to the target position, it advances the motor at most just one step toward the target position and returns.

The correct way to use this library is:

  • Add a call to update() inside your main loop. It should be called as frequently as possible. It will return quickly if there is nothing to be done. This means for example if you are waiting for serial I/O, you should be calling update() while you are waiting.

  • Call setPosition() whenever you need to change the target position of the motor.

The advantage of this over a blocking/synchronous library is that you can control many motors simultanously, and you wont have long periods of inactivity (and potentially missed I/O events) while your motor is moving.

Using the Library

#include "SwitecX25.h"

// 315 degrees of range = 315x3 steps = 945 steps
// declare motor1 with 945 steps on pins 4-7
SwitecX25 motor1(315*3, 4,5,6,7);

// declare motor2 with 945 steps on pins 8-11
SwitecX25 motor2(315*3, 8,9,10,11);

void setup(void) {

  // run both motors against stops to re-zero;   // this is a slow, blocking operation;  

void loop(void) {
  // update motors frequently to allow them to step

  // do stuff, call motorX.setPosition(step) to 
  // direct needle to new position.
Jump to Line
Something went wrong with that request. Please try again.