OLED一款小巧的显示屏,感觉可以做出很可爱的东西。

这次实验的这款是128X64的OLED屏幕 ,

芯片是SSD1306,请确认自家模块芯片型号,不然对不上号啊

使用IIC的方法,简单实验显示示例程序。

(请确认你手头上的模块可以IIC连接,若干不支持那只能SPI方式接线)

先实现连接与显示,之后再进行更深入的应用。

任意门:

Arduino Uno 驱动OLED进阶 显示中英文字

Arduino Uno 驱动OLED进阶 显示图片

Arduino Uno 驱动OLED进阶 显示几何动画

编译的过程,可能会遇到以下问题:

①提示错误

#error("Height incorrect, please fix Adafruit_SSD1306.h!");

错误信息意思是指:

高度不正确,请修正Adafruit_SSD1306.h!

进入Arduino安装文件夹的libraries文件夹的Adfruit_SSD1306-master 找到Adafruit_SSD1306.h

打开此文件,找到第70行左右

默认是定义 SSD1306_128_32 ,由于我们使用的是128*64的OLED,所以,把原来的#define SSD1306_128_32,前面加上//

把#define SSD_128_64 前面的//去掉

最后就如上面图例一样

②模块的IIC 地址问题

模块的地址修改在这个位置,示例程序的61行

这个模块地址我用的是这个,但每个模块可能不一样,具体请咨询购买的商家,又或者可以参考下面链接的,IIC搜索地址程序。

任意门:Arduino 和LCD1602液晶屏 I2C接口实验

实验效果

BOM表

Arduino Uno             *1

OLED 128*64           *1

跳线若干

针脚说明

VCC   接3.3v电源

GND  接地(GND)

SCL   时钟线

SDA   数据线

接线图

程序开源代码

在上代码之前,先下载两个库分别是

Adafruit SSD1306 Library:

https://github.com/adafruit/Adafruit_SSD1306

or

http://download.csdn.net/detail/ling3ye/9729179

Adafruit GFX Library:

https://github.com/adafruit/Adafruit-GFX-Library

or

http://download.csdn.net/detail/ling3ye/9729180

下载后把解压的文件放在 Arduino 安装目录里的 "libraries"

例如:C:\Program Files (x86)\Arduino\libraries

调出示例程序

或者复制以下代码,都是一样的:

  1. /*********************************************************************
  2. This is an example for our Monochrome OLEDs based on SSD1306 drivers
  3. Pick one up today in the adafruit shop!
  4. ------> http://www.adafruit.com/category/63_98
  5. This example is for a 128x64 size display using I2C to communicate
  6. 3 pins are required to interface (2 I2C and one reset)
  7. Adafruit invests time and resources providing this open source code,
  8. please support Adafruit and open-source hardware by purchasing
  9. products from Adafruit!
  10. Written by Limor Fried/Ladyada  for Adafruit Industries.
  11. BSD license, check license.txt for more information
  12. All text above, and the splash screen must be included in any redistribution
  13. *********************************************************************/
  14. #include <SPI.h>
  15. #include <Wire.h>
  16. #include <Adafruit_GFX.h>
  17. #include <Adafruit_SSD1306.h>
  18. #define OLED_RESET 4
  19. Adafruit_SSD1306 display(OLED_RESET);
  20. #define NUMFLAKES 10
  21. #define XPOS 0
  22. #define YPOS 1
  23. #define DELTAY 2
  24. #define LOGO16_GLCD_HEIGHT 16
  25. #define LOGO16_GLCD_WIDTH  16
  26. static const unsigned char PROGMEM logo16_glcd_bmp[] =
  27. { B00000000, B11000000,
  28. B00000001, B11000000,
  29. B00000001, B11000000,
  30. B00000011, B11100000,
  31. B11110011, B11100000,
  32. B11111110, B11111000,
  33. B01111110, B11111111,
  34. B00110011, B10011111,
  35. B00011111, B11111100,
  36. B00001101, B01110000,
  37. B00011011, B10100000,
  38. B00111111, B11100000,
  39. B00111111, B11110000,
  40. B01111100, B11110000,
  41. B01110000, B01110000,
  42. B00000000, B00110000 };
  43. #if (SSD1306_LCDHEIGHT != 64)
  44. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  45. #endif
  46. void setup()   {
  47. Serial.begin(9600);
  48. // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  49. display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  50. // init done
  51. // Show image buffer on the display hardware.
  52. // Since the buffer is intialized with an Adafruit splashscreen
  53. // internally, this will display the splashscreen.
  54. display.display();
  55. delay(2000);
  56. // Clear the buffer.
  57. display.clearDisplay();
  58. // draw a single pixel
  59. display.drawPixel(10, 10, WHITE);
  60. // Show the display buffer on the hardware.
  61. // NOTE: You _must_ call display after making any drawing commands
  62. // to make them visible on the display hardware!
  63. display.display();
  64. delay(2000);
  65. display.clearDisplay();
  66. // draw many lines
  67. testdrawline();
  68. display.display();
  69. delay(2000);
  70. display.clearDisplay();
  71. // draw rectangles
  72. testdrawrect();
  73. display.display();
  74. delay(2000);
  75. display.clearDisplay();
  76. // draw multiple rectangles
  77. testfillrect();
  78. display.display();
  79. delay(2000);
  80. display.clearDisplay();
  81. // draw mulitple circles
  82. testdrawcircle();
  83. display.display();
  84. delay(2000);
  85. display.clearDisplay();
  86. // draw a white circle, 10 pixel radius
  87. display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
  88. display.display();
  89. delay(2000);
  90. display.clearDisplay();
  91. testdrawroundrect();
  92. delay(2000);
  93. display.clearDisplay();
  94. testfillroundrect();
  95. delay(2000);
  96. display.clearDisplay();
  97. testdrawtriangle();
  98. delay(2000);
  99. display.clearDisplay();
  100. testfilltriangle();
  101. delay(2000);
  102. display.clearDisplay();
  103. // draw the first ~12 characters in the font
  104. testdrawchar();
  105. display.display();
  106. delay(2000);
  107. display.clearDisplay();
  108. // draw scrolling text
  109. testscrolltext();
  110. delay(2000);
  111. display.clearDisplay();
  112. // text display tests
  113. display.setTextSize(1);
  114. display.setTextColor(WHITE);
  115. display.setCursor(0,0);
  116. display.println("Hello, world!");
  117. display.setTextColor(BLACK, WHITE); // 'inverted' text
  118. display.println(3.141592);
  119. display.setTextSize(2);
  120. display.setTextColor(WHITE);
  121. display.print("0x"); display.println(0xDEADBEEF, HEX);
  122. display.display();
  123. delay(2000);
  124. display.clearDisplay();
  125. // miniature bitmap display
  126. display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  127. display.display();
  128. delay(1);
  129. // invert the display
  130. display.invertDisplay(true);
  131. delay(1000);
  132. display.invertDisplay(false);
  133. delay(1000);
  134. display.clearDisplay();
  135. // draw a bitmap icon and 'animate' movement
  136. testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
  137. }
  138. void loop() {
  139. }
  140. void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  141. uint8_t icons[NUMFLAKES][3];
  142. // initialize
  143. for (uint8_t f=0; f< NUMFLAKES; f++) {
  144. icons[f][XPOS] = random(display.width());
  145. icons[f][YPOS] = 0;
  146. icons[f][DELTAY] = random(5) + 1;
  147. Serial.print("x: ");
  148. Serial.print(icons[f][XPOS], DEC);
  149. Serial.print(" y: ");
  150. Serial.print(icons[f][YPOS], DEC);
  151. Serial.print(" dy: ");
  152. Serial.println(icons[f][DELTAY], DEC);
  153. }
  154. while (1) {
  155. // draw each icon
  156. for (uint8_t f=0; f< NUMFLAKES; f++) {
  157. display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
  158. }
  159. display.display();
  160. delay(200);
  161. // then erase it + move it
  162. for (uint8_t f=0; f< NUMFLAKES; f++) {
  163. display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
  164. // move it
  165. icons[f][YPOS] += icons[f][DELTAY];
  166. // if its gone, reinit
  167. if (icons[f][YPOS] > display.height()) {
  168. icons[f][XPOS] = random(display.width());
  169. icons[f][YPOS] = 0;
  170. icons[f][DELTAY] = random(5) + 1;
  171. }
  172. }
  173. }
  174. }
  175. void testdrawchar(void) {
  176. display.setTextSize(1);
  177. display.setTextColor(WHITE);
  178. display.setCursor(0,0);
  179. for (uint8_t i=0; i < 168; i++) {
  180. if (i == '\n') continue;
  181. display.write(i);
  182. if ((i > 0) && (i % 21 == 0))
  183. display.println();
  184. }
  185. display.display();
  186. delay(1);
  187. }
  188. void testdrawcircle(void) {
  189. for (int16_t i=0; i<display.height(); i+=2) {
  190. display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
  191. display.display();
  192. delay(1);
  193. }
  194. }
  195. void testfillrect(void) {
  196. uint8_t color = 1;
  197. for (int16_t i=0; i<display.height()/2; i+=3) {
  198. // alternate colors
  199. display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
  200. display.display();
  201. delay(1);
  202. color++;
  203. }
  204. }
  205. void testdrawtriangle(void) {
  206. for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
  207. display.drawTriangle(display.width()/2, display.height()/2-i,
  208. display.width()/2-i, display.height()/2+i,
  209. display.width()/2+i, display.height()/2+i, WHITE);
  210. display.display();
  211. delay(1);
  212. }
  213. }
  214. void testfilltriangle(void) {
  215. uint8_t color = WHITE;
  216. for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
  217. display.fillTriangle(display.width()/2, display.height()/2-i,
  218. display.width()/2-i, display.height()/2+i,
  219. display.width()/2+i, display.height()/2+i, WHITE);
  220. if (color == WHITE) color = BLACK;
  221. else color = WHITE;
  222. display.display();
  223. delay(1);
  224. }
  225. }
  226. void testdrawroundrect(void) {
  227. for (int16_t i=0; i<display.height()/2-2; i+=2) {
  228. display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
  229. display.display();
  230. delay(1);
  231. }
  232. }
  233. void testfillroundrect(void) {
  234. uint8_t color = WHITE;
  235. for (int16_t i=0; i<display.height()/2-2; i+=2) {
  236. display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
  237. if (color == WHITE) color = BLACK;
  238. else color = WHITE;
  239. display.display();
  240. delay(1);
  241. }
  242. }
  243. void testdrawrect(void) {
  244. for (int16_t i=0; i<display.height()/2; i+=2) {
  245. display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
  246. display.display();
  247. delay(1);
  248. }
  249. }
  250. void testdrawline() {
  251. for (int16_t i=0; i<display.width(); i+=4) {
  252. display.drawLine(0, 0, i, display.height()-1, WHITE);
  253. display.display();
  254. delay(1);
  255. }
  256. for (int16_t i=0; i<display.height(); i+=4) {
  257. display.drawLine(0, 0, display.width()-1, i, WHITE);
  258. display.display();
  259. delay(1);
  260. }
  261. delay(250);
  262. display.clearDisplay();
  263. for (int16_t i=0; i<display.width(); i+=4) {
  264. display.drawLine(0, display.height()-1, i, 0, WHITE);
  265. display.display();
  266. delay(1);
  267. }
  268. for (int16_t i=display.height()-1; i>=0; i-=4) {
  269. display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
  270. display.display();
  271. delay(1);
  272. }
  273. delay(250);
  274. display.clearDisplay();
  275. for (int16_t i=display.width()-1; i>=0; i-=4) {
  276. display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
  277. display.display();
  278. delay(1);
  279. }
  280. for (int16_t i=display.height()-1; i>=0; i-=4) {
  281. display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
  282. display.display();
  283. delay(1);
  284. }
  285. delay(250);
  286. display.clearDisplay();
  287. for (int16_t i=0; i<display.height(); i+=4) {
  288. display.drawLine(display.width()-1, 0, 0, i, WHITE);
  289. display.display();
  290. delay(1);
  291. }
  292. for (int16_t i=0; i<display.width(); i+=4) {
  293. display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
  294. display.display();
  295. delay(1);
  296. }
  297. delay(250);
  298. }
  299. void testscrolltext(void) {
  300. display.setTextSize(2);
  301. display.setTextColor(WHITE);
  302. display.setCursor(10,0);
  303. display.clearDisplay();
  304. display.println("scroll");
  305. display.display();
  306. delay(1);
  307. display.startscrollright(0x00, 0x0F);
  308. delay(2000);
  309. display.stopscroll();
  310. delay(1000);
  311. display.startscrollleft(0x00, 0x0F);
  312. delay(2000);
  313. display.stopscroll();
  314. delay(1000);
  315. display.startscrolldiagright(0x00, 0x07);
  316. delay(2000);
  317. display.startscrolldiagleft(0x00, 0x07);
  318. delay(2000);
  319. display.stopscroll();
  320. }
 

arduino驱动oled的更多相关文章

  1. arduino驱动安装

    方法一:使用官方提供的一键安装程序安装 打开Arduino在你电脑上的位置如果你的电脑是32位系统,就运行dpinst-x86.exe如果是64位系统,就运行dpinst-amd64.exe然后在弹出 ...

  2. 使用Arduino驱动基于ST7533芯片的TFT屏

    在合宙通信买了一个1.8寸的TFT屏,驱动芯片是ST7533,本来打算使用Air800直接驱动,但由于其他原因,放弃了.于是尝试使用arduino驱动,为了屏幕刷新速度更快,采用硬件SPI. 硬件连接 ...

  3. Raspberry Pi3驱动Oled ssh1106屏

    Raspberry Pi3可以直接使用GPIO接口驱动OLED屏 一.接线 根据网上随便找的图可以看到树莓派3的GPIO接口引脚顺序 PS:26pin的GPIO为前26针 根据OLED屏的引脚说明,如 ...

  4. TPYBoard v202开发板通过I2C协议驱动oled

    最近无聊的时候研究了一下TPYBoard v202开发板,发现网上TPYBoard开发驱动oled的这块资料比较少,本人测试成功后给大家分享一下经验 下面通过代码讲解一下 1.首先需要导包, 在网上下 ...

  5. Arduino+DS18b20+OLED Display

    DS18b20获取到温度数值保存到变量中,然后和天气图标还有滚动字幕一起发送到OLED 屏幕上显示 需要用到的库均可在Arduino库管理器下载. 电路图: 图中屏幕接线已在代码中写出,温度传感器da ...

  6. win8.1环境下安装arduino驱动问题解决方案

    1. Windows 键+ R, 输入 shutdown.exe /r /o /f /t 00 2.此时电脑会自动重启,进入一下画面,选择Troubleshoot (转载请注明原处:http://ww ...

  7. 最新 Arduino 驱动 12接口/户外 LED显示屏/LED点阵屏/LED单元板

    起因 现有的驱动LED显示屏的资料,比较好的只有这个.但是它驱动的是08接口的室内显示屏,而我要驱动的是12接口的户外显示屏.两种屏幕的区别在于户外屏幕点阵比较稀疏,而且二者的扫描方式,驱动方式都不太 ...

  8. 精简版、GHOST版win7,arduino驱动安装失败的解决方法分享

    arduino组件安装驱动不成功,总是提示系统找不到指定文件. 原因是因为精简版缺少了两个关键的系统文件,导致无法安装.mdmcpq.inf  和 usbser.sys 解决方案详见帖子http:// ...

  9. PMS5003ST+Arduino Nano OLED屏显示

    整合OLED显示和PMS5003报数 #include <Arduino.h> #include <pms.h> /////////////////////////////// ...

随机推荐

  1. maven打包 invalid entry size Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.14.RELEASE:repackage (default) on project

    打包失败,但是不知是具体是什么引起得,使用mvn -e clean package,定位到报错得代码 在定位到代码,打上断点,使用maven 打包debug模式 找到dubbo.properties, ...

  2. JAVA 算法练习(一)

    用java写了几道编程题目,分享给大家 语法和C语言几乎一样,不懂 java 会 c 也可以看明白的. 最大连续数列和 题目说明 对于一个有正有负的整数数组,请找出总和最大的连续数列.给定一个int数 ...

  3. python 2.7编译安装

    一 官网下载python2.7源码: python安装pip python -m ensurepip --default-pip

  4. tomcat添加ssl证书

    Tomcat支持JKS格式证书,从Tomcat7开始也支持PFX格式证书,两种证书格式任选其一. 文件说明: 1. 证书文件xxx.pem,包含两段内容,请不要删除任何一段内容. 2. 如果是证书系统 ...

  5. php IP地址转换

    <?php $enip = ip2long('210.110.11.49); echo $enip."<br />";//-764540111 echo long ...

  6. 17.3.12---logging日志模块level配置操作

    1----logging日志记录模块的使用和配置 logging模块我们不需要单独再安装,经常要调试程序,记录程序运行过程中的一些信息,手工记录调试信息很麻烦,所以python的logging模块,会 ...

  7. Python KNN 学习曲线

    学习曲线的目的是选择更好的模型参数.以最近邻算法为例,选取最近的多少个数据点,才能达到最优.可以控制训练集不动,调整最近的点的个数,绘制学习曲线. import matplotlib.pyplot a ...

  8. tif图片压缩

    tif图片在ImageIo.read获取时,返回为空,导致无法使用,百度了很久,很多人说jai可以,便去看了下,总结如下: public static void CompressPic(String ...

  9. JavaScript详解(二)

    js的流程控制 if语句: if (条件表达式A){ xx; }else if (条件表达式B){ xx; } else{ xx; } switch语句: switch (表达式){ case 值1: ...

  10. Linux中的各种文件类型

    Linux中有一句话:一切皆是文件 1.普通文件( -       regular file ) (1).文本文件 文件中的内容是由文本构成的,文本指的是ASCII码字符.文件里的内容本质上都是数字( ...