This is the description of the Go 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 Go API bindings is part of their general description. Additional documentation can be found on godoc.org.
The example code below is Public Domain (CC0 1.0).
Download (example_hello_world.go)
1package main
2
3import (
4 "fmt"
5 "github.com/Tinkerforge/go-api-bindings/ipconnection"
6 "github.com/Tinkerforge/go-api-bindings/oled_64x48_bricklet"
7)
8
9const ADDR string = "localhost:4223"
10const UID string = "XYZ" // Change XYZ to the UID of your OLED 64x48 Bricklet.
11
12func main() {
13 ipcon := ipconnection.New()
14 defer ipcon.Close()
15 oled, _ := oled_64x48_bricklet.New(UID, &ipcon) // Create device object.
16
17 ipcon.Connect(ADDR) // Connect to brickd.
18 defer ipcon.Disconnect()
19 // Don't use device before ipcon is connected.
20
21 // Clear display
22 oled.ClearDisplay()
23
24 // Write "Hello World" starting from upper left corner of the screen
25 oled.WriteLine(0, 0, "Hello World")
26
27 fmt.Print("Press enter to exit.")
28 fmt.Scanln()
29}
Download (example_pixel_matrix.go)
1package main
2
3import (
4 "fmt"
5 "github.com/Tinkerforge/go-api-bindings/ipconnection"
6 "github.com/Tinkerforge/go-api-bindings/oled_64x48_bricklet"
7)
8
9const ADDR string = "localhost:4223"
10const UID string = "XYZ" // Change XYZ to the UID of your OLED 64x48 Bricklet.
11
12const WIDTH = 64
13const HEIGHT = 48
14
15func drawMatrix(oled oled_64x48_bricklet.OLED64x48Bricklet, pixels [HEIGHT][WIDTH]bool) {
16 var pages [HEIGHT / 8][WIDTH]uint8
17 for colIdx, col := range pages {
18 for rowIdx := range col {
19 for bit := 0; bit < 8; bit++ {
20 if pixels[colIdx*8+bit][rowIdx] {
21 pages[colIdx][rowIdx] |= 1 << uint(bit)
22 }
23 }
24 }
25 }
26
27 oled.NewWindow(0, WIDTH-1, 0, (HEIGHT/8)-1)
28
29 for row := 0; row < HEIGHT/8; row++ {
30 oled.Write(pages[row])
31 }
32}
33
34func main() {
35 ipcon := ipconnection.New()
36 defer ipcon.Close()
37 oled, _ := oled_64x48_bricklet.New(UID, &ipcon) // Create device object.
38
39 ipcon.Connect(ADDR) // Connect to brickd.
40 defer ipcon.Disconnect()
41 // Don't use device before ipcon is connected.
42
43 // Clear display
44 oled.ClearDisplay()
45
46 // Draw checkerboard pattern
47 var pixels [HEIGHT][WIDTH]bool
48 for rowIdx, row := range pixels {
49 for colIdx := range row {
50 pixels[rowIdx][colIdx] = (rowIdx/8)%2 == (colIdx/8)%2
51 }
52 }
53
54 drawMatrix(oled, pixels)
55
56 fmt.Print("Press enter to exit.")
57 fmt.Scanln()
58}
The OLED 64x48 Bricklet API is defined in the package github.com/Tinkerforge/go-api-bindings/oled_64x48_bricklet
Nearly every function of the Go bindings can return an
ipconnection.DeviceError, implementing the error interface. The error can have one of the following values:
ipconnection.DeviceErrorSuccess = 0
ipconnection.DeviceErrorInvalidParameter = 1
ipconnection.DeviceErrorFunctionNotSupported = 2
ipconnection.DeviceErrorUnknownError = 3
which correspond to the values returned from Bricks and Bricklets.
All functions listed below are thread-safe.
| Parameters: |
|
|---|---|
| Returns: |
|
Creates a new OLED64x48Bricklet object with the unique device ID uid and adds
it to the IPConnection ipcon:
device, err := oled_64x48_bricklet.New("YOUR_DEVICE_UID", &ipcon)
This device object can be used after the IPConnection has been connected.
| Parameters: |
|
|---|---|
| Returns: |
|
Appends 64 byte of data to the window as set by NewWindow().
Each row has a height of 8 pixels which corresponds to one byte of data.
Example: if you call NewWindow() 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.
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.
| Parameters: |
|
|---|---|
| Returns: |
|
Sets the window in which you can write with Write(). One row
has a height of 8 pixels.
| Returns: |
|
|---|
Clears the current content of the window as set by NewWindow().
| Parameters: |
|
|---|---|
| Returns: |
|
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.
| Parameters: |
|
|---|---|
| Returns: |
|
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.
| Returns: |
|
|---|
Returns the configuration as set by SetDisplayConfiguration().
| Returns: |
|
|---|
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. There is also a constant for the device identifier of this Bricklet.
Virtual functions don't communicate with the device itself, but operate only on the API bindings device object. They can be called without the corresponding IP Connection object being connected.
| Returns: |
|
|---|
Returns the version of the API definition implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
| Parameters: |
|
|---|---|
| Returns: |
|
Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.
For getter functions this is enabled by default and cannot be disabled,
because those functions will always send a response. For callback configuration
functions it is enabled by default too, but can be disabled by
SetResponseExpected(). For setter functions it is disabled by default
and can be enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
oled_64x48_bricklet.FunctionWrite = 1
oled_64x48_bricklet.FunctionNewWindow = 2
oled_64x48_bricklet.FunctionClearDisplay = 3
oled_64x48_bricklet.FunctionSetDisplayConfiguration = 4
oled_64x48_bricklet.FunctionWriteLine = 6
| Parameters: |
|
|---|---|
| Returns: |
|
Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.
Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.
The following constants are available for this function:
For functionId:
oled_64x48_bricklet.FunctionWrite = 1
oled_64x48_bricklet.FunctionNewWindow = 2
oled_64x48_bricklet.FunctionClearDisplay = 3
oled_64x48_bricklet.FunctionSetDisplayConfiguration = 4
oled_64x48_bricklet.FunctionWriteLine = 6
| Parameters: |
|
|---|---|
| Returns: |
|
Changes the response expected flag for all setter and callback configuration functions of this device at once.
This constant is used to identify a OLED 64x48 Bricklet.
The GetIdentity() function and
the (*IPConnection) RegisterEnumerateCallback()
callback of the IPConnection have a deviceIdentifier parameter to specify
the Brick's or Bricklet's type.
This constant represents the human readable name of a OLED 64x48 Bricklet.