Arduino I2C OLED screen tutorial using U8Glib

arduino oled display ssd1306 u8glib
Share:

About

This tutorial covers how to connect an SSD1306 0.96 inch OLED screen to an Arduino Nano over I2C and display text on it using the U8Glib library.

Hardware Used

Hardware Connections

ArduinoOLED
3.3VVdd
GndGnd
Analog 4SDA
Analog 5SCK
arduino oled display connections
arduino nano oled ssd1306 wiring

U8Glib Install

In this tutorial, I will be using the U8Glib graphics library for the screen. In this tutorial, I do the same but using Adafruits SSD1306 graphics library. 

Method 1:

Downaload the library: https://github.com/olikraus/U8glib_Arduino/releases/tag/1.19.1

In the Arduino IDE :

sketch > include library > Add .ZIP Library > select the  downloaded ZIP

Arduino library manager

Method 2:

Or go to sketch > include library > manage libraries > type u8glib in the search bar and click on install.
Arduino Library Manager u8Glib install

Code

Here is the bare minimum code to make the display work. If you need more info about the library check out the documentation on GitHub. You can find more examples provided in the Arduino IDE: File > Examples > U8glib.
//Include the graphics library.
#include "U8glib.h" 

//Initialize display.
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);

void setup(void)
{
    //Set font.
    u8g.setFont(u8g_font_unifont);
}

void loop(void)
{

    u8g.firstPage();
    do {
        draw();
    } while (u8g.nextPage());

    //Delay before repeating the loop.
    delay(50);
}

void draw(void)
{

    //Write text. (x, y, text)
    u8g.drawStr(20, 40, "Hello World.");
}

Hello World!

Upload the above-provided code and you should have a  Hello World.
ssd1306 display text
Share:

Leave a Reply

Your email address will not be published. Required fields are marked *

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger