How the I2C 12864OLED works

There are many OLED displays of different specifications that are compatible with Arduino, 128x64 is the most common model, and it is also very cheap, about 12~14 yuan per piece on Taobao.

Communication between OLED and Arduino

First of all, devices using the I 2 C bus can use the Wire library to communicate with them. The device address can be from 0x00 to 0xFF, and the corresponding device can be operated by specifying the address.
Secondly, there are many registered addresses in the OLED display, each Each registered address corresponds to a certain function, such as inverting the color, or turning off the display, and the range of the registered address is also 0x00 to 0xFF.
Therefore, basically you only need 3 parameters to make the OLED display execute a certain command, the method is as follows:

Wire.beginTransmission(devAddr);
Wire.write(regAddr);
Wire.write(data);
Wire.endTransmission(); // stop transmitting

For example, to turn off the display of the device at the address of 0x3C, we modify the value of the registered address 0x40 to 0xAE

Wire.beginTransmission(0x3C); // might be different for your display
Wire.write(0x80);
Wire.write(0xAE);
Wire.endTransmission(); // stop transmitting

There are two main registration addresses that we need to know: one is the command address, the other is the data address, you can check the datasheet by yourself


How to control the display of each pixel

The division of the pixel matrix of this screen is quite special. The entire screen is divided into 8 pages in the horizontal direction, and 128 columns in the vertical direction by pixels. Each page-column contains 8 pixels, through a hexadecimal number (In fact, it is a byte, 8 bits) to control, each bit controls a pixel
 

If we want to display a highlight in the upper left corner, we need to send 0x01 to the data address, for example

Wire.beginTransmission(0x3C); // might be different for your display
Wire.write(0x40);
Wire.write(0x01);
Wire.endTransmission(); // stop transmitting




If you need to change the display of the next column, you just need to continue sending data to the data address, the pointer will automatically go to the next column. If it has reached the last column, it depends on the current addressing mode, if it is Page Addressing, it will return To the first column of this page, if it is Horizontal Addressing, it will jump to the first column of the next page. There is also a third addressing mode, Vertical addressing mode, which is not introduced here.

The above is the OLED display mechanism that needs to be understood

Translated from: https://oscarliang.com/arduino-oled-display-library/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324400455&siteId=291194637