[Diao Ye learns programming] Arduino hands-on (84) --- DS1307 clock module 3

insert image description here

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, in accordance with the concept of true knowledge (must be hands-on), for the purpose of learning and communication, here I am going to try and do more experiments one by one. Whether it is successful or not, it will be recorded ——Small progress or unsolvable problems, I hope to be able to throw bricks and spark jade.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 84: DS1307 clock module Tiny RTC I2C module 24C32 memory clock (with battery)

insert image description here

Experimental environment of DS1307 clock module
1. DS1307 clock module experiment hardware list
DS1307 clock module X1
TM1637 four-digit digital tube X1
Arduino Uno development board X1
DuPont lines (9 pieces are prepared)
IIC/I2C 1602 LCD LCD screen module X1
LED Light-emitting diode (blue, green) X2
Proto Shield prototype expansion board (with mini breadboard) X1

insert image description here
2. The software platform required for the sensor module experiment
code programming Arduino IDE (version 1.8.19)
simulation programming Linkboy (version V4.6.3)
graphics programming Mind+ (version V1.7.0 RC2.0)
and learning while editing (online platform https ://ide.codepku.com/?type=Arduino)

3. Download and install the DS1307 driver library
Open https://github.com/, search for "DS1307"

insert image description here
There are a lot of choices, you can try them all when you have time.

insert image description here
4. Experimental wiring diagram

insert image description here

6.8.3. Several experiments on the DS1307 clock module
Program 1: serial port output date and time
(1) Arduino reference open source code

/*
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  程序一:串口输出日期与时间
*/

#include <DFRobot_DS1307.h>

//构造函数
DFRobot_DS1307 DS1307;

void setup() {
    
    
  Serial.begin(115200);

  // 初始化传感器
  while ( !(DS1307.begin()) ) {
    
    
    Serial.println("与设备通讯失败,请检查连接");
    delay(3000);
  }
  Serial.println("好了,可以开始!");

  DS1307.setTypeTime(DS1307.eYR, 2000);

  Serial.print("获取类型时间: ");
  Serial.println(DS1307.getTypeTime(DS1307.eYR));

  //停止 RTC 定时器功能
  DS1307.stop();

  //手动设置时间参数
  uint16_t setTimeBuff[7] = {
    
    5, 50, 12, 7, 10, 4, 2022};
  DS1307.setTime(setTimeBuff);

  //启动RTC计时功能
  DS1307.start();

  //控制 SQW/OUT 引脚的操作
  DS1307.setSqwPinMode(DS1307.eSquareWave_1Hz);
}

void loop() {
    
    
  //获取 SQW/OUT 引脚的当前输出模式
  if (DS1307.eSquareWave_1Hz == DS1307.getSqwPinMode()) {
    
    
    Serial.print("SQW/OUT 引脚:1Hz | ");
  }

  uint16_t getTimeBuff[7] = {
    
    0};
  DS1307.getTime(getTimeBuff);
  char outputarr[128];
  sprintf(outputarr, "日期与时间: %d/%d/%d-%d %d:%d:%d\r\n",
          getTimeBuff[6],
          getTimeBuff[5],
          getTimeBuff[4],
          getTimeBuff[3],
          getTimeBuff[2],
          getTimeBuff[1],
          getTimeBuff[0]
         );
  Serial.print(outputarr);
  delay(1000);//延时1000毫秒
}

(2) The return status of the experimental serial port

insert image description here
(3) Experimental scene diagram

insert image description here
Program 2: DS1307 serial output date and time
(1) Experimental open source simulation programming (Linkboy V4.63)

insert image description here
(2) The return status of the experimental serial port

insert image description here

Program 3: DS1307 serial port output date and time 2
(1) Experimental open source graphics programming (Mind+, learning while editing)

insert image description here
(2) The return status of the experimental serial port

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/132353757