Skip to content

Serial Command Interface

Florian Rau edited this page May 23, 2023 · 21 revisions

The Bpod Stepper Module can communicate with a PC or a Bpod State Machine using a serial command interface.

Motor Parameters

RMS Current

Depending on the specific driver used, the Bpod Stepper Module can support RMS currents of up to 850mA (TMC2130) or up to 2000mA (TMC5160). The module allows for separate current settings for a motor that is moving ("RMS run current") versus one that is resting ("RMS hold current"). Lowering the hold current is an effective way of keeping the temperature of, both, driver and motor at bay whilst not affecting performance. Setting the hold current to 0 mA will result in a freely moving motor spindle at rest.

  • Set RMS run current

    PUT 1 uInt8:  73 ('I')
    PUT 1 uInt16: RMS run current [mA]
    
  • Get RMS run current

    PUT 2 uInt8:  71, 73 ('GI')
    GET 1 uInt16: RMS run current [mA]
    
  • Set RMS hold current

    PUT 1 uInt8:  73 ('i')
    PUT 1 uInt16: RMS hold current [mA]
    
  • Get RMS hold current

    PUT 2 uInt8:  71, 73 ('Gi')
    GET 1 uInt16: RMS hold current [mA]
    

Chopper Mode

You can select between three different chopper modes: a PWM chopper ("spreadCycle"), a voltage chopper ("stealthChop") and a classical constant off-time chopper. The voltage chopper offers extremely quiet operation at standstill and low to medium speeds. Depending on the use case, the PWM chopper can perform better at higher speeds. The constant off-time chopper will perform similarly to the PWM chopper but produce more noise. Refer to the Trinamic website for more details.

  • Set chopper Mmde

    PUT 1 uInt8:  67 ('C')
    PUT 1 uInt8:  chopper mode [0 = PWM, 1 = voltage, 2 = constant T_OFF]
    
  • Get chopper mode

    PUT 2 uInt8:  71, 67 ('GC')
    GET 1 uInt8:  chopper mode [0 = PWM, 1 = voltage, 2 = constant T_OFF]
    

Movement Parameters

All of the motors movements are defined by an acceleration phase, a peak velocity and a deceleration phase (the sole exception being the emergency stop).

  • Set Acceleration

    This parameter is valid for, both, the acceleration and the deceleration phase.

    PUT 1 uInt8:  65 ('A')
    PUT 1 uInt16: acceleration [steps / s^2]
    
  • Get Acceleration

    PUT 2 uInt8:  71, 65 ('GA')
    GET 1 uInt16: acceleration [steps / s^2]
    
  • Set peak velocity

    PUT 1 uInt8:  86 ('V')
    PUT 1 uInt16: peak velocity [steps / s]
    
  • Get peak velocity

    PUT 2 uInt8:  71, 86 ('GV')
    GET 1 uInt16: peak velocity [steps / s]
    

Control of Movement

The following serial commands control the movement of the motor. All movements can be interrupted by activation of an end-switch or issuance of a stop command. The Stepper Module will try to keep track of the position at all times (it should be able to do so unless there is a loss of steps). This way, you can target absolute positions. Some of the following commands can also be bound to one of the IO ports.

  • Move forwards

    Start continuous movement forwards.

    PUT 1 uInt8: 70 ('F')
    
  • Move backwards

    Start continuous movement backwards.

    PUT 1 uInt8: 66 ('B')
    
  • Move to a relative position

    Move a defined number of steps relative to the current position. Positive numbers will result in clockwise, negative numbers in counter-clockwise rotation.

    PUT 1 uInt8: 83 ('S')
    PUT 1 Int16: relative position [steps]
    
  • Move to an absolute position

    PUT 1 uInt8: 80 ('P')
    PUT 1 Int16: absolut position [steps]
    
  • Move to a predefined target

    See also: predefined targets.

    PUT 1 uInt8: 1 … 9 [target ID]
    
  • Get current position

    This will return the current position of the motor. The command can also be used to monitor ongoing movements.

    PUT 2 uInt8: 71, 80 ('GP')
    GET 1 Int16: absolute position [steps]
    
  • Reset absolute position

    This command will reset the current position to zero (without moving the motor).

    PUT 1 uInt8: 90 ('Z')
    
  • Soft stop

    Decelerate the motor to a complete standstill.

    PUT 1 uInt8: 120 ('x')
    
  • Emergency stop

    Stop the motor abruptly. Depending on motor speed this will lead to a loss of steps.

    PUT 1 uInt8: 88 ('X')
    

Predefined targets

The stepper module can store up to 9 target definitions, either absolute or relative, along with individual peak velocities and accelerations. Movement to one of these targets can be triggered by a single byte serial command (see Moving the Motor). Alternatively, you can bind a trigger to one of the IO ports.

  • Define a target

    PUT 1 uInt8:  84 ('T')
    PUT 1 uInt8:  1 … 9 [target ID]
    PUT 1 Int32:  target position [steps]
    PUT 1 uInt16: peak velocity [steps / s, 0 = use global peak velocity]
    PUT 1 uInt16: acceleration [steps / s^2, 0 = use global acceleration]
    PUT 1 uInt8:  positioning mode [0 = absolute, 1 = relative]
    
  • Get the definition of a target

    PUT 1 uInt8:  71 ('G')
    PUT 1 uInt8:  1 … 9 [target ID]
    GET 1 Int32:  target position [steps]
    GET 1 uInt16: peak velocity [steps / s, 0 = use global peak velocity]
    GET 1 uInt16: acceleration [steps / s^2, 0 = use global acceleration]
    PUT 1 uInt8:  positioning mode [0 = absolute, 1 = relative]
    

IO ports

  • Bind function to IO port

    Each of the 6 IO ports can be configured to trigger specific movement commands. Available trigger configurations are: None (0), Move to predefined target position (1 … 9), start forward rotation (70 / 'F'), start backward rotation (66 / 'B'), soft stop (120 / x), emergency stop (88 / 'X'), forward limit (76 / 'L'), backward limit (74 / 'J').

    PUT 1 uInt8: 77 ('M')
    PUT 1 uInt8: 1 … 6 [IO port]
    PUT 1 uInt8: function [0; 1 … 9; 'F'; 'B'; 'x'; 'X'; 'L'; 'J']
    
  • Get function of IO port

    PUT 2 uInt8: 71, 77 ('GM')
    PUT 1 uInt8: 1 … 6 [IO port]
    GET 1 uInt8: function [0; 1 … 9; 'F'; 'B'; 'x'; 'X'; 'L'; 'J']
    
  • Set input configuration of IO port

    When used as inputs the IO ports can be configured with different input modes: floating, pull-up or pull-down.

    PUT 1 uInt8: 82 ('R')
    PUT 1 uInt8: 1 … 6 [number of IO port]
    PUT 1 uInt8: input configuration [0 = floating; 1 = pull-up; 2 = pull-down]
    
  • Get input configuration of IO port

    PUT 2 uInt8: 71, 82 ('GR')
    PUT 1 uInt8: 1 … 6 [number of IO port]
    GET 1 uInt8: input configuration [0 = floating; 1 = pull-up; 2 = pull-down]
    

EEPROM storage

The Stepper Module can store its configuration to non-volatile memory. This way you can define default values for your specific setup. Stored values will automatically be loaded during start-up of the module. This enables the use of the Stepper Module as a headless unit (i.e., without connection to Bpod or USB host).

  • Store settings to EEPROM

    To store the current configuration to EEPROM:

    PUT 1 uInt8: 69 ('E')
    

    The following values will be stored:

    • maximum velocity,
    • acceleration,
    • RMS current,
    • chopper mode,
    • predefined targets,
    • input resistance of IO ports, and
    • function of IO ports.

System Information

  • Get Hardware version

    Identify the Stepper Module's hardware revision

    PUT 2 uInt8: 71, 72 ('GH')
    GET 1 uInt8: hardware revision [multiplied by 10]
    
  • Get driver version

    Identify the installed stepper driver.

    PUT 2 uInt8: 71, 84 ('GT')
    GET 1 uInt8: driver version [0 = unknown, 17 = TMC2130, 48 = TMC5360]
    
  • Get firmware version / USB handshake

    PUT 1 uInt8:  212
    GET 1 uInt32: firmware version
    
  • Get Module info (reserved)

    PUT 1 uInt8:  255