Arduino SPI驱动7引脚0.96寸OLED SSD1306 调试笔记
本帖最后由 幻生幻灭 于 2018-8-9 09:39 编辑昨晚把玩OLED模块,做了个简单的时钟测试。用的是0.96寸OLED显示屏12864和ds1307时钟模块
模块如下图
最终效果如图
过程倒是不复杂,这里只是分享下调试过程和心得
1、了解模块参数
图中可知默认是4线SPI,而不是IIC。并通过模块背侧的短接电阻进行再次确认!
2、下载最新库
https://learn.adafruit.com/monochrome-oled-breakouts/arduino-library-and-examples
其中OLED模块的专用库名称是SSD1306,另外需要配合图形库GFX操作
不建议使用NB的U8glib,因为这个库强大到哭,所以编译和下载都太消耗时间了
3、接线
从参考资料里面扒的接线图
时钟模块这里不做详细说明,OLED的模块引脚对应关系如下图
4、调试
这里采用最下面的样例程序
最关键的是需要根据实际的接线图修改样例中的引脚定义!
// If using software SPI (the default case):
#define OLED_MOSI 11
#define OLED_CLK 13
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
5、完整代码
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
// If using software SPI (the default case):
#define OLED_MOSI 11
#define OLED_CLK 13
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
RTC_DS1307 RTC;
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH16
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);
}
void loop() {
DateTime now = RTC.now();
printDateTime(now);
display.display();
delay(200);
display.clearDisplay();
}
void printDateTime(DateTime dateTime) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20,10);
display.println("- LEO -");
display.setCursor(20,35);
//传送小时
display.print(dateTime.hour(), DEC);
display.print(':');
//传送分钟
display.print(dateTime.minute(), DEC);
display.print(':');
//传送秒
display.print(dateTime.second(), DEC);
}
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/tutorials/interfacing-0-96-oled-display-with-arduino-uno
https://www.brainy-bits.com/connect-and-use-a-spi-oled-display/ 多謝分享多謝分享 很久没见楼主的帖子了,感谢分享这么有启发性的实例。
最近我也在留意显示设备,不过我关注的是电子纸,e-paper或者是e-ink之类的。
虽然设备不同,不过都需要图形库支持,您建议用ada的库很值得借鉴 wing 发表于 2018-8-12 12:15
很久没见楼主的帖子了,感谢分享这么有启发性的实例。
最近我也在留意显示设备,不过我关注的是电子纸,e- ...
哈,是啊。的确这段时间比较懒。ADA家的库的确比较强大。
个人理解,在1306(硬件驱动) -> GFX(图形库) -> HMI
HMI就是实际我们交互的菜单,操作界面啥的 应该还会有一个UI库,或者界面编辑软件
就像Python等一样,你可以写代码做界面,也可以用库调菜单,或者图形化编辑
不过我还没有去深挖这块,相信已经有老外做出过这种UI库了
看说明这种模块很省电,电池能显示一天吧? a461624201 发表于 2018-8-18 23:16
看说明这种模块很省电,电池能显示一天吧?
一天应该没问题,不过电子墨水更省电
页:
[1]