fbpx
Micropython Lesson 6: Onboard LED Screen
Micropython Lesson 6

Using the onboard OLED Screen

Display text, simple logos and images in the OLED screen

Components Required

Magicbit
Buy

Introduction

Color OLED screen on Magicbit can display text as well as simple logos & images.

Learning Outcomes

From this example, you’ll get an understanding about,
  • Using Adafruit OLED library

Theory

Magicbit has a 0.96” OLED screen which can be communicated with from the I2C protocol. The display has the address, 0x3c.

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.

Related Posts
1 Comment
Leave a Reply