树莓派4b——设置DS3231模块 并从DS3231模块读取系统时间


  网上有蛮多关于ds3231模块用法的介绍,但是我在树莓派4B上测试的时候,基本上都用不了。折腾了四五个小时,下面分享下自己探索出来的方法。

主要功能:将DS3231设置成为树莓派的系统时钟,树莓派不联网的情况下,可以自动从DS3231获取系统时间。

1. 驱动下载及安装

下载DS3231模块的驱动

git clone https://github.com/Seeed-Studio/pi-hats.git
cd pi-hats/CAN-HAT

安装驱动

sudo ./install.sh -u rtc_ds3231

重启电脑

sudo shutdown -h now

在这里插入图片描述

2. 设置时间

将时间设置为 2020年 10月1日 20点35分

date 100120352020.00     备注:10120352020

3. 时间测试

date

4. 其他功能

读取硬件时钟并打印结果

sudo hwclock -r

通过硬件时钟设置系统时间

sudo hwclock -s

从当前系统时间设置硬件时钟

sudo hwclock -w

访问帮助以获得更多用途

hwclock --help

参考

  • https://www.seeedstudio.com/blog/2020/07/07/raspberry-pi-rtc-tutorial-using-ds1307-and-ds3231-rtcs-with-raspberry-pi-m/

  • https://shumeipai.nxez.com/2019/05/08/raspberry-pi-configuration-of-ds3231-clock-module-i2c-interface.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值