U8g2 - Pro Mini and SSD1306 OLED - HW I2C

I’ve been desperately trying to get my Arduino Pro Mini and OLED working via hardware I2C and failing. :slightly_frowning_face:

A4 → SDA
A5 → SCL


  • Arduino Pro Mini Atmega168 Module 5V 16MHz
  • SSD1306 I2C 0.91" 128x32 white OLED
  • 2 x 4K7 pull up resistors


#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup(void) {

void loop(void) {
  u8g2.clearBuffer();         // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display

This code all compiles and uploads fine, but nothing shows on the display.
If however I use software I2C…

U8G2_SSD1306_128X32_UNIVISION_F_[b]SW[/b]_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

…everything works as expected and the display shows.

Am I missing some code? Do I need to define the I2C pins in the constructor call for HW I2C?

What am I missing?

Thank you!

Maybe there is a RAM overflow. Wire.h (HW I2C) requires a lot of RAM. Did you try a page mode example instead with HW SPI?


Hi Oliver,
Thank you for your reply and your fantastic library.

YES! You're absolutely spot on, seem it is indeed a RAM issue.

This works fine:

U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

along with the page mode hello world example.

Any tips to minimise RAM use?
Thanks again.

Any tips to minimise RAM use?

Use the Arduino F() macro together with the u8g2.print() function.