oled_sh1106+ds1307 实现
前言
Arduino 有个很强大的开源的库 u8g2 ,它支持了现在绝大多数的OLED屏幕,至于它的基本用法可以参考我的另一篇笔记,当然这只是我自己的学习笔记写的不是太好,我在文章里贴了官方参考链接可以感兴趣可以去看看。当然,你也可以参考这个博主的单片机菜鸟哥
OLED_SH1106
sh1106是一款1.3寸大小的OLED屏幕,一般有I2C接口和SPI接口,可以将其连接到Arduino Board 的硬件I2C或SPI接口,也可以用软件模拟的方式接到数字I/O口
DS1307时钟模块
硬件介绍我这里就略过了
引脚连接:
SDA------>Arduino SDA
SCL------>Arduino SCL
VCC------>Arduino 5V
GND----->Arduino GND
我使用的是,Arduino的 RTClib 库,可以自己下载,首先我们来看看它的示例程序
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(57600);
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// When time needs to be re-set on a previously configured device, the
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop () {
DateTime now = rtc.