SSD1306/SH1106 Driver for esp-idf
Go to file
2024-09-12 16:25:55 +09:00
AnimationDemo Adjusted the latency between frames. 2024-09-12 13:07:06 +09:00
BdfFontDemo Removed unused code 2024-09-12 08:38:52 +09:00
BenchMark Update README.md 2024-04-05 20:00:34 +09:00
BlinkIconDemo added images 2024-04-25 07:31:23 +09:00
components/ssd1306 added ssd1306_rotate_image/ssd1306_display_rotate_text function 2024-09-12 16:21:27 +09:00
CounterDemo Removed unused includes 2022-11-19 08:07:43 +09:00
DeviceAddDemo Update README.md 2024-09-10 20:55:39 +09:00
esp32s2_multi_pcb Update README.md 2024-04-25 16:53:29 +09:00
FreeTypeDemo Update README.md 2024-09-10 17:58:36 +09:00
ImageDemo Update README.md 2023-06-16 08:38:43 +09:00
ImageRotationDemo Added ImageRotationDemo 2023-06-16 08:36:07 +09:00
ImageScrollDemo Removed unused includes 2022-11-19 08:07:43 +09:00
KeyboardDemo Update README.md 2024-09-07 08:07:24 +09:00
MeterDemo Update README.md 2023-12-25 20:11:36 +09:00
MouseIconDemo Changed spaces to TAB 2024-08-22 18:46:08 +09:00
MouseMoveDemo Perform refactoring 2024-08-22 18:47:37 +09:00
MouseSelectDemo added MouseSelectDemo 2024-08-23 09:11:05 +09:00
RebundDemo added RebundDemo project 2024-06-29 07:04:50 +09:00
ScrollCounterDemo Removed unused includes 2022-11-19 08:07:43 +09:00
TextDemo Update README.md 2024-09-11 12:18:25 +09:00
VerticalWritingDemo Update README.md 2024-09-12 16:25:55 +09:00
WrapAroundDemo Update README.md 2024-09-12 13:07:52 +09:00
LICENSE Create LICENSE 2022-05-04 07:24:16 +09:00
README.md Update README.md 2024-09-07 11:48:09 +09:00
SSD1306_DataFormat.txt Update SSD1306_DataFormat.txt 2024-09-10 23:26:29 +09:00

esp-idf-ssd1306

SSD1306/SH1106 driver for esp-idf

I used this repository as a reference.
I used this font file.

Software requirements

ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.

Note for ESP32C2.
ESP-IDF V5.0 ESP32C2 i2c driver has a bug.
ESP-IDF V5.1 is required when using i2c of ESP32C2.

Note for ESP32C6 and ESP32H2.
ESP-IDF V5.1 is required when using ESP32C6 and ESP32H2.

Note for ESP-IDF V5.2.
A new i2c driver is now available in ESP-IDF V5.2.
Under ESP-IDF V5.2 or later, this project uses a new i2c driver.

Installation

git clone https://github.com/nopnop2002/esp-idf-ssd1306
cd esp-idf-ssd1306/TextDemo/
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6/esp32h2}
idf.py menuconfig
idf.py flash

Note for ESP32C3
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32C3 specifications, these pins can also be used as SPI clocks.
I used a raw ESP-C3-13 to verify that these pins could be used as SPI clocks.

Configuration

You have to set this config value with menuconfig.

  • CONFIG_INTERFACE
  • CONFIG_PANEL
  • CONFIG_OFFSETX
  • CONFIG_FLIP
  • CONFIG_SDA_GPIO
  • CONFIG_SCL_GPIO
  • CONFIG_RESET_GPIO
  • CONFIG_MOSI_GPIO
  • CONFIG_SCLK_GPIO
  • CONFIG_CS_GPIO
  • CONFIG_DC_GPIO

config-main


Generic SSD1306 128x32 i2c

128x32 config-128x32_i2c

Generic SSD1306 128x64 i2c

128x64 config-128x64_i2c

Generic SH1106 128x64 i2c

Many sellers sell SH1106 as SSD1306.
SH1106 does not support hardware scrolling.
Left:1.3 inch SH1106
Right:0.96 inch SSD1306

SH1106_i2c config-sh1106_i2c

128x64 TTGO

Unlike other ESP32 development boards, the RTC_CLOCK crystal on this board uses a 26MHz one.
You need to change the Main XTAL frequency to 26MHz using menuconfig.

ESP32-TTGO-1 ESP32-TTGO-2 128x64_Reset config-128x64_TTGO config-128x64_TTGO-2

128x64 ESP-WROOM-32

ESP32-OLED-2 config-ESP-WROOM-32


Generic SSD1306 128x32 SPI

128x32_spi config-128x32_spi

Generic SSD1306 128x64 SPI

D0 is SCLK.
D1 is MOSI.

128x64_spi config-128x64_spi

Generic SH1106 128x64 SPI

Many sellers sell SH1106 as SSD1306.
SH1106 does not support hardware scrolling.
Left:1.3 inch SH1106
Right:0.96 inch SSD1306

SH1106_spi config-sh1106_spi


I2C Clock speed

According to the SSD1306 datasheet, the minimum i2c clock cycle time is 2.5us.
Therefore, the maximum i2c clock frequency is 400KHz.
The i2c clock frequency used by this project is 400KHz.

I2C Port selection

config-i2c-port

XTENSA's ESP32 has two i2c port: I2C_NUM_0/1.
You can use these two ports freely.
If you use this module at the same time as another I2C device using I2C port 0, you must change it to I2C port 1.

Force legacy i2c driver

XTENSA's ESP32 has two i2c port: I2C_NUM_0/1.
I2C_NUM_0/1 are initialized independently, but legacy i2c drivers and new i2c drivers cannot be mixed.
If I2C_NUM_0 is initialized with the legacy i2c driver, I2C_NUM_1 must also be initialized with the legacy i2c driver.
If you use the SSD1306 at the same time as an I2C device that uses a legacy I2C driver, you must initialize the SSD1306 with the legacy I2C driver.
Enabling this will use the legacy i2c driver even after ESP-IDF V5.2.
config-i2c-driver


SPI Clock speed

According to the SSD1306 datasheet, the minimum SPI clock cycle time is 100ns.
Therefore, the maximum SPI clock frequency is 10MHz.
The SPI clock frequency used by this project is 1MHz.
Higher SPI clock frequencies can be specified using spi_clock_speed().
When using 10MHz, you need to be careful about the length of the wire cable.

    //int speed = 1000000; // 1MHz
    //int speed = 2000000; // 2MHz
    //int speed = 4000000; // 4MHz
    //int speed = 6000000; // 6MHz
    //int speed = 8000000; // 8MHz
    int speed = 10000000; // 10MHz
    spi_clock_speed(speed);
    spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);

SPI BUS selection

config-spi-bus

The ESP32 XTENSA series has three SPI BUSs.
SPI1_HOST is used for communication with Flash memory.
You can use SPI2_HOST and SPI3_HOST freely.
When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS.
When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST.
When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work.
Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.


Flip upside down

config_flip

ssd1306_flip