openHAB - DC Brick

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

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

Thing

UID:
  • tinkerforge:brickdc:[UID]
Required firmware version:
  • 2.3.5
Firmware update supported:
  • no
Channels:
Actions:
Parameters:
  • Minimum Voltage – Type: decimal, Default: 6, Unit: V, Min: 0, Max: 65.535
  • The minimum voltage in V, below which the Under Voltage channel is triggered. The minimum possible value that works with the DC Brick is 5V. 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 5V.

  • 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 Reached

This channel is triggered whenever a set velocity is reached. For example: If a velocity of 0 is present, acceleration is set to 50%/s and velocity to 100%, the channel will be triggered after about 2 seconds, when the set velocity is actually reached.

Note

Since we can't get any feedback from the DC 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:brickdc:[UID]:BrickDCVelocityReached
Read only:
  • No
Emergency Shutdown

This channel is triggered if either the current consumption is too high (above 5A) or the temperature of the driver chip is too high (above 175°C). These two possibilities are essentially the same, since the temperature will reach this threshold immediately if the motor consumes too much current. In case of a voltage below 3.3V (external or stack) this listener is triggered as well.

If this listener is triggered, the driver chip gets disabled at the same time. That means, the enable-action has to be called to drive the motor again.

Note

This listener only works in Drive/Brake mode. In Drive/Coast mode it is unfortunately impossible to reliably read the overcurrent/overtemperature signal from the driver chip.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickdc:[UID]:BrickDCEmergencyShutdown
Read only:
  • No
Under Voltage

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

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickdc:[UID]:BrickDCUnderVoltage
Read only:
  • No
Current Velocity

The current velocity of the motor. This value is different from the target velocity whenever the motor is currently accelerating to a goal set by the target velocity channel.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickdc:[UID]:BrickDCCurrentVelocity
Read only:
  • Yes
Unit:
  • Percent
Range:
  • -100 Percent to 100 Percent (Step 0.0030518509475997192 Percent)
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 65535
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Target Velocity

The target velocity of the motor. Depending on the acceleration, the motor is not immediately brought to the velocity but smoothly accelerated.

The velocity describes the duty cycle of the PWM with which the motor is controlled, e.g. a velocity of 10% sets a PWM with a 10% duty cycle. You can not only control the duty cycle of the PWM but also the frequency.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickdc:[UID]:BrickDCVelocity
Read only:
  • No
Unit:
  • Percent
Range:
  • -100 Percent to 100 Percent (Step 0.0030518509475997192 Percent)
Acceleration

The acceleration of the motor. It is given in velocity/s. An acceleration of 30%/s means, that every second the velocity is increased by 30% duty cycle.

For example: If the current velocity is 0 and you want to accelerate to a velocity of 50% in 10 seconds, you should set an acceleration of 5%/s.

If acceleration is set to 0, there is no speed ramping, i.e. a new velocity is immediately given to the motor.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickdc:[UID]:BrickDCAcceleration
Read only:
  • No
PWM Frequency

The frequency of the PWM with which the motor is driven. Often a high frequency is less noisy and the motor runs smoother. However, with a low frequency there are less switches and therefore fewer switching losses. Also with most motors lower frequencies enable higher torque.

If you have no idea what all this means, just ignore this function and use the default frequency of 15000Hz, it will very likely work fine.

Type:
  • Number:Frequency
UID:
  • tinkerforge:brickdc:[UID]:BrickDCPWMFrequency
Read only:
  • No
Unit:
  • Hertz
Range:
  • 1 Hertz to 20000 Hertz (Step 1 Hertz)
Enabled

Enables/Disables the driver chip. The driver parameters can be configured (velocity, acceleration, etc) before it is enabled. When disabled, the configuration is kept (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 by setting the velocity to 0 before disabling the motor power. You have to explicitly wait for the appropriate time after setting the velocity before disabling the driver chip function.

Type:
  • Switch
UID:
  • tinkerforge:brickdc:[UID]:BrickDCEnabled
Read only:
  • No
Full Brake

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.

Set the velocity to 0 if you just want to stop the motor.

Type:
  • Commands (String)
UID:
  • tinkerforge:brickdc:[UID]:BrickDCFullBrake
Read only:
  • No
Commands:
  • Accepts any string
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.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:ElectricPotential
UID:
  • tinkerforge:brickdc:[UID]:BrickDCStackInputVoltage
Read only:
  • Yes
Unit:
  • Volt
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
External Input Voltage

The external input voltage is given via the black power input connector on the DC 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.

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:ElectricPotential
UID:
  • tinkerforge:brickdc:[UID]:BrickDCExternalInputVoltage
Read only:
  • Yes
Unit:
  • Volt
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Current Consumption

The current consumption of the motor

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:ElectricCurrent
UID:
  • tinkerforge:brickdc:[UID]:BrickDCCurrentConsumption
Read only:
  • Yes
Unit:
  • Ampere
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Free-wheeling

Enables/disables free-wheeling: If disabled, the motor is always either driving or braking. There is no freewheeling. Advantages are: A more linear correlation between PWM and velocity, more exact accelerations and the possibility to drive with slower velocities. If enabled, the motor is always either driving or freewheeling. Advantages are: Less current consumption and less demands on the motor and driver chip.

Type:
  • Switch
UID:
  • tinkerforge:brickdc:[UID]:BrickDCFreewheeling
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:brickdc:[UID]")
val hwVersion = actions.brickDCGetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickDCSetVelocity(short velocity)
Parameters:
  • velocity – Type: short, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0

Sets the velocity of the motor. Whereas -32767 is full speed backward, 0 is stop and 32767 is full speed forward. Depending on the acceleration (see Acceleration), the motor is not immediately brought to the velocity but smoothly accelerated.

The velocity describes the duty cycle of the PWM with which the motor is controlled, e.g. a velocity of 3277 sets a PWM with a 10% duty cycle. You can not only control the duty cycle of the PWM but also the frequency, see PWM Frequency.

brickDCGetVelocity()
Return Map:
  • velocity – Type: short, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0

Returns the velocity as set by Target Velocity.

brickDCGetCurrentVelocity()
Return Map:
  • velocity – Type: short, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0

Returns the current velocity of the motor. This value is different from Target Velocity whenever the motor is currently accelerating to a goal set by Target Velocity.

brickDCSetAcceleration(int acceleration)
Parameters:
  • acceleration – Type: int, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000

Sets the acceleration of the motor. It is given in velocity/s. An acceleration of 10000 means, that every second the velocity is increased by 10000 (or about 30% duty cycle).

For example: If the current velocity is 0 and you want to accelerate to a velocity of 16000 (about 50% duty cycle) in 10 seconds, you should set an acceleration of 1600.

If acceleration is set to 0, there is no speed ramping, i.e. a new velocity is immediately given to the motor.

brickDCGetAcceleration()
Return Map:
  • acceleration – Type: int, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000

Returns the acceleration as set by Acceleration.

brickDCFullBrake()

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 Target Velocity with 0 if you just want to stop the motor.

brickDCEnable()

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

brickDCDisable()

Disables the driver chip. The configurations are kept (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 Target Velocity with 0 before disabling the motor power. The Target Velocity function will not wait until the motor is actually stopped. You have to explicitly wait for the appropriate time after calling the Target Velocity function before calling the Enabled function.

brickDCIsEnabled()
Return Map:
  • enabled – Type: boolean, Default: false

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

Advanced Actions

brickDCSetPWMFrequency(int frequency)
Parameters:
  • frequency – Type: int, Unit: 1 Hz, Range: [1 to 20000], Default: 15000

Sets the frequency of the PWM with which the motor is driven. Often a high frequency is less noisy and the motor runs smoother. However, with a low frequency there are less switches and therefore fewer switching losses. Also with most motors lower frequencies enable higher torque.

If you have no idea what all this means, just ignore this function and use the default frequency, it will very likely work fine.

brickDCGetPWMFrequency()
Return Map:
  • frequency – Type: int, Unit: 1 Hz, Range: [1 to 20000], Default: 15000

Returns the PWM frequency as set by PWM Frequency.

brickDCGetStackInputVoltage()
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.

brickDCGetExternalInputVoltage()
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 DC 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.

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

Returns the current consumption of the motor.

brickDCSetDriveMode(short mode)
Parameters:
  • mode – Type: short, Range: See constants, Default: 0

Sets the drive mode. Possible modes are:

  • 0 = Drive/Brake
  • 1 = Drive/Coast

These modes are different kinds of motor controls.

In Drive/Brake mode, the motor is always either driving or braking. There is no freewheeling. Advantages are: A more linear correlation between PWM and velocity, more exact accelerations and the possibility to drive with slower velocities.

In Drive/Coast mode, the motor is always either driving or freewheeling. Advantages are: Less current consumption and less demands on the motor and driver chip.

The following constants are available for this function:

For mode:

  • val DRIVE_MODE_DRIVE_BRAKE = 0
  • val DRIVE_MODE_DRIVE_COAST = 1
brickDCGetDriveMode()
Return Map:
  • mode – Type: short, Range: See constants, Default: 0

Returns the drive mode, as set by Free-wheeling.

The following constants are available for this function:

For mode:

  • val DRIVE_MODE_DRIVE_BRAKE = 0
  • val DRIVE_MODE_DRIVE_COAST = 1
brickDCGetIdentity()
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

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

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

New in version 2.3.1 (Firmware).

brickDCGetChipTemperature()
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.

brickDCGetSendTimeoutCount(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.3 (Firmware).

brickDCGetSPITFPBaudrateConfig()
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.5 (Firmware).

brickDCGetSPITFPErrorCount(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).

brickDCGetSPITFPBaudrate(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

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

Returns the minimum voltage as set by the thing configuration