Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
OLED
Overview
In this lesson, you will learn about OLED Displays using the SSD1306 driver. OLED (Organic Light-Emitting Diodes) displays are widely used in various electronic devices such as smartwatches, mobile phones, and even televisions. The SSD1306 is a single-chip CMOS OLED/PLED driver with controller for organic/polymer light emitting diode dot-matrix graphic display system. It offers a crisp and clear visual output through the means of organic material-based diodes that emit light when an electric current passes through them.
In the code provided, an OLED display is interfaced with an Arduino board via the I2C protocol. The code uses the Adafruit SSD1306 library to control the display. The program covers various functionalities such as:
Displaying text: “Hello world!” is printed on the screen.
Inverted text: The text “Hello world!” is displayed in an inverted color scheme.
Font Size: The text “Hello!” is displayed with an increased font size.
Numerical Display: The numbers 123456789 are displayed.
ASCII Characters: A set of ASCII characters are displayed.
Scrolling: Text is scrolled horizontally across the display.
Bitmap Display: A predefined bitmap image is displayed on the OLED screen.
This OLED display can be used in a multitude of applications including digital clocks, mini game consoles, information displays, and so on. It offers a great way to provide a user interface in compact and portable devices.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
---|---|---|
Elite Explorer Kit |
300+ |
You can also buy them separately from the links below.
COMPONENT INTRODUCTION |
PURCHASE LINK |
---|---|
- |
|
Wiring

Schematic Diagram

Code
Note
You can open the file
15-oled.ino
under the path ofelite-explorer-kit-main\basic_project\15-oled
directly.Or copy this code into Arduino IDE.
Note
To install the library, use the Arduino Library Manager and search for “Adafruit SSD1306” and “Adafruit GFX” and install it.
Code Analysis
Library Inclusion and Initial Definitions: The necessary libraries for interfacing with the OLED are included. Following that, definitions regarding the OLED’s dimensions and I2C address are provided.
Adafruit SSD1306: This library is designed to help with the interfacing of the SSD1306 OLED display. It provides methods to initialize the display, control its settings, and display content.
Adafruit GFX Library: This is a core graphics library for displaying text, producing colors, drawing shapes, etc., on various screens including OLEDs.
Note
To install the library, use the Arduino Library Manager and search for “Adafruit SSD1306” and “Adafruit GFX” and install it.
#include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C
Bitmap Data: Bitmap data for displaying a custom icon on the OLED screen. This data represents an image in a format that the OLED can interpret.
You can use this online tool called image2cpp that can turn your image into an array.
The
PROGMEM
keyword denotes that the array is stored in the program memory of the Arduino microcontroller. Storing data in program memory(PROGMEM) instead of RAM can be helpful for large amounts of data, which would otherwise take up too much space in RAM.static const unsigned char PROGMEM sunfounderIcon[] = {...};
Setup Function (Initialization and Display): The
setup()
function initializes the OLED and displays a series of patterns, texts, and animations.void setup() { ... // Serial initialization and OLED object initialization ... // Displaying various text, numbers, and animations }