KE4041 3231时钟模块(定位孔) 黑色 环保

1.概述

本模块主要用到高精度时钟芯片DS3231。它是低成本、高精度I2C实时时钟(RTC),具有集成的温补晶振(TCXO)和晶体。该器件包含电池输入端,断开主电源时仍可保持精确的计时。集成晶振提高了器件的长期精确度,并减少了生产线的元件数量。DS3231提供商用级和工业级温度范围,采用16引脚300mil的SO封装。模块自带2个定位孔,方便你将模块固定在其他设备。

2.规格参数

工作电压:3.3-5V(DC)

电流:50MA

最大功率:0.25W

工作温度:-10摄氏度 到 +50摄氏度

尺寸:47.6MM *23.8MM

接口:4PIN接口

通信接口:IIC总线接口,最高传输速度400KHz(工作电压为5V时)

时钟精度:0-40℃范围内,精度2ppm,年误差约1分钟

3.接线图

QQ截图20211126102337

4.测试代码

#include <DS3231.h>

#include <Wire.h>

DS3231 clock;

bool century = false;

bool h12Flag;

bool pmFlag;

byte alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits;

bool alarmDy, alarmH12Flag, alarmPmFlag;

void setup() {

// Start the I2C interface

Wire.begin();

// Start the serial interface

Serial.begin(57600);

}

void loop() {

// send what’s going on to the serial monitor.

// Start with the year

Serial.print(“2”);

if (century) { // Won’t need this for 89 years.

Serial.print(“1”);

} else {

Serial.print(“0”);

}

Serial.print(clock.getYear(), DEC);

Serial.print(‘ ‘);

// then the month

Serial.print(clock.getMonth(century), DEC);

Serial.print(” “);

// then the date

Serial.print(clock.getDate(), DEC);

Serial.print(” “);

// and the day of the week

Serial.print(clock.getDoW(), DEC);

Serial.print(” “);

// Finally the hour, minute, and second

Serial.print(clock.getHour(h12Flag, pmFlag), DEC);

Serial.print(” “);

Serial.print(clock.getMinute(), DEC);

Serial.print(” “);

Serial.print(clock.getSecond(), DEC);

// Add AM/PM indicator

if (h12Flag) {

if (pmFlag) {

Serial.print(” PM “);

} else {

Serial.print(” AM “);

}

} else {

Serial.print(” 24h “);

}

// Display the temperature

Serial.print(“T=”);

Serial.print(clock.getTemperature(), 2);

// Tell whether the time is (likely to be) valid

if (clock.oscillatorCheck()) {

Serial.print(” O+”);

} else {

Serial.print(” O-“);

}

// Indicate whether an alarm went off

if (clock.checkIfAlarm(1)) {

Serial.print(” A1!”);

}

if (clock.checkIfAlarm(2)) {

Serial.print(” A2!”);

}

// New line on display

Serial.println();

// Display Alarm 1 information

Serial.print(“Alarm 1: “);

clock.getA1Time(alarmDay, alarmHour, alarmMinute, alarmSecond, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);

Serial.print(alarmDay, DEC);

if (alarmDy) {

Serial.print(” DoW”);

} else {

Serial.print(” Date”);

}

Serial.print(‘ ‘);

Serial.print(alarmHour, DEC);

Serial.print(‘ ‘);

Serial.print(alarmMinute, DEC);

Serial.print(‘ ‘);

Serial.print(alarmSecond, DEC);

Serial.print(‘ ‘);

if (alarmH12Flag) {

if (alarmPmFlag) {

Serial.print(“pm “);

} else {

Serial.print(“am “);

}

}

if (clock.checkAlarmEnabled(1)) {

Serial.print(“enabled”);

}

Serial.println();

// Display Alarm 2 information

Serial.print(“Alarm 2: “);

clock.getA2Time(alarmDay, alarmHour, alarmMinute, alarmBits, alarmDy, alarmH12Flag, alarmPmFlag);

Serial.print(alarmDay, DEC);

if (alarmDy) {

Serial.print(” DoW”);

} else {

Serial.print(” Date”);

}

Serial.print(” “);

Serial.print(alarmHour, DEC);

Serial.print(” “);

Serial.print(alarmMinute, DEC);

Serial.print(” “);

if (alarmH12Flag) {

if (alarmPmFlag) {

Serial.print(“pm”);

} else {

Serial.print(“am”);

}

}

if (clock.checkAlarmEnabled(2)) {

Serial.print(“enabled”);

}

// display alarm bits

Serial.println();

Serial.print(“Alarm bits: “);

Serial.println(alarmBits, BIN);

Serial.println();

delay(1000);

}

5.测试结果

先我们需要先加载ds3231的库,加载完成后上传代码。上传代码完成后上代开串口监视器,设置波特率为57600,我们将看到DS3231检测到的日期、时间、温度、闹钟等等相关信息。

6.资料下载链接

Arduino IDE/Mixly/Scratch/pyhon编程使用资料下载链接

链接:https://pan.baidu.com/s/1TZRg8_eSaEcbYPmJ1667GA
提取码:keye