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



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


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


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.



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)



display.clearDisplay(): Clears the OLED display.

display.setTextSize(2): Set the font size of the text.

display.setCursor(0, 25): Sets the cursor(determines where the next text will appear).

display.println(stuff to print): print the data given on a new line, similar effect like Serial.println.

display.setTextColor(WHITE): Sets the color of the text.

display.display(): Updates the changes to the screen.


Note:: Make a program to display the ADC value of the potentiometer on the OLED display.

Related Posts
1 Comment
Leave a Reply