TCP/IP - Color Bricklet – Tinkerforge

- Getting Started
  - Primer
  - Tutorials
  - FAQ
- Hardware
  - Bricks
  - Bricklets
  - Master Extensions
  - Power Supplies
  - Accessories
  - Timeline
- Software
  - Brick Daemon (brickd)
  - Brick Viewer (brickv)
  - API Bindings
  - Firmwares and Plugins
  - Device Identifier
  - Source Code and Bug Tracking
  - Programming Interface
- Starter Kits
  - Weather Station
  - Hardware Hacking
  - Server Room Monitoring
  - Blinkenlights
  - Internet of Things
  - Camera Slider
- Embedded Boards
  - Raspberry Pi
- Specifications
  - Technical Data
  - TCP/IP Protocol
    - Protocol
    - API
      - Brick Daemon Functions
      - Broadcast Functions
      - General Callbacks
      - Bricks and Bricklets
        - Bricks
        - Bricklets
          - Ambient Light Bricklet
          - Analog In Bricklet
          - Analog Out Bricklet
          - Barometer Bricklet
          - Color Bricklet
            - API
              - Basic Functions
              - Advanced Functions
              - Callback Configuration Functions
              - Callbacks
          - Current12 Bricklet
          - Current25 Bricklet
          - Distance IR Bricklet
          - Distance US Bricklet
          - Dual Button Bricklet
          - Dual Relay Bricklet
          - GPS Bricklet
          - Hall Effect Bricklet
          - Humidity Bricklet
          - Industrial Digital In 4 Bricklet
          - Industrial Digital Out 4 Bricklet
          - Industrial Dual 0-20mA Bricklet
          - Industrial Quad Relay Bricklet
          - IO-16 Bricklet
          - IO-4 Bricklet
          - Joystick Bricklet
          - LCD 16x2 Bricklet
          - LCD 20x4 Bricklet
          - LED Strip Bricklet
          - Line Bricklet
          - Linear Poti Bricklet
          - Moisture Bricklet
          - Motion Detector Bricklet
          - Multi Touch Bricklet
          - NFC/RFID Bricklet
          - Piezo Buzzer Bricklet
          - Piezo Speaker Bricklet
          - PTC Bricklet
          - Remote Switch Bricklet
          - Rotary Encoder Bricklet
          - Rotary Poti Bricklet
          - Segment Display 4x7 Bricklet
          - Solid State Relay Bricklet
          - Sound Intensity Bricklet
          - Temperature Bricklet
          - Temperature IR Bricklet
          - Tilt Bricklet
          - Voltage Bricklet
          - Voltage/Current Bricklet
  - Modbus Protocol
  - Wireshark Dissector

# TCP/IP - Color Bricklet

This is the description of the TCP/IP 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 TCP/IP 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:

  If you want to get the color periodically, it is recommended to use the callback `CALLBACK_COLOR` 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

`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.

`BrickletColor.``get_config`

  Function ID: | 14
  Request: | empty payload

  Response:

  - gain -- uint8
  - integration_time -- uint8

  Returns the configuration as set by `set_config`.

`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.

  `CALLBACK_COLOR` 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).

`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`.

`BrickletColor.``set_debounce_period`

  Function ID: | 6

  Request:

  - debounce -- uint32

  Response: | no response

  Sets the period in ms with which the threshold callback

  - `CALLBACK_COLOR_REACHED`

  is triggered, if the threshold

  - `set_color_callback_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.

  `CALLBACK_ILLUMINANCE` 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.

  `CALLBACK_COLOR_TEMPERATURE` 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.

  `CALLBACK_COLOR` 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.

  `CALLBACK_ILLUMINANCE` 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.

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

The content of this page is licensed under Creative Commons Attribution 3.0 Unported License.