Chapter 13 ESP32 I2C-OLED Display

Learning goals and objectives

  1. The principle of OLED display
  2. Master OLED display test procedures

Introduction to I2C Communication Protocol

  • Same as I2C-reading temperature and humidity chapter

OLED parameter introduction

 

OLED (Organic Light-Emitting Diode), also known as Organic Electroluminesence Display (Organic Electroluminesence Display). OLED is considered to be the best OLED because of its self-illumination, no need for backlight, high contrast ratio, thin thickness, wide viewing angle, fast response speed, flexible panel use, wide operating temperature range, and simple structure and process. Next-generation flat panel display emerging application technology. LCDs all need a backlight, and OLEDs don't because it's self-illuminating. In addition, the power consumption of OLED is much lower than that of LCD, and the power consumption of the same display area is only 1/3 of that of LCD. It is difficult to increase the size of OLED, but the resolution can be very high, which is very suitable for handheld mobile devices.

The common 1.3-inch OLED display is divided into two communication methods: SPI and I2C, and three colors of white, blue, and yellow and blue.

  • OLED Features:
  1. Wide voltage support: 3~5V
  2. Resolution: 128*64
  3. Wide operating temperature range: ‐40°C to 85°C
  4. Display unit is self-illuminating, no backlight required
  5. I2C/SPI communication method, our module uses I2C
  6. Large viewing angle
  7. Ultra-low power consumption (0.04W)
  8. Internal use of SSD1306 driver chip

I2C OLED write timing

The main purpose of OLED is to refresh (write) data.

Hardware Design and Principle

This experimental board uses I2C_1 of ESP32 . The following table is the mapping of our program IO.

I2C_1

Features

Map the pins of the ESP32

SCL

clock

IO33

SDA

data

IO32

If the I2C connection method or pins of the experimental board you are using are different, you only need to modify the pins according to our project, and the control principle of the program is the same.

software design

  1. code logic

 

 

  • The timings of other commands of SHT30 are similar, please refer to the English manual of SHT30.

Hardware Design and Principle

This experimental board uses I2C_1 of ESP32. The following table is the mapping of our program IO.

I2C_1

Features

Map the pins of the ESP32

SCL

clock

IO33

SDA

data

IO32

Introduction to I2C master interface of ESP32

Same as I2C-Temperature and Humidity Collection chapter.

OLED display code writing

  • I2C configuration function

1

2

3

4

5

6

7

8

9

10

11

12

13

14

void i2c_init(void)

{undefined

    //Notes refer to the i2c tutorial of sht30

    i2c_config_t conf;

    conf.mode = I2C_MODE_MASTER;

    conf.sda_io_num = I2C_OLED_MASTER_SDA_IO;

    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;

    conf.scl_io_num = I2C_OLED_MASTER_SCL_IO;

    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;

    conf.master.clk_speed = 400000;

    i2c_param_config(I2C_OLED_MASTER_NUM, &conf);

    i2c_driver_install (I2C_OLED_MASTER_NUM, conf.mode, 0, 0, 0);

}

  • OLED configuration function, refer to SSD1306 manual, there will be initialization code on it, just copy it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

void oled_init (void)

{undefined

    //i2c initialization

    i2c_init();

    //oled configuration

    oled_write_cmd(TURN_OFF_CMD);

    oled_write_cmd (0xAE);

    oled_write_cmd(0X20);

    oled_write_cmd (0X10);

    oled_write_cmd (0XB0);

    oled_write_cmd (0XC8);

    oled_write_cmd (0X00);

    oled_write_cmd (0X10);

    oled_write_cmd(0X40);

    oled_write_cmd (0X81);

    oled_write_cmd (0XFF);

    oled_write_cmd (0XA1);

    oled_write_cmd (0XA6);

    oled_write_cmd (0XA8);

    oled_write_cmd (0X3F);

    oled_write_cmd (0XA4);

    oled_write_cmd(0XD3);

    oled_write_cmd (0X00);

    oled_write_cmd (0XD5);

    oled_write_cmd (0XF0);

    oled_write_cmd (0XD9);

    oled_write_cmd(0X22);

    oled_write_cmd (0XDA);

    oled_write_cmd(0X12);

    oled_write_cmd (0XDB);

    oled_write_cmd(0X20);

    oled_write_cmd (0X8D);

    oled_write_cmd (0X14);

    oled_write_cmd (0XAF);

    //clear the screen

    oled_claer ();

}

 

Main function: I2C initialization, OLED initialization, display string, strong brush OLED display, etc.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

#include <stdio.h>

#include "esp_system.h"

#include <esp_log.h>

#include <freertos / FreeRTOS.h>

#include "freertos/task.h"

#include "oled.h"

#include "fonts.h"

 

void app_main()

{undefined

    unsigned int cnt=0;

    oled_init ();

    oled_show_str(0,0,  "HX ESP32 I2C", &Font_7x10, 1);

    oled_show_str(0,15, "oled example", &Font_7x10, 1);

    oled_show_str(0,30, "QQ:671139854", &Font_7x10, 1);

    oled_show_str(0,45, "All On And Clear",&Font_7x10,1);

    vTaskDelay(10000 / portTICK_PERIOD_MS);

    while(1)

    {undefined

        cnt++;

        oled_claer (); // 清 屏

        vTaskDelay(10 / portTICK_PERIOD_MS);

        oled_all_on (); // 全 显

        vTaskDelay(10 / portTICK_PERIOD_MS);

        ESP_LOGI("OLED", "cnt = %d \r\n", cnt);

    }

}

 

hardware connection

The SHT30 module and ESP32 development board can be connected according to the IO mapping table.

 

Show results

 

OLED Display Summary

 

Click me -> more ESP32 development guide series catalog

Tags: Chapter 13 ESP32 I2C-OLED Display

ESP32 development ESP32 Development Guide ESP32

Related: Chapter 13 ESP32 I2C-OLED Display