MQTT - LCD 20x4 Bricklet

This is the description of the MQTT API bindings for the LCD 20x4 Bricklet. General information and technical specifications for the LCD 20x4 Bricklet are summarized in its hardware description.

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

Examples

The example code below is Public Domain (CC0 1.0).

Hello World

Download (example-hello-world.txt)

1
2
3
4
5
6
7
8
# Change XYZ to the UID of your LCD 20x4 Bricklet

setup:
    # Turn backlight on
    publish '' to tinkerforge/request/lcd_20x4_bricklet/XYZ/backlight_on

    # Write "Hello World"
    publish '{"line": 0, "position": 0, "text": "Hello World"}' to tinkerforge/request/lcd_20x4_bricklet/XYZ/write_line

Button Callback

Download (example-button-callback.txt)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Change XYZ to the UID of your LCD 20x4 Bricklet

setup:
    # Handle incoming button pressed callbacks
    subscribe to tinkerforge/callback/lcd_20x4_bricklet/XYZ/button_pressed
    publish '{"register": true}' to tinkerforge/register/lcd_20x4_bricklet/XYZ/button_pressed # Register button_pressed callback

    # Handle incoming button released callbacks
    subscribe to tinkerforge/callback/lcd_20x4_bricklet/XYZ/button_released
    publish '{"register": true}' to tinkerforge/register/lcd_20x4_bricklet/XYZ/button_released # Register button_released callback

Unicode

Download (example-unicode.txt)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Change XYZ to the UID of your LCD 20x4 Bricklet

setup:
    # Turn backlight on
    publish '' to tinkerforge/request/lcd_20x4_bricklet/XYZ/backlight_on

    function UTF8ToKS006U # This function should convert strings from UTF-8 to the LCD charset. See examples for other languages.

    # Write some strings using the FIXME function to map to the LCD charset
    publish '{"line": 0, "position": 0, "text": UTF8ToKS0066U("Stromstärke: 17µA")}' to tinkerforge/request/lcd_20x4_bricklet/XYZ/write_line
    publish '{"line": 1, "position": 0, "text": UTF8ToKS0066U("Temperatur:  23°C"}' to tinkerforge/request/lcd_20x4_bricklet/XYZ/write_line

    # Write a string directly including characters from the LCD charset
    publish '{"line": 2, "position": 0, "text": "Drehzahl: 750min\u00e9"}' to tinkerforge/request/lcd_20x4_bricklet/XYZ/write_line

API

All published payloads to and from the MQTT bindings are in JSON format.

If an error occures, the bindings publish a JSON object containing the error message as member _ERROR. It is published on the corresponding response topic: .../response/... for .../request/... and .../callback/... for .../register/....

Basic Functions

request/lcd_20x4_bricklet/<UID>/write_line
Request:
  • line – Type: int, Range: [0 to 3]
  • position – Type: int, Range: [0 to 19]
  • text – Type: string, Length: up to 20
Response:
  • no response

Writes text to a specific line with a specific position. The text can have a maximum of 20 characters.

For example: (0, 7, "Hello") will write Hello in the middle of the first line of the display.

The display uses a special charset that includes all ASCII characters except backslash and tilde. The LCD charset also includes several other non-ASCII characters, see the charset specification for details. The Unicode example above shows how to specify non-ASCII characters and how to translate from Unicode to the LCD charset.

request/lcd_20x4_bricklet/<UID>/clear_display
Request:
  • empty payload
Response:
  • no response

Deletes all characters from the display.

request/lcd_20x4_bricklet/<UID>/backlight_on
Request:
  • empty payload
Response:
  • no response

Turns the backlight on.

request/lcd_20x4_bricklet/<UID>/backlight_off
Request:
  • empty payload
Response:
  • no response

Turns the backlight off.

request/lcd_20x4_bricklet/<UID>/is_backlight_on
Request:
  • empty payload
Response:
  • backlight – Type: bool

Returns true if the backlight is on and false otherwise.

Advanced Functions

request/lcd_20x4_bricklet/<UID>/set_config
Request:
  • cursor – Type: bool, Default: false
  • blinking – Type: bool, Default: false
Response:
  • no response

Configures if the cursor (shown as "_") should be visible and if it should be blinking (shown as a blinking block). The cursor position is one character behind the the last text written with request/lcd_20x4_bricklet/<UID>/write_line.

request/lcd_20x4_bricklet/<UID>/get_config
Request:
  • empty payload
Response:
  • cursor – Type: bool, Default: false
  • blinking – Type: bool, Default: false

Returns the configuration as set by request/lcd_20x4_bricklet/<UID>/set_config.

request/lcd_20x4_bricklet/<UID>/is_button_pressed
Request:
  • button – Type: int, Range: [0 to 3]
Response:
  • pressed – Type: bool

Returns true if the button (0 to 2 or 0 to 3 since hardware version 1.2) is pressed.

If you want to react on button presses and releases it is recommended to use the register/lcd_20x4_bricklet/<UID>/button_pressed and register/lcd_20x4_bricklet/<UID>/button_released callbacks.

request/lcd_20x4_bricklet/<UID>/set_custom_character
Request:
  • index – Type: int, Range: [0 to 7]
  • character – Type: [int, ...], Length: 8, Range: [0 to 31]
Response:
  • no response

The LCD 20x4 Bricklet can store up to 8 custom characters. The characters consist of 5x8 pixels and can be addressed with the index 0-7. To describe the pixels, the first 5 bits of 8 bytes are used. For example, to make a custom character "H", you should transfer the following:

  • character[0] = 0b00010001 (decimal value 17)
  • character[1] = 0b00010001 (decimal value 17)
  • character[2] = 0b00010001 (decimal value 17)
  • character[3] = 0b00011111 (decimal value 31)
  • character[4] = 0b00010001 (decimal value 17)
  • character[5] = 0b00010001 (decimal value 17)
  • character[6] = 0b00010001 (decimal value 17)
  • character[7] = 0b00000000 (decimal value 0)

The characters can later be written with request/lcd_20x4_bricklet/<UID>/write_line by using the characters with the byte representation 8 ("\x08" or "\u0008") to 15 ("\x0F" or "\u000F").

You can play around with the custom characters in Brick Viewer version since 2.0.1.

Custom characters are stored by the LCD in RAM, so they have to be set after each startup.

New in version 2.0.1 (Plugin).

request/lcd_20x4_bricklet/<UID>/get_custom_character
Request:
  • index – Type: int, Range: [0 to 7]
Response:
  • character – Type: [int, ...], Length: 8, Range: [0 to 31]

Returns the custom character for a given index, as set with request/lcd_20x4_bricklet/<UID>/set_custom_character.

New in version 2.0.1 (Plugin).

request/lcd_20x4_bricklet/<UID>/set_default_text
Request:
  • line – Type: int, Range: [0 to 3]
  • text – Type: string, Length: up to 20
Response:
  • no response

Sets the default text for lines 0-3. The max number of characters per line is 20.

The default text is shown on the LCD, if the default text counter expires, see request/lcd_20x4_bricklet/<UID>/set_default_text_counter.

New in version 2.0.2 (Plugin).

request/lcd_20x4_bricklet/<UID>/get_default_text
Request:
  • line – Type: int, Range: [0 to 3]
Response:
  • text – Type: string, Length: up to 20

Returns the default text for a given line (0-3) as set by request/lcd_20x4_bricklet/<UID>/set_default_text.

New in version 2.0.2 (Plugin).

request/lcd_20x4_bricklet/<UID>/set_default_text_counter
Request:
  • counter – Type: int, Unit: 1 ms, Range: [-231 to 231 - 1], Default: -1
Response:
  • no response

Sets the default text counter. This counter is decremented each ms by the LCD firmware. If the counter reaches 0, the default text (see request/lcd_20x4_bricklet/<UID>/set_default_text) is shown on the LCD.

This functionality can be used to show a default text if the controlling program crashes or the connection is interrupted.

A possible approach is to call request/lcd_20x4_bricklet/<UID>/set_default_text_counter every minute with the parameter 1000*60*2 (2 minutes). In this case the default text will be shown no later than 2 minutes after the controlling program crashes.

A negative counter turns the default text functionality off.

New in version 2.0.2 (Plugin).

request/lcd_20x4_bricklet/<UID>/get_default_text_counter
Request:
  • empty payload
Response:
  • counter – Type: int, Unit: 1 ms, Range: [-231 to 231 - 1], Default: -1

Returns the current value of the default text counter.

New in version 2.0.2 (Plugin).

request/lcd_20x4_bricklet/<UID>/get_identity
Request:
  • empty payload
Response:
  • uid – Type: string, Length: up to 8
  • connected_uid – Type: string, Length: up to 8
  • position – Type: char, Range: ["a" to "h", "z"]
  • hardware_version – Type: [int, ...], Length: 3
    • 0: major – Type: int, Range: [0 to 255]
    • 1: minor – Type: int, Range: [0 to 255]
    • 2: revision – Type: int, Range: [0 to 255]
  • firmware_version – Type: [int, ...], Length: 3
    • 0: major – Type: int, Range: [0 to 255]
    • 1: minor – Type: int, Range: [0 to 255]
    • 2: revision – Type: int, Range: [0 to 255]
  • device_identifier – Type: int, Range: [0 to 216 - 1]
  • _display_name – Type: string

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). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here. If symbolic output is not disabled, the device identifier is mapped to the corresponding name in the format used in topics.

The display name contains the LCD 20x4's name in a human readable form.

Callbacks

Callbacks can be registered to receive time critical or recurring data from the device. The registration is done with the corresponding .../register/... topic and an optional suffix. This suffix can be used to deregister the callback later.

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.

register/lcd_20x4_bricklet/<UID>/button_pressed
Register Request:
  • register – Type: bool
Callback Response:
  • button – Type: int, Range: [0 to 3]

A callback can be registered for this event by publishing to the .../register/lcd_20x4_bricklet/<UID>/button_pressed[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/lcd_20x4_bricklet/<UID>/button_pressed[/<SUFFIX>] topic for each registered suffix.

This callback is triggered when a button is pressed. The callback payload is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).

register/lcd_20x4_bricklet/<UID>/button_released
Register Request:
  • register – Type: bool
Callback Response:
  • button – Type: int, Range: [0 to 3]

A callback can be registered for this event by publishing to the .../register/lcd_20x4_bricklet/<UID>/button_released[/<SUFFIX>] topic with the payload "true". An added callback can be removed by publishing to the same topic with the payload "false". To support multiple (de)registrations, e.g. for message filtering, an optional suffix can be used.

If the callback is triggered, a message with it's payload is published under the corresponding .../callback/lcd_20x4_bricklet/<UID>/button_released[/<SUFFIX>] topic for each registered suffix.

This callback is triggered when a button is released. The callback payload is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).