OLED Display Showing Text Towards Left

Hi... I have used an OLED display (I2C,128x64) to show 'Hello World!' but the text is always shifted to the left, no matter what I try.

#include <U8glib.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// create a U8glib display object connected to I2C
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

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

  if (u8g.getMode() == U8G_MODE_R3G3B2) {
    u8g.setColorIndex(255); // white
  } else if (u8g.getMode() == U8G_MODE_GRAY2BIT) {
    u8g.setColorIndex(3); // max intensity
  } else if (u8g.getMode() == U8G_MODE_BW) {
    u8g.setColorIndex(1); // pixel on
  } else if (u8g.getMode() == U8G_MODE_HICOLOR) {
    u8g.setHiColorByRGB(255, 255, 255);
  }

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

void draw() {
  u8g.setFont(u8g_font_6x10);
  u8g.drawStr(0, 15, "Hello World!");
}

void loop() {
  // Nothing in the loop for this example
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Show the display.

What have you tried?

If you want to move your character array (c-string) left and right, I saw references to u8g.getStrWidth()

Are you sure your display is an SSD1306, and not an SH1106?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.