SSD1306 OLED Display Scroll Functions and Draw Shapes Using ESP32
SSD1306 OLED Display Scroll Functions and Draw Shapes Using ESP32
Project Components
● ESP 32
● DS18B20 Temperature Sensor
● 4.7 kΩ Resistor
● Jumper Wires
● Breadboard
Methodology
Projected Algorithm
Abstract
This application will show a function on how to control an OLED Display with
MicroPython using ESP32. This SSD1306 OLED Display Scroll Functions and Draw
Shapes using ESP32 can scroll the entire screen horizontally and vertically and it
can also draw various shapes, like rectangle, triangle, circle and line.
The acronym “OLED” stands for Organic Light-Emitting Diode, a technology
that uses LEDs in which the light is produced by organic molecules. OLEDs enable
emissive displays - which means that each pixel is controlled individually and emits
its own light (unlike LCDs in which the light comes from a backlighting unit).
An OLED display have the following advantage: Improved image quality -
better contrast, higher brightness, fuller viewing angle, a wider color range and much
faster refresh rates; Lower power consumption; and Simpler design that enables
ultra-thin, flexible, foldable and transparent displays.
Components:
The materials required for this project are the following:
ESP32
0.96 inch OLED Display
Breadboard
Jumper wires
Methodology:
Before we start, you need to install MicroPython firmware in your ESP32. You also
need to install IDE to write and upload the code to your board. We suggest using
Thonny IDE or uPyCraft IDE.
For an ESP32 Board, follow this schematic diagram:
Scroll in horizontally
The following function scroll_in_screen(screen) scrolls the content of an
entire screen (right to left).
def scroll_in_screen(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)
This function accepts as argument a list of lists. For example:
Each list of the list contains the x coordinate, the y coordinate and the message [x,
y, message].
As an example, we’ll display three rows on the first screen with the following
messages.
Then, to make your screen scrolling from left to right, you just need to call
the scroll_in_screen() function and pass as argument the list of lists:
scroll_in_screen(screen1)
Now, you can use both functions to scroll between screens. For example:
scroll_in_screen(screen1)
scroll_out_screen(4)
scroll_in_screen(screen2)
scroll_out_screen(4)
def scroll_screen_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)
You can use this function to scroll between screens, or to scroll the same screen
over and over again.
scroll_screen_in_out(screen1)
scroll_screen_in_out(screen2)
scroll_screen_in_out(screen3)
Scroll in vertically
The scroll_in_screen_v(screen) scrolls in the content of the entire screen.
def scroll_in_screen_v(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)
def scroll_out_screen_v(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()
def scroll_screen_in_out_v(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)
Follow the previous instructions on how to install a library, but for the GFX library.
Save the GFX library file as gfx.py. Then, you can use the library functionalities by
importing the library in your code.
Link: https://randomnerdtutorials.com/micropython-ssd1306-oled-scroll-shapes-
esp32-esp8266/
Methodology
We’re using a 128×64 OLED display. If you’re using an OLED display with different
dimensions, change that on the following lines:
oled_width = 128
oled_height = 64
Then, you can use the drawing functions we’ll show you next to display shapes.