openHAB - Stepper Brick

This is the description of the openHAB API bindings for the Stepper Brick. General information and technical specifications for the Stepper Brick are summarized in its hardware description.

An installation guide for the openHAB API bindings is part of their general description.

Thing

UID:
  • tinkerforge:brickstepper:[UID]
Required firmware version:
  • 2.3.6
Firmware update supported:
  • no
Channels:
Actions:
Parameters:
  • All Data Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • Specifies the update interval for all data in milliseconds. A value of 0 disables automatic updates.

  • Minimum Voltage – Type: decimal, Default: 8, Unit: V, Min: 0, Max: 65.535
  • The minimum voltage in V, below which the Unter Voltage channel is triggered. The minimum possible value that works with the Stepper Brick is 8V. You can use this function to detect the discharge of a battery that is used to drive the stepper motor. If you have a fixed power supply, you likely do not need this functionality. The default value is 8V.

  • Status LED Config – Type: boolean, Default: true
  • The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.

  • SPITFP Enable Dynamic Baudrate – Type: boolean, Default: true
  • The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is enabled, the Brick will try to adapt the baudrate for the communication between Bricks and Bricklets according to the amount of data that is transferred. The baudrate will be increased exponentially if lots of data is sent/received and decreased linearly if little data is sent/received. This lowers the baudrate in applications where little data is transferred (e.g. a weather station) and increases the robustness. If there is lots of data to transfer (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed. In cases where some data has to transferred as fast as possible every few seconds (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn the dynamic baudrate off to get the highest possible performance. The maximum value of the baudrate can be set per port. If the dynamic baudrate is disabled, the maximum baudrate will be used statically.

  • SPITFP Minimum Dynamic Baudrate – Type: integer, Default: 400000, Min: 400000, Max: 2000000
  • See SPITFP Enable Dynamic Baudrate

  • (Maximum) SPITFP Baudrate Port A – Type: integer, Default: 1400000, Min: 400000, Max: 2000000
  • The baudrate for Bricklet port A. If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference you can decrease the baudrate. If the dynamic baudrate feature is enabled, this is the maximum baudrate. Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in you applications we recommend to not change the baudrate.

  • (Maximum) SPITFP Baudrate Port B – Type: integer, Default: 1400000, Min: 400000, Max: 2000000
  • The baudrate for Bricklet port B. If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference you can decrease the baudrate. If the dynamic baudrate feature is enabled, this is the maximum baudrate. Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in you applications we recommend to not change the baudrate.

Channels

Velocity

The current velocity of the stepper motor in steps per second.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperCurrentVelocity
Read only:
  • Yes
Position

The current position of the stepper motor in steps. On startup the position is 0.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperCurrentPosition
Read only:
  • Yes
Remaining Steps

The remaining steps of the last call of the setSteps() action.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperRemainingSteps
Read only:
  • Yes
Stack Voltage

The stack input voltage in V. The stack input voltage is the voltage that is supplied via the stack, i.e. it is given by a Step-Down or Step-Up Power Supply.

Type:
  • Number:ElectricPotential
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperStackVoltage
Read only:
  • Yes
Unit:
  • Volt
External Voltage

The external input voltage in mV. The external input voltage is given via the black power input connector on the Stepper Brick.

If there is an external input voltage and a stack input voltage, the motor will be driven by the external input voltage. If there is only a stack voltage present, the motor will be driven by this voltage.

<b>Warning: This means, if you have a high stack voltage and a low external voltage, the motor will be driven with the low external voltage. If you then remove the external connection, it will immediately be driven by the high stack voltage</b>

Type:
  • Number:ElectricPotential
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperExternalVoltage
Read only:
  • Yes
Unit:
  • Volt
Current Consumption

The current consumption of the motor in A.

Type:
  • Number:ElectricCurrent
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperCurrentConsumption
Read only:
  • Yes
Unit:
  • Ampere
State

State of the brick:

  • Stop = 1
  • Acceleration = 2
  • Run = 3
  • Deacceleration = 4
  • Direction change to forward = 5
  • Direction change to backward = 6
Type:
  • Number
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperState
Read only:
  • Yes
Previous State

State of the brick:

  • Stop = 1
  • Acceleration = 2
  • Run = 3
  • Deacceleration = 4
  • Direction change to forward = 5
  • Direction change to backward = 6
Type:
  • Number
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperPreviousState
Read only:
  • Yes
Position Reached

This channel is triggered when a position set by the setSteps or setTargetPosition action is reached.

Note

Since we can't get any feedback from the stepper motor, this only works if the acceleration is set smaller or equal to the maximum acceleration of the motor. Otherwise the motor will lag behind the control value and the listener will be triggered too early.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperPositionReached
Read only:
  • No
Unter Voltage

This channel is triggered when the input voltage drops below the configured minimum voltage.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickstepper:[UID]:BrickStepperUnterVoltage
Read only:
  • No

Actions

Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:

val actions = getActions("tinkerforge", "tinkerforge:brickstepper:[UID]")
val hwVersion = actions.brickStepperGetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickStepperSetMaxVelocity(int velocity)
Parameters:
  • velocity – Type: int, Unit: 1 1/s, Range: [0 to 216 - 1]

Sets the maximum velocity of the stepper motor. This function does not start the motor, it merely sets the maximum velocity the stepper motor is accelerated to. To get the motor running use either SetTargetPosition(), SetSteps(), DriveForward() or DriveBackward().

brickStepperGetMaxVelocity()
Return Map:
  • velocity – Type: int, Unit: 1 1/s, Range: [0 to 216 - 1]

Returns the velocity as set by SetMaxVelocity().

brickStepperGetCurrentVelocity()
Return Map:
  • velocity – Type: int, Unit: 1 1/s, Range: [0 to 216 - 1]

Returns the current velocity of the stepper motor.

brickStepperSetSpeedRamping(int acceleration, int deacceleration)
Parameters:
  • acceleration – Type: int, Unit: 1 1/s², Range: [0 to 216 - 1], Default: 1000
  • deacceleration – Type: int, Unit: 1 1/s², Range: [0 to 216 - 1], Default: 1000

Sets the acceleration and deacceleration of the stepper motor. An acceleration of 1000 means, that every second the velocity is increased by 1000 steps/s.

For example: If the current velocity is 0 and you want to accelerate to a velocity of 8000 steps/s in 10 seconds, you should set an acceleration of 800 steps/s².

An acceleration/deacceleration of 0 means instantaneous acceleration/deacceleration (not recommended)

brickStepperGetSpeedRamping()
Return Map:
  • acceleration – Type: int, Unit: 1 1/s², Range: [0 to 216 - 1], Default: 1000
  • deacceleration – Type: int, Unit: 1 1/s², Range: [0 to 216 - 1], Default: 1000

Returns the acceleration and deacceleration as set by SetSpeedRamping().

brickStepperFullBrake()

Executes an active full brake.

Warning

This function is for emergency purposes, where an immediate brake is necessary. Depending on the current velocity and the strength of the motor, a full brake can be quite violent.

Call Stop() if you just want to stop the motor.

brickStepperSetSteps(int steps)
Parameters:
  • steps – Type: int, Range: [-231 to 231 - 1]

Sets the number of steps the stepper motor should run. Positive values will drive the motor forward and negative values backward. The velocity, acceleration and deacceleration as set by SetMaxVelocity() and SetSpeedRamping() will be used.

brickStepperGetSteps()
Return Map:
  • steps – Type: int, Range: [-231 to 231 - 1]

Returns the last steps as set by SetSteps().

brickStepperGetRemainingSteps()
Return Map:
  • steps – Type: int, Range: [-231 to 231 - 1]

Returns the remaining steps of the last call of SetSteps(). For example, if SetSteps() is called with 2000 and GetRemainingSteps() is called after the motor has run for 500 steps, it will return 1500.

brickStepperDriveForward()

Drives the stepper motor forward until DriveBackward() or Stop() is called. The velocity, acceleration and deacceleration as set by SetMaxVelocity() and SetSpeedRamping() will be used.

brickStepperDriveBackward()

Drives the stepper motor backward until DriveForward() or Stop() is triggered. The velocity, acceleration and deacceleration as set by SetMaxVelocity() and SetSpeedRamping() will be used.

brickStepperStop()

Stops the stepper motor with the deacceleration as set by SetSpeedRamping().

brickStepperSetMotorCurrent(int current)
Parameters:
  • current – Type: int, Unit: 1 mA, Range: [100 to 2291], Default: 800

Sets the current with which the motor will be driven.

Warning

Do not set this value above the specifications of your stepper motor. Otherwise it may damage your motor.

brickStepperGetMotorCurrent()
Return Map:
  • current – Type: int, Unit: 1 mA, Range: [100 to 2291], Default: 800

Returns the current as set by SetMotorCurrent().

brickStepperEnable()

Enables the driver chip. The driver parameters can be configured (maximum velocity, acceleration, etc) before it is enabled.

brickStepperDisable()

Disables the driver chip. The configurations are kept (maximum velocity, acceleration, etc) but the motor is not driven until it is enabled again.

Warning

Disabling the driver chip while the motor is still turning can damage the driver chip. The motor should be stopped calling Stop() function before disabling the motor power. The Stop() function will not wait until the motor is actually stopped. You have to explicitly wait for the appropriate time after calling the Stop() function before calling the Disable() function.

brickStepperIsEnabled()
Return Map:
  • enabled – Type: boolean

Returns true if the driver chip is enabled, false otherwise.

Advanced Actions

brickStepperSetCurrentPosition(int position)
Parameters:
  • position – Type: int, Range: [-231 to 231 - 1]

Sets the current steps of the internal step counter. This can be used to set the current position to 0 when some kind of starting position is reached (e.g. when a CNC machine reaches a corner).

brickStepperGetCurrentPosition()
Return Map:
  • position – Type: int, Range: [-231 to 231 - 1]

Returns the current position of the stepper motor in steps. On startup the position is 0. The steps are counted with all possible driving functions (SetTargetPosition(), SetSteps(), DriveForward() or DriveBackward()). It also is possible to reset the steps to 0 or set them to any other desired value with SetCurrentPosition().

brickStepperSetTargetPosition(int position)
Parameters:
  • position – Type: int, Range: [-231 to 231 - 1]

Sets the target position of the stepper motor in steps. For example, if the current position of the motor is 500 and SetTargetPosition() is called with 1000, the stepper motor will drive 500 steps forward. It will use the velocity, acceleration and deacceleration as set by SetMaxVelocity() and SetSpeedRamping().

A call of SetTargetPosition() with the parameter x is equivalent to a call of SetSteps() with the parameter (x - GetCurrentPosition()).

brickStepperGetTargetPosition()
Return Map:
  • position – Type: int, Range: [-231 to 231 - 1]

Returns the last target position as set by SetTargetPosition().

brickStepperSetStepMode(short mode)
Parameters:
  • mode – Type: short, Range: See constants, Default: 8

Sets the step mode of the stepper motor. Possible values are:

  • Full Step = 1
  • Half Step = 2
  • Quarter Step = 4
  • Eighth Step = 8

A higher value will increase the resolution and decrease the torque of the stepper motor.

The following constants are available for this function:

For mode:

  • val STEP_MODE_FULL_STEP = 1
  • val STEP_MODE_HALF_STEP = 2
  • val STEP_MODE_QUARTER_STEP = 4
  • val STEP_MODE_EIGHTH_STEP = 8
brickStepperGetStepMode()
Return Map:
  • mode – Type: short, Range: See constants, Default: 8

Returns the step mode as set by SetStepMode().

The following constants are available for this function:

For mode:

  • val STEP_MODE_FULL_STEP = 1
  • val STEP_MODE_HALF_STEP = 2
  • val STEP_MODE_QUARTER_STEP = 4
  • val STEP_MODE_EIGHTH_STEP = 8
brickStepperGetStackInputVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]

Returns the stack input voltage. The stack input voltage is the voltage that is supplied via the stack, i.e. it is given by a Step-Down or Step-Up Power Supply.

brickStepperGetExternalInputVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]

Returns the external input voltage. The external input voltage is given via the black power input connector on the Stepper Brick.

If there is an external input voltage and a stack input voltage, the motor will be driven by the external input voltage. If there is only a stack voltage present, the motor will be driven by this voltage.

Warning

This means, if you have a high stack voltage and a low external voltage, the motor will be driven with the low external voltage. If you then remove the external connection, it will immediately be driven by the high stack voltage

brickStepperGetCurrentConsumption()
Return Map:
  • current – Type: int, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the current consumption of the motor.

brickStepperSetDecay(int decay)
Parameters:
  • decay – Type: int, Range: [0 to 216 - 1], Default: 10000

Sets the decay mode of the stepper motor. A value of 0 sets the fast decay mode, a value of 65535 sets the slow decay mode and a value in between sets the mixed decay mode.

Changing the decay mode is only possible if synchronous rectification is enabled (see SetSyncRect()).

For a good explanation of the different decay modes see this blog post by Avayan.

A good decay mode is unfortunately different for every motor. The best way to work out a good decay mode for your stepper motor, if you can't measure the current with an oscilloscope, is to listen to the sound of the motor. If the value is too low, you often hear a high pitched sound and if it is too high you can often hear a humming sound.

Generally, fast decay mode (small value) will be noisier but also allow higher motor speeds.

Note

There is unfortunately no formula to calculate a perfect decay mode for a given stepper motor. If you have problems with loud noises or the maximum motor speed is too slow, you should try to tinker with the decay value

brickStepperGetDecay()
Return Map:
  • decay – Type: int, Range: [0 to 216 - 1], Default: 10000

Returns the decay mode as set by SetDecay().

brickStepperSetSyncRect(boolean syncRect)
Parameters:
  • syncRect – Type: boolean, Default: false

Turns synchronous rectification on or off (true or false).

With synchronous rectification on, the decay can be changed (see SetDecay()). Without synchronous rectification fast decay is used.

For an explanation of synchronous rectification see here.

Warning

If you want to use high speeds (> 10000 steps/s) for a large stepper motor with a large inductivity we strongly suggest that you disable synchronous rectification. Otherwise the Brick may not be able to cope with the load and overheat.

brickStepperIsSyncRect()
Return Map:
  • syncRect – Type: boolean, Default: false

Returns true if synchronous rectification is enabled, false otherwise.

brickStepperSetTimeBase(long timeBase)
Parameters:
  • timeBase – Type: long, Unit: 1 s, Range: [0 to 232 - 1], Default: 1

Sets the time base of the velocity and the acceleration of the stepper brick.

For example, if you want to make one step every 1.5 seconds, you can set the time base to 15 and the velocity to 10. Now the velocity is 10steps/15s = 1steps/1.5s.

brickStepperGetTimeBase()
Return Map:
  • timeBase – Type: long, Unit: 1 s, Range: [0 to 232 - 1], Default: 1

Returns the time base as set by SetTimeBase().

brickStepperGetAllData()
Return Map:
  • currentVelocity – Type: int, Unit: 1 1/s, Range: [0 to 216 - 1]
  • currentPosition – Type: int, Range: [-231 to 231 - 1]
  • remainingSteps – Type: int, Range: [-231 to 231 - 1]
  • stackVoltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]
  • externalVoltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]
  • currentConsumption – Type: int, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the following parameters: The current velocity, the current position, the remaining steps, the stack voltage, the external voltage and the current consumption of the stepper motor.

brickStepperGetIdentity()
Return Map:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['0' to '8']
  • hardwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – Type: int, Range: [0 to 216 - 1]

Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.

The position is the position in the stack from '0' (bottom) to '8' (top).

The device identifier numbers can be found here

brickStepperIsStatusLEDEnabled()
Return Map:
  • enabled – Type: boolean, Default: true

Returns true if the status LED is enabled, false otherwise.

New in version 2.3.1 (Firmware).

brickStepperGetChipTemperature()
Return Map:
  • temperature – Type: short, Unit: 1/10 °C, Range: [-215 to 215 - 1]

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has an accuracy of ±15%. Practically it is only useful as an indicator for temperature changes.

brickStepperGetSendTimeoutCount(short communicationMethod)
Parameters:
  • communicationMethod – Type: short, Range: See constants
Return Map:
  • timeoutCount – Type: long, Range: [0 to 232 - 1]

Returns the timeout count for the different communication methods.

The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.

This function is mostly used for debugging during development, in normal operation the counters should nearly always stay at 0.

The following constants are available for this function:

For communicationMethod:

  • val COMMUNICATION_METHOD_NONE = 0
  • val COMMUNICATION_METHOD_USB = 1
  • val COMMUNICATION_METHOD_SPI_STACK = 2
  • val COMMUNICATION_METHOD_CHIBI = 3
  • val COMMUNICATION_METHOD_RS485 = 4
  • val COMMUNICATION_METHOD_WIFI = 5
  • val COMMUNICATION_METHOD_ETHERNET = 6
  • val COMMUNICATION_METHOD_WIFI_V2 = 7

New in version 2.3.4 (Firmware).

brickStepperGetSPITFPBaudrateConfig()
Return Map:
  • enableDynamicBaudrate – Type: boolean, Default: true
  • minimumDynamicBaudrate – Type: long, Unit: 1 Bd, Range: [400000 to 2000000], Default: 400000

Returns the baudrate config, see the thing configuration.

New in version 2.3.6 (Firmware).

brickStepperGetSPITFPErrorCount(char brickletPort)
Parameters:
  • brickletPort – Type: char, Range: ['a' to 'b']
Return Map:
  • errorCountACKChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountMessageChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountFrame – Type: long, Range: [0 to 232 - 1]
  • errorCountOverflow – Type: long, Range: [0 to 232 - 1]

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Brick side. All Bricklets have a similar function that returns the errors on the Bricklet side.

New in version 2.3.3 (Firmware).

brickStepperGetSPITFPBaudrate(char brickletPort)
Parameters:
  • brickletPort – Type: char, Range: ['a' to 'b']
Return Map:
  • baudrate – Type: long, Unit: 1 Bd, Range: [400000 to 2000000], Default: 1400000

Returns the baudrate for a given Bricklet port, see the thing configuration.

New in version 2.3.3 (Firmware).

Trigger Channel Configuration Actions

brickStepperGetAllDataPeriod()
Return Map:
  • period – Type: long, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0

Returns the period as set by the thing configuration.