Skip to content

OLED Wireling Python Tutorial

TinyCircuits OLED Wireling product photo

The OLED screen wirelings come in three different sizes, but can all be programmed using the same OLED Python package.

0.42" OLED Technical Details

HP7240 Specs

  • 72x40 pixel resolution 
  • 0.42" size 
  • White Monochrome
  • Internal boost converter 
  • I²C Interface 

Power Requirements

  • Voltage: 3.0V - 5.5V 

Pins Used

  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line

Dimensions

  • 26mm x 9mm (1.03 inches x 0.355 inches)
  • Max Height (from lower bottom of Wireling to upper top Wireling Connector): 5.00mm (0.197 inches)
  • Weight: 1 gram (.04 ounces)
0.69" OLED Technical Details ER-OLED0.69-1W Specs
  • 96x16 pixel resolution 
  • 0.69" size 
  • White Monochrome
  • Internal boost converter 
  • I²C Interface 
Power Requirements
  • Voltage: 3.0V - 5.5V  ???
  • Current: x.xxmA 
Pins Used
  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line
Dimensions
  • 26mm x 9mm (1.03 inches x 0.355 inches)
  • Max Height: 5.00mm (0.197 inches)
  • Weight: 1 gram (.04 ounces)
0.96" OLEDTechnical Details

ER- OLED0.96-1W Specs

  • 128x64 pixel resolution 
  • 0.96" size (measured diagonally)
  • White Monochrome
  • Internal boost converter 
  • I²C Interface 

Power Requirements

  • Voltage: 3.0V - 5.5V 

Pins Used

  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line

Dimensions

  • 27mm x 21mm (1.06 inches x 0.827 inches)
  • Max Height (from lower bottom of Wireling to upper top Wireling Connector): 5.00mm (0.197 inches)
  • Weight: 1 gram (.04 ounces)

Materials

Hardware

Required Software


Hardware Assembly

Plug your Wireling into the port you plan on using! The default in the included program is port 0.

If you want to use a different port, you just need to change the port value in the program mentioned later.


Programming

Install the necessary Python package:

pip3 install adafruit-circuitpython-ssd1306

Use sudo to install system-wide.


Then you can download (above under Software) the OLED Display Screen Wireling Python example:

oled-example.py
# SSD1306 Screen Example
# Displays pixels, lines, shapes, and text to demonstrate displaying basics
# Author: Laverena Wienclaw for TinyCircuits

# Import all board pins.
import time
import board
import busio
from digitalio import DigitalInOut
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

import tinycircuits_wireling
wireling = tinycircuits_wireling.Wireling() # Enable and power Wireling Pi Hat

port = 0 # IMPORTANT: Select ports 0-3
reset_pin = DigitalInOut(wireling.getBoardPin(port)) # A reset line to reset circuitry
wireling.selectPort(port) 

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
# The I2C address for these displays is 0x3d or 0x3c, change to match
# A reset line may be required if there is no auto-reset circuitry
display = adafruit_ssd1306.SSD1306_I2C(72, 40, i2c, addr=0x3c, reset=reset_pin) # 0.42" Screen
#display = adafruit_ssd1306.SSD1306_I2C(96, 16, i2c, addr=0x3c, reset=reset_pin) # 0.69" Screen
#display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c, reset=reset_pin) # 0.96" Screen

# ----------------------------------------------------------

print("Pixel test")
# Clear the display.  Always call show after changing pixels to make the display
# update visible!
display.fill(0)
display.show()

# Set a pixel in the origin 0,0 position.
display.pixel(0, 0, 1)
# Set a pixel in the middle position.
display.pixel(display.width//2, display.height//2, 1)
# Set a pixel in the opposite corner position.
display.pixel(display.width-1, display.height-1, 1)
display.show()
time.sleep(1)

# ----------------------------------------------------------

print("Lines test")
# we'll draw from corner to corner, lets define all the pair coordinates here
corners = ((0, 0), (0, display.height-1), (display.width-1, 0),
           (display.width-1, display.height-1))

display.fill(0)
for corner_from in corners:
    for corner_to in corners:
        display.line(corner_from[0], corner_from[1],
                     corner_to[0], corner_to[1], 1)
display.show()
time.sleep(1)

# ----------------------------------------------------------

print("Rectangle test")
display.fill(0)
w_delta = display.width / 10
h_delta = display.height / 10
for i in range(11):
    display.rect(0, 0, int(w_delta*i), int(h_delta*i), 1)
display.show()
time.sleep(1)

# ----------------------------------------------------------

print("Text test")
# Create blank image for drawing.
display.fill(0)
image = Image.new('1', (display.width, display.height))
draw = ImageDraw.Draw(image)

# Load a font in 2 different sizes.
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 28)
font2 = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 14)

# Draw the text
draw.text((0, 0), 'Hello!', font=font2, fill=255)
#draw.text((0, 30), 'Hello!', font=font2, fill=255)
#draw.text((34, 46), 'Hello!', font=font2, fill=255)

# Display image
display.image(image)
display.show()

Depending on the screen you plan on using, comment, or uncomment the dimensions of the OLED in the example program where the display variable is initialized. This program will show a variety of behavior including drawing pixels, lines, shapes, and text.


Run Program

Navigate in the terminal to the directory with the file parent to the examples folder.

python3 oled-example.py

More examples?

The Python package used for the TinyCircuits hardware in this tutorial was made by Adafruit, and there are several other examples to use from the GitHub repository of the package. To edit any Adafruit example for use with TinyCircuits hardware, you would just need to insert this code chunk (with different pixel definitions depending on what screen you are using):

import tinycircuits_wireling
wireling = tinycircuits_wireling.Wireling() # Enable and power Wireling Pi Hat

port = 0 # IMPORTANT: Select ports 0-3
reset_pin = DigitalInOut(wireling.getBoardPin(port)) # A reset line to reset circuitry
wireling.selectPort(port) 

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height.  Change these
# to the right size for your display!
display = adafruit_ssd1306.SSD1306_I2C(72, 40, i2c, addr=0x3c, reset=reset_pin) # 0.42" Screen
#display = adafruit_ssd1306.SSD1306_I2C(96, 16, i2c, addr=0x3c, reset=reset_pin) # 0.69" Screen
#display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c, reset=reset_pin) # 0.96" Screen

in place of the regular display initialization:

display = adafruit_ssd1306.SSD1306_I2C(96, 32, i2c, addr=0x3c, reset=reset_pin)

Downloads

0.42" OLED

0.69" OLED

0.96" OLED


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!