oled · Display (OLED)

Displays text or images on the LCD screen.

Class: Oled OledByPiBrain

class openpibo.oled.Oled(w=128, h=64)[source]

Bases: object

Functions: show() clear() set_font() draw_text() draw_image() draw_data() draw_rectangle() draw_ellipse() draw_line() invert() imshow()

Uses the OLED or LCD.

show()[source]

Shows the oled screen.

If you do not use this method, nothing is shown on the oled screen even if you draw.

clear(image=True, fill=True, show=True)[source]

Clears the oled screen.

Parameters:
  • image (bool) – Whether to reset the image

  • fill (bool) – Whether to reset the oled

  • show (bool) – Whether to show on the screen

set_font(filename=None, size=None)[source]

Sets the font and text size for draw_text.

Parameters:
  • filename (str) – Font file path (ttf, otf)

  • size (int) – Font size

draw_text(points, text: str)[source]

Displays text (default font - supports Korean/English/Chinese/Japanese).

Parameters:
  • points (tuple(int, int)) – Top-left coordinates of the text (x, y)

  • text (str) – Text content

draw_image(filename)[source]

Draws an image file. Only png files of size 128x64 are allowed.

Parameters:

filename (str) – Image file path

draw_data(img)[source]

Draws image data (cv2).

Parameters:

img (numpy.ndarray) – Image object

draw_rectangle(points, fill=None)[source]

Draws a rectangle.

Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle (x1, y1, x2, y2)

  • fill (bool) – Whether to fill

draw_ellipse(points, fill=None)[source]

Draws an ellipse.

Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle circumscribing the ellipse (x1, y1, x2, y2)

  • fill (bool) – Whether to fill

draw_line(points)[source]

Draws a straight line.

Parameters:

points (tuple) – Start and end coordinates of the line (x1, y1, x2, y2)

invert()[source]

Inverts the screen.

imshow(img)[source]

Shows image data (cv2) directly on the OLED.

Parameters:

img (numpy.ndarray) – Image object

class openpibo.oled.Oled7735(w=128, h=64)[source]

Bases: object

Functions: show() clear() set_font() draw_text() draw_image() draw_data() draw_rectangle() draw_ellipse() draw_line()

Draws various pictures on piBo’s OLED.

  • View a picture

  • Draw text

  • Draw shapes

Whatever you draw is stored in the instance variable image. You can show it on the oled screen with the show method.

In this class, drawing text or pictures is defined as changing the data of the instance variable image.

example:

from openpibo.oled import OledbyST7735 as Oled

oled = Oled()
# 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
show()[source]

Shows the instance variable image on the oled screen.

If you do not use this method, nothing is shown on the oled screen even if you draw.

example:

# 그림을 그린 후

oled.show()
clear(image=True, fill=True, show=True)[source]

Resets the instance variable image and clears the oled screen.

example:

oled.clear()
Parameters:
  • image (bool) – Whether to reset the image

  • fill (bool) – Whether to reset the oled

  • show (bool) – Whether to show on the screen

set_font(filename=None, size=None)[source]

Sets the font used by the draw_text method.

example:

# 불러올 폰트의 경로가 /home/pi/mydata/font.ttf 라면,

oled.set_font('/home/pi/mydata/font.ttf', 10)
Parameters:
  • filename (str) – Font file path Both ttf and otf font formats are supported.

  • size (int) – Font size The unit is pixels. (default 10)

draw_text(points, text: str, colors=(255, 255, 255))[source]

Draws text. (supports Korean and English)

example:

oled.draw_text((10, 10), '안녕하세요!')
Parameters:
  • points (tuple(int, int)) – Top-left coordinates of the text (x, y)

  • text (str) – Text content

draw_image(filename)[source]

Draws a picture.

Only png files of size 128x64 are allowed.

example:

oled.draw_image('/home/pi/openpibo-files/image/clear.png')
Parameters:

filename (str) – Image file path

draw_data(img)[source]

Takes numpy image data and converts it to an image.

Used to show camera output, which is in numpy format, on the oled screen.

example:

from openpibo.vision import Camera

camera = Camera()
img = camera.read()

oled.draw_data(img)
oled.show()
Parameters:

img (numpy.ndarray) – Image object

draw_rectangle(points, fill=None)[source]

Draws a rectangle.

example:

oled.draw_rectangle((10, 10, 80, 40), True)
Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle (x1, y1, x2, y2)

  • fill (bool) –

    • True : Fills the inside of the rectangle.

    • False : Does not fill the inside of the rectangle.

draw_ellipse(points, fill=None)[source]

Draws an ellipse.

example:

oled.draw_ellipse((10, 10, 80, 40), False)
Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle circumscribing the ellipse (x1, y1, x2, y2)

  • fill (bool) –

    • True : Fills the inside of the ellipse.

    • False : Does not fill the inside of the ellipse.

draw_line(points)[source]

Draws a straight line.

example:

oled.draw_line((30, 20, 60, 50))
Parameters:

points (tuple) – Start and end coordinates of the line (x1, y1, x2, y2)

imshow(img)[source]

Shows image data (cv2) directly on the OLED.

Parameters:

img (numpy.ndarray) – Image object

class openpibo.oled.OledByPiBrain(w=240, h=320)[source]

Bases: object

Functions: show() clear() set_font() draw_text() draw_image() draw_data() draw_rectangle() draw_ellipse() draw_line() imshow()

Uses the OLED or LCD.

show()[source]

Shows the oled screen.

If you do not use this method, nothing is shown on the oled screen even if you draw.

clear(image=True, fill=True, show=True)[source]

Clears the oled screen.

Parameters:
  • image (bool) – Whether to reset the image

  • fill (bool) – Whether to reset the oled

  • show (bool) – Whether to show on the screen

set_font(filename=None, size=None)[source]

Sets the font and text size for draw_text.

Parameters:
  • filename (str) – Font file path (ttf, otf)

  • size (int) – Font size

draw_text(points, text: str, colors=(255, 255, 255))[source]

Displays text (default font - supports Korean/English/Chinese/Japanese).

Parameters:
  • points (tuple(int, int)) – Top-left coordinates of the text (x, y)

  • text (str) – Text content

draw_image(filename)[source]

Draws an image file.

Parameters:

filename (str) – Image file path

draw_data(img)[source]

Draws image data (cv2).

Parameters:

img (numpy.ndarray) – Image object

draw_rectangle(points, fill=None)[source]

Draws a rectangle.

Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle (x1, y1, x2, y2)

  • fill (bool) – Whether to fill

draw_ellipse(points, fill=None)[source]

Draws an ellipse.

Parameters:
  • points (tuple) – Top-left and bottom-right coordinates of the rectangle circumscribing the ellipse (x1, y1, x2, y2)

  • fill (bool) – Whether to fill

draw_line(points)[source]

Draws a straight line.

Parameters:

points (tuple) – Start and end coordinates of the line (x1, y1, x2, y2)

imshow(img)[source]

Shows image data (cv2) directly on the OLED.

Parameters:

img (numpy.ndarray) – Image object