In this tutorial, shows how to use the SSD1306 0.96 inch I2C OLED display with the ESP32. We’ll show you some features of the OLED display, how to connect it to the ESP32 board, and how to write text.
(1) x Elegoo ESP32
(1) x I2C OLED Display
(2) x 400 Tie Points Breadboard
(4) x M-Mwires (Male to Male jumper wires)
I2C OLED Display
The organic light-emitting diode (OLED) display that we’ll use in this tutorial is the SSD1306 model: a monocolor, 0.96-inch display with 128×64 pixels as shown in the following figure.
The model we’re using here has only four pins and communicates with the ESP32 using I2C communication protocol. There are models that come with an extra RESET pin. There are also other OLED displays that communicate using SPI communication.
Because the OLED display uses I2C communication protocol, wiring is very simple. You just need to connect to the ESP32 I2C pins as D21(SDA)、D22(SCL)
To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h libraries. Follow the next instructions to install those libraries.
Here’s some functions that will help you handle the OLED display library to write text or draw simple graphics.
After wiring the OLED display to the Arduino and installing all required libraries, you can use one example from the library to see if everything is working properly.
In your Arduino IDE, go to File > Examples > Adafruit SSD1306 and select the example for the display you’re using.
On ESP32, the I²C pins (SDA & SCL) can be freely remapped to any available GPIOs; you must explicitly call Wire.begin(SDA, SCL). The example wires the OLED to GPIO 21 for SDA and GPIO 22 for SCL—unlike the fixed A4/SDA and A5/SCL on Arduino UNO—adjust as required.
Wire.begin(21,22);
You can click the blue text link to download the program file to your local device, and double-click the file to open it after the download is complete.
Please note: Before opening the file, ensure that you have installed the Arduino IDE development environment and completed the installation of relevant components such as the board support package and driver corresponding to the ESP32 development board. If you have any questions about this operation process, you can refer to the "part 1" chapter of the document for detailed guidance.