Thursday, April 20, 2017

8:45 AM
There are many different sizes of OLED displays that are compatible with the Arduino. I bought some cheap mini I2C OLED from ebay, works pretty well but the library the seller provides was very difficult to understand, so I decided to write my own library OLED driver.

Understanding How the OLED Display Works

Before we go onto explain how we use the library, I think it’s important that we understand how the OLED display works.

How the OLED Display is Communicated with Arduino

The OLED display is connected to the Arduino using i2c buses, so the “wire” library is used here. As you might know i2c communication allows multiple devices to share the same connection, and each device will have a specific address in hex number between 0x00 and 0xFF. You need to specify the device address in order to talk to the device you want.
Within the OLED display, there are many register, each register controls a certain functionality, such as inverting the display colour, or powering down the display. Again each register will have a unique hex address between 0x00 and 0xFF.
So to tell the display to do something, you basically need 3 parameters: device address, register address and the command. The code example would be:
Wire.endTransmission(); // stop transmitting
For example, to shut down the display of address 0x3C, we change the data in register 0x40 (command register), with value 0xAE, which is the shutdown command.
Wire.beginTransmission(0x3C); // might be different for your display
Wire.endTransmission(); // stop transmitting
There are mainly only two registers we need to know here, the command register (mentioned above), and data register, which we use to control the pixels on the screen. 

How to Control Each Pixel on Screen

The matrix arrangement on the display is quite confusing. The screen is divided  into “8 pages” (I know it’s not divided into rows, but pages), and 128 columns. Each page-column unit contains 8 pixels. We control the 8 pixels unit with one hex number (which can be seen as 8-bit-binary number, and each bit controls a pixel).
For example, display a dot on the top left corner, we need to send a hex number 0x01 (B0000 0001) to the data register, e.g.
Wire.beginTransmission(0x3C); // might be different for your display
Wire.endTransmission(); // stop transmitting
To get to the next column, we just need to send the next data, the pointer will automatically increment. Depends on which Addressing Mode we are using, by the time we get to the end of the page columns (col127), we will either move down to the next page automatically (Horizontal Addressing), or the pointer will be reset back to the first column of the same page (Page Addressing). There is also a third addressing mode – the vertical addressing mode. But I don’t think it’s useful so I won’t discuss it here.
So that’s pretty much you need to know to get started coding the OLED Display for Arduino.

Circuit Connection

The OLED I bought is a mono colour, I2C 0.96′ 128×64 OLED display which is about $14. I like I2C because it’s very simple (only 2 data connections), and it leaves other pins available for other devices.

Download Library OLED here

0 komentar:

Post a Comment