This is the description of the Visual Basic .NET 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 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 64x48 Bricklet
8
9 Sub Main()
10 Dim ipcon As New IPConnection() ' Create IP connection
11 Dim oled As New BrickletOLED64x48(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 64x48 Bricklet
9 Const WIDTH As Integer = 64
10 Const HEIGHT As Integer = 48
11
12 Sub DrawMatrix(ByRef oled As BrickletOLED64x48, 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 For row As Integer = 0 To HEIGHT \ 8 - 1
32 oled.Write(pages(row))
33 Next row
34 End Sub
35
36 Sub Main()
37 Dim ipcon As New IPConnection() ' Create IP connection
38 Dim oled As New BrickletOLED64x48(UID, ipcon) ' Create device object
39
40 ipcon.Connect(HOST, PORT) ' Connect to brickd
41 ' Don't use device before ipcon is connected
42
43 ' Clear display
44 oled.ClearDisplay()
45
46 ' Draw checkerboard pattern
47 Dim pixels()() As Boolean = New Boolean(HEIGHT)() {}
48
49 For row As Integer = 0 To HEIGHT - 1
50 pixels(row) = New Boolean(WIDTH) {}
51
52 For column As Integer = 0 To WIDTH - 1
53 pixels(row)(column) = (row \ 8) Mod 2 = (column \ 8) Mod 2
54 Next column
55 Next row
56
57 DrawMatrix(oled, pixels)
58
59 Console.WriteLine("Press key to exit")
60 Console.ReadLine()
61 ipcon.Disconnect()
62 End Sub
63End 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 64x48 Bricklet
11 Const WIDTH As Integer = 64
12 Const HEIGHT As Integer = 48
13
14 Sub DrawImage(ByRef oled As BrickletOLED64x48, 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 For row As Integer = 0 To HEIGHT \ 8 - 1
34 oled.Write(pages(row))
35 Next row
36 End Sub
37
38 Sub Main()
39 Dim ipcon As New IPConnection() ' Create IP connection
40 Dim oled As New BrickletOLED64x48(UID, ipcon) ' Create device object
41
42 ipcon.Connect(HOST, PORT) ' Connect to brickd
43 ' Don't use device before ipcon is connected
44
45 ' Clear display
46 oled.ClearDisplay()
47
48 ' Draw rotating line
49 Dim bitmap As New Bitmap(WIDTH, HEIGHT)
50 Dim originX As Integer = WIDTH \ 2
51 Dim originY As Integer = HEIGHT \ 2
52 Dim length As Integer = HEIGHT \ 2 - 2
53 Dim angle As Integer = 0
54
55 Console.WriteLine("Press enter to exit")
56
57 While Not Console.KeyAvailable
58 Dim radians As Double = Math.PI * angle / 180.0
59 Dim x As Integer = Convert.ToInt32(Math.Floor(originX + length * Math.Cos(radians)))
60 Dim y As Integer = Convert.ToInt32(Math.Floor(originY + length * Math.Sin(radians)))
61
62 Using g As Graphics = Graphics.FromImage(bitmap)
63 g.FillRectangle(Brushes.Black, 0, 0, WIDTH, HEIGHT)
64 g.DrawLine(Pens.White, originX, originY, x, y)
65 End Using
66
67 DrawImage(oled, bitmap)
68 Thread.Sleep(25)
69
70 angle += 1
71 End While
72
73 Console.WriteLine("Press key to exit")
74 Console.ReadLine()
75 ipcon.Disconnect()
76 End Sub
77End 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 oled64x48 As New BrickletOLED64x48("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 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: |
|
|---|
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 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: |
|
|---|
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:
BrickletOLED64x48.FUNCTION_WRITE = 1
BrickletOLED64x48.FUNCTION_NEW_WINDOW = 2
BrickletOLED64x48.FUNCTION_CLEAR_DISPLAY = 3
BrickletOLED64x48.FUNCTION_SET_DISPLAY_CONFIGURATION = 4
BrickletOLED64x48.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:
BrickletOLED64x48.FUNCTION_WRITE = 1
BrickletOLED64x48.FUNCTION_NEW_WINDOW = 2
BrickletOLED64x48.FUNCTION_CLEAR_DISPLAY = 3
BrickletOLED64x48.FUNCTION_SET_DISPLAY_CONFIGURATION = 4
BrickletOLED64x48.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 64x48 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 64x48 Bricklet.