element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Blog Universal monochrome OLED display driver for Azure Sphere (with examples)
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jgroman
  • Date Created: 27 Oct 2019 3:33 PM Date Created
  • Views 1933 views
  • Likes 6 likes
  • Comments 2 comments
  • azure sphere
  • oled display
  • display driver
Related
Recommended

Universal monochrome OLED display driver for Azure Sphere (with examples)

jgroman
jgroman
27 Oct 2019

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! image

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);
    }
}

image

 

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);

 

image

 

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);

 

image

 

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:

  1. Menu Image > Mode > Indexed... > Use black and white (1-bit) palette > Convert
  2. Menu File > Export As... > [change output file extension to .xbm] > Save

image

  • Sign in to reply

Top Comments

  • kmikemoo
    kmikemoo over 5 years ago +1
    Super helpful! THANKS!
  • kmikemoo
    kmikemoo over 5 years ago

    Super helpful!  THANKS!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 5 years ago

    Looks like a nice display.

     

    Dubbie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube