TCP/IP - DC Bricklet 2.0

This is the description of the TCP/IP protocol for the DC Bricklet 2.0. General information and technical specifications for the DC Bricklet 2.0 are summarized in its hardware description.

API

A general description of the TCP/IP protocol structure can be found here.

Basic Functions

BrickletDCV2.set_enabled
Function ID:
  • 1
Request:
  • enabled – Type: bool
Response:
  • no response

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

BrickletDCV2.get_enabled
Function ID:
  • 2
Request:
  • empty payload
Response:
  • enabled – Type: bool, Default: false

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

BrickletDCV2.set_velocity
Function ID:
  • 3
Request:
  • velocity – Type: int16, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0
Response:
  • no response

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 set_motion), 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 set_pwm_frequency.

BrickletDCV2.get_velocity
Function ID:
  • 4
Request:
  • empty payload
Response:
  • velocity – Type: int16, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0

Returns the velocity as set by set_velocity.

BrickletDCV2.get_current_velocity
Function ID:
  • 5
Request:
  • empty payload
Response:
  • velocity – Type: int16, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1], Default: 0

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

BrickletDCV2.set_motion
Function ID:
  • 6
Request:
  • acceleration – Type: uint16, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000
  • deceleration – Type: uint16, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000
Response:
  • no response

Sets the acceleration and deceleration 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 and deceleration is set to 0, there is no speed ramping, i.e. a new velocity is immediately given to the motor.

BrickletDCV2.get_motion
Function ID:
  • 7
Request:
  • empty payload
Response:
  • acceleration – Type: uint16, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000
  • deceleration – Type: uint16, Unit: 100/32767 %/s, Range: [0 to 216 - 1], Default: 10000

Returns the acceleration/deceleration as set by set_motion.

BrickletDCV2.full_brake
Function ID:
  • 8
Request:
  • empty payload
Response:
  • no response

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

BrickletDCV2.get_pwm_frequency
Function ID:
  • 12
Request:
  • empty payload
Response:
  • frequency – Type: uint16, Unit: 1 Hz, Range: [1 to 20000], Default: 15000

Returns the PWM frequency as set by set_pwm_frequency.

BrickletDCV2.get_power_statistics
Function ID:
  • 13
Request:
  • empty payload
Response:
  • voltage – Type: uint16, Unit: 1 mV, Range: [0 to 216 - 1]
  • current – Type: uint16, Unit: 1 mA, Range: [0 to 216 - 1]

Returns input voltage and current usage of the driver.

Advanced Functions

BrickletDCV2.set_drive_mode
Function ID:
  • 9
Request:
  • mode – Type: uint8, Range: See meanings, Default: 0
Response:
  • no response

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 meanings are defined for the elements of this function:

For mode:

  • 0 = Drive Brake
  • 1 = Drive Coast
BrickletDCV2.get_drive_mode
Function ID:
  • 10
Request:
  • empty payload
Response:
  • mode – Type: uint8, Range: See meanings, Default: 0

Returns the drive mode, as set by set_drive_mode.

The following meanings are defined for the elements of this function:

For mode:

  • 0 = Drive Brake
  • 1 = Drive Coast
BrickletDCV2.set_pwm_frequency
Function ID:
  • 11
Request:
  • frequency – Type: uint16, Unit: 1 Hz, Range: [1 to 20000], Default: 15000
Response:
  • no response

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.

BrickletDCV2.set_error_led_config
Function ID:
  • 14
Request:
  • config – Type: uint8, Range: See meanings, Default: 3
Response:
  • no response

Configures the error LED to be either turned off, turned on, blink in heartbeat mode or show an error.

If the LED is configured to show errors it has three different states:

  • Off: No error present.
  • 1s interval blinking: Input voltage too low (below 6V).
  • 250ms interval blinking: Overtemperature or overcurrent.

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Error
BrickletDCV2.get_error_led_config
Function ID:
  • 15
Request:
  • empty payload
Response:
  • config – Type: uint8, Range: See meanings, Default: 3

Returns the LED configuration as set by set_error_led_config

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Error
BrickletDCV2.get_spitfp_error_count
Function ID:
  • 234
Request:
  • empty payload
Response:
  • error_count_ack_checksum – Type: uint32, Range: [0 to 232 - 1]
  • error_count_message_checksum – Type: uint32, Range: [0 to 232 - 1]
  • error_count_frame – Type: uint32, Range: [0 to 232 - 1]
  • error_count_overflow – Type: uint32, 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 Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

BrickletDCV2.set_status_led_config
Function ID:
  • 239
Request:
  • config – Type: uint8, Range: See meanings, Default: 3
Response:
  • no response

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Status
BrickletDCV2.get_status_led_config
Function ID:
  • 240
Request:
  • empty payload
Response:
  • config – Type: uint8, Range: See meanings, Default: 3

Returns the configuration as set by set_status_led_config

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Status
BrickletDCV2.get_chip_temperature
Function ID:
  • 242
Request:
  • empty payload
Response:
  • temperature – Type: int16, Unit: 1 °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 bad accuracy. Practically it is only useful as an indicator for temperature changes.

BrickletDCV2.reset
Function ID:
  • 243
Request:
  • empty payload
Response:
  • no response

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

BrickletDCV2.get_identity
Function ID:
  • 255
Request:
  • empty payload
Response:
  • uid – Type: char[8]
  • connected_uid – Type: char[8]
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • firmware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • device_identifier – Type: uint16, Range: [0 to 216 - 1]

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

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here

Callback Configuration Functions

BrickletDCV2.set_emergency_shutdown_callback_configuration
Function ID:
  • 16
Request:
  • enabled – Type: bool, Default: false
Response:
  • no response

Enable/Disable CALLBACK_EMERGENCY_SHUTDOWN callback.

BrickletDCV2.get_emergency_shutdown_callback_configuration
Function ID:
  • 17
Request:
  • empty payload
Response:
  • enabled – Type: bool, Default: true

Returns the callback configuration as set by set_emergency_shutdown_callback_configuration.

BrickletDCV2.set_velocity_reached_callback_configuration
Function ID:
  • 18
Request:
  • enabled – Type: bool, Default: false
Response:
  • no response

Enable/Disable CALLBACK_VELOCITY_REACHED callback.

BrickletDCV2.get_velocity_reached_callback_configuration
Function ID:
  • 19
Request:
  • empty payload
Response:
  • enabled – Type: bool, Default: false

Returns the callback configuration as set by set_velocity_reached_callback_configuration.

BrickletDCV2.set_current_velocity_callback_configuration
Function ID:
  • 20
Request:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0
  • value_has_to_change – Type: bool, Default: false
Response:
  • no response

The period is the period with which the CALLBACK_CURRENT_VELOCITY callback is triggered periodically. A value of 0 turns the callback off.

If the value has to change-parameter is set to true, the callback is only triggered after the value has changed. If the value didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

BrickletDCV2.get_current_velocity_callback_configuration
Function ID:
  • 21
Request:
  • empty payload
Response:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0
  • value_has_to_change – Type: bool, Default: false

Returns the callback configuration as set by set_current_velocity_callback_configuration.

Callbacks

BrickletDCV2.CALLBACK_EMERGENCY_SHUTDOWN
Function ID:
  • 22
Response:
  • empty payload

This callback 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 callback is triggered as well.

If this callback is triggered, the driver chip gets disabled at the same time. That means, set_enabled has to be called to drive the motor again.

Note

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

BrickletDCV2.CALLBACK_VELOCITY_REACHED
Function ID:
  • 23
Response:
  • velocity – Type: int16, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1]

This callback is triggered whenever a set velocity is reached. For example: If a velocity of 0 is present, acceleration is set to 5000 and velocity to 10000, the CALLBACK_VELOCITY_REACHED callback 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 (see set_motion) is set smaller or equal to the maximum acceleration of the motor. Otherwise the motor will lag behind the control value and the callback will be triggered too early.

BrickletDCV2.CALLBACK_CURRENT_VELOCITY
Function ID:
  • 24
Response:
  • velocity – Type: int16, Unit: 100/32767 %, Range: [-215 + 1 to 215 - 1]

This callback is triggered with the period that is set by set_current_velocity_callback_configuration. The response value is the current velocity used by the motor.

The CALLBACK_CURRENT_VELOCITY callback is only triggered after the set period if there is a change in the velocity.

Internal Functions

Internal functions are used for maintenance tasks such as flashing a new firmware of changing the UID of a Bricklet. These task should be performed using Brick Viewer instead of using the internal functions directly.

BrickletDCV2.set_bootloader_mode
Function ID:
  • 235
Request:
  • mode – Type: uint8, Range: See meanings
Response:
  • status – Type: uint8, Range: See meanings

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

The following meanings are defined for the elements of this function:

For mode:

  • 0 = Bootloader
  • 1 = Firmware
  • 2 = Bootloader Wait For Reboot
  • 3 = Firmware Wait For Reboot
  • 4 = Firmware Wait For Erase And Reboot

For status:

  • 0 = OK
  • 1 = Invalid Mode
  • 2 = No Change
  • 3 = Entry Function Not Present
  • 4 = Device Identifier Incorrect
  • 5 = CRC Mismatch
BrickletDCV2.get_bootloader_mode
Function ID:
  • 236
Request:
  • empty payload
Response:
  • mode – Type: uint8, Range: See meanings

Returns the current bootloader mode, see set_bootloader_mode.

The following meanings are defined for the elements of this function:

For mode:

  • 0 = Bootloader
  • 1 = Firmware
  • 2 = Bootloader Wait For Reboot
  • 3 = Firmware Wait For Reboot
  • 4 = Firmware Wait For Erase And Reboot
BrickletDCV2.set_write_firmware_pointer
Function ID:
  • 237
Request:
  • pointer – Type: uint32, Unit: 1 B, Range: [0 to 232 - 1]
Response:
  • no response

Sets the firmware pointer for write_firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

BrickletDCV2.write_firmware
Function ID:
  • 238
Request:
  • data – Type: uint8[64], Range: [0 to 255]
Response:
  • status – Type: uint8, Range: [0 to 255]

Writes 64 Bytes of firmware at the position as written by set_write_firmware_pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

BrickletDCV2.write_uid
Function ID:
  • 248
Request:
  • uid – Type: uint32, Range: [0 to 232 - 1]
Response:
  • no response

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

BrickletDCV2.read_uid
Function ID:
  • 249
Request:
  • empty payload
Response:
  • uid – Type: uint32, Range: [0 to 232 - 1]

Returns the current UID as an integer. Encode as Base58 to get the usual string version.