OLED常用尺寸
- 72x40,0.42in
- 96x32,0.54in
- 96x16,0.69in
- 64x48,0.71in
- 128x80,0.78in,面板尺寸12.13x23.6mm
- 128x32,0.91in
- 128x64,0.96in/1.09in
图像转字符串
- https://javl.github.io/image2cpp/
- OLED使用时选择
- 2. Image Settings中的Invert image colors(3. preview中背景为黑色)
-
- Draw mode具体情况确定
常见驱动芯片
- ssd1306
- CH1115
- 基本兼容SSD1306,将由SSD1312替代
- SSD1312
- 基本兼容SSD1306,默认图像镜像,解决方案参见SSD1312显示方向
其它小工具
行byte转列byte
- 1x8的位图字节数据(每个字节为水平方向上的8个bit)转换为SSD1306写入的用的格式(每个字节为竖直方向上的8个bit)
- 若以
Horizontal - 1 bit per pixel
生成bitmap,为const unsigned char bitmap_test [] PROGMEM = { 0xf0, ..., 0x00, 0xf0, ..., 0x00, 0xe0, ..., 0x00, 0xe0, ..., 0x00, 0xc0, ..., 0x00, 0xc0, ..., 0x00, 0x80, ..., 0x00, 0x80, ..., 0x00, 0x00, ..., 0x00, 0x00, ..., 0x00, ...
- 若以
Vertical - 1 bit per pixel
生成bitmap,为const unsigned char bitmap_test [] PROGMEM = { 0xff, 0x3f, 0x0f, 0x03, 0x00, ..., 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ..., 0x00, ..
- 转换代码为(
w
和h
分别为width和height)
int idx = 0;
while (idx < w*h){
// load a 8x8 bit matrix each time
setCursorXY(idx%w, idx/w);
byte buffer[8] = {};
for (uint8_t i = 0; i < 8; i++){
byte temp = pgm_read_byte(&bitmap[(idx/w*8)*w+i*w+idx%w]);
for (uint8_t j = 0; j < 8; j++){
buffer[j] |= ( ((temp>>(7-j)) & 1) << i);
}
}
TinyWireM.beginTransmission(OLED_ADDRESS); // begin transmitting
TinyWireM.send(OzOLED_DATA_MODE);//data mode
for (uint8_t i = 0; i < 8; i++){
TinyWireM.send(buffer[i]);
}
TinyWireM.endTransmission(); // stop transmitting
idx += 1;
}
好像没有什么用的8x8 bit矩阵转置代码
- 输入为
const byte *bitmap
byte transpose[8] = {};
for (uint8_t i = 0; i < 8; i++){
byte temp = pgm_read_byte(&bitmap[i]);
for (uint8_t j = 0; j < 8; j++){
transpose[j] |= ((temp>>j) & 1) << (7-i);
}
}
for (uint8_t i = 0; i < 8; i++){
sendData(transpose[i]);
}