ESP32 – 128x32 OLED – SSD1306 Display Interface

by PugazhM in Circuits > Wireless

11514 Views, 1 Favorites, 0 Comments

ESP32 – 128x32 OLED – SSD1306 Display Interface

Circuit_V01.jpeg

This experimentation explains about,128x32 OLED display with ESP32, and using MicroPython for programming the OLED

Visit the "VESZLE - The Art Of Electronics" you tube channel for further information and videos.

https://www.youtube.com/channel/UCY4mekPLfeFinbQHp...

ESP32 - 128x32 OLED Video Link

Abstract

The ESP32 is constructed with Xtensa dual-core (or single-core) 32-bit RISC architecture, operating at 160MHz or 240MHz, with up to 520KiB internal SRAM, integrated with Wi-Fi (802.11 b/g/n) and Bluetooth (v4.2 BR/EDR and BLE (shares the radio with Wi-Fi). The ESP32 provides peripheral interfaces like ADC, DAC, touch sensors, SPI, I2C, I2S, UART, CAN, PWM etc. The ESP32 supports all IEEE 802.11 standard security feature (WFA, WPA/WPA2 and WAPI), and cryptographic hardware acceleration (AES, RSA, SHA-2, ECC, RNG etc). It supports wake up from GPIO / Sensor interrupts, timers and 5uA deep sleep current consumption.

An OLED display works without a backlight because it emits visible light. In low ambient light conditions (such as a dark room), an OLED screen can achieve a higher contrast ratio than an LCD, regardless of whether the LCD. OLEDs represent the future of display technology.

This experimentation explains about,128x32 OLED display with ESP32, and using MicroPython for programming the OLED

Components

Component.jpg

ESP32 Development Board

Micro USB Cable

128x32 OLED Display Module

Reference

“ESP32 – Getting Started MicroPython -- on Board Blink LED” Instruct-able / You-tube by PugazhM

https://www.instructables.com/ESP32-Getting-Starte...

The “ssd1306.py” driver library.

https://github.com/micropython/micropython/blob/ma...

LCD Assistant tool. (http://en.radzio.dxp.pl/bitmap_converter/).

Schematic

Circuit_V01.jpeg

Organic Light Emitting Diodes (OLED) is a flat light emitting technology, made by placing a series of organic thin films between two conductors.

When electrical current is applied, then OLED emits a bright light.

OLEDs are available in many colors. (Red, Green, Blue, Yellow, Amber, White, etc.).

OLEDs are emissive displays that do not require a backlight, self-illumination and so, they are thinner and more efficient than LCD displays

OLEDs represent the future of display technology.

OLED provide the best image quality ever and they can also be made transparent, flexible, foldable and even roll-able and stretchable in the future.

The 128x32 OLED uses SSD1306 device and supports I2C communication interface

OLED displays consumes low power and can functional at 3.3VDC.

The SSD1306 is a single chip common cathode type driver, and drives up to 128 segments of 64 commons.

The SSD1306 embeds with display RAM, oscillator and 256 steps of contrast / brightness control. It provides either I2C interface or SPI interface.

The OLED module is connected / communicates with ESP32 I2C0 bus.

MicroPython provides device driver library, that includes frame buffer, line-shape drawing functionalities, ASCII font decoding, text string handling etc.

Python Program – OLED Display Program

TaskEvent_V01.jpeg

Download MicroPython SSD1306 OLED driver, I2C and SPI interfaces library. “ssd1306.py” driver library from “https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py”

Open the ESP32 as drive, and then copy the library into root directory.

The timer_one is initialized and callbacks the “BlinkLED” functionality for toggling on board LED at 200mS duration. (frequency = 5)

Black and White icons (car, apple, EV battery, ECG heart and phone) of 32x32 pixels are created by using MS Paint and converted into byte array by using LCD assistant tool.

By using MS paint, draw a bigger size icon and then resize into 32x32 pixels. Save the icon as BMP picture. Select option as “Monochrome Bitmap”.

“LCD Assistant” tool can be downloaded from “http://en.radzio.dxp.pl/bitmap_converter/”

Open the icon.bmp at “LCD Assistant” tool. Select byte orientation as “Horizontal” and size as 32x32 and Size endian as “little”, pixel/bytes 8. Save output as byte array.

Later, the icon byte array can be copied into main python program.

Each 32x32 icon contains / needs 1024 pixels or 1024 bits or 128 byte per icon.

OLED is initialized and welcome screen of “ESP32, OLED Display” is displayed in two rows, for about 5 seconds.

CAR, APPLE, EV BATTERY, PHONE and HEART Icons are populated one after another at 5 seconds interval, with 2 rows of useful text information.

'''<br>  Demonstrates ESP32 interface to  128x32 OLED
  # Display Image & text on I2C driven SSD1306 OLED display 
   
 * The ESP32 pin connections for OLED I2C
 
 # OLED Power Pins
 * OLED VCC pin to 3V3
 * OLED GND pin to GND
 
 # OLED I2C Pins
 * OLED SCL pin to GPIO22
 * OLED SDA pin to GPIO21
   
 Name:- M.Pugazhendi
 Date:-  28thSep2021
 Version:- V0.1
 e-mail:- muthuswamy.pugazhendi@gmail.com
'''
import machine
from machine import Pin, I2C
#import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
import utime
toggle = 0
# OLED pixel definition (WxH)
WIDTH  = 128 
HEIGHT = 32
# I2C0 pin assignments
SCL = 22
SDA = 21
#Initialize the onboard LED as output
led = machine.Pin(2,machine.Pin.OUT)
# Toggle LED functionality
def BlinkLED(timer_one):
    global toggle
    if toggle == 1:
        led.value(0)
        toggle = 0
    else:
        led.value(1)
        toggle = 1
        
# Initialize I2C0, Scan and Debug print of SSD1306 I2C device address
i2c = I2C(0, scl=Pin(SCL), sda=Pin(SDA), freq=200000)
k = i2c.scan()
print("Device Address      : ")
print(k)
# Initialize OLED
display = SSD1306_I2C(WIDTH, HEIGHT, i2c)
# Initialize timer_one. Used for toggling the on board LED
timer_one = machine.Timer(0)
# Timer one initialization for on board blinking LED at 200mS interval
timer_one.init(freq=5, mode=machine.Timer.PERIODIC, callback=BlinkLED)
# 32x32 apple icon pixel array
a = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0xE0, 0xFC, 0x00,
0x00, 0xF8, 0xF8, 0x00, 0x00, 0xFC, 0xF0, 0x00, 0x00, 0xFD, 0xE0, 0x00, 0x00, 0xFF, 0xC0, 0x00,
0x00, 0x7F, 0xC0, 0x00, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x0F, 0x82, 0x00, 0x07, 0xFB, 0x9F, 0xE0,
0x1F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFE,
0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE,
0x7F, 0xF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x00
]
phone = bytearray(p)
# 32x32 car icon pixel array
c = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00,
0x00, 0xFF, 0xF8, 0x00, 0x01, 0xC7, 0x1C, 0x00, 0x03, 0x83, 0x0E, 0x00, 0x07, 0x03, 0x0E, 0x00,
0x07, 0x03, 0x07, 0x00, 0xFF, 0xFF, 0xFF, 0xF0, 0xFF, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFE,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x3F, 0xFC, 0x3F, 0xF9, 0x9F, 0xF9, 0x9F,
0xF3, 0xCF, 0xF3, 0xCF, 0x77, 0xEF, 0xF7, 0xEE, 0x07, 0xE0, 0x07, 0xE0, 0x07, 0xE0, 0x07, 0xC0,
0x03, 0xC0, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
car = bytearray(c)
# 32x32 heart icon pixel array
h = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x07, 0xF8, 0x3F, 0xE0, 0x0F, 0xFE, 0x7F, 0xF0,
0x1F, 0xFE, 0x7F, 0xF8, 0x1F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xEF, 0xF8, 0x3F, 0xFF, 0xCF, 0xFC,
0x3F, 0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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x7F, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
battery = bytearray(b)
# Initialize timer_one. Used for toggling the on board LED
timer_one = machine.Timer(0)
# Timer one initialization for on board blinking LED at 200mS interval
timer_one.init(freq=5, mode=machine.Timer.PERIODIC, callback=BlinkLED)
# Display image and text on OLED 
while True:
    # Clear the display
    display.fill(0)
    # Write text in two lines
    display.text("ESP32",10,8)
    display.text("OLED Display",10,22)
    display.show()
    utime.sleep(5)
    
    # Phone icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(phone, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("1234567890",35,8)
    display.text("JOHN CARTER",35,22)
    display.show()
    utime.sleep(5)
    
    # Car icon with, text in two lines
    display.fill(0)
    display.fill(0)
    fb = framebuf.FrameBuffer(car, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("KM  : 85678",35,8)
    display.text("FUEL: 88 %",35,22)
    display.show()
    utime.sleep(5)
    # apple icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(apple, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("1KG: 4.00
    # apple icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(apple, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("1KG: 4.00$",35,8)
    display.text("5KG: 40.00$",35,22)
    display.show()
    utime.sleep(5)
quot;,35,8) display.text("5KG: 40.00
    # apple icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(apple, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("1KG: 4.00$",35,8)
    display.text("5KG: 40.00$",35,22)
    display.show()
    utime.sleep(5)
quot;,35,22) display.show() utime.sleep(5)
    # heart icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(heart, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text("BP  :80/120",35,8)
    display.text("BEAT:72",35,22)
    display.show()
    utime.sleep(5)
    
    # battery icon with, text in two lines
    display.fill(0)
    fb = framebuf.FrameBuffer(battery, 32, 32, framebuf.MONO_HLSB)
    display.blit(fb, 0, 0)
    display.text(" V: 24.58V",35,8)
    display.text(" I: 04.75A",35,22)
    display.show()
    utime.sleep(5)


Downloads

Conclusion

C2.jpg
Result.jpg

The project is successfully completed with ESP32 and 128x32 OLED shield

OLEDs represent the future of display technology and can be used for many embedded projects as mixed image and alpha numerical display. It consumes less power.

Results Video and Links

C1.jpg

Please Visit You Tube for the Videos:,

Visit the "VESZLE - The Art Of Electronics" you tube channel for further information and videos. https://www.youtube.com/channel/UCY4mekPLfeFinbQH...

ESP32 -- 128x32 OLED -- Video