Experiment Effect
A simple demonstration of how to light up the OLED screen with Arduino Uno and display some simple English or characters.
Note! This example uses an OLED screen with an SSD1306 chip, please confirm whether the OLED screen you have uses the same model chip.
Component Description
The OLED display does not require a backlight, thus it can achieve very good contrast in dark environments. Additionally, its pixels consume energy only when they are turned on, so compared to other displays, OLED displays have lower power consumption.
The lack of a backlight greatly reduces the power required to operate the OLED. On average, the display consumes about 20mA, but this depends on the brightness of the display.
The core of this module is a powerful single-chip CMOS OLED driver controller – the SSD1306. It can communicate with microcontrollers in various ways, including I2C and SPI.
SPI is generally faster than I2C but requires more I/O pins. I2C only requires two pins and can share with other I2C peripherals. This is a trade-off between pins and speed. Some models also have an additional RESET pin.
The model used in this example has only four pins and communicates with Arduino using the I2C communication protocol.
The operating voltage of the SSD1306 controller is from 1.65V to 3.3V, while the OLED panel requires a power supply voltage of 7V to 15V. All these different power requirements can be met through an internal charge pump circuit. This allows it to be easily connected to Arduino or any 5V logic microcontroller without the need for any logic level converter.
Regardless of the size of the OLED module, the SSD1306 driver has 1KB of graphic display data RAM (GDDRAM) built into the screen, which stores the bitmap to be displayed. This 1K memory area is organized into 8 pages (from 0 to 7). Each page contains 128 columns/segments (0 to 127). Each column can store 8 bits of data (from 0 to 7).
8 pages x 128 segments x 8 bits of data = 8192 bits = 1024 bytes = 1KB memory
-
Display Technology: OLED (Organic LED)
-
MCU Communication: I2C / SPI
-
Screen Size: 0.96 inches
-
Resolution: 128×64 pixels
-
Operating Voltage: 3.3V – 5V
-
Operating Current: Max 20mA
-
Viewing Angle: 160°
-
Characters per Row: 21
-
Number of Character Rows: 7
Pin Description
GND for Ground VCC for Power Supply (requires 3.3V-5V) SCL for I2C Clock Line SDA for I2C Data Line
BOM List
Name | Quantity |
---|---|
Arduino Uno | x1 |
OLED Screen (SSD1306) | x1 |
Breadboard | x1 |
Jumper Wires (Dupont Wires) | Several |
Wiring Method
Arduino Uno Pin | <-> | OLED Pin |
---|---|---|
GND | <-> | GND |
3.3V | <-> | VCC |
A5 | <-> | SCL |
A4 | <-> | SDA |
Program Points
To run the OLED program smoothly, you need to install the following two libraries. The installation method is simple: open the menu bar in sequence: Menu Bar “Tools” -> “Manage Libraries”
In the pop-up library management window, search for the corresponding keywords, find the corresponding library (be careful to find the correct library name and author), click install, and wait for the installation to complete.
Install Library Adafruit_GFX_Library
Install Library Adafruit_SSD1306
Define Screen Resolution
The versatility of the SSD1306 controller gives this module different sizes and colors: for example, 128×64, 128×32, using the same library for development.
In the following code, the resolution of the OLED screen being used is declared as 128×64. If you are using a different resolution, please make the corresponding modifications.
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
Define Screen I2C Address
The default address of the OLED screen is generally 0x3C, but I have also encountered modules that do not have this address. If sometimes you find that your OLED screen does not light up, it may be that the I2C address is set incorrectly.
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Clear Screen
Use the following code to clear the entire display, turning off all lit pixels.
display.clearDisplay();
Make Screen Changes Effective
Finally, do not forget to use the display() function to make the changes effective on the screen.
display.display();
There are other functions that will help you handle the OLED display library to write text or draw simple graphics.
display.drawPixel(x,y, color) – Draw a pixel at coordinates x,y. display.setTextSize(n) – Set font size, supports font sizes 1-8. display.setCursor(x,y) – Set the coordinates to start displaying text. display.print(“message”) – Print characters at position x,y. display.display() – Call this method to make the changes effective.
Program Code
#include <SPI.h> // Load SPI library
#include <Wire.h> // Load Wire library
#include <Adafruit_GFX.h> // Load Adafruit_GFX library
#include <Adafruit_SSD1306.h> // Load Adafruit_SSD1306 library
// Define the resolution of the OLED screen
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
void setup() {
Serial.begin(9600); // Set serial baud rate
Serial.println("OLED FeatherWing test"); // Serial output
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Set OLED I2C address
display.clearDisplay(); // Clear screen
display.setTextSize(1); // Set font size
display.setTextColor(SSD1306_WHITE); // Set font color
display.setCursor(0,0); // Set coordinates to start displaying text
display.println("Hello World!"); // Output characters
display.println(" by Lingshunlab.com");
display.display(); // Make changes effective on display
}
void loop() {
}
After uploading the program, you will see the screen display the output characters.
Leave a Comment
Your email address will not be published. Required fields are marked *