Home » News » How To Display Text on A OLED Arduino Screen?

How To Display Text on A OLED Arduino Screen?

Views: 222     Author: Tina     Publish Time: 2025-06-09      Origin: Site

Inquire

facebook sharing button
twitter sharing button
line sharing button
wechat sharing button
linkedin sharing button
pinterest sharing button
whatsapp sharing button
sharethis sharing button
How To Display Text on A OLED Arduino Screen?

Content Menu

What is an OLED Display?

Hardware Requirements

Connecting the OLED Display to Arduino

>> I2C Wiring

>> SPI Wiring

Installing Required Libraries

Basic Text Display Functions

Advanced Text Display Techniques

>> Adjusting Font Sizes and Positions

>> Scrolling Text

>> Displaying Multiple Lines

Displaying Images and Custom Bitmaps

Troubleshooting Common Issues

>> Display Not Showing Anything

>> Text Not Appearing

>> Incorrect Font Size or Position

>> Library Conflicts

Example Project: Network Information Display

Conclusion

Frequently Asked Questions

>> 1. How do I find the I2C address of my OLED display?

>> 2. Can I use the same code for SPI and I2C OLED displays?

>> 3. How do I change the font size on the OLED?

>> 4. How can I display both text and images on the OLED?

>> 5. Why is my OLED display showing random pixels or no text?

OLED (Organic Light Emitting Diode) displays are widely favored in Arduino projects due to their compact size, low power consumption, and excellent visibility even in low-light conditions. This guide provides a thorough understanding of how to display text on an OLED screen using Arduino, covering everything from hardware setup to advanced text display techniques.

how to display text on a OLED arduino screen

What is an OLED Display?

An OLED display is a type of screen that emits light from organic compounds when electricity is applied. Unlike traditional LCDs, OLEDs do not require backlighting, which results in better contrast, deeper blacks, and lower power consumption. These features make OLEDs ideal for battery-powered projects and compact devices.

Common small OLED modules used with Arduino are typically 0.96 inches with a resolution of 128x64 pixels, often driven by the SSD1306 controller. These modules are monochrome, meaning they display white pixels on a black background, which enhances readability.

OLED technology also offers fast response times and wide viewing angles, making it suitable for dynamic displays and interactive projects. The absence of backlight means OLED screens can achieve true black by simply turning off pixels, which is not possible with LCDs.

Hardware Requirements

To get started, you will need the following components:

- An Arduino board such as Uno, Nano, Mega, or ESP32

- A 0.96" 128x64 OLED display module with an SSD1306 driver

- Jumper wires for connections

- A breadboard (optional, for easier wiring)

Choosing the right Arduino board depends on your project requirements. For simple text display, an Arduino Uno or Nano is sufficient. For more complex projects involving sensors or network connectivity, boards like the Arduino Mega or ESP32 provide additional features.

The OLED module typically operates at 3.3V or 5V power. It is important to check your specific module's voltage requirements to avoid damage. Most SSD1306 OLED displays are compatible with 3.3V and 5V logic levels.

Connecting the OLED Display to Arduino

OLED displays communicate with the Arduino using either I2C or SPI protocols.

- I2C (Inter-Integrated Circuit): This protocol uses two wires for communication (SDA for data and SCL for clock) along with power and ground. It is simpler to wire and requires fewer pins, making it ideal for projects with limited I/O.

- SPI (Serial Peripheral Interface): This protocol uses more wires (MOSI, SCK, CS, DC, RESET) and can offer faster data transfer rates, but requires more pins. SPI is preferred when you need faster refresh rates or more complex graphical output.

I2C Wiring

The typical wiring for I2C OLED displays is:

- VCC to 3.3V or 5V power

- GND to ground

- SDA to Arduino SDA pin (A4 on Uno)

- SCL to Arduino SCL pin (A5 on Uno)

I2C devices have addresses; most OLED modules use 0x3C or 0x3D. If you have multiple I2C devices, ensure their addresses do not conflict.

SPI Wiring

For SPI OLED displays, the wiring includes:

- VCC to 3.3V or 5V power

- GND to ground

- MOSI to Arduino pin 11

- SCK to Arduino pin 13

- CS to Arduino pin 10

- DC to Arduino pin 9

- RESET to Arduino pin 8

SPI wiring is more complex but can be beneficial for applications requiring faster screen updates or multiple displays.

Installing Required Libraries

To control the OLED display, you need to install the following Arduino libraries:

- Adafruit SSD1306: This library handles the OLED driver functions, communicating with the display controller and managing the screen buffer.

- Adafruit GFX: This library provides graphics functions such as drawing text, shapes, and bitmaps. It works alongside the SSD1306 library to offer a rich set of drawing capabilities.

These libraries can be installed easily through the Arduino IDE Library Manager by searching their names and clicking install. Keeping these libraries up to date ensures compatibility and access to the latest features.

Basic Text Display Functions

Once the hardware is connected and libraries installed, you can use several key functions to display text:

- `clearDisplay()`: Clears the display buffer to remove any previous content.

- `setTextSize(n)`: Sets the font size, where n ranges from 1 (smallest) to 8 (largest). Larger sizes increase readability but reduce the amount of text that fits on the screen.

- `setTextColor(WHITE)`: Sets the text color to white for monochrome displays. Some OLEDs support inverse colors, but typically white text on black background is used.

- `setCursor(x, y)`: Sets the position on the screen where text will start. Coordinates are in pixels, with (0,0) at the top-left corner.

- `println("text")`: Prints a line of text at the current cursor position and moves the cursor to the next line.

- `display()`: Sends the buffer to the OLED to update the physical screen. This function must be called after drawing commands to reflect changes.

Using these functions in combination allows you to create clear and organized text output on the OLED screen.

OLED I2C Display Arduino Text Code

Advanced Text Display Techniques

Adjusting Font Sizes and Positions

Customizing font size and position helps create a professional and readable display. For example, you can use a large font size for headings and smaller fonts for details. Precise cursor positioning allows for columns or aligned text.

Keep in mind that larger fonts consume more pixels vertically and horizontally, so the amount of text visible at once decreases. Planning your layout to balance readability and information density is key.

Scrolling Text

Scrolling text is useful for displaying messages longer than the screen width or height. The OLED library supports several scrolling modes:

- Scroll right: Moves the text horizontally to the right.

- Scroll left: Moves the text horizontally to the left.

- Diagonal scroll right: Scrolls text diagonally down and to the right.

- Diagonal scroll left: Scrolls text diagonally down and to the left.

You can start scrolling with functions like `startscrollright()` and stop scrolling with `stopscroll()`. Scrolling can be combined with static text or graphics for dynamic interfaces.

Displaying Multiple Lines

To display multiple lines of text, use multiple `println()` calls. The cursor automatically moves to the next line after each call. For more control, you can manually set the cursor position before each line to create custom spacing or alignments.

When displaying dynamic content, such as sensor readings or status messages, clearing the display before updating prevents overlapping text.

Displaying Images and Custom Bitmaps

Besides text, OLED screens can display images or custom bitmaps. This capability allows you to add logos, icons, or simple graphics to enhance your project's user interface.

The process involves:

1. Converting an image to a monochrome bitmap array. This can be done using online tools or image editors that support bitmap export.

2. Including the bitmap array in your Arduino sketch as a constant byte array.

3. Using the `drawBitmap(x, y, bitmapArray, width, height, color)` function to render the image at the desired position.

Remember that the OLED screen is monochrome, so images must be simplified accordingly. Complex images may lose detail but can still provide recognizable icons.

Troubleshooting Common Issues

Display Not Showing Anything

If your OLED screen remains blank:

- Double-check all wiring connections and ensure power and ground are correctly connected.

- Verify the I2C address using an I2C scanner sketch. If the address differs from your code, update it accordingly.

- Confirm that the display initialization code matches your hardware (I2C vs SPI).

Text Not Appearing

If the screen powers on but no text is visible:

- Ensure you call the `display()` function after drawing text or graphics.

- Check that the libraries are correctly installed and included in your sketch.

- Verify that the cursor position is within screen bounds.

Incorrect Font Size or Position

If text appears too large, too small, or misplaced:

- Adjust the `setTextSize()` parameter to change font size.

- Use `setCursor(x, y)` to reposition the text.

- Remember that the OLED screen resolution limits how much text fits on the screen.

Library Conflicts

Conflicts between different versions of libraries or other installed libraries can cause issues:

- Remove older or unused libraries from your Arduino libraries folder.

- Use the latest versions of Adafruit SSD1306 and GFX libraries.

- Restart the Arduino IDE after library changes.

Example Project: Network Information Display

A practical application of OLED text display is showing network information on the screen. For example, in an IoT project, you might want to display:

- IP address

- Subnet mask

- Gateway address

- DNS server addresses

Using different font sizes, you can create a clear header and detailed information below. Refreshing the display periodically keeps the information current.

This kind of display is helpful for debugging network connections or providing status feedback without needing a serial monitor.

Conclusion

Displaying text on an OLED Arduino screen is a rewarding project that enhances your Arduino applications with clear visual feedback. By understanding the hardware connections, installing the right libraries, and mastering text display functions, you can create engaging and informative displays.

Experiment with font sizes, scrolling effects, and custom graphics to make your projects stand out. OLED displays offer a versatile and energy-efficient way to add a professional touch to your Arduino creations.

With this comprehensive guide, you are well-equipped to start your journey into OLED text display and explore more advanced features as you gain experience.

Arduino OLED Screen Print Message

Frequently Asked Questions

1. How do I find the I2C address of my OLED display?

Run an I2C scanner sketch on your Arduino to detect connected devices and their addresses. Most OLED displays use 0x3C or 0x3D.

2. Can I use the same code for SPI and I2C OLED displays?

The code structure is similar, but initialization and wiring differ. SPI requires more pins and a different constructor.

3. How do I change the font size on the OLED?

Use the `setTextSize(n)` function, where n ranges from 1 to 8.

4. How can I display both text and images on the OLED?

Use the Adafruit GFX library functions to print text and draw bitmaps, then update the display with `display()`.

5. Why is my OLED display showing random pixels or no text?

Check wiring, I2C address, and ensure `display()` is called after drawing.

News

PRODUCTS

QUICK LINKS

CONTACT

Building 1, Taihong Industrial Park, West Daya Bay, Huizhou, Guangdong, China
  +86 0752 5556588
Copyrights 2025 Huizhou Kelai Electronics Co., Ltd.