Arduino U8g2 OLED Display: Wiring, Code and Simulator

To build this Arduino U8g2 OLED Display project you need an Arduino Uno and an SSD1306 OLED display. U8g2 draws text and a frame on an SSD1306 OLED in page mode, using little RAM. Make the 4 connections in the wiring table, upload the Arduino C++ code, and try another font, like u8g2_font_logisoso24_tn for big digits.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1SSD1306 OLED displaySSD1306 over I²C: DATA (SDA) to A4, CLK (SCL) to A5, VIN to 5V, GND to GND. Address 0x3C.

Wiring

#FromTo
1Arduino Uno A4SSD1306 OLED display DATA
2Arduino Uno A5SSD1306 OLED display CLK
3Arduino Uno 5VSSD1306 OLED display VIN
4Arduino Uno GNDSSD1306 OLED display GND

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an SSD1306 OLED display from the parts palette.
  3. Wire 1. Connect Arduino Uno A4 to SSD1306 OLED display DATA.
  4. Wire 2. Connect Arduino Uno A5 to SSD1306 OLED display CLK.
  5. Wire 3. Connect Arduino Uno 5V to SSD1306 OLED display VIN.
  6. Wire 4. Connect Arduino Uno GND to SSD1306 OLED display GND.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Try another font, like u8g2_font_logisoso24_tn for big digits.

Arduino C++ code

// U8g2: text and a frame on an SSD1306 128x64 OLED over hardware I2C.
#include <U8g2lib.h>
#include <Wire.h>

U8G2_SSD1306_128X64_NONAME_1_HW_I2C oled(U8G2_R0, U8X8_PIN_NONE);

void setup() {
  oled.begin();
}

void loop() {
  oled.firstPage();
  do {
    oled.setFont(u8g2_font_ncenB10_tr);
    oled.drawStr(8, 30, "BitForBytes");
    oled.drawFrame(0, 0, 128, 64);
  } while (oled.nextPage());
  delay(1000);
}

What to try

Try another font, like u8g2_font_logisoso24_tn for big digits.

Frequently asked questions

How do I wire the U8g2 OLED Display project on an Arduino Uno?

Make 4 connections: Arduino Uno A4 to SSD1306 OLED display DATA; Arduino Uno A5 to SSD1306 OLED display CLK; Arduino Uno 5V to SSD1306 OLED display VIN; Arduino Uno GND to SSD1306 OLED display GND.

What parts do I need for this Arduino project?

An Arduino Uno and an SSD1306 OLED display.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

U8g2 draws text and a frame on an SSD1306 OLED in page mode, using little RAM.

More Arduino Uno projects