How to show text with U8g2 library

this is a short guide with a code how to show text in U8g2 Adruino library.

There’s 2 different fonts used as example


I’m using ESP8266 based “wifi Kit 8” from aliexpress with 128×32 i2c oled display, but it can be used on any kind of arduino board.

code:

#include <U8g2lib.h>

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16, /* clock=*/ 5, /* data=*/ 4); //defines oled parameters

void setup(void) {
  u8g2.begin();
  u8g2.enableUTF8Print();
  u8g2.setFontDirection(0);
}

void loop(void) {
  u8g2.clearBuffer();
  u8g2.setCursor(0, 11);                   //text position (left botom corner)
  u8g2.setFont(u8g2_font_unifont_t_latin); //first font             
  u8g2.print("wizzx.tech");                //main text
  u8g2.setCursor(0, 32);                   //botom text position
  u8g2.setFont(u8g2_font_tenfatguys_tn );  //another font (only for numbers)
  u8g2.print("123456789");                 //text 2 with numbers
  u8g2.sendBuffer();
  
  delay(1000);
}

One thought on “How to show text with U8g2 library

  1. Thank you so much for this short tutorial on which pins to use and how to print something simple. There are not many tutorials for this specific device so thank you.

Leave a Reply

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