Sunday, December 28, 2014

Library for 128x64 graphical display OLED. Driver SSD1306.

OK. Now you need a best display for your projects!. Yeah, this display is your best choice. We have got the update 2.0 now.
  
Module Features.
  • Resolution: 128 x 64 dot matrix panel.
  • Power supply: 3.3V ~ 5V
  • Interface: SPI
  • Driver IC: SSD1306
  • Light color: Yellow+blue
Request.
Email contact: armicrocontroller@gmail.com


What version do I need?
The version 1.0 is ideal for microcontroller with few ROM memory, this library has not got graphics functions.

The version 2.0 includes graphic functions and a new scroll function, ideal for projects like mp3 players. This library needs a little more of ROM memory. This version is FREE!.


Description of library.

Initializes the OLED module.
Oled_Init(void)
Example:
Oled_Init();


Sets font that will be used.
Oled_SetFont(_font, _width, _height, _min, _max)
  •  _font: desired font.
  • _width: sets the width in units of pixels.
  • _height: sets the height in units of pixels. 
  • _min: sets the range minimum.
  • _max: sets the range maximum. 
Example:
Oled_SetFont(Terminal12x16, 12, 16, 32, 127);


  • font name : Terminal12x16
  • width 12 pixels
  • height 16 pixels
  • range: start in character 32, end in  character 127
We can use "GLCD Font Creator" to design new fonts, symbols and icons.
Note: Only fonts with multiples of 8 pixels in height (8, 16, 24, 32 ... )


Writes a char on the OLED.
Oled_WriteChar(c, seg, pag)

  • c: char to be written.
  • seg: sets the segment. Valid values: 0..127
  • pag: sets the page. Valid values: 0..7
Example
Oled_WriteChar('A', 10, 3);

Prints text constant on OLED.
Oled_ConstText(buffer, seg, pag)

  • buffer: text to be written.
  • seg: sets the segment. Valid values: 0..127
  • pag: sets the page. Valid values: 0..7
Example:
Oled_ConstText("OLED 128x64", 0, 4);


Prints text variable on OLED.
Oled_Text(buffer, seg, pag)

  • buffer: text to be written.
  • seg: sets the segment. Valid values: 0..127
  • pag: sets the page. Valid values: 0..7
Example:
unsigned char i;
char buffer2[20];
i = 22;
sprintf(buffer2, "%03d", i);
Oled_Text(buffer2, 0, 3);


Prints text constant on OLED with scroll.
Oled_ConstTextScroll(buffer)

  • buffer: text to be written.
Example:
Oled_SetFont(Terminal12x16, 12, 16, 32 , 127);
Oled_ResetScroll();
while(1){
Oled_ConstTextScroll("This is a new scroll function  ");
Delay_ms(50);
}


Prints text variable on OLED with scroll.
Oled_TextScroll(buffer)

  • buffer: text to be written.
Example:
unsigned char i;
char buffer2[20];
i = 22;
sprintf(buffer2, "%03d   ", i);
Oled_SetFont(Terminal12x16, 12, 16, 32 , 127);
Oled_ResetScroll();
while(1){
Oled_TextScroll(buffer2);
Delay_ms(50);
}


Resets the scroll.
Oled_ResetScroll(void)
This function must be called before of a new scroll function.
Example:
Oled_ResetScroll();


Fills OLED memory.
Oled_FillScreen(pattern)

  • pattern: byte to fill OLED memory.
Example:
Oled_FillScreen(0xFF);


Displays bitmap on OLED.
void Oled_Image(buffer)

  • buffer: image to be displayed.
Example:
Oled_Image(truck_bmp);


Displays an image on a desired location.
Oled_Icon(buffer, seg, pag, _width, _height)

  • buffer: image to be displayed.
  • seg: sets the segment. Valid values: 0..127
  • pag: sets the page. Valid values: 0..7
  • _width sets the width of the image.
  • _height sets the height of the image.
Example:
Oled_Icon(icon1, 20, 3, 32, 32);


Inverts the RAM memory.
Oled_InvertRam(seg1, pag1, seg2, pag2)

  • seg1 sets the start segment. Valid values: 0..127
  • pag1 sets the start page. Valid values: 0..7
  • seg2 sets the end segment. Valid values: 0..127
  • pag2 sets the end page. Valid values: 0..7
Example:
Oled_InvertRam(0, 0, 127, 7);


Draws a Pixel on OLED.
Oled_Pixel(x, y, color)

  • x: x position. Valid values: 0..127
  • y: y position. Valid values: 0..63
  • color: color parameter. Valid values: 1,2,3
Example:
Oled_Pixel(40, 40, BLACK);


Draws a Line on OLED.
Oled_Line(x1, y1, x2, y2, color)

  • x1: x coordinate of the line start. Valid values: 0..127
  • y1: y coordinate of the line start. Valid values: 0..63
  • x2: x coordinate of the line end. Valid values: 0..127
  • y2: y coordinate of the line end. Valid values: 0..63
  • color: color parameter. Valid values: 1,2,3
Example:
Oled_Line(0, 16, 127, 50, BLACK);

 
Draws a rectangle on OLED.
Oled_Rectangle(x1, y1, x2, y2, color)

  • x1: x coordinate of the upper left rectangle corner. Valid values: 0..127 
  • y1: y coordinate of the upper left rectangle corner. Valid values: 0..63
  • x2: x coordinate of the lower right rectangle corner. Valid values: 0..127
  • y2: y coordinate of the lower right rectangle corner. Valid values: 0..63
  • color: color parameter. Valid values: 1,2,3
Example:
Oled_Rectangle(16, 16, 112, 46, BLACK);

 
Draws a circle on OLED.
Oled_Circle(x1, y1, radius, color)

  • x1: x coordinate of the circle center. Valid values: 0..127
  • y1: y coordinate of the circle center. Valid values: 0..63
  • radius: radius size
  • color: color parameter. Valid values: 1,2,3
Example:
Oled_Circle(63, 31, 5, BLACK);


Schematic.


New driver V4.0 optimized for SPI and I2C interface.
 
Features.
  • Easy integration.
  • SPI and I2C fast refresh. 
  • 4 modes of rotation. 
  • MCC support.
  • New functions.
  • Microchip and STM32 support.
Displays supported.
  • SSD1306            96x16
  • SSD1306            128x32
  • SSD1306            128x64
  • SSD1309            128x64
  • SH1106              132x64
  • SH1107              64x128
  • UC1609C          192x64
  • ST7565R           128x64
  • NOKIA5110       84x48 
 How to port the library using MPLABX with MCC.
 
 
How to select a display.
 

 How to configure the library to be used on the I2C interface.





 

2 comments:

  1. This 7 segment font looks good. only the digit '6' is look like small 'b' alphabet in first sight. I suggest a top '-' (a)segment in '6' and bottom '-' (d) segment for digit '9'.

    ReplyDelete