Skip to content

Initialize OLED (I2C) (oled_init_hw)

What it does: Initializes I2C, framebuffer and tries to detect the connected OLED controller (SSD1306/ST7567).

oled_init

Inputs

  • SDA_PIN: value of type Value.
  • SCL_PIN: value of type Value.
  • Field HW_I2C: parameter selection in the block menu.

Output

  • None (statement block).

When to use it

  • Once at program start before using all blocks fb_* and oded_refresh.
  • When changing I2C pins or reinitializing the display after an error.

Tips and pitfalls

  • OLED detection looks for I2C addresses 60 (0x3C) and 63 (0x3F); if nothing is found, display will remain unprepared.
  • Perform the initialization once on startup because it recreates the buffer, fbuf and I2C object each time it is called.

Usage example

example_oled_dsiplay

Open example in ESP IDE

Generated Python example

from machine import Pin, I2C

# inicializace OLED + framebufferu
i2c = I2C(0, scl=Pin(22), sda=Pin(21))