U8g2库支持的屏幕类型总表以及构造器选择

Posted perseverance52

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了U8g2库支持的屏幕类型总表以及构造器选择相关的知识,希望对你有一定的参考价值。

U8g2库支持的屏幕类型总表以及构造器选择

介绍

要设置u8g2,请为显示选择正确的构造函数。构造函数名内包含:定义了显示类型、控制器、RAM缓冲区大小和通信协议。如果显示不完全,请尝试使用相同显示控制器名称的构造函数。

构造函数的参数定义了显示的旋转以及显示如何连接到Arduino板。这是Arduino c++接口的“Hello World”示例:

所有构造函数名列表

SSD1305 128X32_NONAME
SSD1305 128X32_ADAFRUIT
SSD1305 128X32_NONAME
SSD1305 128X32_ADAFRUIT
SSD1305 128X64_ADAFRUIT
SSD1305 128X64_RAYSTAR
SSD1305 128X64_ADAFRUIT
SSD1305 128X64_RAYSTAR
SSD1306 2040X16
SSD1306 128X64_NONAME
SSD1306 128X64_VCOMH0
SSD1306 128X64_ALT0
SSD1306 128X64_NONAME
SSD1306 128X64_VCOMH0
SSD1306 128X64_ALT0
SSD1306 72X40_ER
SSD1306 72X40_ER
SH1106 128X64_NONAME
SH1106 128X64_VCOMH0
SH1106 128X64_WINSTAR
SH1106 128X64_NONAME
SH1106 128X64_VCOMH0
SH1106 128X64_WINSTAR
SH1106 72X40_WISE
SH1106 72X40_WISE
SH1106 64X32
SH1106 64X32
SH1107 64X128
SH1107 64X128
SH1107 SEEED_96X96
SH1107 SEEED_96X96
SH1107 128X128
SH1107 PIMORONI_128X128
SH1107 SEEED_128X128
SH1107 128X128
SH1107 PIMORONI_128X128
SH1107 SEEED_128X128
SH1108 160X160
SH1108 160X160
SH1122 256X64
SH1122 256X64
SSD1306 128X32_UNIVISION
SSD1306 128X32_WINSTAR
SSD1306 128X32_UNIVISION
SSD1306 128X32_WINSTAR
SH1106 128X32_VISIONOX
SH1106 128X32_VISIONOX
SSD1306 64X48_ER
SSD1306 64X48_ER
SSD1306 48X64_WINSTAR
SSD1306 48X64_WINSTAR
SSD1306 64X32_NONAME
SSD1306 64X32_1F
SSD1306 64X32_NONAME
SSD1306 64X32_1F
SSD1306 96X16_ER
SSD1306 96X16_ER
SSD1309 128X64_NONAME2
SSD1309 128X64_NONAME2
SSD1309 128X64_NONAME0
SSD1309 128X64_NONAME0
SSD1316 128X32
SSD1316 128X32
SSD1317 96X96
SSD1317 96X96
SSD1318 128X96
SSD1318 128X96_XCP
SSD1318 128X96
SSD1318 128X96_XCP
SSD1325 NHD_128X64
SSD1325 NHD_128X64
SSD0323 OS128064
SSD0323 OS128064
SSD1326 ER_256X32
SSD1326 ER_256X32
SSD1327 WS_96X64
SSD1327 WS_96X64
SSD1327 SEEED_96X96
SSD1327 SEEED_96X96
SSD1327 EA_W128128
SSD1327 MIDAS_128X128
SSD1327 WS_128X128
SSD1327 EA_W128128
SSD1327 MIDAS_128X128
SSD1327 WS_128X128
SSD1327 VISIONOX_128X96
SSD1327 VISIONOX_128X96
SSD1329 128X96_NONAME
SSD1329 96X96_NONAME
LD7032 60X32
LD7032 60X32_ALT
LD7032 60X32
LD7032 60X32_ALT
ST7920 192X32
ST7920 192X32
ST7920 192X32
ST7920 128X64
ST7920 128X64
ST7920 128X64
LS013B7DH03 128X128
LS027B7DH01 400X240
LS027B7DH01 M0_400X240
LS013B7DH05 144X168
UC1701 EA_DOGS102
UC1701 MINI12864
PCD8544 84X48
PCF8812 96X65
HX1230 96X68
UC1604 JLX19264
UC1604 JLX19264
UC1608 ERC24064
UC1608 DEM240064
UC1608 ERC24064
UC1608 DEM240064
UC1608 ERC240120
UC1608 ERC240120
UC1608 240X128
UC1608 240X128
UC1638 160X128
UC1638 192X96
UC1638 192X96
UC1610 EA_DOGXL160
UC1610 EA_DOGXL160
UC1611 EA_DOGM240
UC1611 EA_DOGM240
UC1611 EA_DOGXL240
UC1611 EA_DOGXL240
UC1611 EW50850
UC1611 EW50850
UC1611 CG160160
UC1611 CG160160
UC1611 IDS4073
UC1611 IDS4073
ST7511 AVD_320X240
ST7528 NHD_C160100
ST7528 NHD_C160100
ST7528 ERC16064
ST7528 ERC16064
UC1617 JLX128128
UC1617 JLX128128
ST7565 EA_DOGM128
ST7565 LM6063
ST7565 64128N
ST7565 ZOLEN_128X64
ST7565 LM6059
ST7565 KS0713
ST7565 LX12864
ST7565 ERC12864
ST7565 ERC12864_ALT
ST7565 NHD_C12864
ST7565 JLX12864
ST7565 NHD_C12832
UC1601 128X32
UC1601 128X32
UC1601 128X64
UC1601 128X64
ST7565 EA_DOGM132
ST7567 PI_132X64
ST7567 JLX12864
ST7567 ENH_DG128064
ST7567 ENH_DG128064I
ST7567 OS12864
ST7567 64X32
ST7567 HEM6432
ST7567 64X32
ST7567 HEM6432
ST7571 128X128
ST7571 128X128
ST7586S S028HN118A
ST7586S ERC240160
ST7586S YMC240160
ST7588 JLX12864
ST7588 JLX12864
ST75256 JLX256128
ST75256 WO256X128
ST75256 JLX256128
ST75256 WO256X128
ST75256 JLX256160
ST75256 JLX256160M
ST75256 JLX256160_ALT
ST75256 JLX256160
ST75256 JLX256160M
ST75256 JLX256160_ALT
ST75256 JLX240160
ST75256 JLX240160
ST75256 JLX25664
ST75256 JLX25664
ST75256 JLX172104
ST75256 JLX172104
ST75256 JLX19296
ST75256 JLX19296
ST75320 JLX320240
ST75320 JLX320240
NT7534 TG12864R
IST3020 ERC19264
IST7920 128X128
SBN1661 122X32
SED1520 122X32
KS0108 128X64
KS0108 ERM19264
T7932 150X32
HD44102 100X64
LC7981 160X80
LC7981 160X160
LC7981 240X128
LC7981 240X64
T6963 240X128
T6963 240X64
T6963 256X64
T6963 128X64
T6963 128X64_ALT
T6963 160X80
SSD1320 160X32
SSD1320 160X132
SSD1322 NHD_256X64
SSD1322 NHD_128X64
SSD1606 172X72
SSD1607 200X200
SSD1607 GD_200X200
SSD1607 WS_200X200
IL3820 296X128
IL3820 V2_296X128
SED1330 240X128
RA8835 NHD_240X128
RA8835 320X240
MAX7219 64X8
MAX7219 32X8
MAX7219 8X8
S1D15E06 160100
S1D15721 240X64
A2PRINTER 384X240

U8g2 支持3中不同的绘图模式

  • 全屏缓存模式
  • 页面模式(U8glib 图片轮询)
  • U8c8,纯字符模式

全屏缓存模式(full buffer)

  • 快速
  • 可使用所有的图形程序
  • 需要大量的内存(RAM)
  • 从上面支持的类型中选择一个 U8g2 的构造器,全屏缓存模式的构造器包含了“F”,比如:
U8G2_ST7920_128X64_ F _SW_SPI(rotation, clock, data, cs [, reset])

使用方法

  • 清除缓存内容:u8g2.clearBuffer()。
  • 使用绘图指令绘制图形。
  • 发送缓存数据给显示器以显示:u8g2.sendBuffer()。
void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.drawStr(0,20,"Hello World!");
  u8g2.sendBuffer();
}

页面模式(U8glib 图片轮询)

  • 所有的图形程序可用
  • 要求少量的内存(RAM)
  • 速度慢
  • 从上面支持的类型中,选择一个 U8g2 的构造器,全屏缓存模式的构造器包含了“1”,或者“2,”比如:
U8G2_ST7920_128X64_ 1 _SW_SPI(rotation, clock, data, cs [, reset])

使用方法

  • 调用 u8g2.firstPage()
  • 运行一个 do-while 循环
  • 在循环体内绘制一些图形
  • 循环到U8g2.nextPage()返回真结束
void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(0,24,"Hello World!");
  } while ( u8g2.nextPage() );
}

U8x8 字符模式

  • 快速
  • 不需要内存(RAM)
  • 不能绘制图形
  • 不支持所有显示控制器
  • 从上面支持的类型中,选择一个 U8g2 的构造器,全屏缓存模式的构造器包含了“1”,或者“2,”比如:
U8G2_ST7920_128X64_ 1 _SW_SPI(rotation, clock, data, cs [, reset])

使用方法

  • 所有的绘制指令直接写入显示器
void setup(void) {
  u8x8.begin();
}

void loop(void) {
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0,1,"Hello World!");
}


构造函数的名字

Arduino c++构造函数的名称有以下几个部分:

序号描述示例
1前缀U8G2
2显示控制器UC1701
3显示名称DOGS102
4Buffer Size1, 2 or F (full frame buffer)
5描述4W_SW_SPI

这些部分与_相连。示例的完整构造函数名是U8G2_UC1701_DOGS102_1_4W_SW_SPI。上面列出了所有可用的构造函数名.

  • Buffer Size(缓冲区大小)
```c
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>

/* Constructor */
U8G2_UC1701_DOGS102_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

/* u8g2.begin() is required and will sent the setup/init sequence to the display */
void setup(void) {
  u8g2.begin();
}

/* draw something on the display with the `firstPage()`/`nextPage()` loop*/
void loop(void) {
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(0,20,"Hello World!");
  } while ( u8g2.nextPage() );
  delay(1000);
}

BufferDescription
1Only one page of the display memory is stored in the microcontroller RAM. Use a firstPage()/nextPage() loop for drawing on the display.
2Same as 1, but maintains two pages in the microcontroller RAM. This will be up to two times faster than 1.
FKeep a copy of the full display frame buffer in the microcontroller RAM. Use clearBuffer() to clear the RAM and sendBuffer() to transfer the microcontroller RAM to the display.

The full buffer F option can be used only, if there is sufficient RAM available in the microcontroller. Use option 1 or 2 on a microcontroller with a small amount of RAM. The u8x8 API can be used if there is not even RAM for one page.(翻译:只有当微控制器中有足够的RAM可用时,才可以使用全缓冲区F选项。在带有少量RAM的微控制器上使用选项1或2。如果一个页面甚至没有RAM,也可以使用u8x8 API。)

通信协议是构造函数名称的一部分(参见上面)。支持以下通信协议:

CommunicationDescription
4W_SW_SPI4-wire (clock, data, cs and dc) software emulated SPI
4W_HW_SPI4-wire (clock, data, cs and dc) hardware SPI (based on Arduino SPI library)
2ND_4W_HW_SPIIf supported, second 4-wire hardware SPI (based on Arduino SPI library)
3W_SW_SPI3-wire (clock, data and cs) software emulated SPI
SW_I2CSoftware emulated I2C/TWI
HW_I2CHardware I2C based on the Arduino Wire library
2ND_HW_I2CIf supported, use second hardware I2C (Arduino Wire lib)
68008-bit parallel interface, 6800 protocol
80808-bit parallel interface, 8080 protocol

硬件I2C允许某些控制器类型的引脚重新映射。复位引脚后列出可选引脚编号:
..._HW_I2C([reset [, clock, data]]). Use U8X8_PIN_NONE if the reset input of the display is not connected.( 译文:如果显示的复位输入没有连接,使用U8X8_PIN_NONE)
This might be confusing, because the software emulated I2C constructor lists the required clock and data line before the reset pin:..._SW_I2C(clock, data [, reset])

使用动态分配的页面缓冲区

当使用动态内存分配时,函数*U8G2::begin()将被禁用。

出于这个原因,setup()函数必须在*U8G2::begin()函数的位置上有以下内容:

uint8_t *buf;
void setup(void) {
  buf = (uint8_t *)malloc(u8g2.getBufferSize());
  u8g2.setBufferPtr(buf);
  u8g2.initDisplay();
  u8g2.clearDisplay();
  u8g2.setPowerSave(0);
}

Rotation(用于屏幕显示的翻转角度)

软件模拟的显示旋转是构造函数的第一个参数。

Rotation/MirrorDescription
U8G2_R0No rotation, landscape
U8G2_R190 degree clockwise rotation
U8G2_R2180 degree clockwise rotation
U8G2_R3270 degree clockwise rotation
U8G2_MIRRORNo rotation, landscape, display content is mirrored (v2.6.x)

If supported U8G2_R2 is identical to u8g2::setFlipMode(1).(译文:如果支持U8G2_R2与u8g2::setFlipMode(1)相同。)

构造函数引用

  • SH1106 128X64_NONAME

Controller “sh1106”, Display “128x64_noname” [Description]

U8G2_SH1106_128X64_NONAME_1_SW_I2C(rotation, clock, data [, reset]) [page buffer, size = 128 bytes]
U8G2_SH1106_128X64_NONAME_2_SW_I2C(rotation, clock, data [, reset]) [page buffer, size = 256 bytes]
U8G2_SH1106_128X64_NONAME_F_SW_I2C(rotation, clock, data [, reset]) [full framebuffer, size = 1024 bytes]
U8G2_SH1106_128X64_NONAME_1_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 128 bytes]
U8G2_SH1106_128X64_NONAME_2_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 256 bytes]
U8G2_SH1106_128X64_NONAME_F_HW_I2C(rotation, [reset [, clock, data]]) [full framebuffer, size = 1024 bytes]
U8G2_SH1106_128X64_NONAME_1_2ND_HW_I2C(rotation, [reset]) [page buffer, size = 128 bytes]
U8G2_SH1106_128X64_NONAME_2_2ND_HW_I2C(rotation, [reset]) [page buffer, size = 256 bytes]
U8G2_SH1106_128X64_NONAME_F_2ND_HW_I2C(rotation, [reset]) [full framebuffer, size = 1024 bytes]
  • SSD1306 128X64_NONAME
    Controller “ssd1306”, Display “128x64_noname” [Description]
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(rotation, clock, data [, reset]) [page buffer, size = 128 bytes]
U8G2_SSD1306_128X64_NONAME_2_SW_I2C(rotation, clock, data [, reset]) [page buffer, size = 256 bytes]
U8G2_SSD1306_128X64_NONAME_F_SW_I2C(rotation, clock, data [, reset]) [full framebuffer, size = 1024 bytes]
U8G2_SSD1306_128X64_NONAME_1_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 128 bytes]
U8G2_SSD1306_128X64_NONAME_2_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 256 bytes]
U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rotation, [reset [, clock, data]]) [full framebuffer, size = 1024 bytes]
U8G2_SSD1306_128X64_NONAME_1_2ND_HW_I2C(rotation, [reset]) [page buffer, size = 128 bytes]
U8G2_SSD1306_128X64_NONAME_2_2ND_HW_I2C(rotation, [reset]) [page buffer, size = 256 bytes]
U8G2_SSD1306_128X64_NONAME_F_2ND_HW_I2C(rotation, [reset]) [full framebuffer, size = 1024 bytes]

以上是关于U8g2库支持的屏幕类型总表以及构造器选择的主要内容,如果未能解决你的问题,请参考以下文章

Arduino ESP8266 +0.96“Oled屏幕基于U8g2库实现充电和wifi图标动态显示

开源项目介绍STC32基于u8g2库DMA驱动IIC or SPI OLED屏幕显示

ESP32基于Arduino框架下U8g2驱动I2C OLED 时间显示

基于Lua框架下Air103使用U8g2库驱动I2C OLED图像显示

支持动态或静态片段的不同屏幕尺寸?

ESP8266驱动SSD1306 ESP8266 for Arduino(NodeMCU U8G2库)