Tags: , , ,

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.


  • Computer
  • Arduino UNO
  • USB A Male to B Male Cable
  • OLED TF052

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.

  • GND Connect to microcontroller ground
  • VCC Power supply pin. Typically connected to the 3V or 5V pin of the microcontroller.
  • SCL I2C communication clock
  • SDA I2C connection data.


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:

  • U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE); to set the screen according to type
  • u8x8.begin(); to initialise the screen
  • u8x8.setPowerSave(0) to illuminate the screen
  • u8x8.setFont(u8x8_font_chroma48medium8_r) to set the font used
  • u8x8.setFlipMode(0) to set the orientation.
  • u8x8.drawString() to write on the screen

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

#include <U8x8lib.h>//https://github.com/olikraus/u8glib

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.


  • Make a clock
  • Make an interactive menu with a rotary encoder


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.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?