Now, execute the following:
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -r -f /dev/rtc1
The quickest way to set the time on the BeagleBone Black is to execute the following:
/usr/bin/ntpdate -b -s -u pool.ntp.org
(note on recent Debian OS insatlls you might need to omit the /usr/bin/ part and just run 'ntpdate -b -s -u pool.ntp.org')
To validate the date and time were set correctly, execute:
date #or more comprehensively (the RTC value will be inaccurate, we haven't set it yet): timedatectl
hwclock -w -f /dev/rtc1
hwclock -r -f /dev/rtc1
mkdir /usr/share/rtc_ds1307 nano /usr/share/rtc_ds1307/clock_init.sh
#!/bin/bash sleep 15 echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device hwclock -s -f /dev/rtc1 hwclock -w
nano /lib/systemd/system/rtc-ds1307.service
[Unit] Description=DS1307 RTC Service [Service] Type=simple WorkingDirectory=/usr/share/rtc_ds1307 ExecStart=/bin/bash clock_init.sh SyslogIdentifier=rtc_ds1307 [Install] WantedBy=multi-user.target
systemctl enable rtc-ds1307.service
systemctl start rtc-ds1307.service systemctl stop rtc-ds1307.service
shutdown -r now
Ubuntu Upstart
If you are using Ubuntu and you'd like to have the RTC taken care of by 'upstart' here's some code to do that, place in /etc/init/rtc-ds1307.conf
# Ubuntu upstart file at /etc/init/rtc-ds1307.conf # Enables DS1307 RTC Breakout pre-start script mkdir -p /var/log/rtc-ds1307/ end script start on runlevel [2345] stop on runlevel [06] script exec /usr/share/rtc_ds1307/clock_init.sh >> /var/log/rtc-ds1307/rtc-ds1307.log end script