Skip to main content

Easily display text on an SSD1306 oled display connected to a Raspberry Pi

Project description

OLED SSD1306 Text

Working with Adafruit's adafruit_ssd1306 library can be tedious if all you need is to output to your oled is some lines of text. This is where this helper tool comes in handy.

A minimal hello world:

from board import SCL, SDA
import busio
from oled_text.oled_text import OledText

i2c = busio.I2C(SCL, SDA)

# Create the display, pass its pixel dimensions
oled = OledText(i2c, 128, 64)

# Write to the oled
oled.text("Hello ...", 1)  # Line 1
oled.text("... world!", 2)  # Line 2

More advanced examples

import time
from board import SCL, SDA
import busio
from oled_text.oled_text import OledText

i2c = busio.I2C(SCL, SDA)

# Instantiate the display, passing its dimensions (128x64 or 128x32)
oled = OledText(i2c, 128, 64)

# Output 5 lines (with auto_draw on, the display is painted after every line)
for i in range(1, 6):
	oled.text("Hello Line {}".format(i), i)

time.sleep(1)

# Replacing a single line (keeps the other lines)
oled.text("Brave new line", 2)
time.sleep(2)

# See the repaint framerate
for i in range(10):
    oled.text("Random: {}".format(random.randint(0, 100)), 2)
oled.clear()

# Setting multiple lines with manual .show() (only one display refresh)
oled.layout = OledText.layout_64_1big_3small()
oled.auto_show = False
oled.text("The Title", 1)
oled.text("Line 2 text", 2)
oled.text("Line 3 text", 3)
oled.text("Line 4 text", 4)
oled.show()
oled.auto_show = True
time.sleep(3)

# Use a custom display layout
oled.layout = {
    1: SmallLine(0, 0),
    2: BigLine(5, 15, font="Arimo.ttf", size=24),
    3: BigLine(5, 40, font="Arimo.ttf", size=18)
}
oled.text("I want my layout!")
oled.text("Custom 1", 2)
oled.text("Custom 2", 3)
time.sleep(3)

# Adding own graphics using a onDraw handler
oled.layout = OledText.layout_64_1big_center()
oled.on_draw = lambda draw: draw.rectangle((0, 0, 127, 63), outline=255, fill=0)
oled.text("The Fat Cat", 1)

time.sleep(4)
oled.clear()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oled_text-1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oled_text-1.0-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file oled_text-1.0.tar.gz.

File metadata

  • Download URL: oled_text-1.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.17

File hashes

Hashes for oled_text-1.0.tar.gz
Algorithm Hash digest
SHA256 1c6aa6359a866f4804c03d15050e81f1791f4131bac26819ed727734b642f881
MD5 3474bc441304fa8469e299dffe39c19e
BLAKE2b-256 5bc359b07f6e21e714d607935c058eae3dde2916535c7e9adfd3446e842e170f

See more details on using hashes here.

File details

Details for the file oled_text-1.0-py3-none-any.whl.

File metadata

  • Download URL: oled_text-1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.17

File hashes

Hashes for oled_text-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 053632830c4e8490795fa0647fde7b1bc6ec6e8e19aaa5957123af378d851e39
MD5 82c7815d26c8b75145cee29eb2474ccf
BLAKE2b-256 3df02174243c2d29e8958348fb7b894e45fa3516fe4edb4029d3fdaf327f1f12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page