Arduino IDE下开发掌控板的OLED显示屏

1. 掌控板使用的OLED显示屏

SH1106是一款单片CMOS OLED/PLED驱动器,带控制器,用于有机/聚合物发光二极管点阵图形显示系统。SH1106由132个分段、64个共用点组成,可支持132 x 64的最大显示分辨率。它是专为共阴极型OLED面板而设计的。SH1106内置对比度控制、显示RAM振荡器和高效Dc-Dc转换器,减少外部组件数量和功耗。SH1106适用于各种紧凑便携的应用,如手机的子显示器、计算器、MP3播放器等。
SSD1306和SH1106的区别见
https://blog.csdn.net/fbgbhvgv/article/details/131456957
https://blog.csdn.net/weixin_42150905/article/details/117511216
掌控板官方给的电路手册中给的是SSD1106,如下图所示:
OLED电路

2. 添加库文件

(1)在arduino IDE的库管理中输入"esp32 1306",安装ESP8266 and ESP32 OLED driver for SSD1306 displays库,如下图所示。
管理
(2)在文件菜单中的示例子菜单下找到ESP8266 and ESP32 OLED driver for SSD1306 displays中的SSD1306SimpleDemo示例,如图所示。
在这里插入图片描述

3. 修改代码

(1)在打开的SSD1306SimpleDemo.ino中,讲第35行

#include "SSD1306Wire.h"        // legacy: #include "SSD1306.h"

注释掉。

//#include "SSD1306Wire.h"        // legacy: #include "SSD1306.h"

(2)将第36行

// OR #include "SH1106Wire.h"   // legacy: #include "SH1106.h"

修改为

#include "SH1106Wire.h"

(3)将第54行

SSD1306Wire display(0x3c, SDA, SCL);   // ADDRESS, SDA, SCL  -  SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h

注释掉

//SSD1306Wire display(0x3c, SDA, SCL);   // ADDRESS, SDA, SCL  -  SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h

(4)根据电路图中,SDA连接的是IO23,SCL连接的是IO22,将第57行

SH1106Wire display(0x3c, SDA, SCL);     // ADDRESS, SDA, SCL

修改为

SH1106Wire display(0x3c, 23, 22);     // ADDRESS, SDA, SCL

4.上传运行。

下图是运行界面之一。

在这里插入图片描述

5. 简化代码,只显示画圆的功能。

#include <Wire.h>              
#include "SH1106Wire.h"   

SH1106Wire display(0x3c, 23, 22);     // SDA=23, SCL=22

void setup() {
  // Initialising the UI will init the display too.
  display.init();
  display.flipScreenVertically();
}

void drawCircleDemo() {
  for (int i = 1; i < 8; i++) {
    display.setColor(WHITE);
    display.drawCircle(32, 32, i * 3);
    if (i % 2 == 0) {
      display.setColor(BLACK);
    }
    display.fillCircle(96, 32, 32 - i * 3);
  }
}
void loop() {
  // clear the display
  display.clear();
  // draw the current demo method  
  drawCircleDemo();   
  // write the buffer to the display
  display.display();
  delay(10);
}

6. 参考网址

https://github.com/mvcl/esp32-oled-sh1106

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Arduino上通过IIC连接12864OLED显示屏并显示中文,您需要执行以下步骤: 1. 确定您的OLED显示屏的IIC地址。通常情况下,它应该是0x3C或0x3D。如果您不确定,请参考您的OLED显示屏的规格书。 2. 安装U8g2库。这是一个用于Arduino的库,可让您轻松地与OLED显示屏进行通信。您可以在Arduino IDE中通过菜单“工具”>“库管理器”来安装它。 3. 编写代码。以下是一个基本的示例,可以在Arduino上通过IIC连接12864OLED显示屏并显示中文: ``` #include <U8g2lib.h> #include <Wire.h> U8G2_SH1106_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); void setup() { u8g2.begin(); u8g2.setFont(u8g2_font_wqy12_t_gb2312); } void loop() { u8g2.clearBuffer(); // clear the internal memory u8g2.drawStr(0, 20, "你好,世界!"); // draw a string at position (0,20) u8g2.sendBuffer(); // transfer internal memory to the display delay(1000); // wait a second before updating the display again } ``` 在上面的代码中,我们首先包含了U8g2库和Wire库(用于与IIC总线通信)。然后,我们定义了一个U8g2对象,它使用SH1106控制器,128x64像素,4线软件SPI接口,并将其连接到Arduino的13、11、10、9和8引脚。在`setup()`函数中,我们初始化了U8g2对象,并设置了字体为“文泉驿12号”。在`loop()`函数中,我们首先清除了OLED屏幕的内部存储器,然后在位置(0,20)处绘制了一个字符串“你好,世界!”并将其传输到OLED屏幕上。最后,我们在更新OLED屏幕之前等待了1秒钟。 注意,在上面的示例中,我们使用了一种称为“文泉驿12号”的中文字体。如果您希望使用其他字体,请在U8g2库的文档中查找可用的字体并相应地更改代码。 希望这可以帮助您开始在Arduino上使用12864OLED显示屏并显示中文!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值