Shell - OLED 64x48 Bricklet

This is the description of the Shell API bindings for the OLED 64x48 Bricklet. General information and technical specifications for the OLED 64x48 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 64x48 Bricklet

# Clear display
tinkerforge call oled-64x48-bricklet $uid clear-display

# Write "Hello World" starting from upper left corner of the screen
tinkerforge call oled-64x48-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
#!/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 64x48 Bricklet

screen_width=64
screen_height=48

function draw_matrix {
    declare -A column

    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-64x48-bricklet ${uid} new-window 0 $((${screen_width}-1)) 0 5

    for ((i=0; i<${screen_height}/8; i++))
    do
        write_bytes=""
        for ((j=0; j<${screen_width}; j++))
        do
            write_bytes+=${column[${i},${j}]}
            if ((${j}==${screen_width}-1))
            then
                continue
            fi
            write_bytes+=","
        done
        tinkerforge call oled-64x48-bricklet ${uid} write ${write_bytes}
    done
}

# Clear display
tinkerforge call oled-64x48-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-64x48-bricklet [<option>..] <uid> <function> [<argument>..]
Parameters:
  • <uid> – Type: String
  • <function> – Type: String

The call command is used to call a function of the OLED 64x48 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 64x48 Bricklet and exits
tinkerforge dispatch oled-64x48-bricklet [<option>..] <uid> <callback>
Parameters:
  • <uid> – Type: String
  • <callback> – Type: String

The dispatch command is used to dispatch a callback of the OLED 64x48 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 64x48 Bricklet and exits
tinkerforge call oled-64x48-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-64x48-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-64x48-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 63 and row from 0 to 5 (the whole display) each call of write (red arrow) will write one 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 row and so on. To fill the whole display you need to call write 6 times.

tinkerforge call oled-64x48-bricklet <uid> new-window <column-from> <column-to> <row-from> <row-to>
Parameters:
  • <column-from> – Type: Int, Range: [0 to 63]
  • <column-to> – Type: Int, Range: [0 to 63]
  • <row-from> – Type: Int, Range: [0 to 5]
  • <row-to> – Type: Int, Range: [0 to 5]
Output:
  • no output

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

tinkerforge call oled-64x48-bricklet <uid> clear-display
Output:
  • no output

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

tinkerforge call oled-64x48-bricklet <uid> write-line <line> <position> <text>
Parameters:
  • <line> – Type: Int, Range: [0 to 5]
  • <position> – Type: Int, Range: [0 to 12]
  • <text> – Type: String, Length: up to 13
Output:
  • no output

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

For example: (1, 4, "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-64x48-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-64x48-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-64x48-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