openHAB - IO-4 Bricklet 2.0

This is the description of the openHAB API bindings for the IO-4 Bricklet 2.0. General information and technical specifications for the IO-4 Bricklet 2.0 are summarized in its hardware description.

An installation guide for the openHAB API bindings is part of their general description.

Thing

UID:
  • tinkerforge:brickletio4v2:[UID]
Required firmware version:
  • 2.0.0
Firmware update supported:
  • yes
Channels:
Actions:
Parameters:
  • Pin Configuration 0 – Type: Choice, Default: Input with pull-up
  • Configures the direction of pin 0. Inputs without pull-up will be floating if nothing is connected. Outputs can have an initial state of low or high.
  • Options: Input with pull-up, Input without pull-up, Output (Initial high), Output (Initial low)

  • Pin Configuration 1 – Type: Choice, Default: Input with pull-up
  • Configures the direction of pin 1. Inputs without pull-up will be floating if nothing is connected. Outputs can have an initial state of low or high.
  • Options: Input with pull-up, Input without pull-up, Output (Initial high), Output (Initial low)

  • Pin Configuration 2 – Type: Choice, Default: Input with pull-up
  • Configures the direction of pin 2. Inputs without pull-up will be floating if nothing is connected. Outputs can have an initial state of low or high.
  • Options: Input with pull-up, Input without pull-up, Output (Initial high), Output (Initial low)

  • Pin Configuration 3 – Type: Choice, Default: Input with pull-up
  • Configures the direction of pin 3. Inputs without pull-up will be floating if nothing is connected. Outputs can have an initial state of low or high.
  • Options: Input with pull-up, Input without pull-up, Output (Initial high), Output (Initial low)

  • Status LED Config – Type: Choice, Default: Show Status
  • 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.
  • Options: Off, On, Show Heartbeat, Show Status

Channels

Input Value Pin 0

The logic level that is currently measured on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2InputPin0
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 0 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Input Value Pin 1

The logic level that is currently measured on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2InputPin1
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 1 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Input Value Pin 2

The logic level that is currently measured on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2InputPin2
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 2 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Input Value Pin 3

The logic level that is currently measured on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2InputPin3
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 3 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Update Interval – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Output Value Pin 0

The logic level that is currently set on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2OutputPin0
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 0 is one of Output (Initial high), Output (Initial low).
Output Value Pin 1

The logic level that is currently set on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2OutputPin1
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 1 is one of Output (Initial high), Output (Initial low).
Output Value Pin 2

The logic level that is currently set on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2OutputPin2
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 2 is one of Output (Initial high), Output (Initial low).
Output Value Pin 3

The logic level that is currently set on the pin.

Type:
  • Switch
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2OutputPin3
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 3 is one of Output (Initial high), Output (Initial low).
Monoflop Pin 0

Triggers a monoflop as configured

Type:
  • Commands (String)
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2MonoflopPin0
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 0 is one of Output (Initial high), Output (Initial low).
Commands:
  • Accepts any string
Parameters:
  • Monoflop Duration – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • The time (in ms) that the pin should hold the configured value.

  • Monoflop Value – Type: boolean, Default: true
  • The desired value of the specified channel. Activated means relay closed and Deactivated means relay open.
Monoflop Pin 1

Triggers a monoflop as configured

Type:
  • Commands (String)
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2MonoflopPin1
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 1 is one of Output (Initial high), Output (Initial low).
Commands:
  • Accepts any string
Parameters:
  • Monoflop Duration – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • The time (in ms) that the pin should hold the configured value.

  • Monoflop Value – Type: boolean, Default: true
  • The desired value of the specified channel. Activated means relay closed and Deactivated means relay open.
Monoflop Pin 2

Triggers a monoflop as configured

Type:
  • Commands (String)
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2MonoflopPin2
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 2 is one of Output (Initial high), Output (Initial low).
Commands:
  • Accepts any string
Parameters:
  • Monoflop Duration – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • The time (in ms) that the pin should hold the configured value.

  • Monoflop Value – Type: boolean, Default: true
  • The desired value of the specified channel. Activated means relay closed and Deactivated means relay open.
Monoflop Pin 3

Triggers a monoflop as configured

Type:
  • Commands (String)
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2MonoflopPin3
Read only:
  • No
Predicate:
  • This channel will only be available if Pin Configuration 3 is one of Output (Initial high), Output (Initial low).
Commands:
  • Accepts any string
Parameters:
  • Monoflop Duration – Type: integer, Default: 1000, Unit: ms, Min: 0, Max: 4294967295
  • The time (in ms) that the pin should hold the configured value.

  • Monoflop Value – Type: boolean, Default: true
  • The desired value of the specified channel. Activated means relay closed and Deactivated means relay open.
Edge Count Pin 0

The current value of the edge counter for the selected channel

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2EdgeCountPin0
Read only:
  • Yes
Predicate:
  • This channel will only be available if Pin Configuration 0 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Edge Type – Type: Choice, Default: Rising
  • The edge type parameter configures if rising edges, falling edges or both are counted.
  • Options: Rising, Falling, Both

  • Debounce Time – Type: integer, Default: 100, Min: 0, Max: 255
  • The debounce time in ms.

  • Reset Edge Count On Update – Type: boolean, Default: false
  • Enabling this will reset the edge counter after OpenHAB reads its value. Use this if you want relative edge counts per update.

  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Edge Count Pin 1

The current value of the edge counter for the selected channel

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2EdgeCountPin1
Read only:
  • Yes
Predicate:
  • This channel will only be available if Pin Configuration 1 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Edge Type – Type: Choice, Default: Rising
  • The edge type parameter configures if rising edges, falling edges or both are counted.
  • Options: Rising, Falling, Both

  • Debounce Time – Type: integer, Default: 100, Min: 0, Max: 255
  • The debounce time in ms.

  • Reset Edge Count On Update – Type: boolean, Default: false
  • Enabling this will reset the edge counter after OpenHAB reads its value. Use this if you want relative edge counts per update.

  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Edge Count Pin 2

The current value of the edge counter for the selected channel

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2EdgeCountPin2
Read only:
  • Yes
Predicate:
  • This channel will only be available if Pin Configuration 2 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Edge Type – Type: Choice, Default: Rising
  • The edge type parameter configures if rising edges, falling edges or both are counted.
  • Options: Rising, Falling, Both

  • Debounce Time – Type: integer, Default: 100, Min: 0, Max: 255
  • The debounce time in ms.

  • Reset Edge Count On Update – Type: boolean, Default: false
  • Enabling this will reset the edge counter after OpenHAB reads its value. Use this if you want relative edge counts per update.

  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.
Edge Count Pin 3

The current value of the edge counter for the selected channel

This channel will only update after the configured update interval, not on changed values.

Type:
  • Number:Dimensionless
UID:
  • tinkerforge:brickletio4v2:[UID]:BrickletIO4V2EdgeCountPin3
Read only:
  • Yes
Predicate:
  • This channel will only be available if Pin Configuration 3 is one of Input with pull-up, Input without pull-up.
Parameters:
  • Edge Type – Type: Choice, Default: Rising
  • The edge type parameter configures if rising edges, falling edges or both are counted.
  • Options: Rising, Falling, Both

  • Debounce Time – Type: integer, Default: 100, Min: 0, Max: 255
  • The debounce time in ms.

  • Reset Edge Count On Update – Type: boolean, Default: false
  • Enabling this will reset the edge counter after OpenHAB reads its value. Use this if you want relative edge counts per update.

  • Update Interval – Type: integer, Default: 1000, Unit: ms
  • Specifies the update interval in milliseconds. A value of 0 disables automatic updates.

Actions

Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:

val actions = getActions("tinkerforge", "tinkerforge:brickletio4v2:[UID]")
val hwVersion = actions.brickletIO4V2GetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickletIO4V2SetValue(boolean[] value)
Parameters:
  • value – Type: boolean[], Length: 4

Sets the output value of all four channels. A value of true or false outputs logic 1 or logic 0 respectively on the corresponding channel.

Use Output Value Pin 0 to change only one output channel state.

For example: (True, True, False, False) will turn the channels 0-1 high and the channels 2-3 low.

All running monoflop timers and PWMs will be aborted if this function is called.

Note

This function does nothing for channels that are configured as input. Pull-up resistors can be switched on with the thing configuration.

brickletIO4V2SetSelectedValue(int channel, boolean value)
Parameters:
  • channel – Type: int, Range: [0 to 3]
  • value – Type: boolean

Sets the output value of a specific channel without affecting the other channels.

A running monoflop timer or PWM for the specific channel will be aborted if this function is called.

Note

This function does nothing for channels that are configured as input. Pull-up resistors can be switched on with the thing configuration.

brickletIO4V2GetValue()
Return Map:
  • value – Type: boolean[], Length: 4

Returns the logic levels that are currently measured on the channels. This function works if the channel is configured as input as well as if it is configured as output.

brickletIO4V2GetConfiguration(int channel)
Parameters:
  • channel – Type: int, Range: [0 to 3]
Return Map:
  • direction – Type: char, Range: See constants, Default: 'i'
  • value – Type: boolean, Default: true

Returns the channel configuration as set by the thing configuration.

The following constants are available for this function:

For direction:

  • val DIRECTION_IN = 'i'
  • val DIRECTION_OUT = 'o'

Advanced Actions

brickletIO4V2SetMonoflop(int channel, boolean value, long time)
Parameters:
  • channel – Type: int, Range: [0 to 3]
  • value – Type: boolean
  • time – Type: long, Unit: 1 ms, Range: [0 to 232 - 1]

The first parameter is the desired state of the channel (true means output high and false means output low). The second parameter indicates the time that the channel should hold the state.

If this function is called with the parameters (true, 1500): The channel will turn on and in 1.5s it will turn off again.

A PWM for the selected channel will be aborted if this function is called.

A monoflop can be used as a failsafe mechanism. For example: Lets assume you have a RS485 bus and a IO-4 Bricklet 2.0 is connected to one of the slave stacks. You can now call this function every second, with a time parameter of two seconds. The channel will be high all the time. If now the RS485 connection is lost, the channel will turn low in at most two seconds.

brickletIO4V2SetPWMConfiguration(int channel, long frequency, int dutyCycle)
Parameters:
  • channel – Type: int, Range: [0 to 3]
  • frequency – Type: long, Unit: 1/10 Hz, Range: [0 to 320000000], Default: 0
  • dutyCycle – Type: int, Unit: 1/100 %, Range: [0 to 10000], Default: 0

Activates a PWM for the given channel.

You need to set the channel to output before you call this function, otherwise it will report an invalid parameter error. To turn the PWM off again, you can set the frequency to 0 or any other function that changes a value of the channel (e.g. Output Value Pin 0).

A running monoflop timer for the given channel will be aborted if this function is called.

brickletIO4V2GetEdgeCount(int channel, boolean resetCounter)
Parameters:
  • channel – Type: int, Range: [0 to 3]
  • resetCounter – Type: boolean
Return Map:
  • count – Type: long, Range: [0 to 232 - 1]

Returns the current value of the edge counter for the selected channel. You can configure the edges that are counted with the configuration of Edge Count Pin 0.

If you set the reset counter to true, the count is set back to 0 directly after it is read.

Note

Calling this function is only allowed for channels configured as input.

brickletIO4V2GetMonoflop(int channel)
Parameters:
  • channel – Type: int, Range: [0 to 3]
Return Map:
  • value – Type: boolean
  • time – Type: long, Unit: 1 ms, Range: [0 to 232 - 1]
  • timeRemaining – Type: long, Unit: 1 ms, Range: [0 to 232 - 1]

Returns (for the given channel) the current value and the time as set by Monoflop Pin 0 as well as the remaining time until the value flips.

If the timer is not running currently, the remaining time will be returned as 0.

brickletIO4V2GetEdgeCountConfiguration(int channel)
Parameters:
  • channel – Type: int, Range: [0 to 3]
Return Map:
  • edgeType – Type: int, Range: See constants, Default: 0
  • debounce – Type: int, Unit: 1 ms, Range: [0 to 255], Default: 100

Returns the edge type and debounce time for the selected channel as set by the configuration of Edge Count Pin 0.

Note

Calling this function is only allowed for channels configured as input.

The following constants are available for this function:

For edgeType:

  • val EDGE_TYPE_RISING = 0
  • val EDGE_TYPE_FALLING = 1
  • val EDGE_TYPE_BOTH = 2
brickletIO4V2GetPWMConfiguration(int channel)
Parameters:
  • channel – Type: int, Range: [0 to 3]
Return Map:
  • frequency – Type: long, Unit: 1/10 Hz, Range: [0 to 320000000], Default: 0
  • dutyCycle – Type: int, Unit: 1/100 %, Range: [0 to 10000], Default: 0

Returns the PWM configuration as set by SetPWMConfiguration().

brickletIO4V2GetChipTemperature()
Return Map:
  • temperature – Type: int, 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.

brickletIO4V2GetStatusLEDConfig()
Return Map:
  • config – Type: int, Range: See constants, Default: 3

Returns the configuration as set by the thing configuration

The following constants are available for this function:

For config:

  • val STATUS_LED_CONFIG_OFF = 0
  • val STATUS_LED_CONFIG_ON = 1
  • val STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2
  • val STATUS_LED_CONFIG_SHOW_STATUS = 3
brickletIO4V2GetSPITFPErrorCount()
Return Map:
  • errorCountAckChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountMessageChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountFrame – Type: long, Range: [0 to 232 - 1]
  • errorCountOverflow – Type: long, 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.

brickletIO4V2GetIdentity()
Return Map:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['a' to 'h', 'i', 'z']
  • hardwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – Type: int, 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

Internal Actions

brickletIO4V2ReadUID()
Return Map:
  • uid – Type: long, Range: [0 to 232 - 1]

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