This is the description of the Visual Basic .NET 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 Visual Basic .NET API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (ExampleHelloWorld.vb)
1Imports System
2Imports Tinkerforge
3
4Module ExampleHelloWorld
5 Const HOST As String = "localhost"
6 Const PORT As Integer = 4223
7 Const UID As String = "XYZ" ' Change XYZ to the UID of your OLED 128x64 Bricklet
8
9 Sub Main()
10 Dim ipcon As New IPConnection() ' Create IP connection
11 Dim oled As New BrickletOLED128x64(UID, ipcon) ' Create device object
12
13 ipcon.Connect(HOST, PORT) ' Connect to brickd
14 ' Don't use device before ipcon is connected
15
16 ' Clear display
17 oled.ClearDisplay()
18
19 ' Write "Hello World" starting from upper left corner of the screen
20 oled.WriteLine(0, 0, "Hello World")
21
22 Console.WriteLine("Press key to exit")
23 Console.ReadLine()
24 ipcon.Disconnect()
25 End Sub
26End Module
Download (ExamplePixelMatrix.vb)
1Imports System
2Imports System.Math
3Imports Tinkerforge
4
5Module ExamplePixelMatrix
6 Const HOST As String = "localhost"
7 Const PORT As Integer = 4223
8 Const UID As String = "XYZ" ' Change XYZ to the UID of your OLED 128x64 Bricklet
9 Const WIDTH As Integer = 128
10 Const HEIGHT As Integer = 64
11
12 Sub DrawMatrix(ByRef oled As BrickletOLED128x64, ByVal pixels()() As Boolean)
13 Dim pages()() As Byte = New Byte(HEIGHT \ 8)() {}
14
15 For row As Integer = 0 To HEIGHT \ 8 - 1
16 pages(row) = New Byte(WIDTH) {}
17
18 For column As Integer = 0 To WIDTH - 1
19 pages(row)(column) = 0
20
21 For bit As Integer = 0 To 7
22 If pixels((row * 8) + bit)(column) Then
23 pages(row)(column) = pages(row)(column) Or Convert.ToByte(1 << bit)
24 End If
25 Next bit
26 Next column
27 Next row
28
29 oled.NewWindow(0, WIDTH - 1, 0, HEIGHT \ 8 - 1)
30
31 Dim section() As Byte = New Byte(64) {}
32
33 For row As Integer = 0 To HEIGHT \ 8 - 1
34 For column As Integer = 0 To WIDTH - 1 Step 64
35 Array.Copy(pages(row), column, section, 0, 64)
36 oled.Write(section)
37 Next column
38 Next row
39 End Sub
40
41 Sub Main()
42 Dim ipcon As New IPConnection() ' Create IP connection
43 Dim oled As New BrickletOLED128x64(UID, ipcon) ' Create device object
44
45 ipcon.Connect(HOST, PORT) ' Connect to brickd
46 ' Don't use device before ipcon is connected
47
48 ' Clear display
49 oled.ClearDisplay()
50
51 ' Draw checkerboard pattern
52 Dim pixels()() As Boolean = New Boolean(HEIGHT)() {}
53
54 For row As Integer = 0 To HEIGHT - 1
55 pixels(row) = New Boolean(WIDTH) {}
56
57 For column As Integer = 0 To WIDTH - 1
58 pixels(row)(column) = (row \ 8) Mod 2 = (column \ 8) Mod 2
59 Next column
60 Next row
61
62 DrawMatrix(oled, pixels)
63
64 Console.WriteLine("Press key to exit")
65 Console.ReadLine()
66 ipcon.Disconnect()
67 End Sub
68End Module
1Imports System
2Imports System.Drawing
3Imports System.Math
4Imports System.Threading
5Imports Tinkerforge
6
7Module ExampleScribble
8 Const HOST As String = "localhost"
9 Const PORT As Integer = 4223
10 Const UID As String = "XYZ" ' Change XYZ to the UID of your OLED 128x64 Bricklet
11 Const WIDTH As Integer = 128
12 Const HEIGHT As Integer = 64
13
14 Sub DrawImage(ByRef oled As BrickletOLED128x64, ByVal bitmap As Bitmap)
15 Dim pages()() As Byte = New Byte(HEIGHT \ 8)() {}
16
17 For row As Integer = 0 To HEIGHT \ 8 - 1
18 pages(row) = New Byte(WIDTH) {}
19
20 For column As Integer = 0 To WIDTH - 1
21 pages(row)(column) = 0
22
23 For bit As Integer = 0 To 7
24 If bitmap.GetPixel(column, (row * 8) + bit).GetBrightness() > 0 Then
25 pages(row)(column) = pages(row)(column) Or Convert.ToByte(1 << bit)
26 End If
27 Next bit
28 Next column
29 Next row
30
31 oled.NewWindow(0, WIDTH - 1, 0, HEIGHT \ 8 - 1)
32
33 Dim section() As Byte = New Byte(64) {}
34
35 For row As Integer = 0 To HEIGHT \ 8 - 1
36 For column As Integer = 0 To WIDTH - 1 Step 64
37 Array.Copy(pages(row), column, section, 0, 64)
38 oled.Write(section)
39 Next column
40 Next row
41 End Sub
42
43 Sub Main()
44 Dim ipcon As New IPConnection() ' Create IP connection
45 Dim oled As New BrickletOLED128x64(UID, ipcon) ' Create device object
46
47 ipcon.Connect(HOST, PORT) ' Connect to brickd
48 ' Don't use device before ipcon is connected
49
50 ' Clear display
51 oled.ClearDisplay()
52
53 ' Draw rotating line
54 Dim bitmap As New Bitmap(WIDTH, HEIGHT)
55 Dim originX As Integer = WIDTH \ 2
56 Dim originY As Integer = HEIGHT \ 2
57 Dim length As Integer = HEIGHT \ 2 - 2
58 Dim angle As Integer = 0
59
60 Console.WriteLine("Press enter to exit")
61
62 While Not Console.KeyAvailable
63 Dim radians As Double = Math.PI * angle / 180.0
64 Dim x As Integer = Convert.ToInt32(Math.Floor(originX + length * Math.Cos(radians)))
65 Dim y As Integer = Convert.ToInt32(Math.Floor(originY + length * Math.Sin(radians)))
66
67 Using g As Graphics = Graphics.FromImage(bitmap)
68 g.FillRectangle(Brushes.Black, 0, 0, WIDTH, HEIGHT)
69 g.DrawLine(Pens.White, originX, originY, x, y)
70 End Using
71
72 DrawImage(oled, bitmap)
73 Thread.Sleep(25)
74
75 angle += 1
76 End While
77
78 Console.WriteLine("Press key to exit")
79 Console.ReadLine()
80 ipcon.Disconnect()
81 End Sub
82End Module
Since Visual Basic .NET does not support multiple return values directly, we
use the ByRef keyword to return multiple values from a function.
All functions and procedures listed below are thread-safe.
Creates an object with the unique device ID uid:
Dim oled128x64 As New BrickletOLED128x64("YOUR_DEVICE_UID", ipcon)
This object can then be used after the IP Connection is connected.
| Parameters: |
|
|---|
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 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.
| Parameters: |
|
|---|
Sets the window in which you can write with Write(). One row
has a height of 8 pixels.
Clears the current content of the window as set by NewWindow().
| Parameters: |
|
|---|
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.
| Parameters: |
|
|---|
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.
| Output Parameters: |
|
|---|
Returns the configuration as set by SetDisplayConfiguration().
| Output Parameters: |
|
|---|
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.
| Output Parameters: |
|
|---|
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:
BrickletOLED128x64.FUNCTION_WRITE = 1
BrickletOLED128x64.FUNCTION_NEW_WINDOW = 2
BrickletOLED128x64.FUNCTION_CLEAR_DISPLAY = 3
BrickletOLED128x64.FUNCTION_SET_DISPLAY_CONFIGURATION = 4
BrickletOLED128x64.FUNCTION_WRITE_LINE = 6
| Parameters: |
|
|---|
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:
BrickletOLED128x64.FUNCTION_WRITE = 1
BrickletOLED128x64.FUNCTION_NEW_WINDOW = 2
BrickletOLED128x64.FUNCTION_CLEAR_DISPLAY = 3
BrickletOLED128x64.FUNCTION_SET_DISPLAY_CONFIGURATION = 4
BrickletOLED128x64.FUNCTION_WRITE_LINE = 6
| Parameters: |
|
|---|
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 128x64 Bricklet.
The GetIdentity() function and the
IPConnection.EnumerateCallback
callback of the IP Connection have a deviceIdentifier parameter to specify
the Brick's or Bricklet's type.
This constant represents the human readable name of a OLED 128x64 Bricklet.