树莓派为了节约体积,并没有自带时钟模块,但是如果没有网络,那么所有基于时间的动作都会受到影响。
这时候,你需要一个小东西,某宝搜索“树莓派时钟模块”

如果不加它,断网情况下,开机的时间是上次关机的时间,基于这个时间继续走。


安装完毕,说说如何使用
1、开启I2C功能 ,网上介绍的都是命令行的,我说一下界面上操作


2、树莓派识别RTC模块
在root/config.txt文档末尾添加一行
dtoverlay=i2c-rtc,ds1307
3、date命令查看树莓派时间

4、使用命令hwclock操作RTC模块
sudo hwclock -h 查看帮助,参数都在里面了

hwclock -r #读取RTC模块时间
hwclock -s #将RTC模块时间同步到系统
hwclock -w #系统时间写入RTC模块
5、开机时将RTC模块时间同步到树莓派
修改 /etc/rc.local
$sudo nano /etc/rc.local
在 exit 0 前加入
hwclock -s
6、设置RTC模块时钟
hwclock --set --date "8/11/2019 23:10:45"
7、禁止树莓派自动联网校时
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd
8、树莓派时间与NTP 服务器同步
sudo apt-get install ntpdate
执行更新:sudo ntpdate cn.pool.ntp.org #cn.pool.ntp.org 是国内的ntp服务器
网友评论