This is the description of the Shell 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 Shell API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (example-hello-world.sh)
1 2 3 4 5 6 7 8 9 10 | #!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this
uid=XYZ # Change XYZ to the UID of your LCD 20x4 Bricklet
# Turn backlight on
tinkerforge call lcd-20x4-bricklet $uid backlight-on
# Write "Hello World"
tinkerforge call lcd-20x4-bricklet $uid write-line 0 0 "Hello World"
|
Download (example-button-callback.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this
uid=XYZ # Change XYZ to the UID of your LCD 20x4 Bricklet
# Handle incoming button pressed callbacks
tinkerforge dispatch lcd-20x4-bricklet $uid button-pressed &
# Handle incoming button released callbacks
tinkerforge dispatch lcd-20x4-bricklet $uid button-released &
echo "Press key to exit"; read dummy
kill -- -$$ # Stop callback dispatch in background
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this
uid=XYZ # Change XYZ to the UID of your LCD 20x4 Bricklet
# Turn backlight on
tinkerforge call lcd-20x4-bricklet $uid backlight-on
# Write some strings using sed to map to the LCD charset
# Note: This assumes that the shell supports UTF-8
tinkerforge call lcd-20x4-bricklet $uid write-line 0 0\
"`echo 'Stromstärke: 17µA' | sed 'y/\o134~¥→←°αÄäßεµςρ√¹¤¢ⱠñÖöϴ∞ΩÜüΣπ÷■/\o244\o55\o134\o176\o177\o337\o340\o341\o341\o342\o343\o344\o345\o346\o350\o351\o353\o354\o355\o356\o357\o357\o362\o363\o364\o365\o365\o366\o367\o375\o377/'`"
tinkerforge call lcd-20x4-bricklet $uid write-line 1 0\
"`echo 'Temperatur: 23°C' | sed 'y/\o134~¥→←°αÄäßεµςρ√¹¤¢ⱠñÖöϴ∞ΩÜüΣπ÷■/\o244\o55\o134\o176\o177\o337\o340\o341\o341\o342\o343\o344\o345\o346\o350\o351\o353\o354\o355\o356\o357\o357\o362\o363\o364\o365\o365\o366\o367\o375\o377/'`"
# Write a string directly including characters from the LCD charset
tinkerforge call lcd-20x4-bricklet $uid write-line 2 0\
"`printf 'Drehzahl: 750min\xe9'`"
|
Possible exit codes for all tinkerforge
commands are:
argparse
module is missingThe common options of the call
and dispatch
commands are documented
here. The specific command structure is shown below.
call
lcd-20x4-bricklet
[<option>..] <uid> <function> [<argument>..]¶Parameters: |
|
---|
The call
command is used to call a function of the LCD 20x4 Bricklet. It can take several
options:
--help
shows help for the specific call
command and exits--list-functions
shows a list of known functions of the LCD 20x4 Bricklet and exitsdispatch
lcd-20x4-bricklet
[<option>..] <uid> <callback>¶Parameters: |
|
---|
The dispatch
command is used to dispatch a callback of the LCD 20x4 Bricklet. It can
take several options:
--help
shows help for the specific dispatch
command and exits--list-callbacks
shows a list of known callbacks of the LCD 20x4 Bricklet and exitslcd-20x4-bricklet
<uid> <function>
[<option>..] [<argument>..]¶Parameters: |
|
---|
The <function>
to be called can take different options depending of its
kind. All functions can take the following options:
--help
shows help for the specific function and exitsGetter functions can take the following options:
--execute <command>
shell command line to execute for each incoming
response (see section about output formatting
for details)Setter functions can take the following options:
--expect-response
requests response and waits for itThe --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 sent and errors are silently ignored,
because they cannot be detected.
lcd-20x4-bricklet
<uid> <callback>
[<option>..]¶Parameters: |
|
---|
The <callback>
to be dispatched can take several options:
--help
shows help for the specific callback and exits--execute <command>
shell command line to execute for each incoming
response (see section about output formatting
for details)lcd-20x4-bricklet
<uid> write-line
<line> <position> <text>¶Parameters: |
|
---|---|
Output: |
|
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.
lcd-20x4-bricklet
<uid> clear-display
¶Output: |
|
---|
Deletes all characters from the display.
lcd-20x4-bricklet
<uid> backlight-on
¶Output: |
|
---|
Turns the backlight on.
lcd-20x4-bricklet
<uid> backlight-off
¶Output: |
|
---|
Turns the backlight off.
lcd-20x4-bricklet
<uid> is-backlight-on
¶Output: |
|
---|
Returns true if the backlight is on and false otherwise.
lcd-20x4-bricklet
<uid> set-config
<cursor> <blinking>¶Parameters: |
|
---|---|
Output: |
|
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
write-line
.
lcd-20x4-bricklet
<uid> get-config
¶Output: |
|
---|
Returns the configuration as set by set-config
.
Parameters: |
|
---|---|
Output: |
|
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 button-pressed
and button-released
callbacks.
lcd-20x4-bricklet
<uid> set-custom-character
<index> <character>¶Parameters: |
|
---|---|
Output: |
|
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 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).
lcd-20x4-bricklet
<uid> get-custom-character
<index>¶Parameters: |
|
---|---|
Output: |
|
Returns the custom character for a given index, as set with
set-custom-character
.
New in version 2.0.1 (Plugin).
lcd-20x4-bricklet
<uid> set-default-text
<line> <text>¶Parameters: |
|
---|---|
Output: |
|
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 set-default-text-counter
.
New in version 2.0.2 (Plugin).
lcd-20x4-bricklet
<uid> get-default-text
<line>¶Parameters: |
|
---|---|
Output: |
|
Returns the default text for a given line (0-3) as set by
set-default-text
.
New in version 2.0.2 (Plugin).
lcd-20x4-bricklet
<uid> set-default-text-counter
<counter>¶Parameters: |
|
---|---|
Output: |
|
Sets the default text counter. This counter is decremented each
ms by the LCD firmware. If the counter reaches 0, the default text
(see 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 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).
lcd-20x4-bricklet
<uid> get-default-text-counter
¶Output: |
|
---|
Returns the current value of the default text counter.
New in version 2.0.2 (Plugin).
lcd-20x4-bricklet
<uid> get-identity
¶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', '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.
Callbacks can be used to receive time critical or recurring data from the device:
tinkerforge dispatch lcd-20x4-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 when a button is pressed. The parameter is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).
Output: |
|
---|
This callback is triggered when a button is released. The parameter is the number of the button (0 to 2 or 0 to 3 since hardware version 1.2).