Section 3.5 OLED display
Micropython has built-in support for displaying simple graphics, and there are already libraries to interface with a number of displays. In this section, we'll be using a common OLED display model, the SSD1306.
Subsection 3.5.1 Complete code example
Below is a complete code example for the OLED display.
# Demonstrate how to use the OLED display
# This assumes that you've connected it as follows:
# GND -> GND
# VCC -> 3.3V
# SCL -> D2
# SDA -> D4
from machine import Pin, I2C
import ssd1306
from time import sleep
# Set up the display
i2c = I2C(0, scl=Pin(2), sda=Pin(4))
display = ssd1306.SSD1306_I2C(128, 64, i2c)
# Now show some text on the display
display.fill(0) # First clear the display with 0 (black)
display.text("Hello!", 5, 5) # Draw text located at pixel (5, 5)
display.show() # Send the pixel data to the display to show it