极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 58925|回复: 5

Arduino SPI驱动7引脚0.96寸OLED SSD1306 调试笔记

[复制链接]
发表于 2018-8-9 09:39:21 | 显示全部楼层 |阅读模式
本帖最后由 幻生幻灭 于 2018-8-9 09:39 编辑

昨晚把玩OLED模块,做了个简单的时钟测试。用的是0.96寸OLED显示屏12864和ds1307时钟模块
模块如下图



最终效果如图


过程倒是不复杂,这里只是分享下调试过程和心得
1、了解模块参数

图中可知默认是4线SPI,而不是IIC。并通过模块背侧的短接电阻进行再次确认!


2、下载最新库
https://learn.adafruit.com/monoc ... ibrary-and-examples
其中OLED模块的专用库名称是SSD1306,另外需要配合图形库GFX操作
不建议使用NB的U8glib,因为这个库强大到哭,所以编译和下载都太消耗时间了


3、接线
从参考资料里面扒的接线图
时钟模块这里不做详细说明,OLED的模块引脚对应关系如下图



4、调试
这里采用最下面的样例程序

最关键的是需要根据实际的接线图修改样例中的引脚定义!
  1. // If using software SPI (the default case):
  2. #define OLED_MOSI   11
  3. #define OLED_CLK   13
  4. #define OLED_DC    9
  5. #define OLED_CS    10
  6. #define OLED_RESET 8
  7. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
复制代码


5、完整代码

  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #include "RTClib.h"

  6. // If using software SPI (the default case):
  7. #define OLED_MOSI   11
  8. #define OLED_CLK   13
  9. #define OLED_DC    9
  10. #define OLED_CS    10
  11. #define OLED_RESET 8
  12. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  13. RTC_DS1307 RTC;

  14. #define NUMFLAKES 10
  15. #define XPOS 0
  16. #define YPOS 1
  17. #define DELTAY 2

  18. #define LOGO16_GLCD_HEIGHT 16
  19. #define LOGO16_GLCD_WIDTH  16


  20. #if (SSD1306_LCDHEIGHT != 64)
  21. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  22. #endif

  23. void setup()   {               
  24.   Serial.begin(9600);
  25.   Wire.begin();
  26.   RTC.begin();
  27.   if (! RTC.isrunning()) {
  28.     Serial.println("RTC is NOT running!");
  29.     // following line sets the RTC to the date & time this sketch was compiled
  30.     RTC.adjust(DateTime(__DATE__, __TIME__));
  31.   }
  32.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  33.   display.begin(SSD1306_SWITCHCAPVCC);
  34.   // init done

  35.   // Show image buffer on the display hardware.
  36.   // Since the buffer is intialized with an Adafruit splashscreen
  37.   // internally, this will display the splashscreen.
  38.   display.display();
  39.   delay(1000);
  40. }


  41. void loop() {
  42.   DateTime now = RTC.now();
  43.   printDateTime(now);
  44.   display.display();
  45.   delay(200);
  46.   display.clearDisplay();
  47. }


  48. void printDateTime(DateTime dateTime) {
  49.   display.setTextSize(2);
  50.   display.setTextColor(WHITE);
  51.   display.setCursor(20,10);
  52.   display.println("- LEO -");
  53.   display.setCursor(20,35);
  54.   //传送小时
  55.   display.print(dateTime.hour(), DEC);
  56.   display.print(':');
  57.   //传送分钟
  58.   display.print(dateTime.minute(), DEC);
  59.   display.print(':');
  60.   //传送秒
  61.   display.print(dateTime.second(), DEC);
  62. }


复制代码


6、REF
7引脚0.96寸OLED如何连接ARDUINO MAGE2560,1280
http://www.geek-workshop.com/thread-15655-1-1.html
(出处: 极客工坊)

ADRUINO 使用U8GLIB库 IIC 或者 SPI 驱动OLED液晶屏
http://www.geek-workshop.com/thread-27110-1-1.html
(出处: 极客工坊)

《博哥OLED系列》- 玩转SSD1306-12864 OLED
https://www.arduino.cn/thread-49674-1-1.html
(出处: Arduino中文社区)

https://learn.adafruit.com/monochrome-oled-breakouts
https://github.com/adafruit/Adafruit_SSD1306

http://cyaninfinite.com/tutorial ... ay-with-arduino-uno
https://www.brainy-bits.com/connect-and-use-a-spi-oled-display/

本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2018-8-9 18:50:10 | 显示全部楼层
多謝分享多謝分享
回复 支持 反对

使用道具 举报

发表于 2018-8-12 12:15:15 | 显示全部楼层
很久没见楼主的帖子了,感谢分享这么有启发性的实例。
最近我也在留意显示设备,不过我关注的是电子纸,e-paper或者是e-ink之类的。
虽然设备不同,不过都需要图形库支持,您建议用ada的库很值得借鉴
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-13 08:42:14 | 显示全部楼层
wing 发表于 2018-8-12 12:15
很久没见楼主的帖子了,感谢分享这么有启发性的实例。
最近我也在留意显示设备,不过我关注的是电子纸,e- ...

哈,是啊。的确这段时间比较懒。ADA家的库的确比较强大。
个人理解,在1306(硬件驱动) -> GFX(图形库) -> HMI
HMI就是实际我们交互的菜单,操作界面啥的 应该还会有一个UI库,或者界面编辑软件
就像Python等一样,你可以写代码做界面,也可以用库调菜单,或者图形化编辑
不过我还没有去深挖这块,相信已经有老外做出过这种UI库了
回复 支持 反对

使用道具 举报

发表于 2018-8-18 23:16:57 | 显示全部楼层
看说明这种模块很省电,电池能显示一天吧?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-22 11:51:57 | 显示全部楼层
a461624201 发表于 2018-8-18 23:16
看说明这种模块很省电,电池能显示一天吧?

一天应该没问题,不过电子墨水更省电
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 00:41 , Processed in 0.045147 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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