Site icon AranaCorp

Using an OLED Display with Arduino


The OLED display is a compact graphic display with a resolution of 128 x 64 pixels that allows you to draw and display text to create a graphical interface.


Principle of operation

The OLED display TF052 is based on the SSD1306 circuit and interfaces using I2C communication.


The OLED display has 4 pins for display management. It is powered by the microcontroller and is connected to the I2C bus.


Once your Oled display is correctly connected, you can modify the following code to obtain the desired functionality. In the following example, we will simply perform the display of a meter.
To manage the OLED screen in the programme, the library used is U8x8lib.h whose functions are as follows:

Other more specific functions exist to draw rectangles, lines or to display images.

#include <U8x8lib.h>//

char cstr [16];//To convert int to char

int oledCount  = 0;

U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);

void setup() {
  //Init Serial USB
  Serial.println(F("Initialize System"));
  //Init OLED screen
  drawCentered(1, "Hello World!");
  u8x8.drawString(0, 2, "<-right");
  drawLeft(3, "left->");
  u8x8.drawString(0, 6, "counter =");

void loop() {

void OledCounter() { /* function OledCounter */
  //// Create a counter
  drawLeft(6, itoa(oledCount, cstr, 10));
  oledCount += 1;
  if (oledCount > 255) {
    oledCount = 0;
    drawLeft(6, "    ");

void drawCentered(int lin, char* str) { /* function drawCentered */
  //// Create a counter
  int col = int((16 - String(str).length()) / 2);
  u8x8.drawString(col, lin, str);

void drawLeft(int lin, char* str) { /* function drawLeft */
  //// Create a counter
  int col = 15 - String(str).length();
  u8x8.drawString(col, lin, str);


Observe carefully where the displayed strings are placed and play with the input parameters of the functions to compare their effects. This will allow you to have a better understanding of the library and a better understanding of the Oled module’s functionalities.



Find other examples and tutorials in our Automatic code generator
Code Architect

How useful was this post?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

Exit mobile version