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 -- uint16
  • g -- uint16
  • b -- uint16
  • c -- uint16

Returns the measured color of the sensor. The values have a range of 0 to 65535.

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 -- uint8

Returns the state of the LED. Possible values are:

  • 0: On
  • 1: Off

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

  • 0: on, for light
  • 1: off, for light
BrickletColor.set_config
Function ID:

13

Request:
  • gain -- uint8
  • integration_time -- uint8
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 default values are 60x gain and 154ms integration time.

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

  • 0: 1x, for gain
  • 1: 4x, for gain
  • 2: 16x, for gain
  • 3: 60x, for gain
  • 0: 2ms, for integration_time
  • 1: 24ms, for integration_time
  • 2: 101ms, for integration_time
  • 3: 154ms, for integration_time
  • 4: 700ms, for integration_time
BrickletColor.get_config
Function ID:

14

Request:

empty payload

Response:
  • gain -- uint8
  • integration_time -- uint8

Returns the configuration as set by set_config.

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

  • 0: 1x, for gain
  • 1: 4x, for gain
  • 2: 16x, for gain
  • 3: 60x, for gain
  • 0: 2ms, for integration_time
  • 1: 24ms, for integration_time
  • 2: 101ms, for integration_time
  • 3: 154ms, for integration_time
  • 4: 700ms, for integration_time
BrickletColor.get_illuminance
Function ID:

15

Request:

empty payload

Response:
  • illuminance -- uint32

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 themself 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 -- uint16

Returns the color temperature in Kelvin.

To get a correct color temperature measurement make sure that the color values themself 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 -- char[8]
  • connected_uid -- char[8]
  • position -- char
  • hardware_version -- uint8[3]
  • firmware_version -- uint8[3]
  • device_identifier -- uint16

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' or 'd'.

The device identifier numbers can be found here

Callback Configuration Functions

BrickletColor.set_color_callback_period
Function ID:

2

Request:
  • period -- uint32
Response:

no response

Sets the period in ms 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.

The default value is 0.

BrickletColor.get_color_callback_period
Function ID:

3

Request:

empty payload

Response:
  • period -- uint32

Returns the period as set by set_color_callback_period.

BrickletColor.set_color_callback_threshold
Function ID:

4

Request:
  • option -- char
  • min_r -- uint16
  • max_r -- uint16
  • min_g -- uint16
  • max_g -- uint16
  • min_b -- uint16
  • max_b -- uint16
  • min_c -- uint16
  • max_c -- uint16
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 default value is ('x', 0, 0, 0, 0, 0, 0, 0, 0).

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

  • x: off, for option
  • o: outside, for option
  • i: inside, for option
  • <: smaller, for option
  • >: greater, for option
BrickletColor.get_color_callback_threshold
Function ID:

5

Request:

empty payload

Response:
  • option -- char
  • min_r -- uint16
  • max_r -- uint16
  • min_g -- uint16
  • max_g -- uint16
  • min_b -- uint16
  • max_b -- uint16
  • min_c -- uint16
  • max_c -- uint16

Returns the threshold as set by set_color_callback_threshold.

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

  • x: off, for option
  • o: outside, for option
  • i: inside, for option
  • <: smaller, for option
  • >: greater, for option
BrickletColor.set_debounce_period
Function ID:

6

Request:
  • debounce -- uint32
Response:

no response

Sets the period in ms with which the threshold callback

is triggered, if the threshold

keeps being reached.

The default value is 100.

BrickletColor.get_debounce_period
Function ID:

7

Request:

empty payload

Response:
  • debounce -- uint32

Returns the debounce period as set by set_debounce_period.

BrickletColor.set_illuminance_callback_period
Function ID:

17

Request:
  • period -- uint32
Response:

no response

Sets the period in ms 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.

The default value is 0.

BrickletColor.get_illuminance_callback_period
Function ID:

18

Request:

empty payload

Response:
  • period -- uint32

Returns the period as set by set_illuminance_callback_period.

BrickletColor.set_color_temperature_callback_period
Function ID:

19

Request:
  • period -- uint32
Response:

no response

Sets the period in ms 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.

The default value is 0.

BrickletColor.get_color_temperature_callback_period
Function ID:

20

Request:

empty payload

Response:
  • period -- uint32

Returns the period as set by set_color_temperature_callback_period.

Callbacks

BrickletColor.CALLBACK_COLOR
Function ID:

8

Response:
  • r -- uint16
  • g -- uint16
  • b -- uint16
  • c -- uint16

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 -- uint16
  • g -- uint16
  • b -- uint16
  • c -- uint16

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 -- uint32

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 -- uint16

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

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