esp32 oled example

Esp32 OLED Example: Simple Display Guide & Code

By Joshua Wilson
AD

Embarking on your journey with the ESP32 microcontroller and looking to display some data on an OLED screen? You've come to the right place. In this comprehensive guide, we'll explore how you can use an SSD1306-driven OLED display with your ESP32, providing you with a detailed, step-by-step example.

The ESP32, with its versatile GPIO pins and extensive peripherals, easily interfaces with various displays, including OLEDs. By the end of this guide, you'll have a solid understanding of displaying text, images, and even graphs on your SSD1306 OLED using the ESP32.

Getting Started with ESP32 and SSD1306 OLED

To begin, you need to ensure you have the right hardware and software. This includes your ESP32 development board, a 0.96-inch SSD1306 OLED module, and the Arduino IDE with the appropriate libraries.

AD
ESP32 OLED Display with Arduino IDE | Random Nerd Tutorials
ESP32 OLED Display with Arduino IDE | Random Nerd Tutorials
Complete Guide for Ultrasonic Sensor HC-SR04 with Arduino | Random Nerd Tutorials
Complete Guide for Ultrasonic Sensor HC-SR04 with Arduino | Random Nerd Tutorials
GitHub - lmarzen/esp32-weather-epd: A low-power E-Paper weather display powered by an ESP32 microcontroller. Utilizes the OpenWeatherMap API.
GitHub - lmarzen/esp32-weather-epd: A low-power E-Paper weather display powered by an ESP32 microcontroller. Utilizes the OpenWeatherMap API.

Let's dive into setting up your hardware and software environment for our ESP32 OLED example, and then we'll move on to programming the display.

Hardware Setup

Connect the OLED module to your ESP32 as follows:

Simple ESP32 Internet Radio with OLED Display
Simple ESP32 Internet Radio with OLED Display
Displaying color pictures on a 240*240 TFT screen with ST7789 controller, with an ESP32 WROOM-32
Displaying color pictures on a 240*240 TFT screen with ST7789 controller, with an ESP32 WROOM-32
ESP32 CYD with LVGL: Display Image on the Screen | Random Nerd Tutorials
ESP32 CYD with LVGL: Display Image on the Screen | Random Nerd Tutorials
  • VCC to 3V3
  • GND to GND
  • SDA to any digital pin (e.g., GPIO21)
  • SCL to any digital pin (e.g., GPIO22)

Software Setup

To program the ESP32, we'll use the Arduino IDE.

ESP32 OLED Example: Displaying Hello, World!

Now that we've set up the hardware and software, let's write the code to display "Hello, World!" on our SSD1306 OLED. We'll use the Adafruit GFX and Adafruit SSD1306 libraries to simplify the graphics and display functions.

AD

Include Libraries and Define Pins

At the beginning of your sketch, include the necessary libraries and define the display's connection pins:

ESP32 Built-in OLED Board (Wemos Lolin32): Pinout, Libraries and OLED Control | Random Nerd Tutorials
ESP32 Built-in OLED Board (Wemos Lolin32): Pinout, Libraries and OLED Control | Random Nerd Tutorials
MicroPython- OLED SSD1306 Display with ESP32-ESP8266
MicroPython- OLED SSD1306 Display with ESP32-ESP8266
Play Video With ESP32
Play Video With ESP32
an image of a rasp board with wires attached to it and the components shown below
an image of a rasp board with wires attached to it and the components shown below
an electronic device with the words lvgl displayed next to it and another image
an electronic device with the words lvgl displayed next to it and another image
How to Send SMS from ESP32
How to Send SMS from ESP32
```cpp #include #include #define OLED_RESET 4 Adafruit_SSD1306 display(0x3C, OLED_RESET); ```

Initialize the Display and Clear Screen

Initialize the display with the correct dimensions and I2C pins. Then, clear the screen to prepare for drawing:

```cpp unsigned long startTime = millis(); void setup() { display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); } ```

Create a 'Hello, World!' Loop with Animation

Here's where the magic happens. We'll create a simple animation that cycles through colors, displaying "Hello, World!"

```cpp void loop() { display.setTextColor(WHITE); display.setTextSize(1); display.setCursor(0, 0); display.print("Hello, World!"); display.display(); delay(500); display.invertDisplay(true); delay(1000); display.invertDisplay(false); delay(1000); } ```

With this code, you should now see "Hello, World!" gradually brightening and inverting colors on your SSD1306 OLED. Next, let's explore more advanced OLED displays, such as graphs and custom characters.

Advanced ESP32 OLED Examples

Using more complex libraries like U8glib, you can create even more elaborate designs, displaying graphs, custom fonts, and even bitmap images on your SSD1306 OLED.

The possibilities are endless, from monitoring sensor data to creating interactive games or visualizers. For more inspiration, check out the myriad of ESP32 OLED projects on platforms like Hackster.io and Instructables.

Embracing the ESP32 as your gateway to IoT and wearable electronics, don't hesitate to dive deeper into the microcontroller's capabilities. Whether you're an experienced maker or just beginning your journey, harnessing the power of OLEDs with the ESP32 unleashes a world of creative possibilities. Happy coding!

OLED with ESP32 - Display Text, Draw Shapes and Images
OLED with ESP32 - Display Text, Draw Shapes and Images
Bluetooth System Monitor Using ESP32 + TFT Screen
Bluetooth System Monitor Using ESP32 + TFT Screen
10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
ESP32: TFT Touchscreen On/Off Button - 2.8 inch ILI9341 (Arduino) | Random Nerd Tutorials
ESP32: TFT Touchscreen On/Off Button - 2.8 inch ILI9341 (Arduino) | Random Nerd Tutorials
Bongo Cat Mini Monitor – Animated ESP32 Display - Free 3D Print Model - MakerWorld
Bongo Cat Mini Monitor – Animated ESP32 Display - Free 3D Print Model - MakerWorld
Create a Stunning UI With SquareLine Studio for ESP32 Display | LVGL Tutorial
Create a Stunning UI With SquareLine Studio for ESP32 Display | LVGL Tutorial
Guide for I2C OLED Display with Arduino | Random Nerd Tutorials
Guide for I2C OLED Display with Arduino | Random Nerd Tutorials
the temperature monitor is displayed in this screenshote image, and it shows different types of
the temperature monitor is displayed in this screenshote image, and it shows different types of
BME280 with ESP32 - Display Values on OLED ( Arduino IDE)
BME280 with ESP32 - Display Values on OLED ( Arduino IDE)
Heltec WiFi LoRa 32 - ESP32 with OLED and SX1278 – Robot Zero One
Heltec WiFi LoRa 32 - ESP32 with OLED and SX1278 – Robot Zero One
DAY 5 — ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
DAY 5 — ESP32 Explained | Wi-Fi & Bluetooth Microcontroller Notes
This ESP32 OLED Trick is So Easy 🤯
This ESP32 OLED Trick is So Easy 🤯
ESP32 microcontroller with two circular 240*240 pixel displays (GCA901)
ESP32 microcontroller with two circular 240*240 pixel displays (GCA901)
AD