本帖最后由 幻生幻灭 于 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、调试
这里采用最下面的样例程序
最关键的是需要根据实际的接线图修改样例中的引脚定义! - // 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_WIDTH 16
- #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/tutorial ... ay-with-arduino-uno
https://www.brainy-bits.com/connect-and-use-a-spi-oled-display/ |