OLED is an Organic Light Emitting Diodes. OLED is a flat emitting technology based screen. OLEDs are emissive display that does not require a backlight, so are thinner and more efficient and LCD display which require a white backlight. OLED display are not just thin and efficient, they provide the best image quality ever as LED and LCD and they can also be made transparent, foldable, flexible and even roll able and stretchable in the figure. The pin out are-

Here the driver IC used is SSD1306 which has its I2C protocol. Let’s first look the I2C write protocol

The slave address is 0b011110SA0R/W where SA0 bit provide an extension bit for slave address. Either ‘0111100’ or ‘0111101’ can be selected as slave address of SSD1306. Here bit7 C0 determines the continuation and bit6 D/C represent data or command. D/C = 1 – Data mode and D/C = 0 – Command mode. So for command mode 0x80 and for data mode 0x40. Write function for OLED is
void I2C_Write_OLED(unsigned char addr, unsigned char data) -> Both Data or CMD
void I2C_Write_OLED(unsigned char addr,unsigned char data)
{
I2C_Start(); // Start condition
I2C_Write(SLAVE_ADDR_ACC | WRITE); // Write SW+ADD+Write = 0b01111000
I2C_Write(addr); // Write Address
I2C_Write(data); // Write data
I2C_Stop(); // Stop Communication
}
void sendcommand(unsigned char com) -> cmd function
void sendcommand(unsigned char com)
{
I2C_Write_OLED(OLED_COMMAND,com);
}
void SendChar(unsigned char data) -> character send
void SendChar(unsigned char data)
{
I2C_Write_OLED(OLED_DATA,data);
}
Set the default setting of OLED. The OLED has 128×64 or 128×32 bit pixel. The OLED is nothing but a set of pixel or dot. Let’s look at the pixel mapping –

From the pixel pattern, it has been shown that for 128×64 size OLED has 0-7 pages and 0-127 columns available. For 128×32 size OLED has 0-3 pages and 0-127 columns. If we want to write character of 8×8 pixel mapping then we have 0-7 pages or 8 lines. Let’s print a logo of 128*8piel bitmap, since a picture is nothing but a set of pixel bitmap. If we put the logo of twitter in pixel bitmap of 128*64, then value of the variable is-
const unsigned char Technology[] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xff, 0x7f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7f, 0xff, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xfe,
0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xfd, 0xff, 0xfb, 0xff, 0xf7,
0xf7, 0xf6, 0xf6, 0xf5, 0xf5, 0xf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 0xff, 0xf7, 0xff, 0xef,
0xef, 0xfd, 0xdd, 0xdf, 0xdb, 0xdf, 0xd7, 0xdf, 0xdf, 0x9f, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff,
0xe7, 0xe3, 0xe3, 0xe3, 0xe7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfe, 0xfe,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xff,
0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 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x1f, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0f, 0x1f, 0x1f, 0x1f, 0x0f
};
So the function is simple, just send the pixel bitmap into the OLED-
void logo_write(void) -> Logo write
void logo_write(uint8_t screen)
{
for(int i=0;i<128*8;i++) // show 128* 64 Logo
SendChar(pgm_read_byte(Technology +i));
}
How the characters are writing into the OLED? Since it has 8 pages the pages are write in sequentially. Let’s look at page 2 for more details.

There are 3 different memory addressing mode in SSD1306: page addressing mode, horizontal addressing mode and vertical addressing mode. We use the page addressing mode. In normal display data RAM read or write and page addressing mode, the following steps are required to define the starting RAM access pointer location:

So the pixel location user defined function as follow-
void setXY(unsigned char row,unsigned char col) -> (x,y) coordinate
void setXY(unsigned char row,unsigned char col)
{
sendcommand(0xb0+row); //set page address
sendcommand(0x00+(8*col&0x0f)); //set low col address
sendcommand(0x10+((8*col>>4)&0x0f)); //set high col address
}
Since the OLED has no build in ASCII character. So we have to make our own character for display ASCII character. Let use 8×8 size character, so to display ‘B’ which is ASCII 0x42 is-

Similarly other character can be generated. Build your own front with big or small as you want. Now we have the ‘B’ character, but how to write in exact location you want? Use the following function.
void OLCD_write_string(int X, int Y, char *string) -> String write function
const uint8_t myFont[8] PROGMEM = { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x00, 0x00}
void OLCD_write_string(int X, int Y, char *string)
{
setXY(X,Y);
unsigned char i=0;
while(*string)
{
for(i=0;i<8;i++)
{
SendChar(pgm_read_byte(myFont[*string-0x20]+i));
}
*string++;
}
}
To clear display just sends 0 to all pixels and according to bitmap pattern you can write any shape or image into the OLED. We have written a simple program to display some logo and string into the display. The code is written in ATmega328p just download and connect SDA to SDA and SCL to SCL pin, VCC and ground as usual.







Visit Today : 39
Total Visit : 28454