USB Stepper Motor Controller

Description

USB Stepper Controller Top View USB Stepper Controller Bottom View

The miniature USB Stepper Motor Conteroller by electrobee allows to control a single bipolar motor from your Linux, Mac or Windows computer. Use multiple controllers and a USB hub to control multiple stepper motors.

Specifications

  • Controls one bipolar stepper motor
  • USB 1.1, compatible with USB 2.0
  • 1/2 step resolution
  • Up to 2A per motor coil (adjustable via a trimpot)
  • 8-35V motor voltage
  • Software adjustable step frequency (up to 100k halfsteps/s)
  • Speed ramping (acceleration, deceleration)
  • Dimensions: 5.4×3.0x1.3cm3
  • Mass: 13g
  • Linux, Mac OS X and Windows support
  • Open source firmware and library
  • Sample source code

Programming Environment

Supported Operating Systems

  • Linux
  • Mac OS X
  • Windows 7/Vista/XP/2000 (32-bit)
  • Windows 7/Vista/XP (64-bit) 1)

Supported Languages

  • C/C++
  • Command line interface

Connecting Bipolar Stepper Motors

Connectors

The USB Stepper Motor Controller has three connectors: USB, DC input and stepper motor connector. The USB connector is a mini-B type. The DC connector is a high current jack with 2.5mm inner diameter and 5.5mm outer diameter (mates with Digi-Key Part # CP3-1001-ND). The stepper motor connector is a terminal block with a pitch of 5mm. You can directly connect 14-22 AWG stripped wires.

Stepper Wiring

It's possible to use most 4, 6 and 8 wire stepper motors in bipolar mode as shown above. 8-wire steppers can be connected either with the coils in series or in parallel. With parallel wiring the motor current can be higher while the inductance is lower which is useful if you would like to run the motor at higher speeds. 5 wire steppers are usually unipolar only and cannot be used with this controller.

Basic Operation

The stepper controller keeps track of the stepper position (a 32 bit signed integer). You can set a target position and the stepper will move towards that target while updating the current position. You can also reset that position counter to 0 or any other value like 1000 or -500. Once the stepper finishes moving it sends an interrupt signal to the computer to provide a notification. The computer program might then decide to send a new command. It's not recommended to make any queries to the stepper controller while the stepper is moving as it might result in slight glitches.

The USB Stepper Motor Controller has a speed ramping algorithm to accelerate and decelerate the stepper motor. This permits moving higher loads and accelerating to higher speeds. If you would rather move the stepper at the maximum speed you set all the time, you can disable the speed ramping by setting the acceleration parameter to 0.

Setting Up

Linux

Requirements

  • GCC toolchain with C compiler
  • libusb 0.1.* development package

Building Code

@:~/usb-stepper-1.0$ make -C libstepper && make -C step

Running the step Tool

You may need to run step as superuser.

@:~/usb-stepper-1.0/step$ sudo ./step

Mac OS X

Requirements

Install libusb

After you have MacPorts installed, install libusb:

@:~/usb-stepper-1.0$ sudo port install libusb-compat

Installing Driver

Open terminal and execute the following commands from the usb-stepper folder:

@:~/usb-stepper-1.0$ sudo cp -rf osx/driver/usb-stepper-osx.kext /System/Library/Extensions/
@:~/usb-stepper-1.0$ sudo chmod -R 755 /System/Library/Extensions/usb-stepper-osx.kext
@:~/usb-stepper-1.0$ sudo chown -R 0:0 /System/Library/Extensions/usb-stepper-osx.kext
@:~/usb-stepper-1.0$ sudo rm -rf /System/Library/Extensions.mkext

Reboot system. There is a pre-built step tool inside the osx/ folder that you can use to test control of a stepper motor.

Building Code

@:~/usb-stepper-1.0$ make -C libstepper && make -C step

Windows

Requirements

Installing Driver

If on Windows Vista or Windows 7, you need to enable Test Mode as the libusb driver is unsigned. Run Driver Signature Enforcement Overrider and enable test mode and reboot. Now you can install the driver from the usb-stepper windows/driver folder.

There is a pre-built step tool inside the windows/ folder that you can use to test control of a stepper motor.

Building Code

First install MinGW and MSYS. Copy usb.h from libusb-win32 to MinGW include folder. Copy libusb.a from libusb-win32 to MinGW lib folder. Open MSYS and type the build commands.

@:~/usb-stepper-1.0$ make -C libstepper -f Makefile.windows && make -C step -f Makefile.windows

Using the step Tool

The step tool is a simple command line utility to control USB stepper motors. Please run it without arguments from the command line for available options.

Usage:
        step stepper_index [command] [command]...

Commands:
        --set-enable={0,1}      1 enables stepper, 0 disables it
        --set-speed=1234        Set max. speed of stepper (halfsteps/s)
        --set-accel=1234        Set acceleration of stepper (halfsteps/s/s)
                                Note: to disable ramping, set to 0
        --set-position=1234     Set current position of stepper (halfsteps)
        --set-target=1234       Set target position of stepper (halfsteps)
        --stop                  Emergency stop
        --get-position          Gets the current position (halfsteps)
        --get-target            Gets the target position (halfsteps)
        --wait-stop=1234        Waits until stepper stops or timeout occurs (ms)
        --sleep=1234            Sleep (ms)

Example:
        step 0 --set-enable=1 --set-speed=200 --set-accel=200 --set-target=1000

Examples

The following example works the following sequence:

  • enable stepper[0]
  • set maximum speed to 200 halfsteps/s
  • set acceleration/deceleration to 200 halfsteps/s
  • reset position to 0
  • move stepper to 1000 halfsteps position and wait until it's done (with timeout of 10000 milliseconds)
  • move stepper back to 0 halfsteps position and wait until it's done (with timeout of 10000 milliseconds)
  • move stepper to -500 halfsteps position and wait until it's done (with timeout of 10000 milliseconds)
$> ./step 0 --set-enable=1 --set-speed=200 --set-accel=200 --set-position=0 --set-target=1000 --wait-stop=10000 --set-target=0 --wait-stop=10000 --set-target=-500 --wait-stop=10000

The next example emergency stops stepper[0] (if it's moving) and then disables it.

$> ./step 0 --stop --set-enable=0

Adjusting Motor Current

Download current-calculator.xls below and follow instructions inside. The trim pot is measured as in the picture below and can be adjusted from 0-10kOhm corresponding to coil current of 0-2A.

Measuring trim pot resistance

libstepper Programming Library

libstepper is a C programming library to control USB stepper motors. Please see stepper.h for the available functions. Also the source code for the step tool provides an example on how to call the library functions.

stepper.h

typedef enum {
  OK,
  STEPPER_DISCONNECTED,
  INVALID_FREQUENCY,
  UNEXPECTED_RESPONSE,
  TIMEOUT
} status_t;
 
typedef uint16_t serial_t;
 
/* initialize steppers - call this function before any other */
void stInit();
 
/* deinitialize steppers - call this function at the end of the program */
void stDeinit();
 
/* gets the number of steppers connected */
unsigned int stGetCount();
 
/* gets the serial number of stepper at given index */
serial_t stGetSerial(unsigned int index);
 
/* enables given stepper if enable != 0, otherwise it's disabled */
status_t stEnable(serial_t serial, unsigned char enable);
 
/* emergency stops given stepper */
status_t stStop(serial_t serial);
 
/* sets frequency base for the given stepper (advanced functionality) */
status_t stSetFrequency(serial_t serial, unsigned int hz);
 
/* sets current position to given value (stepper is not moved) */
status_t stSetPosition(serial_t serial, int32_t position);
 
/* sets target position and the given stepper begins moving to it */
status_t stSetTarget(serial_t serial, int32_t target);
 
/* gets current position of the given stepper */
status_t stGetPosition(serial_t serial, int32_t* position);
 
/* gets current target position that the given stepper is moving to */
status_t stGetTarget(serial_t serial, int32_t* position);
 
/* sets maximum speed of the stepper in halfsteps/s */
status_t stSetMaxSpeed(serial_t serial, uint32_t max_speed);
 
/* sets accelleration/deceleration of stepper in halfsteps/s/s */
status_t stSetAcceleration(serial_t serial, uint32_t accel);
 
/* returns true if stepper is running, false otherwise */
int stRunning(serial_t serial);
 
/* function blocks until stepper stops or timeout occurs */
status_t stWaitStop(serial_t serial, uint32_t timeout_ms);

Downloads

usb-stepper-1.2.zip - drivers, libraries and sample programs (Linux, Mac OS X and Windows)

current-calculator.xls - Spreadsheet to calculate coil current from the position of the trimpot

1) Requires Test Mode

Discussion

arman, 2011/11/18 13:52

Hello. Where can i buy this kit?

Ike, 2012/09/02 20:08

my will be for sale real cheap if i cant get it going soon , this is my second attempt and i am ready to move on to something reliable.

Massimo, 2012/05/26 04:48

Hello. Where can i buy this kit?

Ike, 2012/09/02 20:10

getting one is a lot easier than getting it going , ill be selling mine real soon i am going to give it 1 more shot and im done

amit, 2012/06/06 08:02

helo

amit, 2012/06/06 08:03

Helo

Ike, 2012/09/02 20:06

this things driving me nuts keep getting a no shuch file or directory err at my wits end not as easy as they want you to believe win 7

Ike, 2012/09/02 20:14

1 more thing this thing would be a great find if it was even a little supported, the above instructions for windows is of no use as they simply frustrate you,and whats worse there is no one to tell on this site. i would buy 5 more of these today if it acctually would work. but as it stands right now you could not give me another one.

Ike, 2012/09/02 20:35

well its for sale 10.00 ikielee@hotmail.com

 
start.txt · Last modified: 2013/02/20 21:49 by alexei
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki