USB stepper motor controller – develop your own application

We are constantly trying to offer our valued users as much support as possible. We take into account all their suggestions and wishes. Consequently, we decided to reveal PoStep60 USB communication protocol. In addition to I2C and Modbus serial interface, you will now be able to write your own app to communicate with the USB stepper motor controller.

The API describes all read and write commands for complete driver control. Namely, all the settings we make with PoStep60 application now we can completely perform with custom application as well.

About the USB stepper motor controller PoStep60-256

The PoStep60-256 driver incorporate advanced stepper motor driver and external N-channel MOSFETs to drive a bipolar stepper motor or two brushed DC motors. A driver has micro-stepping indexer integrated, which is capable of step modes from full step to 1/256-step. An ultra-smooth motion profile we achieve using adaptive blanking time and various current decay modes, including an auto-mixed decay mode. A simple step/direction or PWM interface allows easy interfacing to controller circuits. An I2C serial interface or Modbus-RTU over RS485 can we further use to control all the driver functions including position control on board.

All running parameters (output current (torque), micro stepping, step mode, decay mode…) can be set over USB and stored on board for stand-alone operation. Internal shutdown functions are provided for over current protection, short circuit protection, under voltage lockout and over temperature. Fault conditions indicate a FAULT LED, and each fault condition can we read in configuration software. All information about stepper motor driver you can find: stepper motor driver- complete explanation.

The API you may find in updated PoStep60 User Manual.

USB protocol description

PoStep60-256 is USB HID-compliant vendor-defined device. It uses OS’s integrated drivers to communicate with software. No additional drivers are necessary to communicate with device. USB stepper motor controller PoStep60 board uses following descriptors:

Each PoStep60 has it’s own unique serial number. The serial number can be used to enumerate USB device when more then one PoStep60 is connected to computer.

Device uses endpoint IN and endpoint OUT descriptor as shown above. Data package size 64 Bytes is the same for both direction. More information you can find in PoStep60 User manual.

How to start programming

At start, choose your favourite software development tool. For our example we used a VisualStudio19 and libusb.h library. For more advanced applications you will need some additional knowledge about the specific driver which you will find in a IC’s data-sheet. The exact IC type number you can find in a PoStep60 user manual.

In next lines we will introduce basic example how connect to device and send a specific command.

First we define PoStep60 specific PID and VID (product and vendor identity) and declare USB session.

Than we initialize the library and connect to the device using next functions:

dev_handle = libusb_open_device_with_vid_pid(ctx, PID, VID);
libusb_kernel_driver_active(dev_handle, 0);
libusb_claim_interface(dev_handle, 0);

After that we will read PoStep60 info registers. In short, we going to use write_PoStep(data) and read_PoStep(data) functions. In that case we will send a GET DEVICE INFO as output_byte[1] = 0x01 command to the device. It is important that the output_data[63] is always 0x00! The response from the driver will be 64 byte long. As an example we will parse data bytes[8…9] and bytes[44…45] and get driver’s supply voltage and temperature, for instance. More about that you should read in PoStep60 user manual chapter “USB Commands”. Finally we send command to move a stepper motor for few second in one direction and then with double speed to a reverse direction. To achieve that we use commands 0xA1(RUN/SLEEP) and 0x90 (WRITE STEP/DIR DATA).

The entire source code you can download here: USB_PoStep60_example.cpp

USB stepper motor controller – conclusion

For developing custom software we can take as an example PoStep60 application. The driver has quite a range of parameters that can be set. You can choose between different modes of operation. Namely, specify micro-stepping, torque and decay parameters, check for driver’s status, save settings to EEPROM and so on. However, for some of them we must write to driver’s specific registers according to chip datasheet. Please, be aware that writing a specific command can lead to suddenly motor movement!

Useful infos

Stepper motor controller IC link.

Under downloads find PoStep60 user manual.

If you are interested using Modbus read this blog.

Here is our CNC controller: Pokeys57CNC

Related Posts

Making Relay8 really smart - free update...
We present a giant upgrade for PoRelay8 devices, which unlocks...
Read more
Record and export data captured with USB...
This article will show you how to record and export...
Read more
PoScope4 release 3.2
Fix We fixed which was causing software crashes when selecting and...
Read more
Slovenščina »