AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

How-to

Sending serial move commands to a stepper driver

Servo and stepper motion Published 4 min read By AutomateDirectUSA engineering team

Short answer

A stepper driver that takes text commands only acts on a complete frame: an opcode such as FL for a relative move, the step count, and a carriage return (ASCII 13). Convert the operator's distance to steps with the measured steps per engineering unit, then send the assembled string from one validated button event.

On this page
  1. What a complete command frame contains
  2. Convert the operator's distance into steps
  3. A worked example: a 2.5 inch move
  4. Send the frame from one validated event
  5. Commission the link before commanding real travel
  6. Decision
  7. Questions asked

A stepper driver with a text command interface only acts on a complete frame: an opcode that names the operation, a numeric field, and a carriage return (ASCII 13) that marks the end of transmission. A relative move is FL followed by the step count; an absolute move uses FP in the same shape. To drive it from an HMI, your application must assemble that string itself: validate the operator's distance, convert it to motor steps, prepend the opcode, append the terminator, and write it to the serial port. A bare number such as 2500 on the wire tells the driver nothing.

What a complete command frame contains #

Text-command stepper drives, such as host-command drivers documented in a command reference, parse three things in order:

  1. The opcode, for example FL for a relative move or FP for an absolute move.
  2. The numeric field: motor steps, as a plain decimal integer with no units, spaces or labels.
  3. The terminator: a carriage return, decimal character code 13. Command packets in this class of drive are terminated by exactly that character.

Anything else in the string, a unit suffix, extra spaces, or a placeholder copied from a manual's syntax line, belongs in the documentation, not on the wire. Parentheses and placeholder letters in a command listing describe where a value goes; they are not literal characters to transmit.

Convert the operator's distance into steps #

The driver counts steps, not inches or millimeters. Two conversions do the work:

  • steps = distance × steps per engineering unit, or equivalently distance ÷ engineering units per step.
  • steps per engineering unit comes from the commissioned axis: motor steps per revolution, times the configured microstepping, times the mechanical ratio, divided by the travel per revolution (screw lead, pulley circumference or pinion pitch).

The motor's full-step count, typically 200 steps per revolution before microstepping, is only the starting point; measure the finished axis over a real travel distance and keep the measured value. If the calculation yields a fractional step, reject the entry or apply a written rounding rule; never let an implicit integer conversion truncate silently.

A worked example: a 2.5 inch move #

Assume the commissioned stage moves 1.000 inch per 1000 steps, so the engineering units per step are 0.001 inch per step.

  • steps = 2.5 in ÷ 0.001 in/step = 2500 steps
  • assembled command: FL2500 plus carriage return (character code 13)
  • absolute equivalent: FP followed by the absolute step position, which only has meaning after the axis has established a position reference.

The transmitted bytes for the relative move are the characters F, L, 2, 5, 0, 0, then the single terminator byte. The 1000 steps per inch is an example for this axis; your number is whatever the measured axis gives.

Send the frame from one validated event #

Trigger transmission from an explicit Move button or an accepted Enter, never from a text-changed event, which fires while the operator is still typing. The handler below is an illustrative example; StepsPerUnit, MinimumAllowedSteps and MaximumAllowedSteps are application constants you set from the commissioned axis and its travel limits, for example 1000 steps per inch, minus 200000 and plus 200000 steps for a 20 inch stage.

Private Sub btnMove_Click(sender As Object, e As EventArgs) Handles btnMove.Click
    Dim distance As Decimal
    If Not Decimal.TryParse(txtDistance.Text, distance) Then Exit Sub
    Dim calculatedSteps As Decimal = distance * StepsPerUnit
    If calculatedSteps <> Decimal.Truncate(calculatedSteps) Then Exit Sub
    Dim steps As Long = CLng(calculatedSteps)
    If steps < MinimumAllowedSteps OrElse steps > MaximumAllowedSteps Then Exit Sub
    Dim command As String = "FL" & steps.ToString()
    If Not SerialPort1.IsOpen Then SerialPort1.Open()
    SerialPort1.Write(command & Chr(13))
End Sub

Do not use a WriteLine call for the payload: its line-ending behavior depends on the component's configured newline string, which may not be the required single carriage return. Append the terminator explicitly. Read the port's baud rate, character format, flow control and device address from a configuration already proven with the driver's own host utility; a correctly framed command looks dead if one of those settings is wrong. Only one application can own the port, so close the host utility before your application opens it. Pulse scaling, as covered in How to Calculate Step and Direction Servo Pulse Scaling, does not apply here: this link carries text, not a pulse train.

Uncouple or disable hazardous motion as the machine design permits and clear the axis travel before testing; a software step limit supplements physical limit protection, it does not replace it. Then:

  1. Log the exact transmitted text and terminator; for the example the log must show FL2500 and character 13.
  2. Command one small move inside the permitted range and confirm direction before increasing distance.
  3. Mark a reference position and compare commanded with measured travel; correct the steps-per-unit constant rather than adding offsets.
  4. Test invalid text, zero, both over-limit values and a fractional-step distance; each must be rejected without motion.

If the port opens but the driver does not act, inspect the transmitted bytes first, then port ownership, serial settings, cable wiring, driver state and command syntax, in that order; each check is cheaper than the next. Do not reach for motion scaling to fix a framing fault.

Decision #

For a relative move: send FL plus the step count plus a carriage return, with the count derived from the measured steps per engineering unit. For an absolute move: send FP plus the absolute position, only after the axis holds a valid reference. For anything that does not move: fix the frame and the serial settings first; the scaling arithmetic comes after the driver is proven to hear you.

Questions asked

Why does the driver ignore a bare number like 2500 sent to the serial port?

A number by itself carries no instruction: the driver's command parser is waiting for an opcode that names the operation and a terminator that marks the end of the frame. Send FL2500 followed by a carriage return (ASCII 13) instead of the step count alone.

Should I send a line feed after the carriage return?

Only if the driver's command reference calls for one. Many host-command drivers treat the carriage return as the end of transmission; adding a line feed after it can leave stray bytes in the receive buffer that corrupt the next command. Match the exact termination the driver manual documents.

How do I set velocity the same way?

Use the driver's documented velocity opcode in the same frame structure: opcode, the numeric value in the driver's units, then the carriage return. Take the opcode and value range from the driver's command reference, and do not type placeholder parentheses from a manual's syntax description into the actual command.

Can I command motion from the keypad's text-changed event?

No. That event fires on every keystroke, including an incomplete entry such as a lone minus sign or decimal point, so the driver would receive partial commands. Trigger transmission only from an explicit Move button or an accepted Enter, after the full value has been validated.

Keep reading

  • Explainer

    Servo Positioning Resolution Versus Stepper Step Angle Explained

    A 0.018° move needs 360 ÷ 0.018 = 20,000 usable feedback counts per revolution, which come from the encoder and the drive's decoding and scaling, not from the servo label. Matching 3,000 command pulses per revolution on a stepper and a servo only matches command scaling; short-time overload capacity and high-speed performance still differ.

    Servo and stepper motion

  • Troubleshooting

    Why a Closed Loop Stepper Will Not Move Above 200 kHz

    The axis sits dead because the kernel exceeds the drive's documented step input limit, making each high or low state narrower than the input can latch. Set the kernel to half the ceiling, derive steps per mm from the drive's command resolution divided by the screw's travel per revolution, and verify the encoder A-channel polarity at the drive terminals.

    Servo and stepper motion

  • Troubleshooting

    Why a Stepper Stalls When Retargeted During Deceleration

    A stepper that seizes and squeals only when a new, farther target arrives during deceleration is being hit with a step change in STEP pulse frequency at the command handover. The driver follows pulses, not your trajectory. Confirm the frequency jump at the driver's STEP input with a scope, then fix how the motion instruction replaces the move; do not start by changing current or motor size.

    Servo and stepper motion