This is the description of the Shell API bindings for the Color Bricklet. General information and technical specifications for the Color Bricklet are summarized in its hardware description.
An installation guide for the Shell API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
1 2 3 4 5 6 7 8 | #!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it
# change to your UID
uid=abc
# get current color
tinkerforge call color-bricklet $uid get-color
|
Download (example-callback.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it
# change to your UID
uid=abc
# set period for color callback to 1s (1000ms)
# note: the color callback is only called every second if the
# color has changed since the last call!
tinkerforge call color-bricklet $uid set-color-callback-period 1000
# handle incoming color callbacks
tinkerforge dispatch color-bricklet $uid color
|
Download (example-threshold.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #!/bin/sh
# connects to localhost:4223 by default, use --host and --port to change it
# change to your UID
uid=abc
# get threshold callbacks with a debounce time of 10 seconds (10000ms)
tinkerforge call color-bricklet $uid set-debounce-period 10000
# Configure threshold for color values,
# RED greater than 100
# GREEN greater than 200
# BLUE greater than 300
# CLEAR greater than 400
tinkerforge call color-bricklet $uid set-color-callback-threshold greater 100 0 200 0 300 0 400 0
# handle incoming color-reached callbacks
tinkerforge dispatch color-bricklet $uid color-reached\
--execute "echo 'Color(R): {r}';
echo 'Color(G): {g}';
echo 'Color(B): {b}';
echo 'Color(C): {c}';
echo '';"
|
Possible exit codes for all tinkerforge commands are:
The common options of the call and dispatch commands are documented here. The specific command structure is shown below.
Parameters: |
|
---|
The call command is used to call a function of the Color Bricklet. It can take several options:
Parameters: |
|
---|
The dispatch command is used to dispatch a callback of the Color Bricklet. It can take several options:
Parameters: |
|
---|
The <function> to be called can take different options depending of its kind. All functions can take the following options:
Getter functions can take the following options:
Setter functions can take the following options:
The --expect-response option for setter functions allows to detect timeouts and other error conditions calls of setters as well. The device will then send a response for this purpose. If this option is not given for a setter function then no response is send and errors are silently ignored, because they cannot be detected.
Parameters: |
|
---|
The <callback> to be dispatched can take several options:
Output: |
|
---|
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 color and set the period with set-color-callback-period.
Output: | no output |
---|
Turns the LED on.
Output: | no output |
---|
Turns the LED off.
Output: |
|
---|
Returns the state of the LED. Possible values are:
The following symbols are available for this function:
Parameters: |
|
---|---|
Output: | no output |
Sets the configuration of the sensor. Gain and integration time can be configured in this way.
For configuring the gain:
For configuring the integration time:
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 symbols are available for this function:
Output: |
|
---|
Returns the configuration as set by set-config.
The following symbols are available for this function:
Output: |
|
---|
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.
Output: |
|
---|
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.
Output: |
|
---|
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.
Parameters: |
|
---|---|
Output: | no output |
Sets the period in ms with which the color callback is triggered periodically. A value of 0 turns the callback off.
color is only triggered if the color has changed since the last triggering.
The default value is 0.
Output: |
|
---|
Returns the period as set by set-color-callback-period.
Parameters: |
|
---|---|
Output: | no output |
Sets the thresholds for the 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 symbols are available for this function:
Output: |
|
---|
Returns the threshold as set by set-color-callback-threshold.
The following symbols are available for this function:
Parameters: |
|
---|---|
Output: | no output |
Sets the period in ms with which the threshold callback
is triggered, if the threshold
keeps being reached.
The default value is 100.
Output: |
|
---|
Returns the debounce period as set by set-debounce-period.
Parameters: |
|
---|---|
Output: | no output |
Sets the period in ms with which the illuminance callback is triggered periodically. A value of 0 turns the callback off.
illuminance is only triggered if the illuminance has changed since the last triggering.
The default value is 0.
Output: |
|
---|
Returns the period as set by set-illuminance-callback-period.
Parameters: |
|
---|---|
Output: | no output |
Sets the period in ms with which the color-temperature callback is triggered periodically. A value of 0 turns the callback off.
color-temperature is only triggered if the color temperature has changed since the last triggering.
The default value is 0.
Output: |
|
---|
Returns the period as set by set-color-temperature-callback-period.
Callbacks can be used to receive time critical or recurring data from the device:
tinkerforge dispatch color-bricklet <uid> example
The available callbacks are described below.
Note
Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.
Output: |
|
---|
This callback is triggered periodically with the period that is set by set-color-callback-period. The parameter is the color of the sensor as RGBC.
color is only triggered if the color has changed since the last triggering.
Output: |
|
---|
This callback is triggered when the threshold as set by set-color-callback-threshold is reached. The parameter 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.
Output: |
|
---|
This callback is triggered periodically with the period that is set by set-illuminance-callback-period. The parameter is the illuminance. See get-illuminance for how to interpret this value.
illuminance is only triggered if the illuminance has changed since the last triggering.
Output: |
|
---|
This callback is triggered periodically with the period that is set by set-color-temperature-callback-period. The parameter is the color temperature in Kelvin.
color-temperature is only triggered if the color temperature has changed since the last triggering.