Saturday 16 January 2016

Hello World 0.96 inch 128X64 I2C OLED, on Arduino Uno, using u8glib library

Introduction:

 OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.
Blue and White Character OLEDs are available from our eBay Store.

Features:

It's a 0.96" 128X64 OLED, I2C (or IIC) interface, with SSD1306 driver, 3.3/5V compatible.

1. A simplified manufacturing process compared to TFT-LCD
2. Self-emitting light, in contrast to the required backlight for TFT-LCD
3. High luminosity 
4. Lightweight and thin (less than 2 mm)
5. Capable of wide viewing angles>160
6. Low operating voltage and power consumption
7. Quick response (< second level)
8. Wide range of operating temperatures (-30c to 70c)

Specifications:


  •          High resolution: 128 * 64
  •       Viewing angle:> 160 degree
  •       Supports many control chip: Fully compatible with Arduino, 51 Series, MSP430 Series, STM32 / 2, CSR IC, etc.
  •       Ultra-low power consumption: full screen lit 0.08W
  •       Voltage: 3V ~ 5V DC
  •       Working Temperature: -30 c ~ 70 c
  •       Module Size: 27.0MM * 27.0MM * 4.1MM
  •       I2C/IIC Interface, need 2 IO only.
  •       Driver IC: SSD1306
  •       Character Colour: White



Hardware Setup:

There are 4 pin on the OLED module, GND, VCC, SCL and SDA. Connect the oled module to your Breadboard. Get four male to male dupont jumper wires and Connect to Arduino as shown in the following image and table:


OLED -> Arduino

-SDA     ->   A4
-SCL      ->   A5
-VCC      ->  3.3V

-GND     ->   GND



Software Setup:

u8glib (Universal Graphics Library for 8 Bit Embedded Systems) is a  graphics library with support for many different displays.
To install u8glib go to manage libraries in Arduino IDE menu:

and from the list of available libraries install u8glib by oliver library.


find and load the HelloWorld example in the library.


In the HelloWorld, only un-comment the following constructor to make it work:
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);

or use the following code:

Arduino Code:

#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);  // I2C / TWI

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 10, "Hello World!");
  u8g.drawStr( 50, 35, "By");
  u8g.drawStr( 10, 56, "Alictronix!");
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();
 
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  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);
  }
}

void loop(void) {
  // picture loop
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  delay(50);
}

Results:



White Character Display:





Blue Character Display:





3 comments:

  1. Where did you get that Fritzing OLED?

    ReplyDelete
  2. i have problem with library << u8g.firstPage(); >>"'u8g' was not declared in this scope"

    ReplyDelete