How to Interface OLED Display with ESP32?
This guide will show you how to connect an OLED display module to an ESP32 development board. In this implementation, we have an OLED Graphic Display that is driven by an SSD1306 OLED Driver IC and exchanges data over SPI. Display text, bitmap images, graphics, and more on an OLED screen with an ESP32 in your next do-it-yourself project.
Introduction
Organic light-emitting diodes (OLEDs) are a type of high-tech display that employs a film of organic substance sandwiched between two electrodes (anode and cathode), which then generates light when a voltage is placed across the electrodes.
An OLED Display’s key benefit is that it generates its own illumination and does not require a separate backlight. Since this is the case, OLED displays typically outperform LCD screens in terms of contrast, brightness, and viewing angle.
Organic light-emitting diodes (OLEDs) are a type of high-tech display that employ a film of organic substance sandwiched between two electrodes (anode and cathode), which then generates light when a voltage is placed across the electrodes.
An OLED Display’s key benefit is that it generates its own illumination and does not require a separate backlight. Since this is the case, OLED displays typically outperform LCD screens in terms of contrast, brightness, and viewing angle.
SSD1306 OLED Display
Is an OLED screen something you’d like to incorporate into your own creation? Do you want to put up a screen that shows things like your IP address, web server address, and other crucial info? If so, I highly recommend looking into the SSD1306 OLED Display Module.
This screen is a 128×64 Monochrome OLED Display. The diagonal length is 0.96 inches. The SSD1306 OLED Driver IC is used in this display.
The SSD1306 OLED Display family includes three distinct types of data connections:
- 8-bit 6800 Parallel Interface
- 3 or 4 wire SPI
- I2C
The I2C and SPI types of OLEDs are particularly widespread. Changing from SPI to I2C is doable (you just have to solder/de-solder certain SMD resistors). It uses 4-wire SPI Communication, which is what my model calls for.
The I2C and SPI types of OLEDs are particularly widespread. Changing from SPI to I2C is doable (you just have to solder/de-solder certain SMD resistors). It uses 4-wire SPI Communication, which is what my model calls for.
So, 8 Pages * 128 Segments * 8 Bits = 8192 Bits (1024 Bytes).
Pinout of OLED Display Module
The following table shows the Pinout of 7-pin SPI based OLED Display Module.
| Pin (Alternative Names) | Description |
| GND | Ground |
| VCC | Power Supply |
| D0 (SCK, SCL, CLK) | Clock |
| D1 (MOSI, SDA) | Data |
| RES (RST) | Reset |
| DC (A0) | Data / Command Selection |
| CS | Chip Select |
Power Supply
The OLED panel itself requires VCC = 7V to 15V, while the SSD1306 OLED Driver IC operates at VDD = 1.65V to 3.3V. The OLED Display Module’s charge pump circuit (for Panel) and regulator (for Driver IC) allow it to meet these varying voltage needs from a single source (usually between 3V and 5V).
The OLED panel itself requires VCC = 7V to 15V, while the SSD1306 OLED Driver IC operates at VDD = 1.65V to 3.3V. The OLED Display Module’s charge pump circuit (for Panel) and regulator (for Driver IC) allow it to meet these varying voltage needs from a single source (usually between 3V and 5V).
ESP32 OLED Display Interface
This allows boards such as Arduino (5V logic) and ESP32 to interface with the OLED Display Module (with 3.3V logic).
As seen in the graphic above, the ESP32 Development Board supports both the High-Speed SPI Interface (HSPI) and the Very-Slow SPI Interface (VSPI). In this case, we can use the VSPI add-on module. When using VSPI with an ESP32, you’ll need to connect these pins:
| VSPI Pin | GPIO Pin |
| VSPI_MOSI | GPIO 23 |
| VSPI_MISO | GPIO 19 |
| VSPI_CLK | GPIO 18 |
| VSPI_CS | GPIO 5 |
Please take note that ESP32 has a total of four SPI peripherals. (SPI-0, –1, –2, –3, and —4). Since SPI Flash IC requires its own unique SPI0 port, SPI1 is able to share the same hardware. This means that the only options for connecting SPI devices are HSPI and VSPI.
The connections between the ESP32 and the OLED Display Module are detailed in the table below. Since this is an SPI OLED Display, seven wires need to be connected.
| OLED Display | ESP32 |
| GND | GND |
| VCC | 3.3V |
| D0 (SCK) | GPIO 18 |
| D1 (MOSI) | GPIO 23 |
| RES | GPIO 17 |
| DC | GPIO 16 |
| CS | GPIO 5 |
Components Required
- ESP32 DevKit Development Board
- OLED Display Module
- Breadboard
- Connecting Wires
- Micro USB Cable
Circuit Diagram
The following image shows the circuit diagram for Interfacing SPI OLED Display with ESP32.
Preparing Arduino IDE
In order to get started writing code for an SSD1306 OLED Display, you’ll need to grab a few libraries for the Arduino IDE.
 Launch the Arduino Integrated Development Environment (IDE), then go to Tools -> Manage Libraries. . . Arduino-IDE-OLED-Library-1
You can start by reading my in-depth guide on setting up the ESP32 Board in the Arduino IDE.
Search for “gfx” and then install “Adafruit GFX Library” once you’ve put in the SSD1306 Library. Lines, circles, rectangles, and other elementary shapes can be displayed with this Adafruit library.
Once the required libraries have been downloaded, you may close the library manager window. Now, in the Arduino IDE, go to Tools > Board > ESP32 Arduino > ESP32 Dev Module and make sure that the ESP32 Board is chosen.
Testing ESP32 OLED Display
Now that we have everything wired up, we can begin writing some test code for the ESP32 to show off some text and images on the OLED Display. Here I am experimenting with the OLED display’s ability to display standard text, inverted text, scrolling text, ASCII characters, and a variety of font sizes.
I also added the necessary code to display various shapes and lines, including rectangles, filled rectangles, rounded rectangles, filled rounded rectangles, circles, filled circles, triangles, and filled triangles.
| Â | #include <SPI.h> |
| Â | #include <Wire.h> |
| Â | #include <Adafruit_GFX.h> |
| Â | #include <Adafruit_SSD1306.h> |
| Â | Â |
| Â | #define SCREEN_WIDTH 128 |
| Â | #define SCREEN_HEIGHT 64 |
| Â | Â |
| Â | #define OLED_MOSI Â 23 |
| Â | #define OLED_CLKÂ Â 18 |
| Â | #define OLED_DC Â Â 16 |
| Â | #define OLED_CS Â Â 5 |
| Â | #define OLED_RESETÂ 17 |
| Â | Â |
| Â | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, |
| Â | OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); |
| Â | Â |
| Â | const unsigned char electronicshub_logo [] PROGMEM = { |
| Â | 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, 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, 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, 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, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x03, 0xe0, 0x07, 0xc3, 0x87, 0xcf, 0x03, 0x02, 0x11, 0x07, 0x04, 0x0f, 0xbd, 0xbd, 0xc7, 0x80, |
| Â | 0x03, 0xe4, 0x07, 0xc3, 0xc7, 0xcf, 0x07, 0x82, 0x11, 0x07, 0x8e, 0x0f, 0xbd, 0xbd, 0xc7, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x06, 0xc1, 0x01, 0x84, 0xc2, 0x11, 0x0d, 0x8a, 0x0f, 0xbd, 0xbd, 0xf3, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x04, 0x61, 0x00, 0x88, 0x42, 0x11, 0x08, 0x8a, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x0c, 0x21, 0x00, 0x88, 0x43, 0x11, 0x10, 0x08, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x00, 0x88, 0x23, 0x11, 0x10, 0x08, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x00, 0x88, 0x23, 0x11, 0x10, 0x08, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x00, 0x90, 0x23, 0x11, 0x10, 0x08, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x00, 0x90, 0x22, 0x91, 0x10, 0x08, 0x0f, 0xbd, 0xbd, 0xf7, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x00, 0x90, 0x22, 0x91, 0x10, 0x0e, 0x0f, 0xbd, 0xbd, 0xc7, 0x80, |
| Â | 0x03, 0x84, 0x07, 0x08, 0x01, 0x00, 0x90, 0x22, 0x91, 0x10, 0x06, 0x0f, 0x81, 0xbd, 0xc7, 0x80, |
| Â | 0x03, 0x84, 0x07, 0x08, 0x01, 0x07, 0x90, 0x22, 0xd1, 0x10, 0x03, 0x0f, 0x81, 0xbd, 0xf7, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x07, 0x10, 0x22, 0x51, 0x10, 0x01, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x06, 0x10, 0x22, 0x51, 0x10, 0x01, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x02, 0x10, 0x22, 0x51, 0x10, 0x01, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x02, 0x08, 0x22, 0x31, 0x10, 0x01, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x08, 0x01, 0x01, 0x08, 0x22, 0x31, 0x10, 0x01, 0x0f, 0xbd, 0xbd, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x0c, 0x21, 0x01, 0x08, 0x42, 0x31, 0x10, 0x01, 0x0f, 0xbd, 0xdb, 0xfb, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x04, 0x61, 0x01, 0x88, 0x42, 0x31, 0x08, 0x99, 0x0f, 0xbd, 0xdb, 0xf3, 0x80, |
| Â | 0x02, 0x04, 0x04, 0x06, 0xc1, 0x00, 0x84, 0xc2, 0x11, 0x0d, 0x8b, 0x0f, 0xbd, 0xc3, 0xc7, 0x80, |
| Â | 0x03, 0xe7, 0xc7, 0xc3, 0xc1, 0x00, 0x87, 0x82, 0x11, 0x07, 0x8e, 0x0f, 0xbd, 0xe7, 0xc7, 0x80, |
| Â | 0x03, 0xe7, 0xc7, 0xc3, 0x81, 0x00, 0x83, 0x02, 0x11, 0x07, 0x06, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, |
| Â | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Â | 0x07, 0xf0, 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, 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| Â | }; |
| Â | Â |
| Â | void setup() |
| Â | { |
| Â | Serial.begin(115200); |
| Â | if(!display.begin(SSD1306_SWITCHCAPVCC)) |
| Â | { |
| Â | Â Serial.println(F(“SSD1306 allocation failed”)); |
| Â | Â for(;;); |
| Â | } |
| Â | Â |
| Â | display.clearDisplay(); |
| Â | display.display(); |
| Â | delay(1000); |
| Â | Â |
| Â | display.clearDisplay(); |
| Â | display.drawBitmap(0, 0, electronicshub_logo, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(1000); |
| Â | Â |
| Â | Â |
| Â | } |
| Â | void loop() |
| Â | { |
| Â | AllPixels(); |
| Â | TextDisplay(); |
| Â | InvertedTextDisplay(); |
| Â | ScrollText(); |
| Â | DisplayChars(); |
| Â | TextSize(); |
| Â | DrawRectangle(); |
| Â | DrawFilledRectangle(); |
| Â | DrawRoundRectangle(); |
| Â | DrawFilledRoundRectangle(); |
| Â | DrawCircle(); |
| Â | DrawFilledCircle(); |
| Â | DrawTriangle(); |
| Â | DrawFilledTriangle(); |
| Â | } |
| Â | Â |
| Â | void AllPixels() |
| Â | { |
| Â | int i; |
| Â | int j; |
| Â | display.clearDisplay(); |
| Â | for(i=0;i<64;i++) |
| Â | { |
| Â | Â for(j=0;j<128;j++) |
| Â | Â { |
| Â | Â Â display.drawPixel(j, i, SSD1306_WHITE); |
| Â | Â Â Â Â |
| Â | Â } |
| Â | Â display.display(); |
| Â | Â delay(30); |
| Â | } |
| Â | Â |
| Â | for(i=0;i<64;i++) |
| Â | { |
| Â | Â for(j=0;j<128;j++) |
| Â | Â { |
| Â | Â Â display.drawPixel(j, i, SSD1306_BLACK); |
| Â | Â Â Â Â |
| Â | Â } |
| Â | Â display.display(); |
| Â | Â delay(30); |
| Â | } |
| Â | Â |
| Â | } |
| Â | Â |
| Â | void TextDisplay() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(5,28); |
| Â | display.println(“Electronics Hub”); |
| Â | display.display(); |
| Â | delay(3000); |
| Â | } |
| Â | Â |
| Â | void InvertedTextDisplay() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); |
| Â | display.setCursor(5,28); |
| Â | display.println(“Electronics Hub”); |
| Â | display.display(); |
| Â | delay(3000); |
| Â | } |
| Â | Â |
| Â | void ScrollText() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setCursor(0,0); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.println(“This is a”); |
| Â | display.println(“Scrolling”); |
| Â | display.println(“Text!”); |
| Â | display.display(); |
| Â | delay(100); |
| Â | display.startscrollright(0x00, 0x0F); |
| Â | delay(2000); |
| Â | //display.stopscroll(); |
| Â | //delay(1000); |
| Â | display.startscrollleft(0x00, 0x0F); |
| Â | delay(2000); |
| Â | //display.stopscroll(); |
| Â | //delay(1000); |
| Â | display.startscrolldiagright(0x00, 0x0F); |
| Â | delay(2000); |
| Â | display.startscrolldiagleft(0x00, 0x0F); |
| Â | delay(2000); |
| Â | display.stopscroll(); |
| Â | } |
| Â | Â |
| Â | void DisplayChars() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | Â |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0, 0); |
| Â | display.cp437(true); |
| Â | Â |
| Â | for(int16_t i=0; i<256; i++) |
| Â | { |
| Â | Â if(i == ‘\n’) |
| Â | Â { |
| Â | Â Â display.write(‘ ‘); |
| Â | Â } |
| Â | Â else |
| Â | Â { |
| Â | Â Â display.write(i); |
| Â | Â } |
| Â | } |
| Â | Â |
| Â | display.display(); |
| Â | delay(4000); |
| Â | } |
| Â | void TextSize() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | Â |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(F(“Size: 1”)); |
| Â | display.println(F(“ABC”)); |
| Â | Â |
| Â | display.setTextSize(2); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.println(“Size: 2”); |
| Â | display.println(F(“ABC”)); |
| Â | Â |
| Â | display.display(); |
| Â | delay(3000); |
| Â | } |
| Â | Â |
| Â | void DrawRectangle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Rectangle”); |
| Â | display.drawRect(0, 15, 90, 45, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | } |
| Â | Â |
| Â | void DrawFilledRectangle() |
| Â | { |
| Â | display.clearDisplay();Â |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Filled Rectangle”); |
| Â | display.fillRect(0, 15, 90, 45, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | Â |
| Â | } |
| Â | Â |
| Â | void DrawRoundRectangle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Round Rectangle”); |
| Â | display.drawRoundRect(0, 15, 90, 45, 10, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | } |
| Â | Â |
| Â | void DrawFilledRoundRectangle() |
| Â | { |
| Â | display.clearDisplay();Â |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Filled Round Rect”); |
| Â | display.fillRoundRect(0, 15, 90, 45, 10, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | Â |
| Â | } |
| Â | Â |
| Â | void DrawCircle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Circle”); |
| Â | display.drawCircle(30, 36, 25, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | } |
| Â | void DrawFilledCircle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Filled Circle”); |
| Â | display.fillCircle(30, 36, 25, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | Â |
| Â | } |
| Â | Â |
| Â | void DrawTriangle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Triangle”); |
| Â | display.drawTriangle(30, 15, 0, 60, 60, 60, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000);Â |
| Â | } |
| Â | Â |
| Â | void DrawFilledTriangle() |
| Â | { |
| Â | display.clearDisplay(); |
| Â | display.setTextSize(1); |
| Â | display.setTextColor(SSD1306_WHITE); |
| Â | display.setCursor(0,0); |
| Â | display.println(“Filled Triangle”); |
| Â | display.fillTriangle(30, 15, 0, 60, 60, 60, SSD1306_WHITE); |
| Â | display.display(); |
| Â | delay(2000); |
| Â | } |
Conclusion
I hope all of you understand How to Interface OLED Display with ESP32. We MATHA ELECTRONICS will be back soon with more informative blogs.