This is the description of the Shell API bindings for the OLED 128x64 Bricklet. General information and technical specifications for the OLED 128x64 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 OLED 128x64 Bricklet
# Clear display
tinkerforge call oled-128x64-bricklet $uid clear-display
# Write "Hello World" starting from upper left corner of the screen
tinkerforge call oled-128x64-bricklet $uid write-line 0 0 "Hello World"
|
Download (example-pixel-matrix.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #!/bin/bash
# Connects to localhost:4223 by default, use --host and --port to change this
# This example requires Bash 4
uid=XYZ # Change XYZ to the UID of your OLED 128x64 Bricklet
SCREEN_WIDTH=128
SCREEN_HEIGHT=64
function draw_matrix {
declare -A column
declare -A column_write
for ((i=0; i<${SCREEN_HEIGHT}/8; i++))
do
for ((j=0; j<${SCREEN_WIDTH}; j++))
do
page=0
for ((k=0; k<8; k++))
do
if ((${pixel_matrix[$((((${i}*8))+${k})),${j}]}))
then
page=$((${page}|$((1<<${k}))))
fi
done
column[${i},${j}]=${page}
done
done
tinkerforge call oled-128x64-bricklet ${uid} new-window 0 $((${SCREEN_WIDTH}-1)) 0 7
for ((i=0; i<${SCREEN_HEIGHT}/8; i++))
do
l=0
for ((j=0; j < ${SCREEN_WIDTH}/2; j++))
do
column_write[${l}]=${column[${i},${j}]}
l=$((l+1))
done
write_bytes=""
for ((j=0; j<${SCREEN_WIDTH}/2; j++))
do
write_bytes+=${column_write[${j}]}
if ((${j}==${SCREEN_HEIGHT}-1))
then
continue
fi
write_bytes+=","
done
tinkerforge call oled-128x64-bricklet ${uid} write ${write_bytes}
l=0
for ((j=${SCREEN_WIDTH}/2; j < ${SCREEN_WIDTH}; j++))
do
column_write[${l}]=${column[${i},${j}]}
l=$((l+1))
done
write_bytes=""
for ((j=0; j<${SCREEN_WIDTH}/2; j++))
do
write_bytes+=${column_write[${j}]}
if ((${j}==${SCREEN_HEIGHT}-1))
then
continue
fi
write_bytes+=","
done
tinkerforge call oled-128x64-bricklet ${uid} write ${write_bytes}
done
}
# Clear display
tinkerforge call oled-128x64-bricklet $uid clear-display
# Draw checkerboard pattern
declare -A pixel_matrix
for ((h=0;h<${SCREEN_HEIGHT};h++))
do
for ((w=0;w<${SCREEN_WIDTH};w++))
do
pixel_matrix[${h},${w}]=$((((${h}/8))%2==((${w}/8))%2))
done
done
draw_matrix
|
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
oled-128x64-bricklet
[<option>..] <uid> <function> [<argument>..]¶Parameters: |
|
---|
The call
command is used to call a function of the OLED 128x64 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 OLED 128x64 Bricklet and exitsdispatch
oled-128x64-bricklet
[<option>..] <uid> <callback>¶Parameters: |
|
---|
The dispatch
command is used to dispatch a callback of the OLED 128x64 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 OLED 128x64 Bricklet and exitsoled-128x64-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.
oled-128x64-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)oled-128x64-bricklet
<uid> write
<data>¶Parameters: |
|
---|---|
Output: |
|
Appends 64 byte of data to the window as set by new-window
.
Each row has a height of 8 pixels which corresponds to one byte of data.
Example: if you call new-window
with column from 0 to 127 and row
from 0 to 7 (the whole display) each call of write
(red arrow) will
write half of a row.
The LSB (D0) of each data byte is at the top and the MSB (D7) is at the bottom of the row.
The next call of write
will write the second half of the row
and the next two the second row and so on. To fill the whole display
you need to call write
16 times.
oled-128x64-bricklet
<uid> new-window
<column-from> <column-to> <row-from> <row-to>¶Parameters: |
|
---|---|
Output: |
|
Sets the window in which you can write with write
. One row
has a height of 8 pixels.
oled-128x64-bricklet
<uid> clear-display
¶Output: |
|
---|
Clears the current content of the window as set by new-window
.
oled-128x64-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 26 characters.
For example: (1, 10, "Hello") will write Hello in the middle of the second line of the display.
You can draw to the display with write
and then add text to it
afterwards.
The display uses a special 5x7 pixel charset. You can view the characters of the charset in Brick Viewer.
The font conforms to code page 437.
oled-128x64-bricklet
<uid> set-display-configuration
<contrast> <invert>¶Parameters: |
|
---|---|
Output: |
|
Sets the configuration of the display.
You can set a contrast value from 0 to 255 and you can invert the color (black/white) of the display.
oled-128x64-bricklet
<uid> get-display-configuration
¶Output: |
|
---|
Returns the configuration as set by set-display-configuration
.
oled-128x64-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.