Example Code for Arduino-Image Display

Last revision 2026/01/26

This article guides users through displaying images on an OLED128x64 using Arduino, covering hardware requirements, software setup, and sample code execution.

Hardware Preparation

Software Preparation

Other Preparation Work

All of the following examples are belong to DFRobot_OLED12864 library files.

  • Open Dfrobot_OLED12864 Image Demo.

Sample Code

Init OLED screen, draw custom XBM image and keep displaying it.

void setup() {
 #include "DFRobot_OLED12864.h"

// Include custom images
#include "images.h"

// Initialize the OLED display using Wire library
DFRobot_OLED12864  display(0x3c);

void setup()
{
    Serial.begin(115200);
    Serial.println();
    Serial.println();
    // Initialising the UI will init the display too.
    display.init();
    display.flipScreenVertically();// flip vertical
    display.clear();
    drawImageDemo();
    display.display();
}

void drawImageDemo()
{
  display.drawXbm(0, 0, Picture_width, Picture_height, Picture_bits);
}

void loop()
{
}

Result

After download this demo the screen will display our logo.

Notice that the picture file "images.h" has been in the project folder, if you need to replace the picture, you can use The Dot Factory to generate bitmaps.

Function Declaration

  • Create an object and write the I2C address.
DFRobot _OLED12864  display(0x3c)
  • Initialize OLED and library.
init()
  • Flip screen vertically.
flipScreenVertically
  • Clear data.
clear()
  • Import the specified width-high data at the x, y-axis position, starting at the top left corner.
drawXbm(0, 0, Picture_width, Picture_height, Picture_bits)
  • Flush the data from OLED to the screen. If not called, the data will only be stored in the OLED and will not be displayed.
display()

Was this article helpful?

TOP