Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to animate text on SSD1306 using MicroPython and ESP8266

By Nikhil Agnihotri October 25, 2022

Organic light-emitting diode or OLED displays have become essential for many embedded devices. OLEDs are considered one of the highest-quality displays to showcase device information. 

Typically, embedded devices use single-screen graphics, but complex interfaces are required when there are several user interactions. For example, such interfaces might use menus or other graphical navigation. Adding a menu or multi-page graphic interface on embedded displays is a complicated task. Microcontrollers have limited flash memory and RAM, so they cannot host rich graphical interfaces. 

The only alternative is animated text. Text can be animated to display menus and submenus, show multiple navigation screens, and host multi-screen user interfaces. 

In this project, we’ll host a multi-screen interface on an SSD1306 OLED controlled using the ESP8266 microcontroller. MicroPython is the embedded firmware, so we’ll use a MicroPython script on the board to host SSD1306’s front end. The user interface will display a collection of screens with horizontal and vertical animated text. 

Components required
1. ESP8266 x1
2. SSD1306 OLED x1
3. Dupont wires
4. Micro USB cable (to connect ESP8266 with computer)

Circuit connections
Connect the SSD1306 OLED with ESP8266 using SPI software. 

  • The OLED’s DC, RST, and CS pins connect with GPIO4, GPIO5, and GPIO15. 
  • The OLED’s D0 and D1 pins connect with GPIO14 and GPIO13. 
  • The OLED’s VCC and GND pins connect to the 3V out and GND of the ESP8266. 

Getting ESP8266 ready
MicroPython IDE must be ready to write, edit, and upload codes before continuing with this project. You can use uPyCraft IDE or Thonny IDE for software development. Ensure the MicroPython firmware is correctly uploaded to ESP8266. Learn how here.

Extending the ssd1306.py library for text animation
MicroPython firmware holds the library for the SSD1306 OLED. To work with the SSD1306 OLED using MicroPython, first learn how to interface SSD1306 with ESP32 and ESP8266. You’ll note that the Github link for the MicroPython source code has changed. The source code on Github also excludes the SSD1306 library. Fortunately, the library is still available in the source code on the official site.  

This library is sufficient for interfacing the SSD1306 OLED with MicroPython’s ports, especially via the SPI port. Interfacing through the I2C port is no longer working properly. 

The library must be extended to create text animations. The following methods should be added to the library’s class SSD1306. 

def fill(self, col):
            self.framebuf.fill(col)
def pixel(self, x, y, col):
        self.framebuf.pixel(x, y, col)
def scroll(self, dx, dy):
        self.framebuf.scroll(dx, dy)
def text(self, string, x, y, col=1):
        self.framebuf.text(string, x, y, col)

The methods added to the SSD1306 class are called the same as in the MicroPython class FrameBuffer. The FrameBuffer class provides a pixel buffer that represents a pixel, line, shape, or text. 

These FrameBuffer methods are used to extend the library…. 

  • FrameBuffer.fill(c): fills the entire frame buffer with a specified color. The SSD1306 OLED driver uses this method to fill the OLED screen with monochromatic color.
  • FrameBuffer.pixel(x, y[, c]): used to get or set the color of a specified pixel. The pixel’s position is passed as arguments ‘x’ and ‘y.’ If it’s used to set the color of the pixel, ‘c’ is the color that’s passed as an argument.
  • FrameBuffer.scroll(dx, dy): used to shift the contents of the FrameBuffer by a given vector. 
  • FrameBuffer.text(s, x, y[, c]): used to write a string text on the OLED display. The text starts printing on the screen from the ‘x’ and ‘y’ pixel positions. The color of the text can be set to ‘c.’ 

The extended SSD1306 library has this source code: 

Uploading the OLED driver using uPyCraft IDE
To use uPyCraft IDE to upload the OLED driver to ESP8266 or ESP32, connect the board to a computer using a USB cable. The MicroPython firmware must already be uploaded to ESP8266/ESP32. 

Next, select the COM port. ESP8266/ESP32 is connected by navigating to Tools-> Serial. Choose your MicroPython board by navigating to Tools->board. Now connect the board to uPyCraft IDE by clicking the connect button. 

Once the board is connected, browse boot.py from the device folder. To add the SSD1306 OLED driver, create a new file by navigating to File->New or clicking the New button.

Copy the SSD1306 OLED driver library code and save the file as ssd1306.py. Then, click the ‘Download and Run’ button to upload the library file to ESP8266/ESP32.

Creating screens
The user interface must be arranged as separate screens to add submenus or a multi-pane layout. This means different submenus or navigation panes open as separate screens on the display. Each screen can be thought of as a list of pixel rows where each row contains a text or shape. 

The following code defines three different screens. Each screen is a list of rows containing plain text. 

screen1_row1 = “Screen 1, row 1”
screen1_row2 = “Screen 1, row 2”
screen1_row3 = “Screen 1, row 3”
screen2_row1 = “Screen 2, row 1”
screen2_row2 = “Screen 2, row 2”
screen3_row1 = “Screen 3, row 1”
screen1 = [[0, 0 , screen1_row1], [0, 16, screen1_row2], [0, 32, screen1_row3]] screen2 = [[0, 0 , screen2_row1], [0, 16, screen2_row2]] screen3 = [[0, 40 , screen3_row1]]  

Scrolling text horizontally
To scroll text horizontally from left to right (with the text entering the screen), the ‘x’ coordinate of each line of text is incremented by four pixels in a nested loop — until the loop variable exceeds the width of the LED.

def scroll_h_in(screen):
  for i in range (0, oled_width+1, 4):
    for line in screen:
      oled.text(line[2], -oled_width+i, line[1])
    oled.show()
    if i!= oled_width:
      oled.fill(0)

To scroll text horizontally left to right (with the text leaving the screen), the ‘x’ coordinate of each line of is incremented by the user-defined number of pixels — until the text disappears from the display.

def scroll_h_out(speed):
  for i in range ((oled_width+1)/speed):
    for j in range (oled_height):
      oled.pixel(i, j, 0)
    oled.scroll(speed,0)
    oled.show()

To scroll text horizontally in and out, the ‘x’ coordinate of each line of is continuously incremented to let the text enter and then leave the screen.

def scroll_h_in_out(screen):
  for i in range (0, (oled_width+1)*2, 1):
    for line in screen:
      oled.text(line[2], -oled_width+i, line[1])
    oled.show()
    if i!= oled_width:
      oled.fill(0)

Scrolling text vertically
To scroll text vertically from top to bottom (with the text entering the screen), the ‘y’ coordinate of each line is incremented by four pixels in a nested loop — until the loop variable exceeds the height of the LED.

def scroll_v_in(screen):
  for i in range (0, (oled_height+1), 1):
    for line in screen:
      oled.text(line[2], line[0], -oled_height+i+line[1])
    oled.show()
    if i!= oled_height:
      oled.fill(0)

To scroll text vertically from top to bottom (with the text leaving the screen), the ‘y’ coordinate of each line is incremented by the user-defined number of pixels — until the text disappears from the display.

def scroll_v_out(speed):
  for i in range ((oled_height+1)/speed):
    for j in range (oled_width):
      oled.pixel(j, i, 0)
    oled.scroll(0,speed)
    oled.show()

To scroll text vertically in and out, the ‘y’ coordinate of each line of is continuously incremented to let the text enter and then leave the screen.

def scroll_v_in_out(screen):
  for i in range (0, (oled_height*2+1), 1):
    for line in screen:
      oled.text(line[2], line[0], -oled_height+i+line[1])
    oled.show()
    if i!= oled_height:
      oled.fill(0)

The MicroPython script
Try the following code in main.py. This script creates three different screens composed of plain text and tests the horizontal and vertical scrolling of each one.

How it works
The script uses the functions added to the SSD1306.py library. It creates screens with plain text and alters the ‘x’ and ‘y’ positions of each line to move horizontally and vertically over the frame of the screen.

Applications
The code demonstrated here can be reused to host a multi-menu user interface on a MicroPython-powered embedded device or a multi-pane graphic interface.

Results

 

You may also like:


  • What is the role of embedded software in electric vehicles?

  • What is the Modbus protocol and how does it work?

  • Getting started with ESP8266 and ESP32 on Arduino IDE

  • Getting started with MicroPython on ESP8266

  • Using MicroPython SSD1306 driver to interface an OLED display with…
  • Interfacing SSD1306 OLED
    How to interface SSD1306 OLED with Arduino using SPI

Filed Under: Microcontrollers, Python, Tutorials
Tagged With: microcontroller, MicroPython, oled, oleddisplay, SSD1306
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe