Arduino UNO DS3231高精度RTC芯片 制作时钟
DS3231 模塊
是一個時鐘模塊,上面包含一個紐扣電池位置,可以在主機(jī)斷電的情況下還可以繼續(xù)計算時間,以便以后記錄使用。
模塊參數(shù):
? 1.尺寸:38mm(長)*22mm(寬)*14mm(高)
? 2.重量:8g
? 3.工作電壓:3.3--5.5V
? 4.時鐘芯片:高精度時鐘芯片DS3231
? 5.時鐘精度:0-40℃范圍內(nèi),精度2ppm,年誤差約1分鐘
? 6.帶2個日歷鬧鐘
? 7.可編程方波輸出
? 8.實時時鐘產(chǎn)生秒、分、時、星期、日期、月和年計時,并提供有效期到2100年的閏年補(bǔ)償
? 9.芯片內(nèi)部自帶溫度傳感器,精度為±3℃
? 10.存儲芯片:AT24C32(存儲容量32K)
? 11.IIC總線接口,最高傳輸速度400KHz(工作電壓為5V時)
? 12.可級聯(lián)其它IIC設(shè)備,24C32地址可通過短路A0/A1/A2修改,默認(rèn)地址為0x57
? 13.帶可充電電池LIR2032,保證系統(tǒng)斷電后,時鐘任然正常走動
實驗效果
通過設(shè)定時間的程序后,
我們運行顯示時間的程序,就可以看到時鐘模塊當(dāng)前的時間了
BOM表
Arduino UNO??? *1
DS3231 時鐘模塊 *1
跳線若干
接線
Arduino ? Uno ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DS3231
? ? GND ? ? ? ? ? ? ? ? ? ? <---> ? ? ? ? ? ? ? ?GND
? ?5V ? ? ? ? ? ? ? ? ? ? ? ? ?<--->? ? ? ? ? ? ? ? VCC
? ?A4(SDA) ? ? ? ? ? ? ? ? ? ? ? ? ?<--->? ? ? ? ? ? ? ? SDA
? ?A5 (SCL) ? ? ? ? ? ? ? ? ? ? ? ??<--->? ? ? ? ? ? ? ? ?SCL
程序
需要下載庫
http://www.rinkydinkelectronics.com/library.php?id=74
設(shè)置時間的程序
// DS3231_Serial_Easy // Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved // web: http://www.RinkyDinkElectronics.com/ // // A quick demo of how to use my DS3231-library to // quickly send time and date information over a serial link // // To use the hardware I2C (TWI) interface of the Arduino you must connect // the pins as follows: // // Arduino Uno/2009: // ---------------------- // DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin // SCL pin -> Arduino Analog 5 or the dedicated SCL pin // // Arduino Leonardo: // ---------------------- // DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin // SCL pin -> Arduino Digital 3 or the dedicated SCL pin // // Arduino Mega: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin // // Arduino Due: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin // // The internal pull-up resistors will be activated when using the // hardware I2C interfaces. // // You can connect the DS3231 to any available pin but if you use any // other than what is described above the library will fall back to // a software-based, TWI-like protocol which will require exclusive access // to the pins used, and you will also have to use appropriate, external // pull-up resistors on the data and clock signals. //#include <DS3231.h>// Init the DS3231 using the hardware interface DS3231 rtc(SDA, SCL);void setup() {// Setup Serial connectionSerial.begin(115200);// Uncomment the next line if you are using an Arduino Leonardo//while (!Serial) {}// Initialize the rtc objectrtc.begin();// The following lines can be uncommented to set the date and timertc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAYrtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014 }void loop() {// Send Day-of-WeekSerial.print(rtc.getDOWStr());Serial.print(" ");// Send dateSerial.print(rtc.getDateStr());Serial.print(" -- ");// Send timeSerial.println(rtc.getTimeStr());// Wait one second before repeating :)delay (1000); }顯示時間的程序
// DS3231_Serial_Easy // Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved // web: http://www.RinkyDinkElectronics.com/ // // A quick demo of how to use my DS3231-library to // quickly send time and date information over a serial link // // To use the hardware I2C (TWI) interface of the Arduino you must connect // the pins as follows: // // Arduino Uno/2009: // ---------------------- // DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin // SCL pin -> Arduino Analog 5 or the dedicated SCL pin // // Arduino Leonardo: // ---------------------- // DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin // SCL pin -> Arduino Digital 3 or the dedicated SCL pin // // Arduino Mega: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin // // Arduino Due: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin // // The internal pull-up resistors will be activated when using the // hardware I2C interfaces. // // You can connect the DS3231 to any available pin but if you use any // other than what is described above the library will fall back to // a software-based, TWI-like protocol which will require exclusive access // to the pins used, and you will also have to use appropriate, external // pull-up resistors on the data and clock signals. //#include <DS3231.h>// Init the DS3231 using the hardware interface DS3231 rtc(SDA, SCL);void setup() {// Setup Serial connectionSerial.begin(115200);// Uncomment the next line if you are using an Arduino Leonardo//while (!Serial) {}// Initialize the rtc objectrtc.begin();// The following lines can be uncommented to set the date and time//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014 }void loop() {// Send Day-of-WeekSerial.print(rtc.getDOWStr());Serial.print(" ");// Send dateSerial.print(rtc.getDateStr());Serial.print(" -- ");// Send timeSerial.println(rtc.getTimeStr());// Wait one second before repeating :)delay (1000); }
思路講解
1,#include <DS3231.h> ? ?//加載DS3231庫
2,DS3231 ?rtc(SDA, SCL); ? ?//設(shè)置I2C
3,rtc.begin(); ? //建立RTC對象
4,
? rtc.setDOW(WEDNESDAY); ? ? // 設(shè)置星期幾,例如 SUNDAY
? rtc.setTime(12, 0, 0); ? ? // 設(shè)置時間 12:00:00 (24小時制)
? rtc.setDate(1, 1, 2014); ? // 設(shè)置日期 ?1月,1日 ,2014 年
如果在顯示程序中,或不需要設(shè)置時間的時候,可以在前面加//給注釋掉
5,
rtc.getDOWStr() ? 獲取星期幾
rtc.getDateStr() ? ?獲取日期
rtc.getTimeStr() ? 獲取時間
總結(jié)
以上是生活随笔為你收集整理的Arduino UNO DS3231高精度RTC芯片 制作时钟的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表内账和表外账
- 下一篇: 四、模型类序列化器ModelSerial