Using the onboard OLED Screen
Display text, simple logos and images in the OLED screen
Components Required
Introduction
Learning Outcomes
- Using Adafruit OLED library
Theory
Methodology
Adafruit OLED library(micropython-ssd1306) is used to handle the LCD, it’s important to install those libraries beforehand.
How to import libraries
1. Select “Manage Packages” from the “Tools” menu.
2. Enter the name of the package you want to install (e.g.micropython-ssd1306 ), and then click on Find package from PyPI.
3. Click on Install to install the package.
First, we create the content we need to print onto the screen and then use display.display command to update the screen.
Code
from machine import Pin, I2C
import ssd1306
from time import sleep
# Magicbit Pin assignment
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
oled.text('Hello, World 1!', 0, 0)
oled.text('Hello, World 2!', 0, 10)
oled.text('Hello, World 3!', 0, 20)
oled.show()
Explanation
oled_width = 128 Define the OLED width
oled_height = 64 Define the OLED height
The oled.text() method accepts the following arguments (Message,X,Y,Color):
- Message: must be of type String
- X position: where the text starts
- Y position: where the text is displayed vertically
- Text color: it can be either black or white. The default color is white and this parameter is optional.
- 0 = black
- 1 = white
oled.show(): Updates the changes to the screen.
Ranga
See https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html for SSD1306 OLED display functions.