关于Arduino uno控制1.3寸或0.96寸OLED显示(2)

本文介绍了如何使用U8glib库在1.3寸和0.96寸OLED屏幕上显示字符,包括接线、驱动代码以及如何修改代码以适应不同尺寸的屏幕。作者还分享了在显示过程中的一些有趣实例,如MineCraft字符的呈现。
摘要由CSDN通过智能技术生成

自从我上次买了个1.3寸OLED,就一发不可收拾......

温馨提示:看完全文再复制代码!

话不多说,正文:

接线:

GND------GND

VCC------5V

SCL------SCL

SDA------SDA

驱动1.3寸或0.96寸OLED的代码也是十分有九分的简单,如下:

#include "U8glib.h"
#include "clib/u8g.h"

//接线:四针oled,Vcc-3.3v或5v,GND-GND,SCL-A5,SDA-A4
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);

//...
const uint8_t bitmap_a[] U8G_PROGMEM = {
  /*--  文字:  M  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x63, 0x63, 0x77, 0x6B, 0x6B, 0x6B, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00

};
const uint8_t bitmap_b[] U8G_PROGMEM = {
  /*--  文字:  i  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x18, 0x18, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, 0x00, 0x00, 0x00

};
const uint8_t bitmap_c[] U8G_PROGMEM = {
  /*--  文字:  n  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00


};
const uint8_t bitmap_d[] U8G_PROGMEM = {
  /*--  文字:  e  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x60, 0x60, 0x3C, 0x00, 0x00, 0x00, 0x00


};
const uint8_t bitmap_e[] U8G_PROGMEM = {
  /*--  文字:  C  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x60, 0x60, 0x60, 0x66, 0x66, 0x3C, 0x00, 0x00, 0x00, 0x00


};
const uint8_t bitmap_f[] U8G_PROGMEM = {
  /*--  文字:  R  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x7F, 0x7F, 0x49, 0x49, 0x77, 0x63, 0x6B, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x7F, 0x7F

};
const uint8_t bitmap_g[] U8G_PROGMEM = {
  /*--  文字:  a  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 0x00, 0x00, 0x00

};
const uint8_t bitmap_h[] U8G_PROGMEM = {
  /*--  文字:  f  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x1E, 0x30, 0x30, 0x30, 0x7E, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00

};
const uint8_t bitmap_i[] U8G_PROGMEM = {
  /*--  文字:  t  --*/
  /*--  @Fixedsys12;  此字体下对应的点阵为:宽x高=8x16   --*/
  0x00, 0x00, 0x00, 0x30, 0x30, 0x7E, 0x30, 0x30, 0x30, 0x30, 0x30, 0x1E, 0x00, 0x00, 0x00, 0x00

};
/*参数解释:drawBitmapP(u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
x:位图左上角的横坐标
y:位图左上角的纵坐标
cnt:在水平方向上的位图的字节数。该位图的宽度是cnt* 8(1字节=8位)
h:位图的高
*bitmap:位图对象
*/

void draw(void) {
  u8g.setColorIndex(1);

  
  u8g.drawBitmapP(1, 20, 1, 16, bitmap_a);
  u8g.drawBitmapP(9, 20, 1, 16, bitmap_b);
  u8g.drawBitmapP(18, 20, 1, 16, bitmap_c);
  u8g.drawBitmapP(27, 20, 1, 16, bitmap_d);
  u8g.drawBitmapP(36, 20, 1, 16, bitmap_e);
  u8g.drawBitmapP(45, 20, 1, 16, bitmap_f);
  u8g.drawBitmapP(54, 20, 1, 16, bitmap_g);
  u8g.drawBitmapP(63, 20, 1, 16, bitmap_h);
  u8g.drawBitmapP(72, 20, 1, 16, bitmap_i);
  
}

void setup() {
}

void loop() {
  u8g.firstPage();
  do {
    draw();
  } while (u8g.nextPage());
}

由于使用了  U8glib.h  库,咱还得去下载一个。。。。。。

显示出来的是:MineCRaft ——因为我刚玩MC不久            φ(* ̄0 ̄)

R变成了一只苦力怕。。。。。。

如果是0.96寸的OLED,把代码第五行的"SH1106"改成"SSD1306"。( ̄︶ ̄)↗注意了! 

文章结束了,可以的话在评论区留个言吧! \^o^/(跪求评论!!!)

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
1.3OLED全套资料 132 X 64 Dot Matrix OLED/PLED Preliminary Segment/Common Driver with Controller 1 V0.2 Features „ Support maximum 132 X 64 dot matrix panel „ Embedded 132 X 64 bits SRAM „ Operating voltage: - Logic voltage supply: VDD1 = 1.65V - 3.5V - DC-DC voltage supply: VDD2 = 3.0V – 4.2V - OLED Operating voltage supply: External VPP supply = 6.4V - 13.0V Internal VPP generator = 6.4V - 9.0V „ Maximum segment output current: 200μA „ Maximum common sink current: 27mA „ 8-bit 6800-series parallel interface, 8-bit 8080-series parallel interface, 3-wire & 4-wire serial peripheral interface, 400KHz fast I2C bus interface „ Programmable frame frequency and multiplexing ratio „ Row re-mapping and column re-mapping (ADC) „ Vertical scrolling „ On-chip oscillator „ Programmable Internal charge pump circuit output „ 256-step contrast control on monochrome passive OLED panel „ Low power consumption - Sleep mode: <5μA - VDD1=0V,VDD2=3.0V – 4.2V: <5μA - VDD1,2=0V,VPP=3.0V – 4.2V: <5μA „ Wide range of operating temperatures: -40 to +85°C „ Available in COG form, thickness: 300μm General Description SH1106 is a single-chip CMOS OLED/PLED driver with controller for organic/polymer light emitting diode dot-matrix graphic display system. SH1106 consists of 132 segments, 64 commons that can support a maximum display resolution of 132 X 64. It is designed for Common Cathode type OLED panel. SH1106 embeds with contrast control, display RAM oscillator and efficient DC-DC converter, which reduces the number of external components and power consumption. SH1106 is suitable for a wide range of compact portable applications, such as sub-display of mobile phone, calculator and MP3 player, etc.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值