Modbus - Color Bricklet

This is the description of the Modbus protocol for the Color Bricklet. General information and technical specifications for the Color Bricklet are summarized in its hardware description.

API

A general description of the Modbus protocol structure can be found here.

Basic Functions

BrickletColor.get_color
Function ID:
  • 1
Request:
  • empty payload
Response:
  • r – Type: uint16, Range: [0 to 216 - 1]
  • g – Type: uint16, Range: [0 to 216 - 1]
  • b – Type: uint16, Range: [0 to 216 - 1]
  • c – Type: uint16, Range: [0 to 216 - 1]

Returns the measured color of the sensor.

The red (r), green (g), blue (b) and clear (c) colors are measured with four different photodiodes that are responsive at different wavelengths:

Chart Responsivity / Wavelength

If you want to get the color periodically, it is recommended to use the CALLBACK_COLOR callback and set the period with set_color_callback_period.

BrickletColor.light_on
Function ID:
  • 10
Request:
  • empty payload
Response:
  • no response

Turns the LED on.

BrickletColor.light_off
Function ID:
  • 11
Request:
  • empty payload
Response:
  • no response

Turns the LED off.

BrickletColor.is_light_on
Function ID:
  • 12
Request:
  • empty payload
Response:
  • light – Type: uint8, Range: See meanings, Default: 1

Returns the state of the LED. Possible values are:

  • 0: On
  • 1: Off

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

For light:

  • 0 = On
  • 1 = Off
BrickletColor.set_config
Function ID:
  • 13
Request:
  • gain – Type: uint8, Range: See meanings, Default: 3
  • integration_time – Type: uint8, Range: See meanings, Default: 3
Response:
  • no response

Sets the configuration of the sensor. Gain and integration time can be configured in this way.

For configuring the gain:

  • 0: 1x Gain
  • 1: 4x Gain
  • 2: 16x Gain
  • 3: 60x Gain

For configuring the integration time:

  • 0: 2.4ms
  • 1: 24ms
  • 2: 101ms
  • 3: 154ms
  • 4: 700ms

Increasing the gain enables the sensor to detect a color from a higher distance.

The integration time provides a trade-off between conversion time and accuracy. With a longer integration time the values read will be more accurate but it will take longer time to get the conversion results.

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

For gain:

  • 0 = 1x
  • 1 = 4x
  • 2 = 16x
  • 3 = 60x

For integration_time:

  • 0 = 2ms
  • 1 = 24ms
  • 2 = 101ms
  • 3 = 154ms
  • 4 = 700ms
BrickletColor.get_config
Function ID:
  • 14
Request:
  • empty payload
Response:
  • gain – Type: uint8, Range: See meanings, Default: 3
  • integration_time – Type: uint8, Range: See meanings, Default: 3

Returns the configuration as set by set_config.

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

For gain:

  • 0 = 1x
  • 1 = 4x
  • 2 = 16x
  • 3 = 60x

For integration_time:

  • 0 = 2ms
  • 1 = 24ms
  • 2 = 101ms
  • 3 = 154ms
  • 4 = 700ms
BrickletColor.get_illuminance
Function ID:
  • 15
Request:
  • empty payload
Response:
  • illuminance – Type: uint32, Unit: ? lx, Range: [0 to 103438]

Returns the illuminance affected by the gain and integration time as set by set_config. To get the illuminance in Lux apply this formula:

lux = illuminance * 700 / gain / integration_time

To get a correct illuminance measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, see set_config.

BrickletColor.get_color_temperature
Function ID:
  • 16
Request:
  • empty payload
Response:
  • color_temperature – Type: uint16, Unit: 1 K, Range: [0 to 216 - 1]

Returns the color temperature.

To get a correct color temperature measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, see set_config.

Advanced Functions

BrickletColor.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', 'i', '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). The Raspberry Pi HAT (Zero) Brick is always at position 'i' and the Bricklet connected to an Isolator Bricklet is always as position 'z'.

The device identifier numbers can be found here

Callback Configuration Functions

BrickletColor.set_color_callback_period
Function ID:
  • 2
Request:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0
Response:
  • no response

Sets the period with which the CALLBACK_COLOR callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_COLOR callback is only triggered if the color has changed since the last triggering.

BrickletColor.get_color_callback_period
Function ID:
  • 3
Request:
  • empty payload
Response:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0

Returns the period as set by set_color_callback_period.

BrickletColor.set_color_callback_threshold
Function ID:
  • 4
Request:
  • option – Type: char, Range: See meanings, Default: 'x'
  • min_r – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_r – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_g – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_g – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_b – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_b – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_c – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_c – Type: uint16, Range: [0 to 216 - 1], Default: 0
Response:
  • no response

Sets the thresholds for the CALLBACK_COLOR_REACHED callback.

The following options are possible:

Option Description
'x' Callback is turned off
'o' Callback is triggered when the temperature is outside the min and max values
'i' Callback is triggered when the temperature is inside the min and max values
'<' Callback is triggered when the temperature is smaller than the min value (max is ignored)
'>' Callback is triggered when the temperature is greater than the min value (max is ignored)

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

For option:

  • 'x' = Off
  • 'o' = Outside
  • 'i' = Inside
  • '<' = Smaller
  • '>' = Greater
BrickletColor.get_color_callback_threshold
Function ID:
  • 5
Request:
  • empty payload
Response:
  • option – Type: char, Range: See meanings, Default: 'x'
  • min_r – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_r – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_g – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_g – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_b – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_b – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • min_c – Type: uint16, Range: [0 to 216 - 1], Default: 0
  • max_c – Type: uint16, Range: [0 to 216 - 1], Default: 0

Returns the threshold as set by set_color_callback_threshold.

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

For option:

  • 'x' = Off
  • 'o' = Outside
  • 'i' = Inside
  • '<' = Smaller
  • '>' = Greater
BrickletColor.set_debounce_period
Function ID:
  • 6
Request:
  • debounce – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 100
Response:
  • no response

Sets the period with which the threshold callback

is triggered, if the threshold

keeps being reached.

BrickletColor.get_debounce_period
Function ID:
  • 7
Request:
  • empty payload
Response:
  • debounce – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 100

Returns the debounce period as set by set_debounce_period.

BrickletColor.set_illuminance_callback_period
Function ID:
  • 17
Request:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0
Response:
  • no response

Sets the period with which the CALLBACK_ILLUMINANCE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_ILLUMINANCE callback is only triggered if the illuminance has changed since the last triggering.

BrickletColor.get_illuminance_callback_period
Function ID:
  • 18
Request:
  • empty payload
Response:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0

Returns the period as set by set_illuminance_callback_period.

BrickletColor.set_color_temperature_callback_period
Function ID:
  • 19
Request:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0
Response:
  • no response

Sets the period with which the CALLBACK_COLOR_TEMPERATURE callback is triggered periodically. A value of 0 turns the callback off.

The CALLBACK_COLOR_TEMPERATURE callback is only triggered if the color temperature has changed since the last triggering.

BrickletColor.get_color_temperature_callback_period
Function ID:
  • 20
Request:
  • empty payload
Response:
  • period – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1], Default: 0

Returns the period as set by set_color_temperature_callback_period.

Callbacks

BrickletColor.CALLBACK_COLOR
Function ID:
  • 8
Response:
  • r – Type: uint16, Range: [0 to 216 - 1]
  • g – Type: uint16, Range: [0 to 216 - 1]
  • b – Type: uint16, Range: [0 to 216 - 1]
  • c – Type: uint16, Range: [0 to 216 - 1]

This callback is triggered periodically with the period that is set by set_color_callback_period. The response value is the color of the sensor as RGBC.

The CALLBACK_COLOR callback is only triggered if the color has changed since the last triggering.

BrickletColor.CALLBACK_COLOR_REACHED
Function ID:
  • 9
Response:
  • r – Type: uint16, Range: [0 to 216 - 1]
  • g – Type: uint16, Range: [0 to 216 - 1]
  • b – Type: uint16, Range: [0 to 216 - 1]
  • c – Type: uint16, Range: [0 to 216 - 1]

This callback is triggered when the threshold as set by set_color_callback_threshold is reached. The response value is the color of the sensor as RGBC.

If the threshold keeps being reached, the callback is triggered periodically with the period as set by set_debounce_period.

BrickletColor.CALLBACK_ILLUMINANCE
Function ID:
  • 21
Response:
  • illuminance – Type: uint32, Unit: ? lx, Range: [0 to 103438]

This callback is triggered periodically with the period that is set by set_illuminance_callback_period. The response value is the illuminance. See get_illuminance for how to interpret this value.

The CALLBACK_ILLUMINANCE callback is only triggered if the illuminance has changed since the last triggering.

BrickletColor.CALLBACK_COLOR_TEMPERATURE
Function ID:
  • 22
Response:
  • color_temperature – Type: uint16, Unit: 1 K, Range: [0 to 216 - 1]

This callback is triggered periodically with the period that is set by set_color_temperature_callback_period. The response value is the color temperature.

The CALLBACK_COLOR_TEMPERATURE callback is only triggered if the color temperature has changed since the last triggering.