数码之家

 找回密码
 立即注册
搜索
查看: 4084|回复: 55

[Arduino] 168种传感器系列实验(181)---1.3寸OLED液晶屏模块

[复制链接]
发表于 2021-9-26 13:34:03 | 显示全部楼层 |阅读模式
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试多做实验,不管成功与否,都会记录下来——小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百八十一:1.3寸OLED液晶屏  I2C IIC通信 4针模块 1106/1306驱动 128*64像素






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

打赏

参与人数 2家元 +60 收起 理由
家睦 + 40
jf201006 + 20 謝謝分享

查看全部打赏

 楼主| 发表于 2021-9-26 13:39:07 | 显示全部楼层
SH1106 是一款带有控制器的单芯片 CMOS OLED/PLED 驱动器,用于有机/聚合物发光二极管点阵图形显示系统。 SH1106由132段、64个公共端组成,可支持最大132 X 64的显示分辨率。专为共阴极型 OLED 面板设计。SH1106 内嵌对比度控制、显示 RAM 振荡器和高效的 DC-DC 转换器,减少了外部元件和功耗。 SH1106 适用于各种紧凑型便携式应用,例如手机、计算器、MP3播放器等副显示。

SH1106功能框图



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 13:44:50 | 显示全部楼层


SH1106的主要特征
„ 支持最大 132 X 64 点阵面板
„ 嵌入式 132 X 64 位 SRAM
„ 工作电压:
- 逻辑电压供应:VDD1 = 1.65V - 3.5V
- DC-DC 电压供应:VDD2 = 3.0V – 4.2V
- OLED 工作电压供应:
外部 VPP 电源 = 6.4V - 13.0V
内部 VPP 发生器 = 6.4V - 9.0V
„ 最大段输出电流:200μA
„ 最大公共吸收电流:27mA
„ 8 位 6800 系列并行接口,8 位 8080 系列
并行接口,3 线和 4 线串行外设
接口,400KHz快速I2
C总线接口
„ 可编程帧频和复用率
„ 行重映射和列重映射 (ADC)
„ 垂直滚动
„ 片上振荡器
„ 可编程内部电荷泵电路输出
„ 单色无源 OLED 上的 256 级对比度控制
控制板
„ 低功耗
- 睡眠模式:<5μA
- VDD1=0V,VDD2=3.0V – 4.2V: <5μA
- VDD1,2=0V,VPP=3.0V – 4.2V: <5μA
„ 工作温度范围广:-40 至 +85°C
„ 可提供 COG 形式,厚度:300μm

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 14:12:04 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 14:13:25 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 14:14:20 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 14:21:03 | 显示全部楼层
I2C接口电路



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:07:00 | 显示全部楼层



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:13:28 | 显示全部楼层
1.3寸OLED液晶屏  I2C IIC通信 4针模块 1106/1306驱动 132*64像素




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:26:18 | 显示全部楼层



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:28:08 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:30:35 | 显示全部楼层
电原理图


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 15:31:28 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 19:09:43 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
  项目之一:点亮SH1106屏幕
  实验接线:
  oled模块    Ardunio Uno
  GND---------GND接地线
  VCC---------5V 接电源
  SDA---------D6
  SCL ------- D4

  实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  3.   实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
  4.   项目之一:点亮SH1106屏幕
  5.   实验接线:
  6.   oled模块    Ardunio Uno
  7.   GND---------GND接地线
  8.   VCC---------5V 接电源
  9.   SDA---------D6
  10.   SCL ------- D4
  11. */

  12. #include <Wire.h>
  13. #include <sh1106.h>

  14. volatile boolean g_writeValue = false;
  15. volatile int g_displayValue = 0;

  16. sh1106_lcd *g_pLCD = NULL;

  17. void setup() {
  18.   Serial.begin(9600);
  19.   g_pLCD = sh1106_lcd::getInstance();
  20.   if (g_pLCD != NULL)
  21.   {
  22.     g_pLCD->ClearScreen();
  23.   }
  24.   g_writeValue = true;
  25. }

  26. // Quick sketch showing functionality of library
  27. void loop() {
  28.   if (g_writeValue == true) {
  29.     g_pLCD->DrawRectangle(2, 2, 128, 62, 2);// draw a box from 0, 0 to 100, 48
  30.     g_pLCD->DrawRectangle(20, 20, 108, 42, 2);
  31.     g_pLCD->FillRectangle(25, 25, 30, 30);
  32.     g_pLCD->FillRectangle(80, 45, 100, 60);
  33.     g_pLCD->Show();
  34.     delay(1000);

  35.     g_pLCD->PrintLine("0123456789");
  36.     g_pLCD->PrintLine("aBcDEF GHIJK");
  37.     g_pLCD->PrintLine("LMNOP QRSTUV");
  38.     g_pLCD->PrintLine("WXYZ");
  39.     g_pLCD->PrintLine("AAAA");
  40.     g_pLCD->PrintLine("EEEE");
  41.     g_pLCD->PrintLine("FFFF");
  42.     g_pLCD->PrintLine("GGGG");
  43.     delay(1000);
  44.     g_pLCD->PrintLine("HHHH");

  45.     g_pLCD->DrawPixel(10, 2, true);
  46.     g_pLCD->DrawPixel(127, 0, true);
  47.     g_pLCD->DrawPixel(127, 63, true);
  48.     g_pLCD->DrawPixel(10, 63, true);
  49.     g_pLCD->DrawPixel(0, 63, true);
  50.     g_pLCD->DrawPixel(63, 3, true);
  51.     g_pLCD->Show();
  52.     delay(1000);
  53.     g_writeValue = false;
  54.   }
  55.   else {
  56.     g_pLCD->ClearScreen();
  57.     g_pLCD->DrawLine(20, 31, 127, 31);
  58.     g_pLCD->DrawLine(0, 0, 115, 50);
  59.     g_pLCD->DrawLine(50, 50, 20, 20);
  60.     g_pLCD->DrawLine(0, 50, 0, 120);
  61.     g_pLCD->DrawLine(64, 0, 64, 64);
  62.     g_pLCD->DrawLine(0, 80, 6, 110);
  63.     g_pLCD->Show();
  64.     while (1);
  65.   }
  66. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 19:15:03 | 显示全部楼层
  实验场景图


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 19:16:42 | 显示全部楼层



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 19:44:06 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
  项目之二:显示二行字符
  实验接线:
  oled模块    Ardunio Uno
  GND---------GND接地线
  VCC---------5V 接电源
  SDA---------D6
  SCL ------- D4

实验开源仿真编程(Linkboy V4.62)



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 19:44:42 | 显示全部楼层
  实验场景图


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 20:00:19 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
  项目之三:基于Adafruit_SH1106库的标准屏幕测试

  实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  3.   实验一百八十一:1.3寸OLED液晶屏 I2C IIC通信 4针模块 1106/1306驱动 132*64像素
  4.   项目之三:基于Adafruit_SH1106库的标准屏幕测试
  5.   实验接线:
  6.   oled模块    Ardunio Uno
  7.   GND---------GND接地线
  8.   VCC---------5V 接电源
  9.   SDA---------D6
  10.   SCL ------- D4
  11. */

  12. //#include <SPI.h>
  13. #include <Wire.h>
  14. #include <Adafruit_GFX.h>
  15. #include <Adafruit_SH1106.h>

  16. #define OLED_RESET 4
  17. Adafruit_SH1106 display(OLED_RESET);

  18. #define NUMFLAKES 10
  19. #define XPOS 0
  20. #define YPOS 1
  21. #define DELTAY 2


  22. #define LOGO16_GLCD_HEIGHT 16
  23. #define LOGO16_GLCD_WIDTH  16
  24. static const unsigned char PROGMEM logo16_glcd_bmp[] =
  25. { B00000000, B11000000,
  26.   B00000001, B11000000,
  27.   B00000001, B11000000,
  28.   B00000011, B11100000,
  29.   B11110011, B11100000,
  30.   B11111110, B11111000,
  31.   B01111110, B11111111,
  32.   B00110011, B10011111,
  33.   B00011111, B11111100,
  34.   B00001101, B01110000,
  35.   B00011011, B10100000,
  36.   B00111111, B11100000,
  37.   B00111111, B11110000,
  38.   B01111100, B11110000,
  39.   B01110000, B01110000,
  40.   B00000000, B00110000
  41. };

  42. #if (SH1106_LCDHEIGHT != 64)
  43. #error("Height incorrect, please fix Adafruit_SH1106.h!");
  44. #endif

  45. void setup()   {
  46.   Serial.begin(9600);

  47.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  48.   display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  49.   // init done

  50.   // Show image buffer on the display hardware.
  51.   // Since the buffer is intialized with an Adafruit splashscreen
  52.   // internally, this will display the splashscreen.
  53.   display.display();
  54.   delay(2000);

  55.   // Clear the buffer.
  56.   display.clearDisplay();

  57.   // draw a single pixel
  58.   display.drawPixel(10, 10, WHITE);
  59.   // Show the display buffer on the hardware.
  60.   // NOTE: You _must_ call display after making any drawing commands
  61.   // to make them visible on the display hardware!
  62.   display.display();
  63.   delay(2000);
  64.   display.clearDisplay();

  65.   // draw many lines
  66.   testdrawline();
  67.   display.display();
  68.   delay(2000);
  69.   display.clearDisplay();

  70.   // draw rectangles
  71.   testdrawrect();
  72.   display.display();
  73.   delay(2000);
  74.   display.clearDisplay();

  75.   // draw multiple rectangles
  76.   testfillrect();
  77.   display.display();
  78.   delay(2000);
  79.   display.clearDisplay();

  80.   // draw mulitple circles
  81.   testdrawcircle();
  82.   display.display();
  83.   delay(2000);
  84.   display.clearDisplay();

  85.   // draw a white circle, 10 pixel radius
  86.   display.fillCircle(display.width() / 2, display.height() / 2, 10, WHITE);
  87.   display.display();
  88.   delay(2000);
  89.   display.clearDisplay();

  90.   testdrawroundrect();
  91.   delay(2000);
  92.   display.clearDisplay();

  93.   testfillroundrect();
  94.   delay(2000);
  95.   display.clearDisplay();

  96.   testdrawtriangle();
  97.   delay(2000);
  98.   display.clearDisplay();

  99.   testfilltriangle();
  100.   delay(2000);
  101.   display.clearDisplay();

  102.   // draw the first ~12 characters in the font
  103.   testdrawchar();
  104.   display.display();
  105.   delay(2000);
  106.   display.clearDisplay();

  107.   // draw scrolling text
  108.   /* testscrolltext();
  109.     delay(2000);
  110.     display.clearDisplay();*/

  111.   // text display tests
  112.   display.setTextSize(1);
  113.   display.setTextColor(WHITE);
  114.   display.setCursor(0, 0);
  115.   display.println("Hello, world!");
  116.   display.setTextColor(BLACK, WHITE); // 'inverted' text
  117.   display.println(3.141592);
  118.   display.setTextSize(2);
  119.   display.setTextColor(WHITE);
  120.   display.print("0x"); display.println(0xDEADBEEF, HEX);
  121.   display.display();
  122.   delay(2000);

  123.   // miniature bitmap display
  124.   display.clearDisplay();
  125.   display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  126.   display.display();

  127.   // invert the display
  128.   display.invertDisplay(true);
  129.   delay(1000);
  130.   display.invertDisplay(false);
  131.   delay(1000);

  132.   // draw a bitmap icon and 'animate' movement
  133.   testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
  134. }

  135. void loop() {
  136. }

  137. void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  138.   uint8_t icons[NUMFLAKES][3];

  139.   // initialize
  140.   for (uint8_t f = 0; f < NUMFLAKES; f++) {
  141.     icons[f][XPOS] = random(display.width());
  142.     icons[f][YPOS] = 0;
  143.     icons[f][DELTAY] = random(5) + 1;

  144.     Serial.print("x: ");
  145.     Serial.print(icons[f][XPOS], DEC);
  146.     Serial.print(" y: ");
  147.     Serial.print(icons[f][YPOS], DEC);
  148.     Serial.print(" dy: ");
  149.     Serial.println(icons[f][DELTAY], DEC);
  150.   }

  151.   while (1) {
  152.     // draw each icon
  153.     for (uint8_t f = 0; f < NUMFLAKES; f++) {
  154.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
  155.     }
  156.     display.display();
  157.     delay(200);

  158.     // then erase it + move it
  159.     for (uint8_t f = 0; f < NUMFLAKES; f++) {
  160.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
  161.       // move it
  162.       icons[f][YPOS] += icons[f][DELTAY];
  163.       // if its gone, reinit
  164.       if (icons[f][YPOS] > display.height()) {
  165.         icons[f][XPOS] = random(display.width());
  166.         icons[f][YPOS] = 0;
  167.         icons[f][DELTAY] = random(5) + 1;
  168.       }
  169.     }
  170.   }
  171. }

  172. void testdrawchar(void) {
  173.   display.setTextSize(1);
  174.   display.setTextColor(WHITE);
  175.   display.setCursor(0, 0);

  176.   for (uint8_t i = 0; i < 168; i++) {
  177.     if (i == '\n') continue;
  178.     display.write(i);
  179.     if ((i > 0) && (i % 21 == 0))
  180.       display.println();
  181.   }
  182.   display.display();
  183. }

  184. void testdrawcircle(void) {
  185.   for (int16_t i = 0; i < display.height(); i += 2) {
  186.     display.drawCircle(display.width() / 2, display.height() / 2, i, WHITE);
  187.     display.display();
  188.   }
  189. }

  190. void testfillrect(void) {
  191.   uint8_t color = 1;
  192.   for (int16_t i = 0; i < display.height() / 2; i += 3) {
  193.     // alternate colors
  194.     display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);
  195.     display.display();
  196.     color++;
  197.   }
  198. }

  199. void testdrawtriangle(void) {
  200.   for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {
  201.     display.drawTriangle(display.width() / 2, display.height() / 2 - i,
  202.                          display.width() / 2 - i, display.height() / 2 + i,
  203.                          display.width() / 2 + i, display.height() / 2 + i, WHITE);
  204.     display.display();
  205.   }
  206. }

  207. void testfilltriangle(void) {
  208.   uint8_t color = WHITE;
  209.   for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {
  210.     display.fillTriangle(display.width() / 2, display.height() / 2 - i,
  211.                          display.width() / 2 - i, display.height() / 2 + i,
  212.                          display.width() / 2 + i, display.height() / 2 + i, WHITE);
  213.     if (color == WHITE) color = BLACK;
  214.     else color = WHITE;
  215.     display.display();
  216.   }
  217. }

  218. void testdrawroundrect(void) {
  219.   for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
  220.     display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, WHITE);
  221.     display.display();
  222.   }
  223. }

  224. void testfillroundrect(void) {
  225.   uint8_t color = WHITE;
  226.   for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
  227.     display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);
  228.     if (color == WHITE) color = BLACK;
  229.     else color = WHITE;
  230.     display.display();
  231.   }
  232. }

  233. void testdrawrect(void) {
  234.   for (int16_t i = 0; i < display.height() / 2; i += 2) {
  235.     display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, WHITE);
  236.     display.display();
  237.   }
  238. }

  239. void testdrawline() {
  240.   for (int16_t i = 0; i < display.width(); i += 4) {
  241.     display.drawLine(0, 0, i, display.height() - 1, WHITE);
  242.     display.display();
  243.   }
  244.   for (int16_t i = 0; i < display.height(); i += 4) {
  245.     display.drawLine(0, 0, display.width() - 1, i, WHITE);
  246.     display.display();
  247.   }
  248.   delay(250);

  249.   display.clearDisplay();
  250.   for (int16_t i = 0; i < display.width(); i += 4) {
  251.     display.drawLine(0, display.height() - 1, i, 0, WHITE);
  252.     display.display();
  253.   }
  254.   for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
  255.     display.drawLine(0, display.height() - 1, display.width() - 1, i, WHITE);
  256.     display.display();
  257.   }
  258.   delay(250);

  259.   display.clearDisplay();
  260.   for (int16_t i = display.width() - 1; i >= 0; i -= 4) {
  261.     display.drawLine(display.width() - 1, display.height() - 1, i, 0, WHITE);
  262.     display.display();
  263.   }
  264.   for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
  265.     display.drawLine(display.width() - 1, display.height() - 1, 0, i, WHITE);
  266.     display.display();
  267.   }
  268.   delay(250);

  269.   display.clearDisplay();
  270.   for (int16_t i = 0; i < display.height(); i += 4) {
  271.     display.drawLine(display.width() - 1, 0, 0, i, WHITE);
  272.     display.display();
  273.   }
  274.   for (int16_t i = 0; i < display.width(); i += 4) {
  275.     display.drawLine(display.width() - 1, 0, i, display.height() - 1, WHITE);
  276.     display.display();
  277.   }
  278.   delay(250);
  279. }

  280. /*void testscrolltext(void) {
  281.   display.setTextSize(2);
  282.   display.setTextColor(WHITE);
  283.   display.setCursor(10,0);
  284.   display.clearDisplay();
  285.   display.println("scroll");
  286.   display.display();

  287.   display.startscrollright(0x00, 0x0F);
  288.   delay(2000);
  289.   display.stopscroll();
  290.   delay(1000);
  291.   display.startscrollleft(0x00, 0x0F);
  292.   delay(2000);
  293.   display.stopscroll();
  294.   delay(1000);
  295.   display.startscrolldiagright(0x00, 0x07);
  296.   delay(2000);
  297.   display.startscrolldiagleft(0x00, 0x07);
  298.   delay(2000);
  299.   display.stopscroll();
  300.   }*/
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-26 20:20:37 | 显示全部楼层
  实验场景图




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2025-5-12 17:32 , Processed in 0.249601 second(s), 11 queries , Redis On.

Powered by Discuz!

© 2006-2025 MyDigit.Net

快速回复 返回顶部 返回列表