class Tinkerforge::BrickletOLED128x64

3.3cm (1.3“) OLED display with 128x64 pixels

Public Class Methods

new(uid, ipcon) click to toggle source

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.

Calls superclass method
# File lib/tinkerforge/bricklet_oled_128x64.rb, line 30
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_WRITE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_NEW_WINDOW] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_CLEAR_DISPLAY] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_SET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_DISPLAY_CONFIGURATION] = RESPONSE_EXPECTED_ALWAYS_TRUE
  @response_expected[FUNCTION_WRITE_LINE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE


  @ipcon.add_device self
end

Public Instance Methods

clear_display() click to toggle source

Clears the current content of the window as set by BrickletOLED128x64#new_window.

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 82
def clear_display
  check_validity

  send_request FUNCTION_CLEAR_DISPLAY, [], '', 8, ''
end
get_display_configuration() click to toggle source

Returns the configuration as set by BrickletOLED128x64#set_display_configuration.

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 99
def get_display_configuration
  check_validity

  send_request FUNCTION_GET_DISPLAY_CONFIGURATION, [], '', 10, 'C ?'
end
get_identity() click to toggle source

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 :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 132
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
new_window(column_from, column_to, row_from, row_to) click to toggle source

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

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 75
def new_window(column_from, column_to, row_from, row_to)
  check_validity

  send_request FUNCTION_NEW_WINDOW, [column_from, column_to, row_from, row_to], 'C C C C', 8, ''
end
set_display_configuration(contrast, invert) click to toggle source

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.

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 92
def set_display_configuration(contrast, invert)
  check_validity

  send_request FUNCTION_SET_DISPLAY_CONFIGURATION, [contrast, invert], 'C ?', 8, ''
end
write(data) click to toggle source

Appends 64 byte of data to the window as set by BrickletOLED128x64#new_window.

Each row has a height of 8 pixels which corresponds to one byte of data.

Example: if you call BrickletOLED128x64#new_window with column from 0 to 127 and row from 0 to 7 (the whole display) each call of BrickletOLED128x64#write (red arrow) will write half of a row.

.. image

/Images/Bricklets/bricklet_oled_128x64_display.png

:scale: 100 %
:alt: Display pixel order
:align: center
:target: ../../_images/Bricklets/bricklet_oled_128x64_display.png

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 BrickletOLED128x64#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 BrickletOLED128x64#write 16 times.

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 67
def write(data)
  check_validity

  send_request FUNCTION_WRITE, [data], 'C64', 8, ''
end
write_line(line, position, text) click to toggle source

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 BrickletOLED128x64#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.

# File lib/tinkerforge/bricklet_oled_128x64.rb, line 116
def write_line(line, position, text)
  check_validity

  send_request FUNCTION_WRITE_LINE, [line, position, text], 'C C Z26', 8, ''
end