Shell - OLED 128x64 Bricklet

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.

Examples

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

Hello World

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"

Pixel Matrix

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

API

Possible exit codes for all tinkerforge commands are:

  • 1: interrupted (ctrl+c)
  • 2: syntax error
  • 21: Python 2.5 or newer is required
  • 22: Python argparse module is missing
  • 23: socket error
  • 24: other exception
  • 25: invalid placeholder in format string
  • 26: authentication error
  • 201: timeout occurred
  • 209: invalid argument value
  • 210: function is not supported
  • 211: unknown error

Command Structure

The common options of the call and dispatch commands are documented here. The specific command structure is shown below.

tinkerforge call oled-128x64-bricklet [<option>..] <uid> <function> [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

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 exits
tinkerforge dispatch oled-128x64-bricklet [<option>..] <uid> <callback>
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

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 exits
tinkerforge call oled-128x64-bricklet <uid> <function> [<option>..] [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

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 exits

Getter 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 it

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 sent and errors are silently ignored, because they cannot be detected.

tinkerforge dispatch oled-128x64-bricklet <uid> <callback> [<option>..]
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

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)

Basic Functions

tinkerforge call oled-128x64-bricklet <uid> write <data>
Parameters:
  • <data> – Type: Int Array, Length: 64, Range: [0 to 255]
Output:
  • no 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.

Display pixel order

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.

tinkerforge call oled-128x64-bricklet <uid> new-window <column-from> <column-to> <row-from> <row-to>
Parameters:
  • <column-from> – Type: Int, Range: [0 to 127]
  • <column-to> – Type: Int, Range: [0 to 127]
  • <row-from> – Type: Int, Range: [0 to 7]
  • <row-to> – Type: Int, Range: [0 to 7]
Output:
  • no output

Sets the window in which you can write with write. One row has a height of 8 pixels.

tinkerforge call oled-128x64-bricklet <uid> clear-display
Output:
  • no output

Clears the current content of the window as set by new-window.

tinkerforge call oled-128x64-bricklet <uid> write-line <line> <position> <text>
Parameters:
  • <line> – Type: Int, Range: [0 to 7]
  • <position> – Type: Int, Range: [0 to 25]
  • <text> – Type: String, Length: up to 26
Output:
  • no 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.

Advanced Functions

tinkerforge call oled-128x64-bricklet <uid> set-display-configuration <contrast> <invert>
Parameters:
  • <contrast> – Type: Int, Range: [0 to 255], Default: 143
  • <invert> – Type: Bool, Default: false
Output:
  • no 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.

tinkerforge call oled-128x64-bricklet <uid> get-display-configuration
Output:
  • contrast – Type: Int, Range: [0 to 255], Default: 143
  • invert – Type: Bool, Default: false

Returns the configuration as set by set-display-configuration.

tinkerforge call oled-128x64-bricklet <uid> get-identity
Output:
  • 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 Array, 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 Array, 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]

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