Site icon AranaCorp

Using a 0.91in OLED display with Arduino

5
(2)

The 0.91in OLED display is a compact graphic display with a resolution of 128×32 pixels that allows you to draw and display text to create a graphical interface. Among all the displays available for the Arduino, the OLED display is taking more and more space on the market. Since they are thinner and do not require backlighting, they are easy to insert in miniaturized projects.

Material

Principle of operation

The 0.91in OLED display is a monochrome display driven by the SSD1306 IC and interfaces using I2C communication.

Scheme

The OLED screen has 4 pins to allow the management of the display. It is powered by the microcontroller and connects to the I2C bus.

Code

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 realize the display of a counter.to manage the OLED screen, the libraries used are Adafruit_GFX.h and Adafruit_SSD1306.h whose functions to know are the following:

Other more specific functions exist to draw rectangles, lines or to display images. Once you have mastered these functions, it will be easy to display what you want.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

byte compteur;

void setup() {
  Serial.begin(9600);

  Serial.println("OLED intialized");
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
}

void loop() {


  for (compteur = 0 ; compteur < 25 ; compteur++) {
    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("test compteur");
    display.print("compteur: ");
    display.println(compteur);
    display.display();
    delay(1000);
  }
}

Result

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 the functionalities of the Oled module.

Applications

Sources

Retrouvez nos tutoriels et d’autres exemples dans notre générateur automatique de code
La Programmerie

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

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

Exit mobile version