When looking for a driver for my noname 128x64 OLED display I remembered that I used quite excellent u8g2 library once and it was really painless and seamless experience. What is u8g2? Let me quote the description from GitHub:
U8g2 is a monochrome graphics library for embedded devices. U8g2 supports monochrome OLEDs and LCDs, which include the following controllers: SSD1305, SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1329, SSD1606, SSD1607, SH1106, SH1107, SH1108, SH1122, T6963, RA8835, LC7981, PCD8544, PCF8812, HX1230, UC1601, UC1604, UC1608, UC1610, UC1611, UC1701, ST7565, ST7567, ST7588, ST75256, NT7534, IST3020, ST7920, LD7032, KS0108, SED1520, SBN1661, IL3820, MAX7219 (see here for a full list).
I decided to check whether it would be possible to modify u8g2 so that it could be used with Azure Sphere, too. Turns out the author of u8g2 prepared some callback hooks just for this purpose and the only thing remaining was to write our device specific callback functions for handling I2C and system delays.
I packaged u8g2 and Azure Sphere specific callbacks into a library you can find here: https://github.com/jgroman/azsphere_lib_u8g2 The library can be easily added to your project, also there are two example projects included. Have fun using this library in your own projects!
u8g2 on Azure Sphere examples
Display setup
Consult u8g2 documentation for correct display type. This example shows initialization of noname 128x64 OLED with SSD1306 controller.
// OLED device descriptor for u8g2 static u8g2_t g_u8g2; // Set lib_u8g2 I2C interface file descriptor and device address lib_u8g2_set_i2c(g_fd_i2c, I2C_ADDR_OLED); // Set display type and callbacks u8g2_Setup_ssd1306_i2c_128x64_noname_f(&g_u8g2, U8G2_R0, lib_u8g2_byte_i2c, lib_u8g2_custom_cb); // Initialize display descriptor u8g2_InitDisplay(&g_u8g2); // Wake up display u8g2_SetPowerSave(&g_u8g2, 0);
Lightweight u8x8 sublibrary text output
char buff[30]; uint8_t i, j; u8x8_SetFont(&g_u8x8, u8x8_font_amstrad_cpc_extended_f); for (i = 0; i < 8; i++) { for (j = 0; j < 16; j++) { sprintf(buff, "%c", j + (16 * i) + 65); u8x8_DrawString(&g_u8x8, j, i, buff); } }
u8g2 variable fonts
u8g2_ClearBuffer(&g_u8g2); u8g2_SetFont(&g_u8g2, u8g2_font_oldwizard_tr); lib_u8g2_DrawCenteredStr(&g_u8g2, 10, "element14"); u8g2_SetFont(&g_u8g2, u8g2_font_t0_22b_tr); lib_u8g2_DrawCenteredStr(&g_u8g2, 30, "element14"); u8g2_SetFont(&g_u8g2, u8g2_font_helvB18_tr); lib_u8g2_DrawCenteredStr(&g_u8g2, 60, "element14"); u8g2_SendBuffer(&g_u8g2);
u8g2 graphics
u8g2_ClearBuffer(&g_u8g2); u8g2_DrawBox(&g_u8g2, 0, 0, 30, 20); u8g2_DrawFrame(&g_u8g2, 98, 0, 30, 20); u8g2_DrawDisc(&g_u8g2, 64, 32, 20, U8G2_DRAW_UPPER_RIGHT | U8G2_DRAW_LOWER_LEFT); u8g2_DrawCircle(&g_u8g2, 64, 32, 30, U8G2_DRAW_ALL); u8g2_DrawFrame(&g_u8g2, 0, 44, 30, 20); u8g2_DrawBox(&g_u8g2, 98, 44, 30, 20); u8g2_SetFont(&g_u8g2, u8g2_font_unifont_t_symbols); u8g2_DrawGlyph(&g_u8g2, 106, 18, 0x2603); /* dec 9731/hex 2603 Snowman */ u8g2_SendBuffer(&g_u8g2);
u8g2 bitmaps
u8g2_ClearBuffer(&g_u8g2); u8g2_DrawXBM(&g_u8g2, 0, 0, e14_logo_width, e14_logo_height, e14_logo_bits); u8g2_SendBuffer(&g_u8g2);
XBM is source code friendly bitmap format. You can convert your own images to XBM for example using Gimp:
- Menu Image > Mode > Indexed... > Use black and white (1-bit) palette > Convert
- Menu File > Export As... > [change output file extension to .xbm] > Save
Top Comments