Arduino UNO DS3231高精度RTC芯片 制作时钟
来源:互联网 发布:unity3d 怎么用 编辑:程序博客网 时间:2024/05/16 10:11
DS3231 模块
是一个时钟模块,上面包含一个纽扣电池位置,可以在主机断电的情况下还可以继续计算时间,以便以后记录使用。
模块参数:
1.尺寸:38mm(长)*22mm(宽)*14mm(高)
2.重量:8g
3.工作电压:3.3--5.5V
4.时钟芯片:高精度时钟芯片DS3231
5.时钟精度:0-40℃范围内,精度2ppm,年误差约1分钟
6.带2个日历闹钟
7.可编程方波输出
8.实时时钟产生秒、分、时、星期、日期、月和年计时,并提供有效期到2100年的闰年补偿
9.芯片内部自带温度传感器,精度为±3℃
10.存储芯片:AT24C32(存储容量32K)
11.IIC总线接口,最高传输速度400KHz(工作电压为5V时)
12.可级联其它IIC设备,24C32地址可通过短路A0/A1/A2修改,默认地址为0x57
13.带可充电电池LIR2032,保证系统断电后,时钟任然正常走动
实验效果
通过设定时间的程序后,
我们运行显示时间的程序,就可以看到时钟模块当前的时间了
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
设置时间的程序
// 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 interfaceDS3231 rtc(SDA, SCL);void setup(){ // Setup Serial connection Serial.begin(115200); // Uncomment the next line if you are using an Arduino Leonardo //while (!Serial) {} // Initialize the rtc object rtc.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-Week Serial.print(rtc.getDOWStr()); Serial.print(" "); // Send date Serial.print(rtc.getDateStr()); Serial.print(" -- "); // Send time Serial.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 interfaceDS3231 rtc(SDA, SCL);void setup(){ // Setup Serial connection Serial.begin(115200); // Uncomment the next line if you are using an Arduino Leonardo //while (!Serial) {} // Initialize the rtc object rtc.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-Week Serial.print(rtc.getDOWStr()); Serial.print(" "); // Send date Serial.print(rtc.getDateStr()); Serial.print(" -- "); // Send time Serial.println(rtc.getTimeStr()); // Wait one second before repeating :) delay (1000);}
思路讲解
1,#include <DS3231.h> //加载DS3231库
2,DS3231 rtc(SDA, SCL); //设置I2C
3,rtc.begin(); //建立RTC对象
4,
rtc.setDOW(WEDNESDAY); // 设置星期几,例如 SUNDAY
rtc.setTime(12, 0, 0); // 设置时间 12:00:00 (24小时制)
rtc.setDate(1, 1, 2014); // 设置日期 1月,1日 ,2014 年
如果在显示程序中,或不需要设置时间的时候,可以在前面加//给注释掉
5,
rtc.getDOWStr() 获取星期几
rtc.getDateStr() 获取日期
rtc.getTimeStr() 获取时间
- Arduino UNO DS3231高精度RTC芯片 制作时钟
- 树莓派添加RTC时钟模块DS3231
- RTC实时时钟芯片
- 树莓派使用上RTC实时时钟(DS3231,I2C接口)
- DIY一块DS3231的高精度时钟模块,让时钟DS3231/DS1302自动识别
- 实时时钟芯片DS3231应用笔记,使用指南,FAQ全集
- PCF8563/DS1302/DS1307/DS3231等常见时钟芯片驱动程序
- STM32F10x芯片RTC实时时钟
- Arduino 控制 DS1302 时钟芯片
- Arduino - Tiny RTC 12C 时钟模块
- nufront平台添加RTC时钟芯片ds1307
- rtc时钟芯片驱动(Linux驱动6)
- Arduino使用时钟模块(Tiny RTC i2C)
- rpi3 添加实时时钟DS3231
- 树莓派 加时钟模块DS3231
- arduino uno + nokia 5110
- 认识 Arduino UNO
- Arduino Uno 开发简介
- bootstrap-table复选框默认选中。(从数据库获取到对应的状态进行判断是否为选中状态)
- Android酷炫实用的开源框架(UI框架)
- 关于heapsize & heapgrowthlimit
- myeclipse安装SVN 插件
- der pem cer crt key pfx等概念及区别
- Arduino UNO DS3231高精度RTC芯片 制作时钟
- 拒绝无用功,封装一个通用的 PopupWindow
- springBoot service 事务注解@Transactional不起作用的解决
- Wkwebview sdf
- 关于PHP程序员技术职业生涯规划【转】
- JMeter参数化
- 小白新闻介绍
- jsonp跨域请求
- 不再以讹传讹,GET和POST的真正区别