Display Class

๐Ÿ–ฅ๏ธ 0.96โ€‘inch OLED Display (128ร—64)

๐Ÿ“Œ Description

The 0.96โ€‘inch OLED display is a compact screen that can show text, numbers, and simple graphics. It uses the SSD1306 driver chip and communicates with the microcontroller via I2C (only 4 pins: VCC, GND, SDA, SCL). Compared to the 0.91โ€‘inch version, this one has a higher resolution (128ร—64), which means more space for text and images.

๐ŸŽฏ Use

In our projects, the OLED 128ร—64 is used to:

  • Display multiple lines of text.
  • Show sensor readings or robot status.
  • Draw icons, logos, or simple animations.

๐Ÿ‘‰ Think of the OLED as the robotโ€™s dashboard โ€” it shows information clearly and compactly.

ย Module parameters

Pin name Description
GND GND (Power Input Negative)
VCC VCC (Power Input Cathode)
SCL Clock signal communication pin
SDA Bidirectional data communication pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 terminal wire
  • Installation method: four-screw fixation

๐Ÿ–ฅ๏ธ Code Explanation

import machine
import oled128x64
from expression_picture import Heart

# Configure I2C communication (pins 22 = SCL, 21 = SDA)
i2c_extend = machine.SoftI2C(scl = machine.Pin(22), sda = machine.Pin(21), freq = 100000)

# Initialize OLED with SSD1306 driver, address 0x3c
oled = oled128x64.OLED(i2c_extend, address=0x3c, font_address=0x3A0000, types=0)

# Display text in different positions
oled.shows('Clu-Bots', x = 0, y = 0, size = 1, space = 0, center = True)   # Centered on line 1
oled.shows('Clu-Bots', x = 0, y = 10, size = 1, space = 0, center = False) # Left aligned on line 2
oled.shows('Clu-Bots', x = 0, y = 30, size = 1, space = 0, center = True)  # Centered on line 3

# Display a heart image at position (0,45)
oled.image(Heart, x = 0, y = 45, size = 1)

Step by Step

  1. import machine, oled128x64 โ†’ Tools for pins and OLED control.
  2. from expression_picture import Heart โ†’ Imports a predefined heart image.
  3. i2c_extend = machine.SoftI2C(...) โ†’ Sets up I2C communication using pins 22 (SCL) and 21 (SDA).
  4. oled = oled128x64.OLED(...) โ†’ Initializes the OLED display with SSD1306 driver at address 0x3c.
  5. oled.shows(...) โ†’ Displays the text โ€œCluโ€‘Botsโ€ in different positions (centered or left aligned).
  6. oled.image(...) โ†’ Draws the heart image at the bottom of the screen.

๐Ÿ‘‰ Together, this program shows text in multiple styles and an image on the OLED.


โœ… Conclusion of the Test

  • If the OLED shows โ€œCluโ€‘Botsโ€ in different positions and a heart icon at the bottom, the program is working correctly.
  • This test demonstrates how the robot can combine text and graphics on a small OLED screen.
  • Later, you can use this display to show menus, sensor values, or animations to make the robot more interactive.
On this page